diff options
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/MoveTable.cpp | 8 | ||||
| -rw-r--r-- | src/components/MoveTable.hpp | 3 | ||||
| -rw-r--r-- | src/components/Scrollbar.cpp | 36 | ||||
| -rw-r--r-- | src/components/Scrollbar.hpp | 2 |
4 files changed, 49 insertions, 0 deletions
diff --git a/src/components/MoveTable.cpp b/src/components/MoveTable.cpp index 4878275..88767b1 100644 --- a/src/components/MoveTable.cpp +++ b/src/components/MoveTable.cpp @@ -69,6 +69,9 @@ std::uint32_t MoveTable::UpdateMoves(CMI::HalfMove *m, std::uint32_t line, move_bound.text = m->GetSAN(); move_bound.ShouldApplyScroll = true; bool isMouseOver = IsMouseOver(move_bound); + // Save in cache: + MovesStates[m].Bound=move_bound; + MovesStates[m].Line=line; //---------- Update current focus move ---------- if (isMouseOver) { @@ -346,4 +349,9 @@ std::uint32_t MoveTable::DrawVariations(CMI::HalfMove *m, std::uint32_t line, } return (line); } + +void MoveTable::GetMoveXY(CMI::HalfMove* m, double &X, double &Y){ + X=MovesStates.at(m).Bound.x; + Y=MovesStates.at(m).Bound.y; +} } // namespace cgeditor
\ No newline at end of file diff --git a/src/components/MoveTable.hpp b/src/components/MoveTable.hpp index 1b6323e..3a50a8d 100644 --- a/src/components/MoveTable.hpp +++ b/src/components/MoveTable.hpp @@ -50,6 +50,8 @@ class MoveTable : public Component { typedef struct MoveState { bool IsFolded=false; bool IsHidden=false; + int Line=0; + Element Bound; } MoveState; std::uint32_t UpdateMoves(CMI::HalfMove *, std::uint32_t, std::uint32_t,bool only_black); std::int32_t CurrentMove; @@ -66,5 +68,6 @@ public: void Refresh(); std::vector<Element> GetVariationsMarging() { return (VariationMargins); } void SyncCache(); + void GetMoveXY(CMI::HalfMove* m, double &X, double &Y); }; } // namespace cgeditor
\ No newline at end of file diff --git a/src/components/Scrollbar.cpp b/src/components/Scrollbar.cpp index 76c5c1a..ac713e9 100644 --- a/src/components/Scrollbar.cpp +++ b/src/components/Scrollbar.cpp @@ -109,4 +109,40 @@ void Scrollbar::Refresh() { elements.push_back(bar); } +void Scrollbar::Focus(double XorY){ + double MTCanvasHeight = status->CanvasHeight - status->ScrollbarWidth; + double MTCanvasWidth = status->CanvasWidth - status->ScrollbarWidth; + // Check horizontal or vertical and if should scroll + if(IsHorizontal && status->MoveTableMaxX > MTCanvasWidth){ + // First normalize: + XorY-=MTCanvasWidth; // Do not scroll on first page + XorY=std::max(0.0,XorY); // Ensure focus is greater than 0 + XorY=std::min(XorY,(status->MoveTableMaxX-MTCanvasWidth)); // Ensure focus is than scroll max + // Then compute percent and apply scroll + double percent = XorY / (status->MoveTableMaxX-MTCanvasWidth); + status->ScrollX = + -(status->MoveTableMaxX - MTCanvasWidth) * percent; + // Do not forget to update scrollbar: + double maxScroll = bg.width - bar.width; + bar.x = maxScroll * percent; + bar.x = std::max(bg.x, bar.x); + bar.x = std::min(bg.x + maxScroll, bar.x); + } + else if(status->MoveTableMaxY > MTCanvasHeight){ + // First normalize: + XorY-=MTCanvasHeight; // Do not scroll on first page + XorY=std::max(0.0,XorY); // Ensure focus is greater than 0 + XorY=std::min(XorY,(status->MoveTableMaxY-MTCanvasHeight)); // Ensure focus is than scroll max + // Then compute percent and apply scroll + double percent = XorY / (status->MoveTableMaxY-MTCanvasHeight); + status->ScrollY = + -(status->MoveTableMaxY - MTCanvasHeight) * percent; + // Do not forget to update scrollbar: + double maxScroll = bg.height - bar.height; + bar.y = maxScroll * percent; + bar.y = std::max(bg.y, bar.y); + bar.y = std::min(bg.y + maxScroll, bar.y); + } +} + } // namespace cgeditor
\ No newline at end of file diff --git a/src/components/Scrollbar.hpp b/src/components/Scrollbar.hpp index 3ed97ae..fa49eca 100644 --- a/src/components/Scrollbar.hpp +++ b/src/components/Scrollbar.hpp @@ -12,5 +12,7 @@ class Scrollbar : public Component { public: Scrollbar(Status* s,bool IsHorizontal); void Refresh(); + /// @brief Goto a given graphical coordinate (if possible using current scroll range) + void Focus(double XorY); }; } // namespace cgeditor
\ No newline at end of file |
