Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Loic Guegan
ochess
Commits
eaede20d
Commit
eaede20d
authored
Nov 18, 2020
by
Loic Guegan
Browse files
Improve PGN Editor
parent
e912656a
Pipeline
#217756682
passed with stage
in 8 minutes and 23 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
165 additions
and
87 deletions
+165
-87
src/editor/Move.hpp
src/editor/Move.hpp
+1
-0
src/editor/PGNEditor.cpp
src/editor/PGNEditor.cpp
+134
-77
src/editor/PGNEditor.hpp
src/editor/PGNEditor.hpp
+3
-0
src/editor/Shape.hpp
src/editor/Shape.hpp
+2
-2
src/editor/State.hpp
src/editor/State.hpp
+2
-0
src/gui/editor/Editor.cpp
src/gui/editor/Editor.cpp
+23
-8
No files found.
src/editor/Move.hpp
View file @
eaede20d
...
...
@@ -15,5 +15,6 @@ public:
std
::
string
move
;
Move
*
next
;
std
::
vector
<
Move
*>
variations
;
Move
(
std
::
string
move
)
:
move
(
move
),
next
(
nullptr
){}
};
}
src/editor/PGNEditor.cpp
View file @
eaede20d
...
...
@@ -9,19 +9,19 @@
#include <iostream>
namespace
pgneditor
{
void
PGNEditor
::
Render
(
State
*
state
){
this
->
state
=
state
;
this
->
WhiteToPlay
=
state
->
WhiteToPlay
;
this
->
MoveCount
=
1
;
this
->
LineCount
=
1
;
this
->
CurrentX
=
state
->
leftMargin
+
state
->
hintBarWidth
;
this
->
CurrentY
=
state
->
topMargin
;
this
->
canvasW
=
state
->
canvasW
-
state
->
scrollbarThickness
;
this
->
canvasH
=
state
->
canvasH
-
state
->
scrollbarThickness
;
this
->
MaxX
=
1
;
this
->
MaxY
=
1
;
this
->
MinX
=
0
;
this
->
MinY
=
0
;
void
PGNEditor
::
Render
(
State
*
state
)
{
this
->
state
=
state
;
this
->
WhiteToPlay
=
state
->
WhiteToPlay
;
this
->
MoveCount
=
1
;
this
->
LineCount
=
1
;
this
->
CurrentX
=
state
->
leftMargin
+
state
->
hintBarWidth
;
this
->
CurrentY
=
state
->
topMargin
;
this
->
canvasW
=
state
->
canvasW
-
state
->
scrollbarThickness
;
this
->
canvasH
=
state
->
canvasH
-
state
->
scrollbarThickness
;
this
->
MaxX
=
1
;
this
->
MaxY
=
1
;
this
->
MinX
=
0
;
this
->
MinY
=
0
;
// Start Drawing
this
->
DrawHintBar
();
...
...
@@ -29,102 +29,159 @@ void PGNEditor::Render(State *state){
this
->
DrawScrollBars
();
}
void
PGNEditor
::
DrawHintBar
(){
Shape
hintBar
(
0
,
0
,
state
->
hintBarWidth
,
canvasH
);
hintBar
.
target
=
Shape
::
HINTBAR
;
void
PGNEditor
::
DrawHintBar
()
{
Shape
hintBar
(
0
,
0
,
state
->
hintBarWidth
,
canvasH
);
hintBar
.
target
=
Shape
::
HINTBAR
;
DrawCall
(
hintBar
);
}
void
PGNEditor
::
DrawScrollBars
(){
void
PGNEditor
::
DrawScrollBars
()
{
// Never issue a call to DrawCall here (otherwise MaxX and MaxY will be corrupted)
// First draw scrolling corner on the bottom right side
Shape
corner
(
canvasW
,
canvasH
,
state
->
scrollbarThickness
,
state
->
scrollbarThickness
);
corner
.
target
=
Shape
::
SCROLLBAR_CORNER
;
if
(
corner
.
x
<=
state
->
mouseX
&&
corner
.
y
<=
state
->
mouseY
&&
state
->
canvasW
>=
state
->
mouseX
&&
state
->
canvasH
>=
state
->
mouseY
)
corner
.
mouseHover
=
true
;
Shape
corner
(
canvasW
,
canvasH
,
state
->
scrollbarThickness
,
state
->
scrollbarThickness
);
corner
.
target
=
Shape
::
SCROLLBAR_CORNER
;
if
(
corner
.
x
<=
state
->
mouseX
&&
corner
.
y
<=
state
->
mouseY
&&
state
->
canvasW
>=
state
->
mouseX
&&
state
->
canvasH
>=
state
->
mouseY
)
corner
.
mouseHover
=
true
;
Draw
(
corner
);
// Compute scrollbal size
double
HSSize
=
(
double
)
canvasW
*
((
double
)
canvasW
/
std
::
max
(
canvasW
,
MaxX
-
MinX
));
double
VSSize
=
(
double
)
canvasH
*
((
double
)
canvasH
/
std
::
max
(
canvasH
,
MaxY
-
MinY
));
double
HSSize
=
(
double
)
canvasW
*
((
double
)
canvasW
/
std
::
max
(
canvasW
,
MaxX
-
MinX
));
double
VSSize
=
(
double
)
canvasH
*
((
double
)
canvasH
/
std
::
max
(
canvasH
,
MaxY
-
MinY
));
Shape
HS
(
state
->
offsetX
,
canvasH
,
HSSize
,
state
->
scrollbarThickness
);
HS
.
target
=
Shape
::
SCROLLBAR_H
;
Shape
VS
(
canvasW
,
state
->
offsetY
,
state
->
scrollbarThickness
,
VSSize
);
VS
.
target
=
Shape
::
SCROLLBAR_V
;
Shape
HS
(
state
->
offsetX
,
canvasH
,
HSSize
,
state
->
scrollbarThickness
);
HS
.
target
=
Shape
::
SCROLLBAR_H
;
Shape
VS
(
canvasW
,
state
->
offsetY
,
state
->
scrollbarThickness
,
VSSize
);
VS
.
target
=
Shape
::
SCROLLBAR_V
;
// Check mouse over
if
(
HS
.
x
<=
state
->
mouseX
&&
HS
.
y
<=
state
->
mouseY
&&
(
HS
.
x
+
HSSize
)
>=
state
->
mouseX
&&
(
HS
.
y
+
state
->
scrollbarThickness
)
>=
state
->
mouseY
)
HS
.
mouseHover
=
true
;
if
(
VS
.
x
<=
state
->
mouseX
&&
VS
.
y
<=
state
->
mouseY
&&
(
VS
.
x
+
state
->
scrollbarThickness
)
>=
state
->
mouseX
&&
(
VS
.
y
+
VSSize
)
>=
state
->
mouseY
)
VS
.
mouseHover
=
true
;
if
(
HS
.
x
<=
state
->
mouseX
&&
HS
.
y
<=
state
->
mouseY
&&
(
HS
.
x
+
HSSize
)
>=
state
->
mouseX
&&
(
HS
.
y
+
state
->
scrollbarThickness
)
>=
state
->
mouseY
)
HS
.
mouseHover
=
true
;
if
(
VS
.
x
<=
state
->
mouseX
&&
VS
.
y
<=
state
->
mouseY
&&
(
VS
.
x
+
state
->
scrollbarThickness
)
>=
state
->
mouseX
&&
(
VS
.
y
+
VSSize
)
>=
state
->
mouseY
)
VS
.
mouseHover
=
true
;
Draw
(
HS
);
Draw
(
VS
);
}
void
PGNEditor
::
DrawLine
(
Move
*
line
){
if
(
WhiteToPlay
){
Shape
bg
(
CurrentX
,
CurrentY
,
state
->
counterW
,
state
->
rowWidth
);
bg
.
target
=
Shape
::
MOVE_COUNTER
;
DrawCall
(
bg
);
Shape
count
(
std
::
to_string
(
MoveCount
)
+
"."
,
CurrentX
,
CurrentY
);
count
.
target
=
Shape
::
MOVE_COUNTER
;
DrawCall
(
count
);
CurrentX
+=
state
->
counterW
;
}
Shape
bg
(
CurrentX
,
CurrentY
,
state
->
colWidth
,
state
->
rowWidth
);
bg
.
target
=
Shape
::
MOVE
;
DrawCall
(
bg
);
Shape
move
(
line
->
move
,
CurrentX
,
CurrentY
);
move
.
target
=
Shape
::
MOVE
;
DrawCall
(
move
);
CurrentX
+=
state
->
colWidth
;
if
(
!
WhiteToPlay
){
CurrentX
-=
(
state
->
colWidth
*
2
+
state
->
counterW
);
// *2 Because we just increment it above
void
PGNEditor
::
DrawLine
(
Move
*
line
)
{
DrawCount
();
int
CurrentXBack
=
CurrentX
;
CurrentX
+=
state
->
counterW
;
if
(
WhiteToPlay
)
{
DrawMove
(
line
->
move
);
if
(
line
->
next
!=
nullptr
){
CurrentX
+=
state
->
colWidth
;
DrawMove
(
line
->
next
->
move
);
}
// Restore state
CurrentX
=
CurrentXBack
;
CurrentY
+=
state
->
rowWidth
;
DrawVariations
(
line
);
// Draw White Variations
if
(
line
->
next
!=
nullptr
){
WhiteToPlay
=
false
;
DrawVariations
(
line
->
next
);
// Draw black Variations
WhiteToPlay
=
true
;
line
=
line
->
next
;
// Update line pointer
}
}
else
{
CurrentX
+=
state
->
colWidth
;
DrawMove
(
line
->
move
);
// Restore state
CurrentX
=
CurrentXBack
;
CurrentY
+=
state
->
rowWidth
;
MoveCount
++
;
DrawVariations
(
line
);
WhiteToPlay
=
true
;
}
if
(
line
->
next
!=
nullptr
){
WhiteToPlay
=!
WhiteToPlay
;
MoveCount
++
;
if
(
line
->
next
!=
nullptr
)
DrawLine
(
line
->
next
);
}
void
PGNEditor
::
DrawVariations
(
Move
*
line
){
if
(
line
->
variations
.
size
()
>
0
)
{
bool
WhiteToPlayBak
=
WhiteToPlay
;
int
CurrentXBack
=
CurrentX
;
int
MoveCountBak
=
MoveCount
;
CurrentX
+=
state
->
variationOffset
;
// Draw separator
Shape
sep
(
CurrentX
,
CurrentY
,
state
->
counterW
+
state
->
colWidth
*
2
,
state
->
varationSepW
);
sep
.
target
=
Shape
::
VAR_SEP
;
DrawCall
(
sep
);
CurrentY
+=
state
->
varationSepW
;
for
(
auto
move
:
line
->
variations
)
{
DrawLine
(
move
);
}
WhiteToPlay
=
WhiteToPlayBak
;
CurrentX
=
CurrentXBack
;
MoveCount
=
MoveCountBak
;
}
}
void
PGNEditor
::
DrawMove
(
std
::
string
move
)
{
Shape
bg
(
CurrentX
,
CurrentY
,
state
->
colWidth
,
state
->
rowWidth
);
bg
.
target
=
Shape
::
MOVE
;
DrawCall
(
bg
);
Shape
moveS
(
move
,
CurrentX
,
CurrentY
);
moveS
.
target
=
Shape
::
MOVE
;
DrawCall
(
moveS
);
}
void
PGNEditor
::
DrawCount
()
{
Shape
bg
(
CurrentX
,
CurrentY
,
state
->
counterW
,
state
->
rowWidth
);
bg
.
target
=
Shape
::
MOVE_COUNTER
;
DrawCall
(
bg
);
std
::
string
dots
=
"."
;
if
(
!
WhiteToPlay
)
dots
+=
".."
;
Shape
count
(
std
::
to_string
(
MoveCount
)
+
dots
,
CurrentX
,
CurrentY
);
count
.
target
=
Shape
::
MOVE_COUNTER
;
DrawCall
(
count
);
}
void
PGNEditor
::
DrawCall
(
Shape
shape
){
shape
.
x
+=
state
->
offsetX
;
shape
.
y
+=
state
->
offsetY
;
void
PGNEditor
::
DrawCall
(
Shape
shape
)
{
shape
.
x
+=
state
->
offsetX
;
shape
.
y
+=
state
->
offsetY
;
int
height
=
shape
.
GetHeight
(
state
);
int
width
=
shape
.
GetWidth
(
state
);
int
height
=
shape
.
GetHeight
(
state
);
int
width
=
shape
.
GetWidth
(
state
);
int
maxX
=
shape
.
x
+
width
;
int
maxY
=
shape
.
y
+
height
;
int
maxX
=
shape
.
x
+
width
;
int
maxY
=
shape
.
y
+
height
;
if
(
maxX
>
MaxX
)
MaxX
=
maxX
;
if
(
maxY
>
MaxY
)
MaxY
=
maxY
;
if
(
shape
.
x
<
MinX
)
MinX
=
shape
.
x
;
if
(
shape
.
y
<
MinY
)
MinY
=
shape
.
y
;
if
(
maxX
>
MaxX
)
MaxX
=
maxX
;
if
(
maxY
>
MaxY
)
MaxY
=
maxY
;
if
(
shape
.
x
<
MinX
)
MinX
=
shape
.
x
;
if
(
shape
.
y
<
MinY
)
MinY
=
shape
.
y
;
if
(
shape
.
x
<=
state
->
mouseX
&&
shape
.
y
<=
state
->
mouseY
&&
maxX
>=
state
->
mouseX
&&
maxY
>=
state
->
mouseY
)
shape
.
mouseHover
=
true
;
if
(
shape
.
x
<=
state
->
mouseX
&&
shape
.
y
<=
state
->
mouseY
&&
maxX
>=
state
->
mouseX
&&
maxY
>=
state
->
mouseY
)
shape
.
mouseHover
=
true
;
// Issue a draw only if necessary
if
(
shape
.
x
<=
canvasW
&&
shape
.
y
<=
canvasH
)
if
(
maxX
>=
0
&&
maxY
>=
0
)
Draw
(
shape
);
if
(
shape
.
x
<=
canvasW
&&
shape
.
y
<=
canvasH
)
if
(
maxX
>=
0
&&
maxY
>=
0
)
Draw
(
shape
);
}
}
src/editor/PGNEditor.hpp
View file @
eaede20d
...
...
@@ -31,9 +31,12 @@ private:
int
MaxY
,
MinY
;
void
DrawLine
(
Move
*
line
);
void
DrawVariations
(
Move
*
line
);
void
DrawScrollBars
();
void
DrawHintBar
();
void
DrawCall
(
Shape
shape
);
void
DrawCount
();
void
DrawMove
(
std
::
string
move
);
protected:
void
Render
(
State
*
state
);
virtual
void
Draw
(
Shape
shape
)
=
0
;
...
...
src/editor/Shape.hpp
View file @
eaede20d
...
...
@@ -24,11 +24,11 @@ public:
MOVE
,
MOVE_CURRENT
,
MOVE_COUNTER
,
LINE_INDEX
,
SCROLLBAR_H
,
SCROLLBAR_V
,
SCROLLBAR_CORNER
,
HINTBAR
HINTBAR
,
VAR_SEP
}
TARGET
;
double
x
,
y
;
...
...
src/editor/State.hpp
View file @
eaede20d
...
...
@@ -31,6 +31,7 @@ public:
int
hintBarWidth
;
// @brief Size of the move counter column
int
counterW
;
int
varationSepW
;
State
(){
moveline
=
nullptr
;
...
...
@@ -50,6 +51,7 @@ public:
leftMargin
=
10
;
hintBarWidth
=
30
;
counterW
=
20
;
varationSepW
=
5
;
}
};
...
...
src/gui/editor/Editor.cpp
View file @
eaede20d
...
...
@@ -16,17 +16,32 @@ Editor::Editor(wxFrame *parent) :
this
->
SetBackgroundColour
(
*
wxWHITE
);
state
=
new
State
();
pgneditor
::
Move
*
w1
=
new
pgneditor
::
Move
();
w1
->
move
=
"e5"
;
state
->
moveline
=
w1
;
pgneditor
::
Move
*
w1
=
new
pgneditor
::
Move
(
"e5"
);
pgneditor
::
Move
*
b1
=
new
pgneditor
::
Move
();
b1
->
move
=
"e6"
;
pgneditor
::
Move
*
b1
=
new
pgneditor
::
Move
(
"e6"
);
w1
->
next
=
b1
;
pgneditor
::
Move
*
w2
=
new
pgneditor
::
Move
();
w2
->
move
=
"d4"
;
pgneditor
::
Move
*
w2
=
new
pgneditor
::
Move
(
"d4"
)
;
b1
->
next
=
w2
;
pgneditor
::
Move
*
b2
=
new
pgneditor
::
Move
(
"d5"
);
w2
->
next
=
b2
;
pgneditor
::
Move
*
Varw1
=
new
pgneditor
::
Move
(
"d3"
);
pgneditor
::
Move
*
Varb1
=
new
pgneditor
::
Move
(
"a5"
);
pgneditor
::
Move
*
Varw2
=
new
pgneditor
::
Move
(
"a3"
);
pgneditor
::
Move
*
Varb2
=
new
pgneditor
::
Move
(
"b5"
);
Varw1
->
next
=
Varb1
;
Varb1
->
next
=
Varw2
;
Varw2
->
next
=
Varb2
;
w1
->
variations
.
push_back
(
Varw1
);
b1
->
variations
.
push_back
(
Varw1
);
state
->
moveline
=
w1
;
this
->
Bind
(
wxEVT_CHAR_HOOK
,
&
Editor
::
OnKeyDown
,
this
);
this
->
Bind
(
wxEVT_MOTION
,
&
Editor
::
MouseMove
,
this
);
}
...
...
@@ -63,7 +78,7 @@ void Editor::Draw(Shape shape) {
||
shape
.
target
==
Shape
::
SCROLLBAR_CORNER
)
DC
->
SetBrush
(
wxColour
(
184
,
184
,
184
));
else
if
(
shape
.
target
==
Shape
::
SCROLLBAR_H
||
shape
.
target
==
Shape
::
SCROLLBAR_V
)
||
shape
.
target
==
Shape
::
SCROLLBAR_V
||
shape
.
target
==
Shape
::
VAR_SEP
)
DC
->
SetBrush
(
wxColour
(
100
,
100
,
100
));
DC
->
DrawRectangle
(
shape
.
x
,
shape
.
y
,
shape
.
w
,
shape
.
h
);
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment