aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-02-17 08:33:32 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-02-17 08:33:32 +0100
commit3e818c0f0ca741fe8404e841a93b1401aacc4301 (patch)
treeb607ac09a553f909e0eb5fc56582351bcd1d99d6
parentfbb36fc82e7d069cdc91831aba8ccbdf063d5187 (diff)
Improve editor move icons management
-rw-r--r--examples/wxWidgets/main.cpp6
-rw-r--r--src/Types.hpp11
-rw-r--r--src/components/MoveTable.cpp35
-rw-r--r--src/components/MoveTable.hpp1
4 files changed, 39 insertions, 14 deletions
diff --git a/examples/wxWidgets/main.cpp b/examples/wxWidgets/main.cpp
index 20e6d3f..99e8839 100644
--- a/examples/wxWidgets/main.cpp
+++ b/examples/wxWidgets/main.cpp
@@ -34,8 +34,8 @@ private:
wxSize sz = GetClientSize();
CGEditor::status.CanvasWidth = sz.GetWidth();
CGEditor::status.CanvasHeight = sz.GetHeight();
- CGEditor::status.UseMoveImages =
- false; // Piece image should be drawn before the move ?
+ CGEditor::status.UseMoveIcons =
+ true; // Piece image should be drawn before the move ?
const wxPoint pt = wxGetMousePosition();
CGEditor::status.MouseX = pt.x - this->GetScreenPosition().x;
@@ -133,7 +133,7 @@ private:
dc->SetBrush(*wxLIGHT_GREY_BRUSH);
dc->DrawRectangle(recToDraw);
}
- if (CGEditor::status.UseMoveImages) {
+ if (CGEditor::status.UseMoveIcons) {
dc->DrawText(wxString(e.text), wxPoint(e.x, Middle(e).y));
} else {
dc->DrawText(wxString(e.text), Middle(e));
diff --git a/src/Types.hpp b/src/Types.hpp
index db8b6f3..68aa3fe 100644
--- a/src/Types.hpp
+++ b/src/Types.hpp
@@ -23,7 +23,13 @@ enum class Property : std::uint32_t {
Dots = 1 << 13, // Move dots
Movenumber = 1 << 14,
Current = 1 << 15,
- Mouseover = 1 << 16 // Set on every element where mouse is over
+ Mouseover = 1 << 16, // Set on every element where mouse is over
+ Pawn = 1 << 17,
+ Knight = 1 << 18,
+ Bishop = 1 << 19,
+ Rook = 1 << 20,
+ Queen = 1 << 21,
+ King = 1 << 22
};
Property operator|(Property lhs, Property rhs);
Property &operator|=(Property &lhs, Property rhs);
@@ -64,6 +70,7 @@ typedef struct Status {
double MoveWidth = 100, MoveHeight = 50;
double MarginBarWidth = 50;
double ScrollbarWidth = 30;
+ double MoveIconWidth = 25;
double MenuX, MenuY;
double MoveX, MoveY;
std::uint16_t CommentLinePerRow = 2;
@@ -75,7 +82,7 @@ typedef struct Status {
bool LeftClick, RightClick;
/// @brief Can be use to close the menu
bool IsMenuOpen = false;
- bool UseMoveImages = false;
+ bool UseMoveIcons = false;
double MoveTableMaxX = 0, MoveTableMaxY = 0;
/// @brief User should set it to true when mouse is dragging
bool IsDrag = false;
diff --git a/src/components/MoveTable.cpp b/src/components/MoveTable.cpp
index e7f7af3..71142dd 100644
--- a/src/components/MoveTable.cpp
+++ b/src/components/MoveTable.cpp
@@ -2,9 +2,8 @@
namespace cgeditor {
-MoveTable::MoveTable(Status *s) : Component(s) {
- ImageWidth = status->MoveWidth * 0.25; // Image is 25% of the cell
-}
+MoveTable::MoveTable(Status *s) : Component(s) {}
+
void MoveTable::Refresh() {
status->MoveTableMaxX = 0;
status->MoveTableMaxY = 0;
@@ -16,7 +15,7 @@ void MoveTable::Refresh() {
// We only set the type after the call to UpdateMoves()
// This way only a single move will be the current move
if (CurrentMove >= 0) {
- if (status->UseMoveImages) {
+ if (status->UseMoveIcons) {
elements[CurrentMove].prop |= Property::Current;
elements[CurrentMove + 1].prop |= Property::Current;
} else {
@@ -90,13 +89,13 @@ std::uint32_t MoveTable::UpdateMoves(CGEHalfMove *m, std::uint32_t line,
}
//---------- Draw move ----------
- if (status->UseMoveImages) {
+ if (status->UseMoveIcons) {
// Image
Element img;
img.prop = Property::Image | Property::Move;
img.x = move_bound.x;
img.y = status->MoveHeight * line;
- img.width = ImageWidth;
+ img.width = status->MoveIconWidth;
img.height = status->MoveHeight;
img.ShouldApplyScroll = true;
elements.push_back(img);
@@ -104,9 +103,29 @@ std::uint32_t MoveTable::UpdateMoves(CGEHalfMove *m, std::uint32_t line,
Element e;
e.prop = move_bound.prop | Property::Text;
e.text = m->move;
- e.x = ImageWidth + move_bound.x;
+ if (m->move.size() > 0) {
+ char c = m->move[0];
+ if (!(c == 'a' || c == 'b' || c == 'c' || c == 'd' || c == 'e' ||
+ c == 'f' || c == 'O' || c == '0')) {
+ e.text = m->move.substr(1, m->move.size());
+ if (c == 'N') {
+ e.prop |= Property::Knight;
+ } else if (c == 'B') {
+ e.prop |= Property::Bishop;
+ } else if (c == 'R') {
+ e.prop |= Property::Rook;
+ } else if (c == 'Q') {
+ e.prop |= Property::Queen;
+ } else {
+ e.prop |= Property::King;
+ }
+ } else {
+ e.prop |= Property::Pawn;
+ }
+ }
+ e.x = status->MoveIconWidth + move_bound.x;
e.y = status->MoveHeight * line;
- e.width = status->MoveWidth - ImageWidth;
+ e.width = status->MoveWidth - status->MoveIconWidth;
e.height = status->MoveHeight;
e.ShouldApplyScroll = true;
elements.push_back(e);
diff --git a/src/components/MoveTable.hpp b/src/components/MoveTable.hpp
index d220f5e..28ebd12 100644
--- a/src/components/MoveTable.hpp
+++ b/src/components/MoveTable.hpp
@@ -48,7 +48,6 @@ namespace cgeditor {
class MoveTable : public Component {
std::uint32_t UpdateMoves(CGEHalfMove *, std::uint32_t, std::uint32_t,bool only_black);
std::int32_t CurrentMove;
- double ImageWidth;
std::vector<Element> VariationMargins;
bool IsMouseOver(const Element &e) const;
std::uint32_t DrawComment(CGEHalfMove *m, std::uint32_t line, std::uint32_t indent,