mirror of
https://gitlab.com/manzerbredes/cgeditor.git
synced 2025-04-05 17:46:28 +02:00
Update
This commit is contained in:
parent
f1f638100f
commit
2bb6730df8
7 changed files with 62 additions and 51 deletions
|
@ -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");
|
||||
|
|
|
@ -29,6 +29,9 @@ 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);
|
||||
|
||||
// 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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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)) ||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
// 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});
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
if (status->LeftClick && IsMouseOver(e)) {
|
||||
status->Events.push_back({Event::Type::CommentSelected, m});
|
||||
}
|
||||
line += CommentRows; // Skip right amount of lines
|
||||
line += nrow; // Skip right amount of lines
|
||||
// Since we already increment line for black later on:
|
||||
if (m->IsBlack || m->variations.size() > 0) {
|
||||
line--;
|
||||
|
|
Loading…
Add table
Reference in a new issue