mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
'Edit' and 'gallery' button for symbol editor
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@522 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -11,10 +11,96 @@
|
||||
|
||||
// ----------------------------------------------------------------------------- : SymbolValueEditor
|
||||
|
||||
IMPLEMENT_VALUE_EDITOR(Symbol) {}
|
||||
IMPLEMENT_VALUE_EDITOR(Symbol)
|
||||
, button_down(-2)
|
||||
{}
|
||||
|
||||
void SymbolValueEditor::draw(RotatedDC& dc) {
|
||||
SymbolValueViewer::draw(dc);
|
||||
// draw helper text if there are no symbols
|
||||
if (symbols.empty()) {
|
||||
dc.SetFont(wxFont(10,wxSWISS,wxNORMAL,wxNORMAL));
|
||||
dc.SetTextForeground(*wxBLACK);
|
||||
RealSize text_size = dc.GetTextExtent(_("double click to edit symbol"));
|
||||
dc.DrawText(_("double click to edit symbol"), align_in_rect(ALIGN_MIDDLE_CENTER, text_size, style().getRect()));
|
||||
}
|
||||
if (nativeLook()) {
|
||||
// draw editor buttons
|
||||
dc.SetFont(*wxNORMAL_FONT);
|
||||
drawButton(dc, 0, _("Edit"));
|
||||
drawButton(dc, 1, _("Gallery"));
|
||||
}
|
||||
}
|
||||
void SymbolValueEditor::drawButton(RotatedDC& dc, int button, const String& text) {
|
||||
bool down = button == button_down;
|
||||
double size = style().height;
|
||||
double x = style().right - size - (size + 1) * button;
|
||||
double y = style().top;
|
||||
// draw button
|
||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||
dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
|
||||
dc.DrawRectangle(RealRect(x, y, size, size));
|
||||
dc.SetPen(wxSystemSettings::GetColour(down ? wxSYS_COLOUR_BTNSHADOW : wxSYS_COLOUR_BTNHIGHLIGHT));
|
||||
dc.DrawLine(RealPoint(x,y),RealPoint(x+size,y));
|
||||
dc.DrawLine(RealPoint(x,y),RealPoint(x,y+size));
|
||||
dc.SetPen(wxSystemSettings::GetColour(down ? wxSYS_COLOUR_BTNHIGHLIGHT : wxSYS_COLOUR_BTNSHADOW));
|
||||
dc.DrawLine(RealPoint(x+size-1,y),RealPoint(x+size-1,y+size));
|
||||
dc.DrawLine(RealPoint(x,y+size-1),RealPoint(x+size,y+size-1));
|
||||
// draw text
|
||||
RealSize text_size = dc.GetTextExtent(text);
|
||||
dc.DrawText(text, align_in_rect((Alignment)(ALIGN_BOTTOM | ALIGN_CENTER), text_size, RealRect(x, y, size,size*0.9)));
|
||||
}
|
||||
|
||||
int SymbolValueEditor::findButton(const RealPoint& pos) {
|
||||
if (pos.y < style().top || pos.y >= style().bottom) return -1;
|
||||
int button = (int)floor( (style().right - pos.x) / (style().height + 1) );
|
||||
if (button >= 0 && button <= 1) return button;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool SymbolValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent&) {
|
||||
if (!nativeLook()) return false;
|
||||
int button = findButton(pos);
|
||||
if (button != button_down) {
|
||||
button_down = button;
|
||||
viewer.redraw(*this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool SymbolValueEditor::onMotion(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
if (button_down != -2) {
|
||||
int button = findButton(pos);
|
||||
if (button != button_down) {
|
||||
button_down = button;
|
||||
viewer.redraw(*this);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SymbolValueEditor::onLeftUp(const RealPoint& pos, wxMouseEvent&) {
|
||||
if (!nativeLook()) return false;
|
||||
if (button_down == 0) {
|
||||
// edit
|
||||
button_down = -2;
|
||||
viewer.redraw(*this);
|
||||
SymbolWindow* wnd = new SymbolWindow(nullptr, valueP(), viewer.getSet());
|
||||
wnd->Show();
|
||||
return true;
|
||||
} else if (button_down == 1) {
|
||||
// gallery
|
||||
button_down = -2;
|
||||
viewer.redraw(*this);
|
||||
// TODO
|
||||
return true;
|
||||
} else {
|
||||
button_down = -2;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool SymbolValueEditor::onLeftDClick(const RealPoint& pos, wxMouseEvent&) {
|
||||
// TODO : use SetWindow as parent? Maybe not, the symbol editor will stay open when mainwindow closes
|
||||
// Use SetWindow as parent? Maybe not, the symbol editor will stay open when mainwindow closes
|
||||
SymbolWindow* wnd = new SymbolWindow(nullptr, valueP(), viewer.getSet());
|
||||
wnd->Show();
|
||||
return true;
|
||||
|
||||
@@ -20,8 +20,20 @@ class SymbolValueEditor : public SymbolValueViewer, public ValueEditor {
|
||||
public:
|
||||
DECLARE_VALUE_EDITOR(Symbol);
|
||||
|
||||
virtual void draw(RotatedDC& dc);
|
||||
virtual bool onLeftDown (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual bool onLeftUp (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual bool onLeftDClick(const RealPoint& pos, wxMouseEvent&);
|
||||
virtual bool onMotion (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual void determineSize(bool);
|
||||
private:
|
||||
/// Draw a button, buttons are numbered from the right
|
||||
void drawButton(RotatedDC& dc, int button, const String& text);
|
||||
/// Is there a button at the given position? returns the button index, or -1 if there is no button
|
||||
int findButton(const RealPoint& pos);
|
||||
|
||||
// button, or -1 for mouse down, but not on button, or -2 for mouse not down
|
||||
int button_down;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
Reference in New Issue
Block a user