Improve editor move icons management

This commit is contained in:
Loic Guegan 2022-02-17 08:33:32 +01:00
parent fbb36fc82e
commit 3e818c0f0c
4 changed files with 39 additions and 14 deletions

View file

@ -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));

View file

@ -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;

View file

@ -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);

View file

@ -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,