aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-12-31 09:40:39 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-12-31 09:40:39 +0100
commit2bb6730df8094c89af5a07d394fc02c43aea24eb (patch)
treeb531e2027961db3b15ccf649d6e015d62e8a392f /src
parentf1f638100f4bcd88b31c3412e961dbbb5e12ad0a (diff)
Update
Diffstat (limited to 'src')
-rw-r--r--src/CGEHalfMove.cpp20
-rw-r--r--src/CGEHalfMove.hpp12
-rw-r--r--src/CGEditor.cpp3
-rw-r--r--src/Types.hpp3
-rw-r--r--src/components/MoveTable.cpp60
5 files changed, 51 insertions, 47 deletions
diff --git a/src/CGEHalfMove.cpp b/src/CGEHalfMove.cpp
index 669b568..4deb57b 100644
--- a/src/CGEHalfMove.cpp
+++ b/src/CGEHalfMove.cpp
@@ -23,26 +23,6 @@ CGEHalfMove::CGEHalfMove(std::string move)
this->move = move;
}
-void CGEHalfMove::SetComment(const std::string &c) {
- if (c.size() > 0) {
- NbLineComment = 1;
- for (const char &c : c) {
- if (c == '\n') {
- NbLineComment++;
- }
- }
- this->comment = c;
- }
- else {
- this->comment="";
- NbLineComment=0;
- }
-}
-
-std::string CGEHalfMove::GetComment() { return (comment); }
-
-std::uint16_t CGEHalfMove::GetNbLineComment() { return (this->NbLineComment); }
-
void CGEHalfMove::RemoveChild(CGEHalfMove *m) {
std::uint32_t i = 0;
bool found = false;
diff --git a/src/CGEHalfMove.hpp b/src/CGEHalfMove.hpp
index abef708..28f6c34 100644
--- a/src/CGEHalfMove.hpp
+++ b/src/CGEHalfMove.hpp
@@ -10,10 +10,6 @@ namespace cgeditor {
*
*/
class CGEHalfMove {
- /// @brief Comment linked to the move
- std::string comment;
- /// @brief Number of line in @a comment
- std::uint16_t NbLineComment = 0;
public:
CGEHalfMove();
@@ -26,6 +22,8 @@ public:
std::string move;
/// @brief Current NAG
std::string nag;
+ /// @brief Comment linked to the move
+ std::string comment;
CGEHalfMove *MainLine;
CGEHalfMove *Parent;
@@ -37,12 +35,6 @@ public:
/// @brief Variations of the move
std::vector<CGEHalfMove *> variations;
- /// @brief Set comment and update number of lines
- void SetComment(const std::string &c);
- /// @brief Get current value of comment
- std::string GetComment();
- /// @brief Get number of lines in comment
- std::uint16_t GetNbLineComment();
/// @brief Remove a move from the MainLine and/or variations
void RemoveChild(CGEHalfMove *m);
};
diff --git a/src/CGEditor.cpp b/src/CGEditor.cpp
index fc7c567..1d5eaea 100644
--- a/src/CGEditor.cpp
+++ b/src/CGEditor.cpp
@@ -77,7 +77,8 @@ void CGEditor::CallDrawElement(Element e) {
e.y += status.ScrollY;
}
}
-
+ DrawElement(e);
+return;
// Check if element is visible
if (((e.x) >= 0 && ((e.x) <= status.CanvasWidth) && (e.y) >= 0 &&
((e.y) <= status.CanvasHeight)) ||
diff --git a/src/Types.hpp b/src/Types.hpp
index 7f54d0a..5d24115 100644
--- a/src/Types.hpp
+++ b/src/Types.hpp
@@ -73,6 +73,9 @@ typedef struct Status {
double NagRightMargin = 0;
double MarginBarWidth = 50;
double ScrollbarWidth = 30;
+ double TextCharWidth=14, TextCharHeight=24;
+ /// @brief How many char per line for comments
+ std::uint16_t CharPerLine=100;
double MoveIconWidth = 25;
std::uint16_t CommentLinePerRow = 2;
/// @brief Ask the editor to scroll for a specific amout of pixels
diff --git a/src/components/MoveTable.cpp b/src/components/MoveTable.cpp
index 9e8ee38..c3cbcbf 100644
--- a/src/components/MoveTable.cpp
+++ b/src/components/MoveTable.cpp
@@ -1,4 +1,5 @@
#include "MoveTable.hpp"
+#include <iostream>
namespace cgeditor {
@@ -175,7 +176,7 @@ std::uint32_t MoveTable::UpdateMoves(CGEHalfMove *m, std::uint32_t line,
}
//---------- Comments ----------
- if (m->GetNbLineComment() > 0) {
+ if (m->comment.size() > 0) {
line = DrawComment(m, line, indent, move_bound, indent_black);
}
@@ -187,7 +188,7 @@ std::uint32_t MoveTable::UpdateMoves(CGEHalfMove *m, std::uint32_t line,
//---------- Mainline ----------
if (m->MainLine != NULL) {
only_black = (m->MainLine->IsBlack &&
- (m->GetNbLineComment() > 0 || m->variations.size()));
+ (m->comment.size() > 0 || m->variations.size()));
if (m->IsBlack) {
line = UpdateMoves(m->MainLine, line + 1, indent, only_black);
} else {
@@ -210,32 +211,59 @@ std::uint32_t MoveTable::DrawComment(CGEHalfMove *m, std::uint32_t line,
}
// Print comment
line++;
- // Computer number of rows for the comment
- std::uint16_t CommentRows = m->GetNbLineComment() / status->CommentLinePerRow;
- if (m->GetNbLineComment() % status->CommentLinePerRow > 0) {
- CommentRows++;
- }
- // Draw comment
+
+
+ /// ----- Compute comment bounding box values
+ int nchar=m->comment.size();
+ int nline=ceil((double)nchar/(double)status->CharPerLine);
+ std::uint16_t nrow=ceil((nline*status->TextCharHeight)/status->MoveHeight);
+ std::cout << nrow <<std::endl;
+ int width=status->CharPerLine*status->TextCharWidth;
+ int height=nrow*status->MoveHeight;
+
+ // Draw comment background
Element e;
- e.prop = Property::Text | Property::Comment;
+ e.prop = Property::Rectangle | Property::Comment;
e.x = move_bound.x -
(indent_black *
status->MoveWidth); // status->MarginBarWidth + status->MoveX;
e.y = status->MoveHeight * line;
e.width = -1; // Negative width means expands to the edge of the canvas
- e.height = CommentRows * status->MoveHeight;
- e.text = m->GetComment();
+ e.height = height;
e.ShouldApplyScroll = true;
elements.push_back(e);
- // Do not forget to add marging before comment
- if (indent > 0) {
- e.x -= status->MarginBarWidth;
- VariationMargins.push_back(e);
+ // Update scrolling
+ if ((e.x + width) > status->MoveTableMaxX) {
+ status->MoveTableMaxX = e.x + width;
}
+ if ((e.y + height) > status->MoveTableMaxY) {
+ status->MoveTableMaxY = e.y + height;
+ }
+ // Handle events:
if (status->LeftClick && IsMouseOver(e)) {
status->Events.push_back({Event::Type::CommentSelected, m});
}
- line += CommentRows; // Skip right amount of lines
+ // Now draw each lines of the comment:
+ Element l;
+ l.prop = Property::Comment|Property::Text;
+ l.x=e.x;
+ l.y=e.y;
+ std::cout <<"x=" << l.x << " y="<<l.y<< " width="<<width<<std::endl;
+ l.width=width;
+ l.height=status->MoveHeight;
+ l.ShouldApplyScroll = true;
+ for(int i=0;i<nline;i++){
+ std::cout << "BAM!" << std::endl;
+ l.text=m->comment.substr(i*status->CharPerLine,status->CharPerLine);
+ elements.push_back(l);
+ l.y+=status->TextCharHeight;
+ }
+ // Do not forget to add marging before comment if indented:
+ if (indent > 0) {
+ e.x -= status->MarginBarWidth;
+ VariationMargins.push_back(e);
+ }
+ line += nrow; // Skip right amount of lines
// Since we already increment line for black later on:
if (m->IsBlack || m->variations.size() > 0) {
line--;