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 = ¤t_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 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+width) || 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 <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="<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) {