Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a crash and clean up YACReaderFlowGL #198

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 22 additions & 46 deletions common/gl/yacreader_flow_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,10 @@ bool YACReaderFlowGL::animate(YACReader3DVector &currentVector, YACReader3DVecto

return false;
}
void YACReaderFlowGL::drawCover(const YACReader3DImage &image)
void YACReaderFlowGL::drawCover(int index)
{
const YACReader3DImage &image = images[index];

float w = image.width;
float h = image.height;

Expand Down Expand Up @@ -507,9 +509,9 @@ void YACReaderFlowGL::drawCover(const YACReader3DImage &image)
glEnd();
glDisable(GL_TEXTURE_2D);

if (showMarks && loaded[image.index] && marks[image.index] != Unread) {
if (showMarks && loaded[index] && marks[index] != Unread) {
glEnable(GL_TEXTURE_2D);
if (marks[image.index] == Read)
if (marks[index] == Read)
markTexture->bind();
else
readingTexture->bind();
Expand Down Expand Up @@ -551,25 +553,15 @@ void YACReaderFlowGL::cleanupAnimation()

void YACReaderFlowGL::draw()
{
int CS = currentSelected;
int count;

const int CS = currentSelected;
//Draw right Covers
for (count = numObjects - 1; count > -1; count--) {
if (count > CS) {
drawCover(images[count]);
}
}

for (int i = numObjects - 1; i > CS; --i)
drawCover(i);
//Draw left Covers
for (count = 0; count < numObjects - 1; count++) {
if (count < CS) {
drawCover(images[count]);
}
}

for (int i = 0; i < CS; ++i)
drawCover(i);
//Draw Center Cover
drawCover(images[CS]);
drawCover(CS);
}

void YACReaderFlowGL::showPrevious()
Expand Down Expand Up @@ -673,26 +665,23 @@ void YACReaderFlowGL::updatePositions()
stopAnimationTimer();
}

void YACReaderFlowGL::insert(char *name, QOpenGLTexture *texture, float x, float y, int item)
void YACReaderFlowGL::insert(const char *name, QOpenGLTexture *texture, float x, float y)
{
startAnimationTimer();

Q_UNUSED(name)
//set a new entry
if (item == -1) {
images.push_back(YACReader3DImage());

item = numObjects;
numObjects++;
images.push_back(YACReader3DImage());

calcVector(images[item].current, item);
images[item].current.z = images[item].current.z - 1;
}
const auto item = numObjects;
numObjects++;

calcVector(images[item].current, item);
images[item].current.z = images[item].current.z - 1;

images[item].texture = texture;
images[item].width = x;
images[item].height = y;
images[item].index = item;
//strcpy(cfImages[item].name,name);
}

Expand All @@ -712,14 +701,7 @@ void YACReaderFlowGL::remove(int item)
}

QOpenGLTexture *texture = images[item].texture;

int count = item;
while (count <= numObjects - 2) {
images[count].index--;
count++;
}
images.removeAt(item);

if (texture != defaultTexture)
delete (texture);

Expand All @@ -737,13 +719,10 @@ void YACReaderFlowGL::replace(char *name, QOpenGLTexture *texture, float x, floa
startAnimationTimer();

Q_UNUSED(name)
if (images[item].index == item) {
images[item].texture = texture;
images[item].width = x;
images[item].height = y;
loaded[item] = true;
} else
loaded[item] = false;
images[item].texture = texture;
images[item].width = x;
images[item].height = y;
loaded[item] = true;
}

void YACReaderFlowGL::populate(int n)
Expand Down Expand Up @@ -1246,13 +1225,11 @@ void YACReaderComicFlowGL::resortCovers(QList<int> newOrder)
QVector<YACReaderComicReadStatus> marksNew;
QVector<YACReader3DImage> imagesNew;

int index = 0;
foreach (int i, newOrder) {
pathsNew << paths.at(i);
loadedNew << loaded.at(i);
marksNew << marks.at(i);
imagesNew << images.at(i);
imagesNew.last().index = index++;
}

paths = pathsNew;
Expand Down Expand Up @@ -1326,7 +1303,6 @@ void YACReaderPageFlowGL::updateImageData()
float y = 1 * (float(img.height()) / img.width());
QString s = "cover";
replace(s.toLocal8Bit().data(), texture, x, y, idx);
loaded[idx] = true;
}
}

Expand Down
8 changes: 2 additions & 6 deletions common/gl/yacreader_flow_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ struct YACReader3DImage {
float width;
float height;

int index;

YACReader3DVector current;
YACReader3DVector animEnd;
};
Expand Down Expand Up @@ -112,7 +110,7 @@ class YACReaderFlowGL : public QOpenGLWidget, public ScrollManagement
void calcVector(YACReader3DVector &vector, int pos);
//returns true if the animation is finished for Current
bool animate(YACReader3DVector &currentVector, YACReader3DVector &toVector);
void drawCover(const YACReader3DImage &image);
void drawCover(int index);

void udpatePerspective(int width, int height);

Expand Down Expand Up @@ -194,9 +192,7 @@ class YACReaderFlowGL : public QOpenGLWidget, public ScrollManagement
//updates the coverflow
void updatePositions();
//inserts a new item to the coverflow
//if item is set to a value > -1 it updates a already set value
//otherwise a new entry is set
void insert(char *name, QOpenGLTexture *texture, float x, float y, int item = -1);
void insert(const char *name, QOpenGLTexture *texture, float x, float y);
//removes a item
virtual void remove(int item);
//replaces the texture of the item 'item' with Tex
Expand Down