Debug comments$

This commit is contained in:
Loic Guegan 2022-12-31 11:47:56 +01:00
parent 2bb6730df8
commit 144a3ddfb5
5 changed files with 39 additions and 36 deletions

View file

@ -29,9 +29,10 @@ private:
void OnPaint(wxPaintEvent &event) { void OnPaint(wxPaintEvent &event) {
wxPaintDC current_dc(this); wxPaintDC current_dc(this);
dc = &current_dc; 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 // Refresh canvas size
wxSize sz = GetClientSize(); wxSize sz = GetClientSize();

View file

@ -1,5 +1,5 @@
#include "CGEditor.hpp" #include "CGEditor.hpp"
#include <iostream>
namespace cgeditor { namespace cgeditor {
CGEditor::CGEditor() { CGEditor::CGEditor() {
@ -77,18 +77,19 @@ void CGEditor::CallDrawElement(Element e) {
e.y += status.ScrollY; e.y += status.ScrollY;
} }
} }
DrawElement(e);
return; // Check if element visible if not just leave
// Check if element is visible if((e.x+e.width)<0 || status.CanvasWidth < e.x)
if (((e.x) >= 0 && ((e.x) <= status.CanvasWidth) && (e.y) >= 0 && return;
((e.y) <= status.CanvasHeight)) || if((e.y+e.height)<0 || status.CanvasHeight < e.y)
((e.x + e.width) >= 0 && ((e.x + e.width) <= status.CanvasWidth) && return;
(e.y + e.height) >= 0 && ((e.y + e.height) <= status.CanvasHeight))) {
if (e.IsOver(status.MouseX, status.MouseY)) { // Check if mouse over
e.prop |= Property::Mouseover; if (e.IsOver(status.MouseX, status.MouseY)) {
} e.prop |= Property::Mouseover;
DrawElement(e);
} }
DrawElement(e);
} }
void CGEditor::DrawComponent(Component *c) { void CGEditor::DrawComponent(Component *c) {

View file

@ -3,10 +3,10 @@
namespace cgeditor { namespace cgeditor {
bool Element::IsOver(const double &X, const double &Y) const { bool Element::IsOver(const double &X, const double &Y) const {
if (width < 0) { // Check if no overlap
return (x >= x && Y >= y && Y <= (y + height)); if(X<x|| X>(x+width) || Y<y || Y>(y+height))
} return false;
return ((X >= x && X <= (x + width) && Y >= y && Y <= (y + height))); return true;
} }
Property operator|(Property lhs, Property rhs) { Property operator|(Property lhs, Property rhs) {

View file

@ -73,11 +73,13 @@ typedef struct Status {
double NagRightMargin = 0; double NagRightMargin = 0;
double MarginBarWidth = 50; double MarginBarWidth = 50;
double ScrollbarWidth = 30; 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 /// @brief How many char per line for comments
std::uint16_t CharPerLine=100; std::uint16_t CommentCharPerLine=20;
double MoveIconWidth = 25; double MoveIconWidth = 25;
std::uint16_t CommentLinePerRow = 2;
/// @brief Ask the editor to scroll for a specific amout of pixels /// @brief Ask the editor to scroll for a specific amout of pixels
double EventVScroll = 0, EventHScroll = 0; double EventVScroll = 0, EventHScroll = 0;
/// @brief Amount of pixel to scroll elements /// @brief Amount of pixel to scroll elements

View file

@ -209,16 +209,13 @@ std::uint32_t MoveTable::DrawComment(CGEHalfMove *m, std::uint32_t line,
((indent + 1) / 2 * status->MarginBarWidth), ((indent + 1) / 2 * status->MarginBarWidth),
status->MoveHeight * line); status->MoveHeight * line);
} }
// Print comment line++; // Goto the right line
line++;
/// ----- Compute comment bounding box values /// ----- Compute comment bounding box values
int nchar=m->comment.size(); int nchar=m->comment.size();
int nline=ceil((double)nchar/(double)status->CharPerLine); int nline=ceil((double)nchar/(double)status->CommentCharPerLine);
std::uint16_t nrow=ceil((nline*status->TextCharHeight)/status->MoveHeight); std::uint16_t nrow=ceil(((nline*status->CommentCharHeight)+2*status->CommentPadding)/status->MoveHeight);
std::cout << nrow <<std::endl; int width=status->CommentCharPerLine*status->CommentCharWidth+2*status->CommentPadding;
int width=status->CharPerLine*status->TextCharWidth;
int height=nrow*status->MoveHeight; int height=nrow*status->MoveHeight;
// Draw comment background // 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}); status->Events.push_back({Event::Type::CommentSelected, m});
} }
// Now draw each lines of the comment: // Now draw each lines of the comment:
Element l; Element l; // One line
l.prop = Property::Comment|Property::Text; l.prop = Property::Comment|Property::Text;
l.x=e.x; l.x=e.x+status->CommentPadding;
l.y=e.y; l.y=e.y+status->CommentPadding;
std::cout <<"x=" << l.x << " y="<<l.y<< " width="<<width<<std::endl;
l.width=width; l.width=width;
l.height=status->MoveHeight; l.height=status->CommentCharHeight;
l.ShouldApplyScroll = true; l.ShouldApplyScroll = true;
for(int i=0;i<nline;i++){ for(int i=0;i<nline;i++){
std::cout << "BAM!" << std::endl; l.text=m->comment.substr(i*status->CommentCharPerLine,status->CommentCharPerLine);
l.text=m->comment.substr(i*status->CharPerLine,status->CharPerLine); // Remove leading space:
if(l.text.size()>2 && l.text[0]==' '){
l.text=l.text.substr(1,l.text.size());
}
elements.push_back(l); elements.push_back(l);
l.y+=status->TextCharHeight; l.y+=status->CommentCharHeight;
} }
// Do not forget to add marging before comment if indented: // Do not forget to add marging before comment if indented:
if (indent > 0) { if (indent > 0) {