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