Commit c823df22 authored by Loic Guegan's avatar Loic Guegan
Browse files

Debug scroll

parent ebb5abf8
Pipeline #219400274 passed with stage
in 8 minutes and 56 seconds
......@@ -37,9 +37,9 @@ void PGNEditor::Render(State *state) {
}
void PGNEditor::DrawHintBar() {
Shape hintBar(0, -state->offsetY, state->hintBarWidth, canvasH);
Shape hintBar(state->offsetX, 0, state->hintBarWidth, canvasH);
hintBar.target = Shape::HINTBAR;
DrawCall(hintBar);
Draw(hintBar); // Do not issues a DrawCall here (MaxY will change);
}
void PGNEditor::DrawScrollBars() {
......@@ -63,31 +63,45 @@ void PGNEditor::DrawScrollBars() {
Shape HS(-state->offsetX, canvasH, HSSize, state->scrollbarThickness);
HS.target = Shape::SCROLLBAR_H;
Shape VS(canvasW, -state->offsetY, state->scrollbarThickness, VSSize);
VS.target = Shape::SCROLLBAR_V;
if(state->IsDragging){
if(LastMouseClickOnHS){
state->offsetX-=(state->mouseX-LastMouseClickX);
CurrentHSX+=(state->mouseX-LastMouseClickX);
LastMouseClickX=state->mouseX;
state->offsetX=-std::min(std::max(0,-state->offsetX),state->canvasW);
if(std::abs(state->offsetX)>=(canvasW-HSSize))
state->offsetX=-(canvasW-HSSize);
else if(state->offsetX>=0)
state->offsetX=0;
if(CurrentHSX<=0)
CurrentHSX=0;
else if(CurrentHSX>=(canvasW-HSSize))
CurrentHSX=(canvasW-HSSize);
double percent=0;
if((canvasW-HSSize)>0)
percent=CurrentHSX/(canvasW-HSSize);
int maxOffset=(MaxX-MinX)-canvasW;
state->offsetX=-(double)maxOffset*percent;
}
if(LastMouseClickOnVS){
state->offsetY-=(state->mouseY-LastMouseClickY);
CurrentVSY+=(state->mouseY-LastMouseClickY);
LastMouseClickY=state->mouseY;
if(std::abs(state->offsetY)>=(canvasH-VSSize))
state->offsetY=-(canvasH-VSSize);
else if(state->offsetY>=0)
state->offsetY=0;
if(CurrentVSY<=0)
CurrentVSY=0;
else if(CurrentVSY>=(canvasH-VSSize))
CurrentVSY=(canvasH-VSSize);
double percent=0;
if((canvasH-VSSize)>0)
percent=CurrentVSY/(canvasH-VSSize);
int maxOffset=std::max((MaxY-MinY)-canvasH,0);
state->offsetY=-(double)maxOffset*percent;
}
}
//std::cout << "MaxY:" << MaxY << " MinY " << MinY << " Diff:"<< MaxY-MinY << std::endl << std::flush;
Shape HS(CurrentHSX, canvasH, HSSize, state->scrollbarThickness);
HS.target = Shape::SCROLLBAR_H;
Shape VS(canvasW,CurrentVSY, state->scrollbarThickness, VSSize);
VS.target = Shape::SCROLLBAR_V;
// Check mouse over
if (HS.x <= state->mouseX && HS.y <= state->mouseY
......@@ -207,10 +221,10 @@ void PGNEditor::DrawCall(Shape shape) {
int maxX = shape.x + width;
int maxY = shape.y + height;
if (maxX > MaxX)
MaxX = maxX;
if (maxY > MaxY)
MaxY = maxY;
if ((maxX+ state->extraCanvasMargin) > MaxX)
MaxX = (maxX+ state->extraCanvasMargin);
if ((maxY+ state->extraCanvasMargin) > MaxY)
MaxY = (maxY+ state->extraCanvasMargin);
if (shape.x < MinX)
MinX = shape.x;
if (shape.y < MinY)
......
......@@ -30,6 +30,7 @@ private:
bool LastMouseClickOnHS;
bool LastMouseClickOnVS;
int CurrentVSY;
int CurrentHSX;
/// @brief Used by scrollbars
int MaxX,MinX;
......@@ -46,7 +47,7 @@ protected:
void Render(State *state);
virtual void Draw(Shape shape) = 0;
public:
PGNEditor():LastMouseClickOnHS(false),LastMouseClickOnVS(false){
PGNEditor():LastMouseClickOnHS(false),LastMouseClickOnVS(false),CurrentVSY(0),CurrentHSX(0){
}
};
......
......@@ -35,6 +35,7 @@ public:
/// @brief Size of the move counter column
int counterW;
int varationSepW;
int extraCanvasMargin;
State(){
moveline=nullptr;
......@@ -57,6 +58,7 @@ public:
varationSepW=5;
MouseClick=false;
IsDragging=false;
extraCanvasMargin=50;
}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment