Commit 6de7c020 authored by Loic Guegan's avatar Loic Guegan
Browse files

Debug editor

parent 2a8a2047
Pipeline #219658698 passed with stage
in 8 minutes and 51 seconds
......@@ -7,8 +7,7 @@
#pragma once
#include "Move.hpp"
#include "Types.hpp"
namespace pgneditor {
class EditorConfig {
......@@ -18,28 +17,27 @@ public:
/// @brief How much units variations should be shifted to the right
int VarOffset;
/// @brief Width of a column/row
int colWidth,rowWidth;
Size Cell;
int scrollbarThickness;
/// @brief Font size in px
int fontSize;
int topMargin,leftMargin;
int hintBarWidth;
int TopMarging,LeftMarging;
int HintBarWidth;
/// @brief Size of the move counter column
int counterW;
int CounterCellWidth;
int VarSepH;
int ExtraCanvasSize;
EditorConfig(){
EditorConfig():Cell(50,20){
VarOffset=20;
colWidth=50;
rowWidth=20;
scrollbarThickness=20;
fontSize=16;
WhiteToPlay=true;
topMargin=10;
leftMargin=10;
hintBarWidth=30;
counterW=20;
TopMarging=10;
LeftMarging=10;
HintBarWidth=30;
CounterCellWidth=20;
VarSepH=10;
ExtraCanvasSize=50;
}
......
......@@ -10,12 +10,21 @@
#include <string>
namespace pgneditor {
/**
* @brief Move type handled by the editor
*/
class Move {
public:
/// @brief The move in SAN notation
std::string *move;
/// @brief Move that follows this one
Move* next;
/// @brief Variation of the following (@a next) move
std::vector<Move*> variations;
/// @brief Is the variation of this move folded ?
bool fold;
Move():move(nullptr),next(nullptr),fold(false){}
/// @brief A free pointer that can be use by the user
void* data;
Move():move(nullptr),next(nullptr),fold(false),data(nullptr){}
};
}
......@@ -18,8 +18,8 @@ float clamp(float d, float min, float max) {
}
void PGNEditor::Render() {
this->MoveCount = 1;
this->CurrentX = Config.leftMargin + Config.hintBarWidth;
this->CurrentY = Config.topMargin;
this->CurrentX = Config.LeftMarging + Config.HintBarWidth;
this->CurrentY = Config.TopMarging;
InCanvasSize.w = CanvasSize.w - Config.scrollbarThickness;
InCanvasSize.h = CanvasSize.h - Config.scrollbarThickness;
this->MaxX = CurrentX;
......@@ -37,6 +37,7 @@ void PGNEditor::Render() {
this->DrawLine(MoveLine);
this->DrawScrollBars();
// Reset Boolean
IsMouseClicked = false;
IsMouseDoubleClicked=false;
IsMouseDragging=false;
......@@ -46,7 +47,7 @@ void PGNEditor::Render() {
void PGNEditor::DrawHintBar() {
// Never issue a call to DrawCall here (otherwise MaxX and MaxY will be corrupted)
Shape hintBar(Offset.x, 0, Config.hintBarWidth, InCanvasSize.h);
Shape hintBar(Offset.x, 0, Config.HintBarWidth, InCanvasSize.h);
hintBar.target = Shape::HINTBAR;
Draw(hintBar); // Do not issues a DrawCall here (MaxY will change);
}
......@@ -169,30 +170,31 @@ void PGNEditor::DrawScrollBars() {
void PGNEditor::DrawLine(Move *line) {
DrawCount();
int CurrentXBack = CurrentX;
CurrentX += Config.counterW;
CurrentX += Config.CounterCellWidth;
if (WhiteToPlay) {
DrawMove(*line->move);
DrawMove(line);
if (line->next != nullptr) {
CurrentX += Config.colWidth;
DrawMove(*line->next->move);
CurrentX += Config.Cell.w;
DrawMove(line->next);
}
// Restore state
CurrentX = CurrentXBack;
CurrentY += Config.rowWidth;
CurrentY += Config.Cell.h;
WhiteToPlay = false;
DrawVariations(line); // Draw White Variations
WhiteToPlay = true;
if (line->next != nullptr) {
WhiteToPlay = false;
DrawVariations(line->next); // Draw black Variations
WhiteToPlay = true;
line = line->next; // Update line pointer
}
} else {
CurrentX += Config.colWidth;
DrawMove(*line->move);
CurrentX += Config.Cell.w;
DrawMove(line);
// Restore state
CurrentX = CurrentXBack;
CurrentY += Config.rowWidth;
CurrentY += Config.Cell.h;
DrawVariations(line);
WhiteToPlay = true;
}
......@@ -212,7 +214,7 @@ void PGNEditor::DrawVariations(Move *line) {
CurrentX += Config.VarOffset;
// Draw separator
Shape sep(CurrentX, CurrentY, Config.counterW + Config.colWidth * 2,
Shape sep(CurrentX, CurrentY, Config.CounterCellWidth + Config.Cell.w * 2,
Config.VarSepH);
if(line->fold)
sep.target=Shape::VAR_SEP_FOLD;
......@@ -224,6 +226,7 @@ void PGNEditor::DrawVariations(Move *line) {
if(IsMouseClicked||IsMouseDoubleClicked){
if(MouseHover(sep)){
if(IsMouseDoubleClicked){
line->fold=false;
for (auto move : line->variations)
UnfoldLine(move);
}
......@@ -246,16 +249,18 @@ void PGNEditor::DrawVariations(Move *line) {
}
}
void PGNEditor::DrawMove(std::string move) {
Shape bg(CurrentX, CurrentY, Config.colWidth, Config.rowWidth);
void PGNEditor::DrawMove(Move* move) {
Shape bg(CurrentX, CurrentY, Config.Cell.w, Config.Cell.h);
bg.target = Shape::MOVE;
bg.move=move;
DrawCall(bg);
Shape moveS(move, CurrentX, CurrentY);
Shape moveS(*move->move, CurrentX, CurrentY);
moveS.target = Shape::MOVE;
moveS.move=move;
DrawCall(moveS);
}
void PGNEditor::DrawCount() {
Shape bg(CurrentX, CurrentY, Config.counterW, Config.rowWidth);
Shape bg(CurrentX, CurrentY, Config.CounterCellWidth, Config.Cell.h);
bg.target = Shape::MOVE_COUNTER;
DrawCall(bg);
std::string dots = ".";
......
......@@ -44,7 +44,7 @@ private:
void DrawHintBar();
void DrawCall(Shape shape);
void DrawCount();
void DrawMove(std::string move);
void DrawMove(Move* move);
bool MouseHover(Shape shape);
void UnfoldLine(Move*line);
protected:
......@@ -61,6 +61,9 @@ protected:
void ScrollV(int percent);
void ScrollH(int percent);
void SetEditorConfig(EditorConfig config);
EditorConfig GetEditorConfig(){
return(Config);
}
public:
PGNEditor():PGNEditor(EditorConfig()){}
......
......@@ -41,17 +41,19 @@ public:
TARGET target;
bool mouseHover;
bool mouseClick;
Move *move;
Shape(double x,double y,double w, double h):
x(x),y(y),w(w),h(h),radius(0),type(RECTANGLE),target(NA),mouseHover(false),mouseClick(false){
x(x),y(y),w(w),h(h),radius(0),type(RECTANGLE),target(NA),mouseHover(false),mouseClick(false),move(nullptr){
}
Shape(std::string text, double x,double y):
x(x),y(y),w(0),h(0),radius(0),text(text),type(TEXT),target(NA),mouseHover(false),mouseClick(false){
x(x),y(y),w(0),h(0),radius(0),text(text),type(TEXT),target(NA),mouseHover(false),mouseClick(false),move(nullptr){
}
Shape(double x,double y, double radius):
x(x),y(y),w(0),h(0),radius(radius),type(CIRCLE),target(NA),mouseHover(false),mouseClick(false){
x(x),y(y),w(0),h(0),radius(radius),type(CIRCLE),target(NA),mouseHover(false),mouseClick(false),move(nullptr){
}
int GetWidth(EditorConfig* state){
switch(type){
case RECTANGLE:
......
......@@ -9,10 +9,13 @@
namespace pgneditor {
/**
* @brief Define a position
*/
class Point {
public:
int x,y;
Point(int X,int Y):x(X),y(Y){}
Point():x(0),y(0){
}
bool operator==(const Point p) const{
......@@ -20,9 +23,13 @@ public:
}
};
/**
* @brief Define a size
*/
class Size {
public:
int w,h;
Size(int W,int H):w(W),h(H){}
Size():w(0),h(0){
}
......
......@@ -4,7 +4,6 @@ namespace ochess {
namespace gui {
Skin::Skin() {
wxInitAllImageHandlers();
for (auto &theme : CNF.ListPiecesThemes()) {
LOG(trace)
......
......@@ -25,6 +25,7 @@ Editor::Editor(wxFrame *parent) :
ochess::pgn::PGN pgn("/home/loic/test.pgn");
pgn.parseNextGame();
MoveLine = &(pgn.game->GetFirstMove()->editorMove);
skin.ResizePieces((PGNEditor::GetEditorConfig()).fontSize);
}
......@@ -93,7 +94,26 @@ void Editor::Draw(Shape shape) {
case Shape::TEXT:
//if (shape.mouseHover)
//DC->SetTextForeground(*wxRED);
DC->DrawText(shape.text, shape.x, shape.y);
if(shape.target==Shape::MOVE){
ochess::model::Move *m=(ochess::model::Move *)shape.move->data;
if(!m->isLongCastle && !m->isShortCastle){
char p='p';
if(!m->isPawn){
shape.text.erase(0,1);
p=std::tolower(m->piece);
}
if(m->isWhite)
p=std::toupper(p);
DC->DrawBitmap(*skin.Get(p),wxPoint(shape.x,shape.y));
DC->DrawText(shape.text, shape.x+16, shape.y);
}
else
DC->DrawText(shape.text, shape.x, shape.y);
}
else {
DC->DrawText(shape.text, shape.x, shape.y);
}
DC->SetTextForeground(*wxBLACK);
break;
}
......
......@@ -13,8 +13,9 @@
#endif
#include <wx/event.h>
#include "gui/board/controller/Skin.hpp"
#include "editor/PGNEditor.hpp"
#include "model/Move.hpp"
using namespace pgneditor;
......@@ -23,6 +24,7 @@ namespace gui {
class Editor: public wxPanel, public PGNEditor {
wxDC *DC;
Skin skin;
public:
Editor(wxFrame *parent);
void OnPaint(wxPaintEvent& event);
......
......@@ -18,8 +18,9 @@ namespace ochess
Move::Move() : parent(nullptr), main(nullptr), isCheck(false), isPromotion(false),
isCheckMate(false), isPawn(false),
isCapture(false), isLongCastle(false), isShortCastle(false), promoteTo('?'), col('?'),
clk{0}, egt{0}, emt{0}, mct{0},piece('?'),moveId(1) {
clk{0}, egt{0}, emt{0}, mct{0},piece('?'),moveId(1),isWhite(true) {
editorMove.move=&SANMove;
editorMove.data=this;
}
void Move::dump()
{
......@@ -53,6 +54,7 @@ namespace ochess
}
void Move::expand(Move *m)
{
m->isWhite=!this->isWhite;
if(this->main==nullptr){
this->main=m;
this->editorMove.next=&(m->editorMove);
......
......@@ -38,6 +38,7 @@ namespace ochess
bool isCapture;
bool isLongCastle;
bool isShortCastle;
bool isWhite;
char promoteTo;
char col;
short clk[3];
......
......@@ -44,6 +44,9 @@ public:
return(false);
OC_INIT_LOG(TraceEnable);
wxInitAllImageHandlers();
ochess::gui::MainFrame *frame = new ochess::gui::MainFrame("OChess",
wxPoint(50, 50), wxSize(450, 340));
frame->Show(true);
......
......@@ -252,7 +252,9 @@ namespace ochess
while (NEXTCHAR() == '(')
{
read(); // Skip parenthesis for the parseLine function
l->variations.push_back(parseLine(l));
Move *var=parseLine(l);
var->isWhite=!l->isWhite;
l->variations.push_back(var);
skipSpaces();
}
......@@ -260,7 +262,7 @@ namespace ochess
Move *newMove = new Move();
newMove->parent = l;
newMove->moveId = l->moveId; // By default same of id of the parent
l->main = newMove;
l->expand(newMove);
l = newMove;
// Just in case even if variations modify the game result (recursive call)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment