aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-12-31 11:47:56 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-12-31 11:47:56 +0100
commit144a3ddfb55fbf17cec4baaa73542664d68a3b05 (patch)
tree43add38a2cd05d52349a6561bd4d9ed8df94f862
parent2bb6730df8094c89af5a07d394fc02c43aea24eb (diff)
Debug comments$
-rw-r--r--examples/wxWidgets/main.cpp5
-rw-r--r--src/CGEditor.cpp25
-rw-r--r--src/Types.cpp8
-rw-r--r--src/Types.hpp8
-rw-r--r--src/components/MoveTable.cpp29
5 files changed, 39 insertions, 36 deletions
diff --git a/examples/wxWidgets/main.cpp b/examples/wxWidgets/main.cpp
index 6a9cf6c..35a3100 100644
--- a/examples/wxWidgets/main.cpp
+++ b/examples/wxWidgets/main.cpp
@@ -29,9 +29,10 @@ 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);
+ // Just in case you want to fetch font sizes to configure comment text:
+ //wxSize fontsize=dc->GetTextExtent("a");
+ //wxLogDebug("width=%d, height=%d",fontsize.x,fontsize.y);
// Refresh canvas size
wxSize sz = GetClientSize();
diff --git a/src/CGEditor.cpp b/src/CGEditor.cpp
index 1d5eaea..4edf95e 100644
--- a/src/CGEditor.cpp
+++ b/src/CGEditor.cpp
@@ -1,5 +1,5 @@
#include "CGEditor.hpp"
-
+#include <iostream>
namespace cgeditor {
CGEditor::CGEditor() {
@@ -77,18 +77,19 @@ 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)) ||
- ((e.x + e.width) >= 0 && ((e.x + e.width) <= status.CanvasWidth) &&
- (e.y + e.height) >= 0 && ((e.y + e.height) <= status.CanvasHeight))) {
- if (e.IsOver(status.MouseX, status.MouseY)) {
- e.prop |= Property::Mouseover;
- }
- DrawElement(e);
+
+ // Check if element visible if not just leave
+ if((e.x+e.width)<0 || status.CanvasWidth < e.x)
+ return;
+ if((e.y+e.height)<0 || status.CanvasHeight < e.y)
+ return;
+
+ // Check if mouse over
+ if (e.IsOver(status.MouseX, status.MouseY)) {
+ e.prop |= Property::Mouseover;
}
+
+ DrawElement(e);
}
void CGEditor::DrawComponent(Component *c) {
diff --git a/src/Types.cpp b/src/Types.cpp
index 76bf398..accc99c 100644
--- a/src/Types.cpp
+++ b/src/Types.cpp
@@ -3,10 +3,10 @@
namespace cgeditor {
bool Element::IsOver(const double &X, const double &Y) const {
- if (width < 0) {
- return (x >= x && Y >= y && Y <= (y + height));
- }
- return ((X >= x && X <= (x + width) && Y >= y && Y <= (y + height)));
+ // Check if no overlap
+ if(X<x|| X>(x+width) || Y<y || Y>(y+height))
+ return false;
+ return true;
}
Property operator|(Property lhs, Property rhs) {
diff --git a/src/Types.hpp b/src/Types.hpp
index 5d24115..8c03ff0 100644
--- a/src/Types.hpp
+++ b/src/Types.hpp
@@ -73,11 +73,13 @@ typedef struct Status {
double NagRightMargin = 0;
double MarginBarWidth = 50;
double ScrollbarWidth = 30;
- double TextCharWidth=14, TextCharHeight=24;
+ /// @brief The following is not very accuracy but at least work for computing comments bounding boxes and placement
+ double CommentCharWidth=9, CommentCharHeight=24;
+ /// @brief The following is not a "precise" padding since we add online a multiple of MoveHeight
+ std::uint8_t CommentPadding=5;
/// @brief How many char per line for comments
- std::uint16_t CharPerLine=100;
+ std::uint16_t CommentCharPerLine=20;
double MoveIconWidth = 25;
- std::uint16_t CommentLinePerRow = 2;
/// @brief Ask the editor to scroll for a specific amout of pixels
double EventVScroll = 0, EventHScroll = 0;
/// @brief Amount of pixel to scroll elements
diff --git a/src/components/MoveTable.cpp b/src/components/MoveTable.cpp
index c3cbcbf..7e51c9f 100644
--- a/src/components/MoveTable.cpp
+++ b/src/components/MoveTable.cpp
@@ -209,16 +209,13 @@ std::uint32_t MoveTable::DrawComment(CGEHalfMove *m, std::uint32_t line,
((indent + 1) / 2 * status->MarginBarWidth),
status->MoveHeight * line);
}
- // Print comment
- line++;
-
+ line++; // Goto the right line
/// ----- 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 nline=ceil((double)nchar/(double)status->CommentCharPerLine);
+ std::uint16_t nrow=ceil(((nline*status->CommentCharHeight)+2*status->CommentPadding)/status->MoveHeight);
+ int width=status->CommentCharPerLine*status->CommentCharWidth+2*status->CommentPadding;
int height=nrow*status->MoveHeight;
// Draw comment background
@@ -244,19 +241,21 @@ std::uint32_t MoveTable::DrawComment(CGEHalfMove *m, std::uint32_t line,
status->Events.push_back({Event::Type::CommentSelected, m});
}
// Now draw each lines of the comment:
- Element l;
+ Element l; // One line
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.x=e.x+status->CommentPadding;
+ l.y=e.y+status->CommentPadding;
l.width=width;
- l.height=status->MoveHeight;
+ l.height=status->CommentCharHeight;
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);
+ l.text=m->comment.substr(i*status->CommentCharPerLine,status->CommentCharPerLine);
+ // Remove leading space:
+ if(l.text.size()>2 && l.text[0]==' '){
+ l.text=l.text.substr(1,l.text.size());
+ }
elements.push_back(l);
- l.y+=status->TextCharHeight;
+ l.y+=status->CommentCharHeight;
}
// Do not forget to add marging before comment if indented:
if (indent > 0) {