mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 21:06:59 -04:00
New rotation system (see forum thread).
Major changes: - when rotating, the top left corner of the rectangle stays in place. - ValueViewers get a dc that is pre-rotated/translated for them, i.e. (0,0) is the top-left of the viewer (with ValueViewer::getRotation). - moved 'angle' from individual Styles to the Style base class. - any rotation angle is now possible. angle is still an int for now. This warrants a version bump git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@782 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -210,15 +210,19 @@ void DataEditor::onLeftDown(wxMouseEvent& ev) {
|
||||
}
|
||||
void DataEditor::onLeftUp(wxMouseEvent& ev) {
|
||||
if (HasCapture()) ReleaseMouse();
|
||||
RealPoint pos = mousePoint(ev);
|
||||
if (current_editor && current_viewer && current_viewer->containsPoint(pos)) {
|
||||
current_editor->onLeftUp(pos, ev);
|
||||
if (current_editor && current_viewer) {
|
||||
RealPoint pos = mousePoint(ev, *current_viewer);
|
||||
if (current_viewer->containsPoint(pos)) {
|
||||
current_editor->onLeftUp(pos, ev);
|
||||
}
|
||||
}
|
||||
}
|
||||
void DataEditor::onLeftDClick(wxMouseEvent& ev) {
|
||||
RealPoint pos = mousePoint(ev);
|
||||
if (current_editor && current_viewer && current_viewer->containsPoint(pos)) {
|
||||
current_editor->onLeftDClick(pos, ev);
|
||||
if (current_editor && current_viewer) {
|
||||
RealPoint pos = mousePoint(ev, *current_viewer);
|
||||
if (current_viewer->containsPoint(pos)) {
|
||||
current_editor->onLeftDClick(pos, ev);
|
||||
}
|
||||
}
|
||||
}
|
||||
void DataEditor::onRightDown(wxMouseEvent& ev) {
|
||||
@@ -227,22 +231,25 @@ void DataEditor::onRightDown(wxMouseEvent& ev) {
|
||||
selectField(ev, &ValueEditor::onRightDown);
|
||||
}
|
||||
void DataEditor::onMouseWheel(wxMouseEvent& ev) {
|
||||
RealPoint pos = mousePoint(ev);
|
||||
if (current_editor && current_viewer && current_viewer->containsPoint(pos)) {
|
||||
if (current_editor->onMouseWheel(pos, ev)) return;
|
||||
if (current_editor && current_viewer) {
|
||||
RealPoint pos = mousePoint(ev, *current_viewer);
|
||||
if (current_viewer->containsPoint(pos)) {
|
||||
if (current_editor->onMouseWheel(pos, ev)) return;
|
||||
}
|
||||
}
|
||||
ev.Skip();
|
||||
}
|
||||
|
||||
void DataEditor::onMotion(wxMouseEvent& ev) {
|
||||
RealPoint pos = mousePoint(ev);
|
||||
if (current_editor && ev.LeftIsDown()) {
|
||||
if (current_editor && current_viewer) {
|
||||
RealPoint pos = mousePoint(ev, *current_viewer);
|
||||
current_editor->onMotion(pos, ev);
|
||||
}
|
||||
if (!HasCapture()) {
|
||||
// find editor under mouse
|
||||
ValueViewer* new_hovered_viewer = nullptr;
|
||||
FOR_EACH_REVERSE(v,viewers) { // find high z index fields first
|
||||
RealPoint pos = mousePoint(ev, *v);
|
||||
if (v->containsPoint(pos) && v->getField()->editable) {
|
||||
new_hovered_viewer = v.get();
|
||||
break;
|
||||
@@ -250,6 +257,7 @@ void DataEditor::onMotion(wxMouseEvent& ev) {
|
||||
}
|
||||
if (hovered_viewer && hovered_viewer != new_hovered_viewer) {
|
||||
ValueEditor* e = hovered_viewer->getEditor();
|
||||
RealPoint pos = mousePoint(ev, *hovered_viewer);
|
||||
if (e) e->onMouseLeave(pos, ev);
|
||||
}
|
||||
hovered_viewer = new_hovered_viewer;
|
||||
@@ -257,6 +265,7 @@ void DataEditor::onMotion(wxMouseEvent& ev) {
|
||||
wxFrame* frame = dynamic_cast<wxFrame*>( wxGetTopLevelParent(this) );
|
||||
if (hovered_viewer) {
|
||||
ValueEditor* e = hovered_viewer->getEditor();
|
||||
RealPoint pos = mousePoint(ev, *hovered_viewer);
|
||||
wxCursor c;
|
||||
if (e) c = e->cursor(pos);
|
||||
if (c.Ok()) SetCursor(c);
|
||||
@@ -274,7 +283,7 @@ void DataEditor::onMouseLeave(wxMouseEvent& ev) {
|
||||
// on mouse leave for editor
|
||||
if (hovered_viewer) {
|
||||
ValueEditor* e = hovered_viewer->getEditor();
|
||||
if (e) e->onMouseLeave(mousePoint(ev), ev);
|
||||
if (e) e->onMouseLeave(mousePoint(ev,*hovered_viewer), ev);
|
||||
hovered_viewer = nullptr;
|
||||
}
|
||||
// clear status text
|
||||
@@ -283,18 +292,20 @@ void DataEditor::onMouseLeave(wxMouseEvent& ev) {
|
||||
}
|
||||
|
||||
void DataEditor::selectField(wxMouseEvent& ev, bool (ValueEditor::*event)(const RealPoint&, wxMouseEvent&)) {
|
||||
RealPoint pos = mousePoint(ev);
|
||||
// change viewer/editor
|
||||
ValueEditor* old_editor = current_editor;
|
||||
selectFieldNoEvents(pos);
|
||||
selectFieldNoEvents(ev);
|
||||
if (old_editor != current_editor) {
|
||||
// selection has changed, send focus events
|
||||
if (old_editor) old_editor->onLoseFocus();
|
||||
if (current_editor) current_editor->onFocus();
|
||||
}
|
||||
// pass event
|
||||
if (current_editor && current_viewer && current_viewer->containsPoint(pos)) {
|
||||
(current_editor->*event)(pos, ev);
|
||||
if (current_editor && current_viewer) {
|
||||
RealPoint pos = mousePoint(ev, *current_viewer);
|
||||
if (current_viewer->containsPoint(pos)) {
|
||||
(current_editor->*event)(pos, ev);
|
||||
}
|
||||
}
|
||||
// refresh?
|
||||
if (old_editor != current_editor) {
|
||||
@@ -303,10 +314,10 @@ void DataEditor::selectField(wxMouseEvent& ev, bool (ValueEditor::*event)(const
|
||||
onChange();
|
||||
}
|
||||
}
|
||||
void DataEditor::selectFieldNoEvents(const RealPoint& p) {
|
||||
void DataEditor::selectFieldNoEvents(const wxMouseEvent& ev) {
|
||||
FOR_EACH_EDITOR_REVERSE { // find high z index fields first
|
||||
if (v->getField()->editable && (v->containsPoint(p) ||
|
||||
(nativeLook() && p.y >= v->getStyle()->top && p.y < v->getStyle()->bottom) )) {
|
||||
if (v->getField()->editable && (v->containsPoint(mousePoint(ev,*v)) ||
|
||||
(nativeLook() && ev.GetY() >= v->getStyle()->top && ev.GetY() < v->getStyle()->bottom) )) {
|
||||
current_viewer = v.get();
|
||||
current_editor = e;
|
||||
return;
|
||||
@@ -314,8 +325,10 @@ void DataEditor::selectFieldNoEvents(const RealPoint& p) {
|
||||
}
|
||||
}
|
||||
|
||||
RealPoint DataEditor::mousePoint(const wxMouseEvent& ev) {
|
||||
return getRotation().trInv(RealPoint(ev.GetX(), ev.GetY()));
|
||||
RealPoint DataEditor::mousePoint(const wxMouseEvent& ev, const ValueViewer& viewer) {
|
||||
Rotation rot = getRotation();
|
||||
Rotater r(rot,viewer.getRotation());
|
||||
return rot.trInv(RealPoint(ev.GetX(), ev.GetY()));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Keyboard events
|
||||
|
||||
@@ -118,9 +118,9 @@ class DataEditor : public CardViewer {
|
||||
/** Sends an event to the event function of the current viewer */
|
||||
void selectField(wxMouseEvent& ev, bool (ValueEditor::*event)(const RealPoint&, wxMouseEvent&));
|
||||
// selectField, but don't send events
|
||||
void selectFieldNoEvents(const RealPoint& pos);
|
||||
void selectFieldNoEvents(const wxMouseEvent&);
|
||||
/// Convert mouse coordinates to internal coordinates
|
||||
RealPoint mousePoint(const wxMouseEvent&);
|
||||
RealPoint mousePoint(const wxMouseEvent&, const ValueViewer& viewer);
|
||||
|
||||
// Create tab index ordering of the (editable) viewers
|
||||
void createTabIndex();
|
||||
|
||||
@@ -38,7 +38,7 @@ wxSize CardViewer::DoGetBestSize() const {
|
||||
void CardViewer::redraw(const ValueViewer& v) {
|
||||
if (drawing) return;
|
||||
up_to_date = false;
|
||||
RefreshRect(getRotation().tr(v.boundingBox()), false);
|
||||
RefreshRect(getRotation().trRectToBB(v.boundingBox()), false);
|
||||
}
|
||||
|
||||
void CardViewer::onChange() {
|
||||
@@ -98,7 +98,7 @@ bool CardViewer::shouldDraw(const ValueViewer& v) const {
|
||||
// int dx = GetScrollPos(wxHORIZONTAL), dy = GetScrollPos(wxVERTICAL);
|
||||
// wxRegion clip = GetUpdateRegion();
|
||||
// clip.Offset(dx, dy);
|
||||
return GetUpdateRegion().Contains(getRotation().tr(v.boundingBox().toRect()).toRect()) != wxOutRegion;
|
||||
return GetUpdateRegion().Contains(getRotation().trRectToBB(v.boundingBox().toRect()).toRect()) != wxOutRegion;
|
||||
}
|
||||
|
||||
// helper class for overdrawDC()
|
||||
@@ -133,7 +133,7 @@ Rotation CardViewer::getRotation() const {
|
||||
if (!stylesheet) stylesheet = set->stylesheet;
|
||||
StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet);
|
||||
int dx = GetScrollPos(wxHORIZONTAL), dy = GetScrollPos(wxVERTICAL);
|
||||
return Rotation(ss.card_angle(), stylesheet->getCardRect().move(-dx,-dy,0,0), ss.card_zoom(), 1.0, true);
|
||||
return Rotation(ss.card_angle(), stylesheet->getCardRect().move(-dx,-dy,0,0), ss.card_zoom(), 1.0, ROTATION_ATTACH_TOP_LEFT);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Event table
|
||||
|
||||
@@ -39,14 +39,14 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) {
|
||||
Style& s = *v.getStyle();
|
||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||
dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
||||
dc.DrawRectangle(s.getRect().grow(1));
|
||||
dc.DrawRectangle(s.getInternalRect().grow(1));
|
||||
// draw label
|
||||
dc.SetFont(*wxNORMAL_FONT);
|
||||
// TODO : tr using stylesheet or using game?
|
||||
dc.DrawText(tr(*set->game, s.fieldP->name, capitalize_sentence(s.fieldP->name)),
|
||||
RealPoint(margin_left, s.top + 1));
|
||||
RealPoint(margin_left - s.left, 1));
|
||||
// draw 3D border
|
||||
draw_control_border(this, dc.getDC(), dc.tr(RealRect(s.left - 1, s.top - 1, s.width + 2, s.height + 2)));
|
||||
draw_control_border(this, dc.getDC(), dc.trRectStraight(s.getInternalRect().grow(1)));
|
||||
}
|
||||
// draw viewer
|
||||
v.draw(dc);
|
||||
@@ -152,10 +152,10 @@ void NativeLookEditor::onScroll(wxScrollWinEvent& ev) {
|
||||
}
|
||||
void NativeLookEditor::onMouseWheel(wxMouseEvent& ev) {
|
||||
// send scroll event to field under cursor
|
||||
RealPoint pos = mousePoint(ev);
|
||||
FOR_EACH_EDITOR_REVERSE { // find high z index fields first
|
||||
RealPoint pos = mousePoint(ev, *v);
|
||||
if (v->containsPoint(pos) && v->getField()->editable) {
|
||||
bool scrolled = e->onMouseWheel(mousePoint(ev), ev);
|
||||
bool scrolled = e->onMouseWheel(pos, ev);
|
||||
if (scrolled) return;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user