mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Allow ValueViewers to have a bounding box different from the Style's. This closes #64.
This commit is contained in:
@@ -150,7 +150,7 @@ struct CompareTabOrder {
|
||||
};
|
||||
|
||||
bool is_enabled(ValueViewerP const& v) {
|
||||
return v->getField()->editable && v->getStyle()->isVisible();
|
||||
return v->getField()->editable && v->isVisible();
|
||||
}
|
||||
|
||||
bool DataEditor::selectWithTab(vector<ValueViewerP>::iterator const& it) {
|
||||
@@ -210,7 +210,7 @@ bool DataEditor::search(Iterator it, Iterator end, FindInfo& find, bool from_sta
|
||||
for (;it != end; ++it) {
|
||||
ValueViewer* viewer = *it;
|
||||
if (viewer == current_viewer) include = true;
|
||||
if (include && viewer->getField()->editable && viewer->getStyle()->isVisible()) {
|
||||
if (include && viewer->getField()->editable && viewer->isVisible()) {
|
||||
ValueEditor* editor = viewer->getEditor();
|
||||
if (editor) {
|
||||
if (editor && editor->search(find, from_start || viewer != current_viewer)) {
|
||||
|
||||
@@ -44,7 +44,7 @@ void CardViewer::redraw(const ValueViewer& v) {
|
||||
// causing the two viewers to continously refresh.
|
||||
if (drawing_card()) return;
|
||||
up_to_date = false;
|
||||
RefreshRect(getRotation().trRectToBB(v.boundingBox()), false);
|
||||
RefreshRect(getRotation().trRectToBB(v.boundingBoxBorder()), false);
|
||||
}
|
||||
|
||||
void CardViewer::onChange() {
|
||||
@@ -112,7 +112,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().trRectToBB(v.boundingBox().toRect()).toRect()) != wxOutRegion;
|
||||
return GetUpdateRegion().Contains(getRotation().trRectToBB(v.boundingBoxBorder().toRect()).toRect()) != wxOutRegion;
|
||||
}
|
||||
|
||||
// helper class for overdrawDC()
|
||||
|
||||
@@ -35,14 +35,13 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) {
|
||||
ValueEditor* e = v.getEditor();
|
||||
if (!e || e->drawLabel()) {
|
||||
// draw control border and box
|
||||
Style& s = *v.getStyle();
|
||||
draw_control_box(this, dc.getDC(), dc.trRectToBB(s.getInternalRect().grow(1)), current_editor == e, e != nullptr);
|
||||
draw_control_box(this, dc.getDC(), dc.getExternalRect().grow(1), current_editor == e, e != nullptr);
|
||||
// draw label
|
||||
dc.SetFont(*wxNORMAL_FONT);
|
||||
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
|
||||
// TODO : tr using stylesheet or using game?
|
||||
dc.DrawText(tr(getStylePackage(), s.fieldP->caption, identity),
|
||||
RealPoint(margin_left - s.left, 1));
|
||||
dc.DrawText(tr(getStylePackage(), v.getField()->caption, identity),
|
||||
RealPoint(margin_left - v.bounding_box.x, 1));
|
||||
}
|
||||
// draw viewer
|
||||
v.draw(dc);
|
||||
@@ -76,15 +75,15 @@ void NativeLookEditor::resizeViewers() {
|
||||
StyleP s = v->getStyle();
|
||||
ValueEditor* e = v->getEditor();
|
||||
if (!e || e->drawLabel()) {
|
||||
s->left = margin + label_width;
|
||||
v->bounding_box.x = margin + label_width;
|
||||
} else {
|
||||
s->left = margin;
|
||||
v->bounding_box.x = margin;
|
||||
}
|
||||
s->top = y;
|
||||
s->width = w - s->left - margin;
|
||||
s->height = default_height;
|
||||
v->bounding_box.y = y;
|
||||
v->bounding_box.width = w - v->bounding_box.x - margin;
|
||||
v->bounding_box.height = s->height() == 0 ? default_height : s->height;
|
||||
if (e) e->determineSize();
|
||||
y += s->height + vspace;
|
||||
y += v->bounding_box.height + vspace;
|
||||
}
|
||||
y = y - vspace + margin;
|
||||
SetVirtualSize(w, (int)y);
|
||||
@@ -93,17 +92,6 @@ void NativeLookEditor::resizeViewers() {
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@ TextFieldP TextCtrl::getFieldP() {
|
||||
}
|
||||
void TextCtrl::updateSize() {
|
||||
wxSize cs = GetClientSize();
|
||||
Style& style = getStyle();
|
||||
style.width = cs.GetWidth() - 2;
|
||||
style.height = cs.GetHeight() - 2;
|
||||
ValueViewer& viewer = *viewers.front();
|
||||
viewer.bounding_box.width = cs.GetWidth() - 2;
|
||||
viewer.bounding_box.height = cs.GetHeight() - 2;
|
||||
viewers.front()->getEditor()->determineSize(true);
|
||||
}
|
||||
|
||||
@@ -76,9 +76,9 @@ void TextCtrl::onChangeSet() {
|
||||
// initialize
|
||||
if (viewers.empty()) {
|
||||
// create a field, style and value
|
||||
TextFieldP field(new TextField);
|
||||
TextStyleP style(new TextStyle(field));
|
||||
TextValueP value(new FakeTextValue(field, nullptr, false, false));
|
||||
TextFieldP field = make_intrusive<TextField>();
|
||||
TextStyleP style = make_intrusive<TextStyle>(field);
|
||||
TextValueP value = make_intrusive<FakeTextValue>(field, nullptr, false, false);
|
||||
// set stuff
|
||||
field->index = 0;
|
||||
field->multi_line = multi_line;
|
||||
|
||||
@@ -287,7 +287,7 @@ void DropDownList::redrawArrowOnParent() {
|
||||
shared_ptr<RotatedDC> dcP = editor.overdrawDC();
|
||||
RotatedDC& dc = *dcP;
|
||||
Rotater r(dc, viewer->getRotation());
|
||||
draw_drop_down_arrow(&editor, dc.getDC(), dc.trRectToBB(dc.getInternalRect().grow(1)), IsShown());
|
||||
draw_drop_down_arrow(&editor, dc.getDC(), dc.getExternalRect().grow(1), IsShown());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,11 +275,11 @@ void ChoiceValueEditor::onLoseFocus() {
|
||||
void ChoiceValueEditor::draw(RotatedDC& dc) {
|
||||
ChoiceValueViewer::draw(dc);
|
||||
if (nativeLook()) {
|
||||
draw_drop_down_arrow(&editor(), dc.getDC(), dc.trRectToBB(style().getInternalRect().grow(1)), drop_down->IsShown());
|
||||
draw_drop_down_arrow(&editor(), dc.getDC(), dc.getExternalRect().grow(1), drop_down->IsShown());
|
||||
}
|
||||
}
|
||||
void ChoiceValueEditor::determineSize(bool) {
|
||||
style().height = max(style().height(), 16.);
|
||||
bounding_box.height = max(bounding_box.height, 16.);
|
||||
}
|
||||
|
||||
void ChoiceValueEditor::change(const Defaultable<String>& c) {
|
||||
|
||||
@@ -148,7 +148,7 @@ void ColorValueEditor::draw(RotatedDC& dc) {
|
||||
}
|
||||
}
|
||||
void ColorValueEditor::determineSize(bool) {
|
||||
style().height = 20;
|
||||
bounding_box.height = 20;
|
||||
}
|
||||
|
||||
void ColorValueEditor::change(const Defaultable<Color>& c) {
|
||||
|
||||
@@ -14,5 +14,5 @@
|
||||
IMPLEMENT_VALUE_EDITOR(Info) {}
|
||||
|
||||
void InfoValueEditor::determineSize(bool) {
|
||||
style().height = 26;
|
||||
bounding_box.height = 26;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ void MultipleChoiceValueEditor::determineSize(bool force_fit) {
|
||||
item_height = 18;
|
||||
// height depends on number of items and item height
|
||||
int item_count = field().choices->lastId();
|
||||
style().height = item_count * item_height;
|
||||
bounding_box.height = item_count * item_height;
|
||||
}
|
||||
|
||||
bool MultipleChoiceValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
|
||||
@@ -101,11 +101,11 @@ void PackageChoiceValueEditor::onLoseFocus() {
|
||||
void PackageChoiceValueEditor::draw(RotatedDC& dc) {
|
||||
PackageChoiceValueViewer::draw(dc);
|
||||
if (nativeLook()) {
|
||||
draw_drop_down_arrow(&editor(), dc.getDC(), dc.trRectToBB(style().getInternalRect().grow(1)), drop_down && drop_down->IsShown());
|
||||
draw_drop_down_arrow(&editor(), dc.getDC(), dc.getExternalRect().grow(1), drop_down && drop_down->IsShown());
|
||||
}
|
||||
}
|
||||
void PackageChoiceValueEditor::determineSize(bool) {
|
||||
style().height = max(style().height(), 16.);
|
||||
bounding_box.height = max(bounding_box.height, 16.);
|
||||
}
|
||||
|
||||
void PackageChoiceValueEditor::change(const String& c) {
|
||||
|
||||
@@ -27,7 +27,7 @@ void SymbolValueEditor::draw(RotatedDC& dc) {
|
||||
dc.SetFont(wxFont(10,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL));
|
||||
dc.SetTextForeground(*wxBLACK);
|
||||
RealSize text_size = dc.GetTextExtent(_("double click to edit symbol"));
|
||||
dc.DrawText(_("double click to edit symbol"), align_in_rect(ALIGN_MIDDLE_CENTER, text_size, style().getInternalRect()));
|
||||
dc.DrawText(_("double click to edit symbol"), align_in_rect(ALIGN_MIDDLE_CENTER, text_size, dc.getInternalRect()));
|
||||
}
|
||||
if (nativeLook()) {
|
||||
// draw editor buttons
|
||||
@@ -38,9 +38,9 @@ void SymbolValueEditor::draw(RotatedDC& dc) {
|
||||
}
|
||||
void SymbolValueEditor::drawButton(RotatedDC& dc, int button, const String& text) {
|
||||
bool down = button == button_down;
|
||||
double height = style().height;
|
||||
double width = style().height + 2;
|
||||
double x = style().width - width - (width + 1) * button;
|
||||
double height = bounding_box.height;
|
||||
double width = bounding_box.height + 2;
|
||||
double x = bounding_box.width - width - (width + 1) * button;
|
||||
double y = 0;
|
||||
// draw button
|
||||
draw_button(&editor(), dc.getDC(), dc.trRectToBB(RealRect(x,y,width,height)), false, down, true);
|
||||
@@ -54,8 +54,8 @@ void SymbolValueEditor::drawButton(RotatedDC& dc, int button, const String& text
|
||||
}
|
||||
|
||||
int SymbolValueEditor::findButton(const RealPoint& pos) {
|
||||
if (pos.y < 0 || pos.y >= style().height) return -1;
|
||||
int button = (int)floor( (style().width - pos.x) / (style().height + 3) );
|
||||
if (pos.y < 0 || pos.y >= bounding_box.height) return -1;
|
||||
int button = (int)floor( (bounding_box.width - pos.x) / (bounding_box.height + 3) );
|
||||
if (button >= 0 && button <= 1) return button;
|
||||
return -1;
|
||||
}
|
||||
@@ -107,7 +107,8 @@ bool SymbolValueEditor::onLeftDClick(const RealPoint& pos, wxMouseEvent&) {
|
||||
}
|
||||
|
||||
void SymbolValueEditor::determineSize(bool) {
|
||||
style().height = 50;
|
||||
if (style().height == 0) style().height = 50;
|
||||
bounding_box.height = 50;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+10
-8
@@ -627,7 +627,7 @@ wxMenu* TextValueEditor::getMenu(int type) const {
|
||||
void TextValueEditor::draw(RotatedDC& dc) {
|
||||
if (nativeLook()) {
|
||||
// clip the dc to the region of this control
|
||||
dc.SetClippingRegion(style().getInternalRect());
|
||||
dc.SetClippingRegion(dc.getInternalRect());
|
||||
}
|
||||
// update scrollbar
|
||||
prepareDrawScrollbar(dc);
|
||||
@@ -663,7 +663,7 @@ void TextValueEditor::redrawSelection(size_t old_selection_start_i, size_t old_s
|
||||
Rotater r(dc, getRotation());
|
||||
if (nativeLook()) {
|
||||
// clip the dc to the region of this control
|
||||
dc.SetClippingRegion(style().getInternalRect());
|
||||
dc.SetClippingRegion(dc.getInternalRect());
|
||||
}
|
||||
// clear old selection by drawing it again
|
||||
if (!old_drop_down_shown) {
|
||||
@@ -727,9 +727,8 @@ bool TextValueEditor::containsPoint(const RealPoint& pos) const {
|
||||
if (word_lists.empty()) return false;
|
||||
return (bool) findWordList(pos);
|
||||
}
|
||||
RealRect TextValueEditor::boundingBox() const {
|
||||
if (word_lists.empty()) return ValueViewer::boundingBox();
|
||||
RealRect r = style().getInternalRect().grow(1);
|
||||
RealRect TextValueEditor::boundingBoxBorder() const {
|
||||
RealRect r = ValueViewer::boundingBoxBorder();
|
||||
FOR_EACH_CONST(wl, word_lists) {
|
||||
r.width = max(r.width, wl->rect.right() + 9);
|
||||
}
|
||||
@@ -1255,14 +1254,16 @@ void TextValueEditor::determineSize(bool force_fit) {
|
||||
// muliline, determine scrollbar size
|
||||
Rotation rot = parent.getRotation();
|
||||
Rotater r(rot, getRotation());
|
||||
if (!force_fit) style().height = 100;
|
||||
if (!force_fit) {
|
||||
style().height = bounding_box.height = 100;
|
||||
}
|
||||
int sbw = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
|
||||
RealPoint pos = rot.tr(RealPoint(0,0));
|
||||
scrollbar->SetSize(
|
||||
(int)(pos.x + rot.trX(style().width) + 1 - sbw),
|
||||
(int)(pos.x + rot.trX(bounding_box.width) + 1 - sbw),
|
||||
(int)pos.y - 1,
|
||||
(int)sbw,
|
||||
(int)rot.trY(style().height) + 2);
|
||||
(int)rot.trY(bounding_box.height) + 2);
|
||||
v.reset(true);
|
||||
} else {
|
||||
// Height depends on font
|
||||
@@ -1272,6 +1273,7 @@ void TextValueEditor::determineSize(bool force_fit) {
|
||||
dc.SetFont(style().font.toWxFont(1.0));
|
||||
style().height = dc.GetCharHeight() + 2 + style().padding_top + style().padding_bottom;
|
||||
}
|
||||
bounding_box.height = style().height;
|
||||
}
|
||||
|
||||
void TextValueEditor::onShow(bool showing) {
|
||||
|
||||
@@ -92,7 +92,7 @@ public:
|
||||
wxCursor cursor(const RealPoint& pos) const override;
|
||||
void determineSize(bool force_fit = false) override;
|
||||
bool containsPoint(const RealPoint& p) const override;
|
||||
RealRect boundingBox() const override;
|
||||
RealRect boundingBoxBorder() const override;
|
||||
void onShow(bool) override;
|
||||
void draw(RotatedDC&) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user