aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CGEditor.cpp8
-rw-r--r--src/CGEditor.hpp2
-rw-r--r--src/components/MoveTable.cpp8
-rw-r--r--src/components/MoveTable.hpp3
-rw-r--r--src/components/Scrollbar.cpp36
-rw-r--r--src/components/Scrollbar.hpp2
6 files changed, 58 insertions, 1 deletions
diff --git a/src/CGEditor.cpp b/src/CGEditor.cpp
index fadbdc8..cf405db 100644
--- a/src/CGEditor.cpp
+++ b/src/CGEditor.cpp
@@ -1,5 +1,5 @@
#include "CGEditor.hpp"
-#include <iostream>
+
namespace cgeditor {
CGEditor::CGEditor() {
@@ -180,4 +180,10 @@ std::uint8_t CGEditor::GetNAGId(const std::string& symbol) const{
return 0;
}
+void CGEditor::FocusOnMove(CMI::HalfMove* move){
+ double X,Y;
+ MT->GetMoveXY(move,X,Y);
+ SBH->Focus(X+status.MoveWidth);
+ SBV->Focus(Y+status.MoveHeight);
+}
} // namespace cgeditor
diff --git a/src/CGEditor.hpp b/src/CGEditor.hpp
index e8b5286..72c2785 100644
--- a/src/CGEditor.hpp
+++ b/src/CGEditor.hpp
@@ -40,5 +40,7 @@ public:
std::string GetNAGSymbol(const std::uint8_t) const;
/// @brief Convert NAG symbol to id using the NagTable
std::uint8_t GetNAGId(const std::string&) const;
+ /// @brief Try to scroll to focus on a given move
+ void FocusOnMove(CMI::HalfMove*);
};
} // namespace cgeditor \ No newline at end of file
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