mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 21:06:59 -04:00
Changed all resources to .png files;
Added 'snap to grid' to symbol editor git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@207 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -120,8 +120,8 @@ void GalleryList::onChar(wxKeyEvent& ev) {
|
||||
|
||||
wxSize GalleryList::DoGetBestSize() const {
|
||||
wxSize ws = GetSize(), cs = GetClientSize();
|
||||
const int w = item_size.x + SPACING;
|
||||
const int h = item_size.y + SPACING;
|
||||
const int w = item_size.x + 2*MARGIN + 2*BORDER;
|
||||
const int h = item_size.y + 2*MARGIN + 2*BORDER;
|
||||
return wxSize(w, h) + ws - cs;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,9 +56,9 @@ void SymbolBasicShapeEditor::destroyUI(wxToolBar* tb, wxMenuBar* mb) {
|
||||
tb->RemoveChild(sidesL);
|
||||
tb->RemoveChild(sides);
|
||||
// HACK: hardcoded size of rest of toolbar
|
||||
tb->DeleteToolByPos(4); // delete separator
|
||||
tb->DeleteToolByPos(4); // delete sidesL
|
||||
tb->DeleteToolByPos(4); // delete sides
|
||||
tb->DeleteToolByPos(7); // delete separator
|
||||
tb->DeleteToolByPos(7); // delete sidesL
|
||||
tb->DeleteToolByPos(7); // delete sides
|
||||
#if wxVERSION_NUMBER < 2600
|
||||
delete sides;
|
||||
delete sidesL;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <gui/symbol/basic_shape_editor.hpp>
|
||||
#include <gui/util.hpp>
|
||||
#include <data/action/symbol.hpp>
|
||||
#include <data/settings.hpp>
|
||||
#include <util/window_id.hpp>
|
||||
#include <wx/dcbuffer.h>
|
||||
|
||||
@@ -65,7 +66,18 @@ void SymbolControl::onModeChange(wxCommandEvent& ev) {
|
||||
}
|
||||
|
||||
void SymbolControl::onExtraTool(wxCommandEvent& ev) {
|
||||
if (editor) editor->onCommand(ev.GetId());
|
||||
switch (ev.GetId()) {
|
||||
case ID_VIEW_GRID:
|
||||
settings.symbol_grid = !settings.symbol_grid;
|
||||
Refresh(false);
|
||||
break;
|
||||
case ID_VIEW_GRID_SNAP:
|
||||
settings.symbol_grid_snap = !settings.symbol_grid_snap;
|
||||
Refresh(false);
|
||||
break;
|
||||
default:
|
||||
if (editor) editor->onCommand(ev.GetId());
|
||||
}
|
||||
}
|
||||
|
||||
void SymbolControl::onAction(const Action& action, bool undone) {
|
||||
@@ -135,6 +147,25 @@ void SymbolControl::draw(DC& dc) {
|
||||
clearDC(dc, Color(0, 128, 0));
|
||||
// draw symbol iself
|
||||
SymbolViewer::draw(dc);
|
||||
// draw grid
|
||||
if (settings.symbol_grid) {
|
||||
wxSize s = dc.GetSize();
|
||||
int lines = settings.symbol_grid_size;
|
||||
for (int i = 0 ; i <= lines ; ++i) {
|
||||
int x = rotation.trS((double)i/lines-0.0001);
|
||||
//dc.SetPen(Color(0, i%5 == 0 ? 64 : 31, 0));
|
||||
//dc.SetPen(Color(i%5 == 0 ? 64 : 31, 0, 0));
|
||||
dc.SetLogicalFunction(wxAND);
|
||||
dc.SetPen(i%5 == 0 ? Color(191,255,191) : Color(191, 255, 191));
|
||||
dc.DrawLine(x, 0, x, s.y);
|
||||
dc.DrawLine(0, x, s.x, x);
|
||||
dc.SetLogicalFunction(wxOR);
|
||||
dc.SetPen(i%5 == 0 ? Color(0,63,0) : Color(0, 31, 0));
|
||||
dc.DrawLine(x, 0, x, s.y);
|
||||
dc.DrawLine(0, x, s.x, x);
|
||||
}
|
||||
dc.SetLogicalFunction(wxCOPY);
|
||||
}
|
||||
// draw editing overlay
|
||||
if (editor) {
|
||||
editor->draw(dc);
|
||||
@@ -196,7 +227,7 @@ void SymbolControl::onChar(wxKeyEvent& ev) {
|
||||
}
|
||||
|
||||
void SymbolControl::onSize(wxSizeEvent& ev) {
|
||||
wxSize s = ev.GetSize();
|
||||
wxSize s = GetClientSize();
|
||||
rotation.setZoom(min(s.GetWidth(), s.GetHeight()));
|
||||
Refresh(false);
|
||||
}
|
||||
@@ -213,6 +244,12 @@ void SymbolControl::onUpdateUI(wxUpdateUIEvent& ev) {
|
||||
case ID_MODE_PAINT:
|
||||
ev.Enable(false); // TODO
|
||||
break;
|
||||
case ID_VIEW_GRID:
|
||||
ev.Check(settings.symbol_grid);
|
||||
break;
|
||||
case ID_VIEW_GRID_SNAP:
|
||||
ev.Check(settings.symbol_grid_snap);
|
||||
break;
|
||||
default:
|
||||
if (ev.GetId() >= ID_CHILD_MIN && ev.GetId() < ID_CHILD_MAX) {
|
||||
editor->onUpdateUI(ev); // foward to editor
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <gui/util.hpp>
|
||||
#include <gfx/bezier.hpp>
|
||||
#include <data/action/symbol_part.hpp>
|
||||
#include <data/settings.hpp>
|
||||
#include <util/window_id.hpp>
|
||||
#include <util/error.hpp>
|
||||
|
||||
@@ -172,8 +173,8 @@ void SymbolPointEditor::destroyUI(wxToolBar* tb, wxMenuBar* mb) {
|
||||
tb->DeleteTool(ID_LOCK_DIR);
|
||||
tb->DeleteTool(ID_LOCK_SIZE);
|
||||
// HACK: hardcoded size of rest of toolbar
|
||||
tb->DeleteToolByPos(4); // delete separator
|
||||
tb->DeleteToolByPos(4); // delete separator
|
||||
tb->DeleteToolByPos(7); // delete separator
|
||||
tb->DeleteToolByPos(7); // delete separator
|
||||
// TODO : menu bar
|
||||
//mb->Remove(2)
|
||||
}
|
||||
@@ -215,8 +216,10 @@ void SymbolPointEditor::onCommand(int id) {
|
||||
switch (id) {
|
||||
case ID_SEGMENT_LINE: case ID_SEGMENT_CURVE:
|
||||
onChangeSegment( static_cast<SegmentMode>(id - ID_SEGMENT) );
|
||||
break;
|
||||
case ID_LOCK_FREE: case ID_LOCK_DIR: case ID_LOCK_SIZE:
|
||||
onChangeLock( static_cast<LockMode>(id - ID_LOCK) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,6 +276,10 @@ void SymbolPointEditor::onMouseMove(const Vector2D& from, const Vector2D& to, wx
|
||||
control.Refresh(false);
|
||||
}
|
||||
|
||||
template <typename Event> int snap(Event& ev) {
|
||||
return settings.symbol_grid_snap != ev.ShiftDown() ? settings.symbol_grid_size : 0; // shift toggles snap
|
||||
}
|
||||
|
||||
void SymbolPointEditor::onMouseDrag(const Vector2D& from, const Vector2D& to, wxMouseEvent& ev) {
|
||||
Vector2D delta = to - from;
|
||||
if (selection == SELECTED_LINE && ev.AltDown()) {
|
||||
@@ -293,6 +300,7 @@ void SymbolPointEditor::onMouseDrag(const Vector2D& from, const Vector2D& to, wx
|
||||
getSymbol()->actions.add(controlPointMoveAction);
|
||||
}
|
||||
controlPointMoveAction->constrain = ev.ControlDown(); // ctrl constrains
|
||||
controlPointMoveAction->snap = snap(ev);
|
||||
controlPointMoveAction->move(delta);
|
||||
new_point += delta;
|
||||
control.Refresh(false);
|
||||
@@ -302,7 +310,8 @@ void SymbolPointEditor::onMouseDrag(const Vector2D& from, const Vector2D& to, wx
|
||||
handleMoveAction = new HandleMoveAction(selected_handle);
|
||||
getSymbol()->actions.add(handleMoveAction);
|
||||
}
|
||||
handleMoveAction->constrain = ev.ControlDown(); // ctrl constrains
|
||||
handleMoveAction->constrain = ev.ControlDown(); // ctrl constrains
|
||||
handleMoveAction->snap = snap(ev);
|
||||
handleMoveAction->move(delta);
|
||||
control.Refresh(false);
|
||||
}
|
||||
@@ -323,14 +332,16 @@ void SymbolPointEditor::onKeyChange(wxKeyEvent& ev) {
|
||||
SetStatusText(_("Alt + drag to move curve; double click to add control point on this line"));
|
||||
}
|
||||
control.Refresh(false);
|
||||
} else if (ev.GetKeyCode() == WXK_CONTROL) {
|
||||
// constrain changed
|
||||
} else if (ev.GetKeyCode() == WXK_CONTROL || ev.GetKeyCode() == WXK_SHIFT) {
|
||||
// constrain/snap changed
|
||||
if (controlPointMoveAction) {
|
||||
controlPointMoveAction->constrain = ev.ControlDown();
|
||||
controlPointMoveAction->snap = snap(ev);
|
||||
controlPointMoveAction->move(Vector2D()); //refresh action
|
||||
control.Refresh(false);
|
||||
} else if (handleMoveAction) {
|
||||
handleMoveAction->constrain = ev.ControlDown();
|
||||
handleMoveAction->snap = snap(ev);
|
||||
handleMoveAction->move(Vector2D()); //refresh action
|
||||
control.Refresh(false);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <gui/util.hpp>
|
||||
#include <util/window_id.hpp>
|
||||
#include <data/action/symbol.hpp>
|
||||
#include <data/settings.hpp>
|
||||
#include <gfx/gfx.hpp>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(SymbolPartP);
|
||||
@@ -122,7 +123,7 @@ void SymbolSelectEditor::destroyUI(wxToolBar* tb, wxMenuBar* mb) {
|
||||
tb->DeleteTool(ID_PART_OVERLAP);
|
||||
tb->DeleteTool(ID_PART_BORDER);
|
||||
// HACK: hardcoded size of rest of toolbar
|
||||
tb->DeleteToolByPos(4); // delete separator
|
||||
tb->DeleteToolByPos(7); // delete separator
|
||||
}
|
||||
|
||||
void SymbolSelectEditor::onUpdateUI(wxUpdateUIEvent& ev) {
|
||||
@@ -173,6 +174,40 @@ int SymbolSelectEditor::modeToolId() {
|
||||
// ----------------------------------------------------------------------------- : Mouse Events
|
||||
|
||||
void SymbolSelectEditor::onLeftDown (const Vector2D& pos, wxMouseEvent& ev) {
|
||||
have_dragged = true;
|
||||
// change selection
|
||||
// Are we on a handle?
|
||||
int dx, dy;
|
||||
if (onAnyHandle(pos, &dx, &dy)) return; // don't change the selection
|
||||
// Select the part under the cursor
|
||||
SymbolPartP part = findPart(pos);
|
||||
if (part) {
|
||||
if (ev.ShiftDown()) {
|
||||
// toggle selection
|
||||
set<SymbolPartP>::iterator it = control.selected_parts.find(part);
|
||||
if (it != control.selected_parts.end()) {
|
||||
control.selected_parts.erase(it);
|
||||
} else {
|
||||
control.selected_parts.insert(part);
|
||||
}
|
||||
} else {
|
||||
if (control.selected_parts.find(part) != control.selected_parts.end()) {
|
||||
// already selected, do nothing
|
||||
have_dragged = false; // we haven't done anything
|
||||
} else {
|
||||
// select the part under the cursor
|
||||
control.selected_parts.clear();
|
||||
control.selected_parts.insert(part);
|
||||
}
|
||||
}
|
||||
} else if (!ev.ShiftDown()) {
|
||||
// select nothing
|
||||
control.selected_parts.clear();
|
||||
}
|
||||
// selection has changed
|
||||
updateBoundingBox();
|
||||
control.signalSelectionChange();
|
||||
control.Refresh(false);
|
||||
}
|
||||
|
||||
void SymbolSelectEditor::onLeftUp (const Vector2D& pos, wxMouseEvent& ev) {
|
||||
@@ -180,39 +215,18 @@ void SymbolSelectEditor::onLeftUp (const Vector2D& pos, wxMouseEvent& ev) {
|
||||
// stop editing
|
||||
resetActions();
|
||||
} else {
|
||||
// mouse not moved, change selection
|
||||
// Are we on a handle?
|
||||
int dx, dy;
|
||||
if (onAnyHandle(pos, &dx, &dy)) return; // don't change the selection
|
||||
// Select the part under the cursor
|
||||
SymbolPartP part = findPart(pos);
|
||||
if (part) {
|
||||
if (ev.ShiftDown()) {
|
||||
// toggle selection
|
||||
set<SymbolPartP>::iterator it = control.selected_parts.find(part);
|
||||
if (it != control.selected_parts.end()) {
|
||||
control.selected_parts.erase(it);
|
||||
} else {
|
||||
control.selected_parts.insert(part);
|
||||
}
|
||||
} else {
|
||||
if (control.selected_parts.find(part) != control.selected_parts.end()) {
|
||||
// already selected, don't change selection
|
||||
// instead switch between rotate and resize mode
|
||||
rotate = !rotate;
|
||||
} else {
|
||||
// select the part under the cursor
|
||||
control.selected_parts.clear();
|
||||
control.selected_parts.insert(part);
|
||||
}
|
||||
// mouse not moved -> change selection
|
||||
if (!have_dragged && !ev.ShiftDown()) {
|
||||
int dx, dy;
|
||||
if (onAnyHandle(pos, &dx, &dy)) return; // don't change the selection
|
||||
// Find the part under the cursor
|
||||
SymbolPartP part = findPart(pos);
|
||||
if (control.selected_parts.find(part) != control.selected_parts.end()) {
|
||||
// already selected, don't change selection
|
||||
// instead switch between rotate and resize mode
|
||||
rotate = !rotate;
|
||||
}
|
||||
} else if (!ev.ShiftDown()) {
|
||||
// select nothing
|
||||
control.selected_parts.clear();
|
||||
}
|
||||
// selection has changed
|
||||
updateBoundingBox();
|
||||
control.signalSelectionChange();
|
||||
}
|
||||
control.Refresh(false);
|
||||
}
|
||||
@@ -261,7 +275,12 @@ void SymbolSelectEditor::onMouseMove (const Vector2D& from, const Vector2D& to,
|
||||
control.Refresh(false);
|
||||
}
|
||||
|
||||
template <typename Event> int snap(Event& ev) {
|
||||
return settings.symbol_grid_snap != ev.ShiftDown() ? settings.symbol_grid_size : 0; // shift toggles snap
|
||||
}
|
||||
|
||||
void SymbolSelectEditor::onMouseDrag (const Vector2D& from, const Vector2D& to, wxMouseEvent& ev) {
|
||||
have_dragged = true;
|
||||
if (control.selected_parts.empty()) return;
|
||||
if (!isEditing()) {
|
||||
// we don't have an action yet, determine what to do
|
||||
@@ -294,6 +313,7 @@ void SymbolSelectEditor::onMouseDrag (const Vector2D& from, const Vector2D& to,
|
||||
if (moveAction) {
|
||||
// move the selected parts
|
||||
moveAction->constrain = ev.ControlDown();
|
||||
moveAction->snap = snap(ev);
|
||||
moveAction->move(to - from);
|
||||
} else if (scaleAction) {
|
||||
// scale the selected parts
|
||||
@@ -303,7 +323,9 @@ void SymbolSelectEditor::onMouseDrag (const Vector2D& from, const Vector2D& to,
|
||||
if (scaleX == 1) dMax.x = delta.x;
|
||||
if (scaleY == -1) dMin.y = delta.y;
|
||||
if (scaleY == 1) dMax.y = delta.y;
|
||||
scaleAction->constrain = ev.ControlDown();
|
||||
// scaleAction->constrain = ev.ControlDown();
|
||||
scaleAction->constrain = true; // always constrain diagonal scaling
|
||||
scaleAction->snap = snap(ev);
|
||||
scaleAction->move(dMin, dMax);
|
||||
} else if (rotateAction) {
|
||||
// rotate the selected parts
|
||||
@@ -315,7 +337,8 @@ void SymbolSelectEditor::onMouseDrag (const Vector2D& from, const Vector2D& to,
|
||||
Vector2D delta = to-from;
|
||||
delta = delta.mul(Vector2D(scaleY, scaleX));
|
||||
delta = delta.div(maxV - minV);
|
||||
shearAction->constrain = ev.ControlDown();
|
||||
// shearAction->constrain = ev.ControlDown();
|
||||
shearAction->snap = snap(ev);
|
||||
shearAction->move(delta);
|
||||
}
|
||||
control.Refresh(false);
|
||||
@@ -324,21 +347,28 @@ void SymbolSelectEditor::onMouseDrag (const Vector2D& from, const Vector2D& to,
|
||||
// ----------------------------------------------------------------------------- : Key Events
|
||||
|
||||
void SymbolSelectEditor::onKeyChange (wxKeyEvent& ev) {
|
||||
if (ev.GetKeyCode() == WXK_CONTROL) {
|
||||
if (ev.GetKeyCode() == WXK_CONTROL || ev.GetKeyCode() == WXK_SHIFT) {
|
||||
// changed constrains
|
||||
if (moveAction) {
|
||||
moveAction->constrain = ev.ControlDown();
|
||||
moveAction->snap = snap(ev);
|
||||
moveAction->move(Vector2D()); // apply constrains
|
||||
control.Refresh(false);
|
||||
} else if (scaleAction) {
|
||||
// only allow constrained scaling in diagonal direction
|
||||
scaleAction->constrain = ev.ControlDown();
|
||||
// scaleAction->constrain = ev.ControlDown();
|
||||
scaleAction->constrain = true; // always constrain diagonal scaling
|
||||
scaleAction->snap = snap(ev);
|
||||
scaleAction->update(); // apply constrains
|
||||
control.Refresh(false);
|
||||
} else if (rotateAction) {
|
||||
rotateAction->constrain = ev.ControlDown();
|
||||
rotateAction->rotateBy(0); // apply constrains
|
||||
control.Refresh(false);
|
||||
} else if (shearAction) {
|
||||
shearAction->snap = snap(ev);
|
||||
shearAction->move(Vector2D()); // apply constrains
|
||||
control.Refresh(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -408,7 +438,7 @@ void SymbolSelectEditor::updateBoundingBox() {
|
||||
minV = piecewise_min(minV, p->min_pos);
|
||||
maxV = piecewise_max(maxV, p->max_pos);
|
||||
}
|
||||
// Find rotation center
|
||||
/* // Find rotation center
|
||||
center = Vector2D(0,0);
|
||||
FOR_EACH(p, control.selected_parts) {
|
||||
Vector2D size = p->max_pos - p->min_pos;
|
||||
@@ -416,6 +446,8 @@ void SymbolSelectEditor::updateBoundingBox() {
|
||||
center += p->min_pos + size;
|
||||
}
|
||||
center /= control.selected_parts.size();
|
||||
*/
|
||||
center = (minV + maxV) / 2;
|
||||
}
|
||||
|
||||
void SymbolSelectEditor::resetActions() {
|
||||
|
||||
@@ -78,6 +78,8 @@ class SymbolSelectEditor : public SymbolEditorBase {
|
||||
double startAngle;
|
||||
// what side are we dragging/rotating on?
|
||||
int scaleX, scaleY;
|
||||
// have we dragged?
|
||||
bool have_dragged;
|
||||
// Do we want to rotate?
|
||||
bool rotate;
|
||||
// Graphics assets
|
||||
|
||||
@@ -96,6 +96,9 @@ void SymbolWindow::init(Window* parent, SymbolP symbol) {
|
||||
tb->AddSeparator();
|
||||
tb->AddTool(ID_EDIT_UNDO, _("Undo"), load_resource_tool_image(_("undo")), wxNullBitmap, wxITEM_NORMAL, _TOOL_1_("undo",wxEmptyString));
|
||||
tb->AddTool(ID_EDIT_REDO, _("Redo"), load_resource_tool_image(_("redo")), wxNullBitmap, wxITEM_NORMAL, _TOOL_1_("redo",wxEmptyString));
|
||||
tb->AddSeparator();
|
||||
tb->AddTool(ID_VIEW_GRID, _("Grid"), load_resource_tool_image(_("grid")), wxNullBitmap, wxITEM_CHECK, _TOOL_("grid"));
|
||||
tb->AddTool(ID_VIEW_GRID_SNAP,_("Snap"), load_resource_tool_image(_("grid_snap")), wxNullBitmap, wxITEM_CHECK, _TOOL_("snap"));
|
||||
tb->Realize();
|
||||
|
||||
// Edit mode toolbar
|
||||
|
||||
+1
-1
@@ -122,7 +122,7 @@ wxIcon load_resource_icon(const String& name) {
|
||||
|
||||
wxBitmap load_resource_tool_image(const String& name) {
|
||||
#if defined(__WXMSW__)
|
||||
return wxBitmap(_("tool/") + name);
|
||||
return load_resource_image(_("tool/") + name);
|
||||
#else
|
||||
return load_resource_image(_("tool/") + name);
|
||||
#endif
|
||||
|
||||
@@ -46,8 +46,6 @@ wxCursor load_resource_cursor(const String& name);
|
||||
wxIcon load_resource_icon(const String& name);
|
||||
|
||||
/// Load an image for use in a toolbar (filename: tool/...) from a resource
|
||||
/** Note: should ONLY be used for ".bmp" images for now
|
||||
*/
|
||||
wxBitmap load_resource_tool_image(const String& name);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Platform look
|
||||
|
||||
Reference in New Issue
Block a user