aboutsummaryrefslogtreecommitdiff
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
parentf1f638100f4bcd88b31c3412e961dbbb5e12ad0a (diff)
Update
-rw-r--r--examples/wxWidgets/MyHalfMove.cpp8
-rw-r--r--examples/wxWidgets/main.cpp7
-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
7 files changed, 62 insertions, 51 deletions
diff --git a/examples/wxWidgets/MyHalfMove.cpp b/examples/wxWidgets/MyHalfMove.cpp
index c1d1ab3..0e08113 100644
--- a/examples/wxWidgets/MyHalfMove.cpp
+++ b/examples/wxWidgets/MyHalfMove.cpp
@@ -128,7 +128,7 @@ MyHalfMove *BuildExampleGame() {
m2 = new MyHalfMove("Bc4");
m->SetMainline(m2);
- m->SetComment("Italian Opening");
+ m->comment="Italian Opening";
m = m2;
m2 = new MyHalfMove("Bc5");
@@ -136,7 +136,7 @@ MyHalfMove *BuildExampleGame() {
m = m2;
m2 = new MyHalfMove("c3");
- m2->SetComment("Giuoco Pianissimo");
+ m2->comment="Giuoco Pianissimo";
m->SetMainline(m2);
m = m2;
@@ -158,7 +158,7 @@ MyHalfMove *BuildExampleGame() {
{
MyHalfMove *var = new MyHalfMove("Re1");
- var->SetComment("Also possible");
+ var->comment="Also possible";
m->AddVariation(var);
MyHalfMove *var2 = new MyHalfMove("a6");
@@ -185,6 +185,8 @@ MyHalfMove *BuildExampleGame() {
m2 = new MyHalfMove("a6");
m->SetMainline(m2);
+ m->comment="Test for a very long comment, to see how line breaks are handle by the framework.";
+ m->comment+="Test for a very long comment, to see how line breaks are handle by the framework.";
m = m2;
m2 = new MyHalfMove("Bb3");
diff --git a/examples/wxWidgets/main.cpp b/examples/wxWidgets/main.cpp
index 99e8839..6a9cf6c 100644
--- a/examples/wxWidgets/main.cpp
+++ b/examples/wxWidgets/main.cpp
@@ -29,6 +29,9 @@ private:
void OnPaint(wxPaintEvent &event) {
wxPaintDC current_dc(this);
dc = &current_dc;
+ wxSize fontsize=dc->GetTextExtent("a");
+
+ wxLogDebug("width=%d, height=%d",fontsize.x,fontsize.y);
// Refresh canvas size
wxSize sz = GetClientSize();
@@ -105,6 +108,8 @@ private:
dc->SetBrush(*wxLIGHT_GREY_BRUSH);
} else if (e.prop & cgeditor::Property::Button) {
dc->SetBrush(*wxBLACK_BRUSH);
+ } else if (e.prop & cgeditor::Property::Comment) {
+ dc->SetBrush(*wxYELLOW_BRUSH);
}
wxRect recToDraw(e.x, e.y, e.width, e.height);
dc->DrawRectangle(recToDraw);
@@ -118,7 +123,7 @@ private:
dc->DrawText(wxString(e.text), Middle(e));
} else if (e.prop & cgeditor::Property::Comment) {
wxRect recToDraw(e.x, e.y, e.width, e.height);
- dc->SetBrush(*wxYELLOW_BRUSH);
+ dc->SetBrush(*wxBLUE_BRUSH);
dc->DrawRectangle(recToDraw);
dc->DrawText(wxString(e.text), wxPoint(e.x, e.y));
} else if (e.prop & cgeditor::Property::Menuitem) {
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--;