mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -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:
@@ -303,7 +303,7 @@ void SymbolFont::getCharInfo(RotatedDC& dc, Context& ctx, double font_size, cons
|
||||
|
||||
RealSize SymbolFont::symbolSize(Context& ctx, double font_size, const DrawableSymbol& sym) {
|
||||
if (sym.symbol) {
|
||||
return addDiagonal(sym.symbol->size(ctx, *this, font_size), spacing);
|
||||
return add_diagonal(sym.symbol->size(ctx, *this, font_size), spacing);
|
||||
} else {
|
||||
return defaultSymbolSize(ctx, font_size);
|
||||
}
|
||||
@@ -312,9 +312,9 @@ RealSize SymbolFont::symbolSize(Context& ctx, double font_size, const DrawableSy
|
||||
RealSize SymbolFont::defaultSymbolSize(Context& ctx, double font_size) {
|
||||
SymbolInFont* def = defaultSymbol();
|
||||
if (def) {
|
||||
return addDiagonal(def->size(ctx, *this, font_size), spacing);
|
||||
return add_diagonal(def->size(ctx, *this, font_size), spacing);
|
||||
} else {
|
||||
return addDiagonal(RealSize(1,1), spacing);
|
||||
return add_diagonal(RealSize(1,1), spacing);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -382,7 +382,7 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars,
|
||||
accept_word = true;
|
||||
}
|
||||
// Add size of the character
|
||||
word_size = addHorizontal(word_size, c.size);
|
||||
word_size = add_horizontal(word_size, c.size);
|
||||
positions_word.push_back(word_size.width);
|
||||
// Did the word become too long?
|
||||
if (style.field().multi_line && !break_now) {
|
||||
@@ -411,7 +411,7 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars,
|
||||
line.positions.push_back(line_size.width + p);
|
||||
}
|
||||
// add size; next word
|
||||
line_size = addHorizontal(line_size, word_size);
|
||||
line_size = add_horizontal(line_size, word_size);
|
||||
word_size = RealSize(0, 0);
|
||||
word_start = i + 1;
|
||||
positions_word.clear();
|
||||
@@ -445,7 +445,7 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars,
|
||||
FOR_EACH(p, positions_word) {
|
||||
line.positions.push_back(line_size.width + p);
|
||||
}
|
||||
line_size = addHorizontal(line_size, word_size);
|
||||
line_size = add_horizontal(line_size, word_size);
|
||||
// the last line
|
||||
if (line_size.height < 0.01 && !lines.empty()) {
|
||||
// if a line has 0 height, use the height of the line above it, but at most once
|
||||
@@ -477,7 +477,7 @@ void TextViewer::alignLines(RotatedDC& dc, const vector<CharInfo>& chars, const
|
||||
if (l.line_height) break; // not an empty line
|
||||
}
|
||||
// amount to shift all lines vertically
|
||||
RealSize s = addDiagonal(
|
||||
RealSize s = add_diagonal(
|
||||
dc.getInternalSize(),
|
||||
-RealSize(style.padding_left+style.padding_right, style.padding_top + style.padding_bottom));
|
||||
double vdelta = align_delta_y(style.alignment, s.height, height);
|
||||
|
||||
@@ -41,12 +41,11 @@ void MultipleChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
}
|
||||
|
||||
void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const String& choice, bool active) {
|
||||
double margin = 0, height = 0;
|
||||
RealSize size;
|
||||
if (nativeLook() && (style().render_style & RENDER_CHECKLIST)) {
|
||||
height = 10;
|
||||
margin = 11;
|
||||
wxRect rect = dc.tr(RealRect(pos,RealSize(10,10)));
|
||||
wxRect rect = dc.tr(RealRect(pos + RealSize(1,1), RealSize(12,12)));
|
||||
draw_checkbox(nullptr, dc.getDC(), rect, active); // TODO
|
||||
size = add_horizontal(size, RealSize(14,16));
|
||||
}
|
||||
if (style().render_style & RENDER_IMAGE) {
|
||||
map<String,ScriptableImage>::iterator it = style().choice_images.find(cannocial_name_form(choice));
|
||||
@@ -54,21 +53,22 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const
|
||||
ScriptImageP i = it->second.update(viewer.getContext(), *viewer.stylesheet, 0, 0);
|
||||
if (i) {
|
||||
// TODO : alignment?
|
||||
dc.DrawImage(i->image, pos, i->combine == COMBINE_NORMAL ? style().combine : i->combine);
|
||||
margin += dc.trInvS(i->image.GetWidth()) + 1;
|
||||
height = max(height, dc.trInvS(i->image.GetHeight()));
|
||||
dc.DrawImage(i->image, pos + RealSize(size.width, 0), i->combine == COMBINE_NORMAL ? style().combine : i->combine);
|
||||
size = add_horizontal(size, dc.trInv(RealSize(i->image.GetWidth() + 1, i->image.GetHeight())));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (style().render_style & RENDER_TEXT) {
|
||||
// draw text
|
||||
// TODO: alignment
|
||||
dc.DrawText(tr(*viewer.stylesheet, choice, capitalize(choice)), pos + RealSize(margin, 0));
|
||||
// TODO: determine size
|
||||
String text = tr(*viewer.stylesheet, choice, capitalize(choice));
|
||||
RealSize text_size = dc.GetTextExtent(text);
|
||||
dc.DrawText(text, align_in_rect(ALIGN_MIDDLE_LEFT, text_size,
|
||||
RealRect(pos + RealSize(size.width + 1, 0), RealSize(0,size.height))));
|
||||
size = add_horizontal(size, text_size);
|
||||
}
|
||||
if (style().direction == HORIZONTAL) {
|
||||
pos.x += margin + style().spacing;
|
||||
pos.x += size.width + style().spacing;
|
||||
} else {
|
||||
pos.y += height + style().spacing;
|
||||
pos.y += size.height + style().spacing;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ class RealSize {
|
||||
* #### + $$$ = ####$$$
|
||||
* #### ####...
|
||||
*/
|
||||
inline RealSize addHorizontal(const RealSize& a, const RealSize& b) {
|
||||
inline RealSize add_horizontal(const RealSize& a, const RealSize& b) {
|
||||
return RealSize(a.width + b.width, max(a.height, b.height));
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ inline RealSize addHorizontal(const RealSize& a, const RealSize& b) {
|
||||
* $$$.
|
||||
* $$$.
|
||||
*/
|
||||
inline RealSize addVertical(const RealSize& a, const RealSize& b) {
|
||||
inline RealSize add_vertical(const RealSize& a, const RealSize& b) {
|
||||
return RealSize(max(a.width, b.width), a.height + b.height);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ inline RealSize addVertical(const RealSize& a, const RealSize& b) {
|
||||
* ....$$$
|
||||
* ....$$$
|
||||
*/
|
||||
inline RealSize addDiagonal(const RealSize& a, const RealSize& b) {
|
||||
inline RealSize add_diagonal(const RealSize& a, const RealSize& b) {
|
||||
return RealSize(a.width + b.width, a.height + b.height);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user