mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 05:07: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:
@@ -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();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user