mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 21:06:59 -04:00
added scrollbar to NativeLookEditor
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@223 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -210,7 +210,7 @@ void DataEditor::onMouseLeave(wxMouseEvent& ev) {
|
||||
if (frame) frame->SetStatusText(wxEmptyString);
|
||||
}
|
||||
|
||||
void DataEditor::selectField(wxMouseEvent& ev, void (ValueEditor::*event)(const RealPoint&, wxMouseEvent&)) {
|
||||
void DataEditor::selectField(wxMouseEvent& ev, bool (ValueEditor::*event)(const RealPoint&, wxMouseEvent&)) {
|
||||
RealPoint pos = mousePoint(ev);
|
||||
// change viewer/editor
|
||||
ValueEditor* old_editor = current_editor;
|
||||
@@ -242,10 +242,7 @@ void DataEditor::selectFieldNoEvents(const RealPoint& p) {
|
||||
}
|
||||
|
||||
RealPoint DataEditor::mousePoint(const wxMouseEvent& ev) {
|
||||
StyleSheetP stylesheet = set->stylesheetFor(card);
|
||||
StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet);
|
||||
Rotation rot(ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom());
|
||||
return rot.trInv(RealPoint(ev.GetX(), ev.GetY()));
|
||||
return getRotation().trInv(RealPoint(ev.GetX(), ev.GetY()));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Keyboard events
|
||||
|
||||
@@ -67,14 +67,14 @@ class DataEditor : public CardViewer {
|
||||
virtual void onInit();
|
||||
|
||||
// --------------------------------------------------- : Data
|
||||
private:
|
||||
DECLARE_EVENT_TABLE();
|
||||
|
||||
ValueViewer* current_viewer; ///< The currently selected viewer
|
||||
ValueEditor* current_editor; ///< The currently selected editor, corresponding to the viewer
|
||||
vector<ValueViewer*> by_tab_index; ///< The editable viewers, sorted by tab index
|
||||
|
||||
private:
|
||||
// --------------------------------------------------- : Events
|
||||
DECLARE_EVENT_TABLE();
|
||||
|
||||
|
||||
void onLeftDown (wxMouseEvent&);
|
||||
void onLeftUp (wxMouseEvent&);
|
||||
@@ -96,7 +96,7 @@ class DataEditor : public CardViewer {
|
||||
|
||||
/// Changes the selection to the field at the specified coordinates
|
||||
/** Sends an event to the event function of the current viewer */
|
||||
void selectField(wxMouseEvent& ev, void (ValueEditor::*event)(const RealPoint&, wxMouseEvent&));
|
||||
void selectField(wxMouseEvent& ev, bool (ValueEditor::*event)(const RealPoint&, wxMouseEvent&));
|
||||
// selectField, but don't send events
|
||||
void selectFieldNoEvents(const RealPoint& pos);
|
||||
/// Convert mouse coordinates to internal coordinates
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <gui/control/card_viewer.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <data/settings.hpp>
|
||||
#include <render/value/viewer.hpp>
|
||||
#include <wx/dcbuffer.h>
|
||||
|
||||
@@ -32,7 +33,7 @@ wxSize CardViewer::DoGetBestSize() const {
|
||||
|
||||
void CardViewer::redraw(const ValueViewer& v) {
|
||||
up_to_date = false;
|
||||
RefreshRect(v.boundingBox(), false);
|
||||
RefreshRect(getRotation().tr(v.boundingBox()), false);
|
||||
}
|
||||
|
||||
void CardViewer::onChange() {
|
||||
@@ -66,12 +67,16 @@ void CardViewer::onPaint(wxPaintEvent&) {
|
||||
up_to_date = false;
|
||||
}
|
||||
wxBufferedPaintDC dc(this, buffer);
|
||||
dc.SetClippingRegion(GetUpdateRegion());
|
||||
// scrolling
|
||||
// int dx = GetScrollPos(wxHORIZONTAL), dy = GetScrollPos(wxVERTICAL);
|
||||
// dc.SetDeviceOrigin(-dx, -dy);
|
||||
wxRegion clip = GetUpdateRegion();
|
||||
// clip.Offset(dx, dy);
|
||||
dc.SetClippingRegion(clip);
|
||||
// draw
|
||||
if (!up_to_date) {
|
||||
up_to_date = true;
|
||||
dc.BeginDrawing();
|
||||
draw(dc);
|
||||
dc.EndDrawing();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +85,10 @@ void CardViewer::drawViewer(RotatedDC& dc, ValueViewer& v) {
|
||||
}
|
||||
|
||||
bool CardViewer::shouldDraw(const ValueViewer& v) const {
|
||||
return GetUpdateRegion().Contains(v.boundingBox().toRect()) != wxOutRegion;
|
||||
// int dx = GetScrollPos(wxHORIZONTAL), dy = GetScrollPos(wxVERTICAL);
|
||||
// wxRegion clip = GetUpdateRegion();
|
||||
// clip.Offset(dx, dy);
|
||||
return GetUpdateRegion().Contains(getRotation().tr(v.boundingBox().toRect()).toRect()) != wxOutRegion;
|
||||
}
|
||||
|
||||
// helper class for overdrawDC()
|
||||
@@ -102,7 +110,15 @@ shared_ptr<DC> CardViewer::overdrawDC() {
|
||||
// don't call from onPaint
|
||||
assert(!inOnPaint());
|
||||
#endif
|
||||
return shared_ptr<DC>((wxBufferedDC*)(new OverdrawDC(this)));
|
||||
return shared_ptr<DC>((wxBufferedDC*)new OverdrawDC(this));
|
||||
}
|
||||
|
||||
Rotation CardViewer::getRotation() const {
|
||||
// Same as DataViewer::getRotation, only taking into account scrolling
|
||||
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(), true);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Event table
|
||||
|
||||
@@ -33,6 +33,9 @@ class CardViewer : public wxControl, public DataViewer {
|
||||
/// Invalidate and redraw (the area of) a single value viewer
|
||||
void redraw(const ValueViewer&);
|
||||
|
||||
/// The rotation to use
|
||||
virtual Rotation getRotation() const;
|
||||
|
||||
protected:
|
||||
/// Return the desired size of control
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
|
||||
@@ -21,7 +21,8 @@ NativeLookEditor::NativeLookEditor(Window* parent, int id, long style)
|
||||
{}
|
||||
|
||||
Rotation NativeLookEditor::getRotation() const {
|
||||
return Rotation(0, RealRect(RealPoint(0,0),GetClientSize()));
|
||||
int dx = GetScrollPos(wxHORIZONTAL), dy = GetScrollPos(wxVERTICAL);
|
||||
return Rotation(0, RealRect(RealPoint(-dx,-dy),GetClientSize()));
|
||||
}
|
||||
|
||||
void NativeLookEditor::draw(DC& dc) {
|
||||
@@ -43,7 +44,7 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) {
|
||||
dc.DrawText(tr(*set->game, s.fieldP->name, capitalize_sentence(s.fieldP->name)),
|
||||
RealPoint(margin_left, s.top + 1));
|
||||
// draw 3D border
|
||||
draw_control_border(this, dc.getDC(), RealRect(s.left - 1, s.top - 1, s.width + 2, s.height + 2));
|
||||
draw_control_border(this, dc.getDC(), dc.tr(RealRect(s.left - 1, s.top - 1, s.width + 2, s.height + 2)));
|
||||
}
|
||||
// draw viewer
|
||||
v.draw(dc);
|
||||
@@ -52,8 +53,8 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) {
|
||||
void NativeLookEditor::resizeViewers() {
|
||||
// size stuff
|
||||
double y = margin;
|
||||
int w;
|
||||
GetClientSize(&w, 0);
|
||||
int w, h;
|
||||
GetClientSize(&w, &h);
|
||||
const int default_height = 17;
|
||||
// Set editor sizes
|
||||
FOR_EACH(v, viewers) {
|
||||
@@ -70,6 +71,23 @@ void NativeLookEditor::resizeViewers() {
|
||||
if (e) e->determineSize();
|
||||
y += s->height + vspace;
|
||||
}
|
||||
SetVirtualSize(w,y);
|
||||
SetScrollbar(wxVERTICAL, 0, h, y);
|
||||
if (y >= h) {
|
||||
// Doesn't fit vertically, add scrollbar and resize
|
||||
/*
|
||||
y = margin;
|
||||
FOR_EACH(v, viewers) {
|
||||
StyleP s = v->getStyle();
|
||||
ValueEditor* e = v->getEditor();
|
||||
s->top = y;
|
||||
s->width = s->width - wxSystemSettings::GetMetric(wxSYS_VSCROLL_X, this);
|
||||
if (e) e->determineSize();
|
||||
y += s->height + vspace;
|
||||
}
|
||||
*/
|
||||
// create scrollbar
|
||||
}
|
||||
}
|
||||
|
||||
void NativeLookEditor::onInit() {
|
||||
@@ -87,9 +105,65 @@ void NativeLookEditor::onSize(wxSizeEvent& ev) {
|
||||
resizeViewers();
|
||||
Refresh(false);
|
||||
}
|
||||
void NativeLookEditor::onScroll(wxScrollWinEvent& ev) {
|
||||
if (ev.GetOrientation() == wxVERTICAL) {
|
||||
int y = GetScrollPos(wxVERTICAL);
|
||||
int page = GetClientSize().y; // view size
|
||||
// determine new y offset
|
||||
// NOTE: can't use case, these are not constants
|
||||
if (ev.GetEventType() == wxEVT_SCROLLWIN_TOP) {
|
||||
y = 0;
|
||||
} else if (ev.GetEventType() == wxEVT_SCROLLWIN_BOTTOM) {
|
||||
y = numeric_limits<int>::max();
|
||||
} else if (ev.GetEventType() == wxEVT_SCROLLWIN_LINEUP) {
|
||||
y = y - 10;
|
||||
} else if (ev.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN) {
|
||||
y = y + 10;
|
||||
} else if (ev.GetEventType() == wxEVT_SCROLLWIN_PAGEUP) {
|
||||
y = y - page;
|
||||
} else if (ev.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN) {
|
||||
y = y + page;
|
||||
} else if (ev.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK ||
|
||||
ev.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE) {
|
||||
y = ev.GetPosition();
|
||||
}
|
||||
scrollTo(wxVERTICAL, y);
|
||||
}
|
||||
}
|
||||
void NativeLookEditor::onMouseWheel(wxMouseEvent& ev) {
|
||||
if (current_editor) {
|
||||
bool scrolled = current_editor->onMouseWheel(mousePoint(ev), ev);
|
||||
if (scrolled) return;
|
||||
}
|
||||
int toScroll = 10 * ev.GetWheelRotation() * ev.GetLinesPerAction() / ev.GetWheelDelta(); // note: up is positive
|
||||
int y = GetScrollPos(wxVERTICAL);
|
||||
scrollTo(wxVERTICAL, y - toScroll);
|
||||
}
|
||||
|
||||
void NativeLookEditor::scrollTo(int direction, int pos) {
|
||||
if (direction == wxVERTICAL) {
|
||||
int y = GetScrollPos(wxVERTICAL);
|
||||
int height = GetVirtualSize().y; // height
|
||||
int page = GetClientSize().y; // view size
|
||||
int bottom = max(0, height - page);
|
||||
pos = max(0, min(bottom, pos));
|
||||
if (pos != y) {
|
||||
SetScrollPos(wxVERTICAL, pos);
|
||||
// move child controls
|
||||
FOR_EACH(v, viewers) {
|
||||
ValueEditor* e = v->getEditor();
|
||||
if (e) e->determineSize();
|
||||
}
|
||||
// redraw
|
||||
onChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(NativeLookEditor, DataEditor)
|
||||
EVT_SIZE (NativeLookEditor::onSize)
|
||||
EVT_SCROLLWIN (NativeLookEditor::onScroll)
|
||||
EVT_MOUSEWHEEL (NativeLookEditor::onMouseWheel)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
|
||||
@@ -41,6 +41,9 @@ class NativeLookEditor : public DataEditor {
|
||||
DECLARE_EVENT_TABLE();
|
||||
|
||||
void onSize(wxSizeEvent&);
|
||||
void onScroll(wxScrollWinEvent&);
|
||||
void onMouseWheel(wxMouseEvent&);
|
||||
void scrollTo(int direction, int pos);
|
||||
/// Resize the viewers so they match with this control
|
||||
void resizeViewers();
|
||||
};
|
||||
|
||||
@@ -307,18 +307,19 @@ void DropDownList::onMotion(wxMouseEvent& ev) {
|
||||
|
||||
// ----------------------------------------------------------------------------- : DropDownList : Parent events
|
||||
|
||||
void DropDownList::onMouseInParent(wxMouseEvent& ev, bool open_in_place) {
|
||||
bool DropDownList::onMouseInParent(wxMouseEvent& ev, bool open_in_place) {
|
||||
if (IsShown()) hide(false);
|
||||
else show(open_in_place, wxPoint(ev.GetX(), ev.GetY()));
|
||||
return true;
|
||||
}
|
||||
|
||||
void DropDownList::onCharInParent(wxKeyEvent& ev) {
|
||||
bool DropDownList::onCharInParent(wxKeyEvent& ev) {
|
||||
// keyboard codes
|
||||
int k = ev.GetKeyCode();
|
||||
if (IsShown()) {
|
||||
if (open_sub_menu) {
|
||||
// sub menu always takes keys
|
||||
open_sub_menu->onCharInParent(ev);
|
||||
return open_sub_menu->onCharInParent(ev);
|
||||
} else {
|
||||
switch (k) {
|
||||
case WXK_UP:
|
||||
@@ -356,15 +357,18 @@ void DropDownList::onCharInParent(wxKeyEvent& ev) {
|
||||
selected_item = index;
|
||||
showSubMenu();
|
||||
Refresh(false);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if (k==WXK_SPACE || k==WXK_RETURN || k==WXK_DOWN) {
|
||||
// drop down list is not shown yet, show it now
|
||||
show(false, wxPoint(0,0));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : DropDownList : Event table
|
||||
|
||||
@@ -35,9 +35,9 @@ class DropDownList : public wxPopupWindow {
|
||||
|
||||
// --------------------------------------------------- : Parent control
|
||||
/// Takes all keyboard events from a FieldEditor
|
||||
void onCharInParent(wxKeyEvent&);
|
||||
bool onCharInParent(wxKeyEvent&);
|
||||
/// Takes a mouse event from the parent, show/hide as appropriate
|
||||
void onMouseInParent(wxMouseEvent&, bool open_in_place);
|
||||
bool onMouseInParent(wxMouseEvent&, bool open_in_place);
|
||||
|
||||
protected:
|
||||
// --------------------------------------------------- : Selection
|
||||
|
||||
+2
-1
@@ -37,9 +37,10 @@ int focused_control(const Window* window) {
|
||||
/// Fill a DC with a single color
|
||||
void clearDC(DC& dc, const wxBrush& brush) {
|
||||
wxSize size = dc.GetSize();
|
||||
wxPoint pos = dc.GetDeviceOrigin(); // don't you love undocumented methods?
|
||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||
dc.SetBrush(brush);
|
||||
dc.DrawRectangle(0, 0, size.GetWidth(), size.GetHeight());
|
||||
dc.DrawRectangle(-pos.x, -pos.y, size.GetWidth(), size.GetHeight());
|
||||
}
|
||||
|
||||
void clearDC_black(DC& dc) {
|
||||
|
||||
@@ -228,13 +228,13 @@ ChoiceValueEditor::~ChoiceValueEditor() {
|
||||
thumbnail_thread.abort(this);
|
||||
}
|
||||
|
||||
void ChoiceValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
bool ChoiceValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
//HACK TODO REMOVEME
|
||||
thumbnail_thread.abortAll();
|
||||
drop_down->onMouseInParent(ev, style().popup_style == POPUP_DROPDOWN_IN_PLACE && !nativeLook());
|
||||
return drop_down->onMouseInParent(ev, style().popup_style == POPUP_DROPDOWN_IN_PLACE && !nativeLook());
|
||||
}
|
||||
void ChoiceValueEditor::onChar(wxKeyEvent& ev) {
|
||||
drop_down->onCharInParent(ev);
|
||||
bool ChoiceValueEditor::onChar(wxKeyEvent& ev) {
|
||||
return drop_down->onCharInParent(ev);
|
||||
}
|
||||
void ChoiceValueEditor::onLoseFocus() {
|
||||
drop_down->hide(false);
|
||||
@@ -243,7 +243,7 @@ void ChoiceValueEditor::onLoseFocus() {
|
||||
void ChoiceValueEditor::draw(RotatedDC& dc) {
|
||||
ChoiceValueViewer::draw(dc);
|
||||
if (nativeLook()) {
|
||||
draw_drop_down_arrow(&editor(), dc.getDC(), style().getRect().grow(1), drop_down->IsShown());
|
||||
draw_drop_down_arrow(&editor(), dc.getDC(), dc.tr(style().getRect().grow(1)), drop_down->IsShown());
|
||||
}
|
||||
}
|
||||
void ChoiceValueEditor::determineSize(bool) {
|
||||
|
||||
@@ -25,8 +25,8 @@ class ChoiceValueEditor : public ChoiceValueViewer, public ValueEditor {
|
||||
~ChoiceValueEditor();
|
||||
|
||||
// --------------------------------------------------- : Events
|
||||
virtual void onLeftDown(const RealPoint& pos, wxMouseEvent& ev);
|
||||
virtual void onChar(wxKeyEvent& ev);
|
||||
virtual bool onLeftDown(const RealPoint& pos, wxMouseEvent& ev);
|
||||
virtual bool onChar(wxKeyEvent& ev);
|
||||
virtual void onLoseFocus();
|
||||
|
||||
virtual void draw(RotatedDC& dc);
|
||||
|
||||
@@ -128,11 +128,11 @@ IMPLEMENT_VALUE_EDITOR(Color)
|
||||
, drop_down(new DropDownColorList(&editor(), *this))
|
||||
{}
|
||||
|
||||
void ColorValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
drop_down->onMouseInParent(ev, !nativeLook());
|
||||
bool ColorValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
return drop_down->onMouseInParent(ev, !nativeLook());
|
||||
}
|
||||
void ColorValueEditor::onChar(wxKeyEvent& ev) {
|
||||
drop_down->onCharInParent(ev);
|
||||
bool ColorValueEditor::onChar(wxKeyEvent& ev) {
|
||||
return drop_down->onCharInParent(ev);
|
||||
}
|
||||
void ColorValueEditor::onLoseFocus() {
|
||||
drop_down->hide(false);
|
||||
@@ -141,7 +141,7 @@ void ColorValueEditor::onLoseFocus() {
|
||||
void ColorValueEditor::draw(RotatedDC& dc) {
|
||||
ColorValueViewer::draw(dc);
|
||||
if (nativeLook()) {
|
||||
draw_drop_down_arrow(&editor(), dc.getDC(), style().getRect().grow(1), drop_down->IsShown());
|
||||
draw_drop_down_arrow(&editor(), dc.getDC(), dc.tr(style().getRect().grow(1)), drop_down->IsShown());
|
||||
}
|
||||
}
|
||||
void ColorValueEditor::determineSize(bool) {
|
||||
|
||||
@@ -23,8 +23,8 @@ class ColorValueEditor : public ColorValueViewer, public ValueEditor {
|
||||
DECLARE_VALUE_EDITOR(Color);
|
||||
|
||||
// --------------------------------------------------- : Events
|
||||
virtual void onLeftDown(const RealPoint& pos, wxMouseEvent& ev);
|
||||
virtual void onChar(wxKeyEvent& ev);
|
||||
virtual bool onLeftDown(const RealPoint& pos, wxMouseEvent& ev);
|
||||
virtual bool onChar(wxKeyEvent& ev);
|
||||
virtual void onLoseFocus();
|
||||
|
||||
virtual void draw(RotatedDC& dc);
|
||||
|
||||
@@ -39,16 +39,16 @@ class ValueEditor {
|
||||
/// This editor loses focus
|
||||
virtual void onLoseFocus() {}
|
||||
|
||||
/// Handle mouse events
|
||||
virtual void onLeftDown (const RealPoint& pos, wxMouseEvent& ev) {}
|
||||
virtual void onLeftUp (const RealPoint& pos, wxMouseEvent& ev) {}
|
||||
virtual void onLeftDClick (const RealPoint& pos, wxMouseEvent& ev) {}
|
||||
virtual void onRightDown (const RealPoint& pos, wxMouseEvent& ev) {}
|
||||
virtual void onMotion (const RealPoint& pos, wxMouseEvent& ev) {}
|
||||
virtual void onMouseWheel (const RealPoint& pos, wxMouseEvent& ev) {}
|
||||
/// Handle mouse events, return true if the event is used
|
||||
virtual bool onLeftDown (const RealPoint& pos, wxMouseEvent& ev) { return false; }
|
||||
virtual bool onLeftUp (const RealPoint& pos, wxMouseEvent& ev) { return false; }
|
||||
virtual bool onLeftDClick (const RealPoint& pos, wxMouseEvent& ev) { return false; }
|
||||
virtual bool onRightDown (const RealPoint& pos, wxMouseEvent& ev) { return false; }
|
||||
virtual bool onMotion (const RealPoint& pos, wxMouseEvent& ev) { return false; }
|
||||
virtual bool onMouseWheel (const RealPoint& pos, wxMouseEvent& ev) { return false; }
|
||||
|
||||
/// Key events
|
||||
virtual void onChar(wxKeyEvent& ev) {}
|
||||
virtual bool onChar(wxKeyEvent& ev) { return false; }
|
||||
|
||||
/// a context menu is requested, add extra items to the menu m
|
||||
/** return false to suppress menu */
|
||||
|
||||
@@ -16,15 +16,14 @@
|
||||
|
||||
IMPLEMENT_VALUE_EDITOR(Image) {}
|
||||
|
||||
void ImageValueEditor::onLeftDClick(const RealPoint&, wxMouseEvent&) {
|
||||
bool ImageValueEditor::onLeftDClick(const RealPoint&, wxMouseEvent&) {
|
||||
String filename = wxFileSelector(_("Open image file"), _(""), _(""), _(""),
|
||||
_("All images|*.bmp;*.jpg;*.png;*.gif|Windows bitmaps (*.bmp)|*.bmp|JPEG images (*.jpg;*.jpeg)|*.jpg;*.jpeg|PNG images (*.png)|*.png|GIF images (*.gif)|*.gif|TIFF images (*.tif;*.tiff)|*.tif;*.tiff"),
|
||||
wxOPEN);
|
||||
if (filename.empty()) {
|
||||
return;
|
||||
} else {
|
||||
if (!filename.empty()) {
|
||||
sliceImage(wxImage(filename));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImageValueEditor::sliceImage(const Image& image) {
|
||||
|
||||
@@ -20,7 +20,7 @@ class ImageValueEditor : public ImageValueViewer, public ValueEditor {
|
||||
public:
|
||||
DECLARE_VALUE_EDITOR(Image);
|
||||
|
||||
virtual void onLeftDClick(const RealPoint&, wxMouseEvent&);
|
||||
virtual bool onLeftDClick(const RealPoint&, wxMouseEvent&);
|
||||
|
||||
// --------------------------------------------------- : Clipboard
|
||||
|
||||
|
||||
@@ -13,10 +13,11 @@
|
||||
|
||||
IMPLEMENT_VALUE_EDITOR(Symbol) {}
|
||||
|
||||
void SymbolValueEditor::onLeftDClick(const RealPoint& pos, wxMouseEvent&) {
|
||||
bool SymbolValueEditor::onLeftDClick(const RealPoint& pos, wxMouseEvent&) {
|
||||
// TODO : 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;
|
||||
}
|
||||
|
||||
void SymbolValueEditor::determineSize(bool) {
|
||||
|
||||
@@ -20,7 +20,7 @@ class SymbolValueEditor : public SymbolValueViewer, public ValueEditor {
|
||||
public:
|
||||
DECLARE_VALUE_EDITOR(Symbol);
|
||||
|
||||
virtual void onLeftDClick(const RealPoint& pos, wxMouseEvent&);
|
||||
virtual bool onLeftDClick(const RealPoint& pos, wxMouseEvent&);
|
||||
virtual void determineSize(bool);
|
||||
};
|
||||
|
||||
|
||||
+22
-12
@@ -71,15 +71,17 @@ TextValueEditor::~TextValueEditor() {
|
||||
|
||||
// ----------------------------------------------------------------------------- : Mouse
|
||||
|
||||
void TextValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
bool TextValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
select_words = false;
|
||||
moveSelection(TYPE_INDEX, v.indexAt(style().getRotation().trInv(pos)), !ev.ShiftDown(), MOVE_MID);
|
||||
return true;
|
||||
}
|
||||
void TextValueEditor::onLeftUp(const RealPoint& pos, wxMouseEvent&) {
|
||||
bool TextValueEditor::onLeftUp(const RealPoint& pos, wxMouseEvent&) {
|
||||
// TODO: lookup position of click?
|
||||
return false;
|
||||
}
|
||||
|
||||
void TextValueEditor::onMotion(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
bool TextValueEditor::onMotion(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
if (ev.LeftIsDown()) {
|
||||
size_t index = v.indexAt(style().getRotation().trInv(pos));
|
||||
if (select_words) {
|
||||
@@ -98,27 +100,30 @@ void TextValueEditor::onMotion(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
moveSelection(TYPE_INDEX, index, false, MOVE_MID);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextValueEditor::onLeftDClick(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
bool TextValueEditor::onLeftDClick(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
select_words = true;
|
||||
size_t index = v.indexAt(style().getRotation().trInv(pos));
|
||||
moveSelection(TYPE_INDEX, prevWordBoundry(index), true, MOVE_MID);
|
||||
moveSelection(TYPE_INDEX, nextWordBoundry(index), false, MOVE_MID);
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextValueEditor::onRightDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
bool TextValueEditor::onRightDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
size_t index = v.indexAt(style().getRotation().trInv(pos));
|
||||
if (index < min(selection_start_i, selection_end_i) ||
|
||||
index > max(selection_start_i, selection_end_i)) {
|
||||
// only move cursor when outside selection
|
||||
moveSelection(TYPE_INDEX, index, !ev.ShiftDown(), MOVE_MID);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Keyboard
|
||||
|
||||
void TextValueEditor::onChar(wxKeyEvent& ev) {
|
||||
bool TextValueEditor::onChar(wxKeyEvent& ev) {
|
||||
fixSelection();
|
||||
switch (ev.GetKeyCode()) {
|
||||
case WXK_LEFT:
|
||||
@@ -166,7 +171,7 @@ void TextValueEditor::onChar(wxKeyEvent& ev) {
|
||||
if (selection_start == selection_end) {
|
||||
// Walk over a <sep> as if we are the LEFT key
|
||||
moveSelection(TYPE_CURSOR, prevCharBoundry(selection_end), true, MOVE_LEFT);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
replaceSelection(wxEmptyString, _("Backspace"));
|
||||
@@ -195,6 +200,7 @@ void TextValueEditor::onChar(wxKeyEvent& ev) {
|
||||
replaceSelection(escape(String(ev.GetUnicodeKey(), 1)), _("Typing"));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Other events
|
||||
@@ -629,13 +635,15 @@ void TextValueEditor::determineSize(bool force_fit) {
|
||||
style().angle = 0; // no rotation in nativeLook
|
||||
if (scrollbar) {
|
||||
// muliline, determine scrollbar size
|
||||
Rotation rot = viewer.getRotation();
|
||||
if (!force_fit) style().height = 100;
|
||||
int sbw = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
|
||||
RealPoint pos = rot.tr(style().getPos());
|
||||
scrollbar->SetSize(
|
||||
int(style().left + style().width - sbw + 1),
|
||||
int(style().top - 1),
|
||||
int(sbw),
|
||||
int(style().height + 2));
|
||||
(int)pos.x + rot.trS(style().width) + 1 - sbw,
|
||||
(int)pos.y - 1,
|
||||
(int)sbw,
|
||||
(int)rot.trS(style().height) + 2);
|
||||
v.reset();
|
||||
} else {
|
||||
// Height depends on font
|
||||
@@ -654,13 +662,15 @@ void TextValueEditor::onShow(bool showing) {
|
||||
}
|
||||
}
|
||||
|
||||
void TextValueEditor::onMouseWheel(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
bool TextValueEditor::onMouseWheel(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
if (scrollbar) {
|
||||
int toScroll = ev.GetWheelRotation() * ev.GetLinesPerAction() / ev.GetWheelDelta(); // note: up is positive
|
||||
int target = min(max(scrollbar->GetScrollPos(wxVERTICAL) - toScroll, 0),
|
||||
scrollbar->GetScrollRange(wxVERTICAL) - scrollbar->GetScrollThumb(wxVERTICAL));
|
||||
scrollTo(target);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TextValueEditor::scrollTo(int pos) {
|
||||
|
||||
@@ -36,18 +36,18 @@ class TextValueEditor : public TextValueViewer, public ValueEditor {
|
||||
virtual void onFocus();
|
||||
virtual void onLoseFocus();
|
||||
|
||||
virtual void onLeftDown (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual void onLeftUp (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual void onLeftDClick(const RealPoint& pos, wxMouseEvent&);
|
||||
virtual void onRightDown (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual void onMotion (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual void onMouseWheel(const RealPoint& pos, wxMouseEvent& ev);
|
||||
virtual bool onLeftDown (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual bool onLeftUp (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual bool onLeftDClick(const RealPoint& pos, wxMouseEvent&);
|
||||
virtual bool onRightDown (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual bool onMotion (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual bool onMouseWheel(const RealPoint& pos, wxMouseEvent& ev);
|
||||
|
||||
virtual bool onContextMenu(wxMenu& m, wxContextMenuEvent&);
|
||||
virtual wxMenu* getMenu(int type) const;
|
||||
virtual bool onCommand(int);
|
||||
|
||||
virtual void onChar(wxKeyEvent&);
|
||||
virtual bool onChar(wxKeyEvent&);
|
||||
|
||||
// --------------------------------------------------- : Actions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user