mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Allow "Default" in slider fields
This commit is contained in:
+53
-47
@@ -15,12 +15,12 @@
|
|||||||
#include <util/rotation.hpp>
|
#include <util/rotation.hpp>
|
||||||
#include <gfx/gfx.hpp>
|
#include <gfx/gfx.hpp>
|
||||||
#include <wx/dcbuffer.h>
|
#include <wx/dcbuffer.h>
|
||||||
|
|
||||||
bool DropDownList::slider_loaded;
|
bool DropDownList::slider_loaded;
|
||||||
wxBitmap DropDownList::slider_left;
|
wxBitmap DropDownList::slider_left;
|
||||||
wxBitmap DropDownList::slider_right;
|
wxBitmap DropDownList::slider_right;
|
||||||
wxBitmap DropDownList::slider_center;
|
wxBitmap DropDownList::slider_center;
|
||||||
wxBitmap DropDownList::slider_tick;
|
wxBitmap DropDownList::slider_tick;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : DropDownHider
|
// ----------------------------------------------------------------------------- : DropDownHider
|
||||||
|
|
||||||
@@ -110,15 +110,15 @@ void DropDownList::show(bool in_place, wxPoint pos, RealRect* rect) {
|
|||||||
}
|
}
|
||||||
// determine dropdown size
|
// determine dropdown size
|
||||||
RealSize border_size(2,2); // GetClientSize() - GetSize(), assume 1px borders
|
RealSize border_size(2,2); // GetClientSize() - GetSize(), assume 1px borders
|
||||||
RealSize size;
|
RealSize size;
|
||||||
if (is_slider) {
|
if (is_slider) {
|
||||||
size.height = 70 + marginH * 2;
|
size.height = 70 + marginH * 2;
|
||||||
size.width = min(1000.0, max(150.0, max(100.0 + count, item_size.width + marginW * 2)));
|
size.width = min(1000.0, max(150.0, max(100.0 + count, item_size.width + marginW * 2)));
|
||||||
} else {
|
} else {
|
||||||
int line_count = 0;
|
int line_count = 0;
|
||||||
for (size_t i = 0; i < count; ++i) if (lineBelow(i)) line_count += 1;
|
for (size_t i = 0; i < count; ++i) if (lineBelow(i)) line_count += 1;
|
||||||
size.height = item_size.height * count + marginH * 2 + line_count;
|
size.height = item_size.height * count + marginH * 2 + line_count;
|
||||||
size.width = item_size.width + marginW * 2;
|
size.width = item_size.width + marginW * 2;
|
||||||
}
|
}
|
||||||
// determine placement
|
// determine placement
|
||||||
int parent_height = 0;
|
int parent_height = 0;
|
||||||
@@ -316,37 +316,40 @@ void DropDownList::draw(DC& dc) {
|
|||||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||||
dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
||||||
dc.DrawRectangle(0, 0, cs.x, cs.y);
|
dc.DrawRectangle(0, 0, cs.x, cs.y);
|
||||||
dc.SetFont(*wxNORMAL_FONT);
|
dc.SetFont(*wxNORMAL_FONT);
|
||||||
if (is_slider) {
|
if (is_slider) {
|
||||||
// If it's a slider, draw the slider
|
// If it's a slider, draw the slider
|
||||||
cs = GetClientSize();
|
cs = GetClientSize();
|
||||||
dc.SetPen(*wxBLACK_PEN);
|
dc.SetPen(*wxBLACK_PEN);
|
||||||
dc.SetFont(wxFont(12, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, _("Arial")));
|
dc.SetFont(wxFont(12, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, _("Arial")));
|
||||||
|
|
||||||
|
String first_item = capitalize(itemText(0));
|
||||||
|
if (first_item == _("Default")) first_item = capitalize(itemText(1));
|
||||||
|
String last_item = capitalize(itemText(count-1));
|
||||||
int first_text_width;
|
int first_text_width;
|
||||||
dc.GetTextExtent(capitalize(itemText(0)), &first_text_width, nullptr);
|
|
||||||
int last_text_width;
|
int last_text_width;
|
||||||
dc.GetTextExtent(capitalize(itemText(count-1)), &last_text_width, nullptr);
|
dc.GetTextExtent(first_item, &first_text_width, nullptr);
|
||||||
dc.DrawText(capitalize(itemText(0)), marginW + 4, 14);
|
dc.GetTextExtent(last_item, &last_text_width, nullptr);
|
||||||
dc.DrawText(capitalize(itemText(count-1)), cs.x - marginW - 4 - last_text_width, 14);
|
dc.DrawText(first_item, marginW + 8, 14);
|
||||||
|
dc.DrawText(last_item, cs.x - last_text_width - marginW - 8, 14);
|
||||||
int slider_start = first_text_width + marginW + 16;
|
|
||||||
int slider_end = cs.x - (last_text_width + marginW + 16);
|
int slider_start = first_text_width + marginW + 20;
|
||||||
dc.DrawBitmap(slider_left, slider_start, 14);
|
int slider_end = cs.x - last_text_width - marginW - 20;
|
||||||
|
dc.DrawBitmap(slider_left, slider_start, 14);
|
||||||
for (size_t i = slider_start + 19; i < slider_end - 19; i+=19) {
|
for (size_t i = slider_start + 19; i < slider_end - 19; i+=19) {
|
||||||
dc.DrawBitmap(slider_center, i, 14);
|
dc.DrawBitmap(slider_center, i, 14);
|
||||||
}
|
}
|
||||||
dc.DrawBitmap(slider_right, slider_end - 19, 14);
|
dc.DrawBitmap(slider_right, slider_end - 19, 14);
|
||||||
|
int selected_index = selected_item < 0 ? 0 : selected_item;
|
||||||
int selected_index = selected_item < 0 ? 0 : selected_item;
|
int slider_pos = round((double)selected_index/(count-1) * (slider_end - slider_start)) + slider_start;
|
||||||
int slider_pos = round((double)selected_index/(count - 1) * (slider_end - slider_start)) + slider_start;
|
dc.DrawBitmap(slider_tick, slider_pos - 7, 9); // -7 cause the slider_tick bitmap is 15 pixels wide
|
||||||
dc.DrawBitmap(slider_tick, slider_pos - 7, 9); // -7 cause the bitmap is 15 pixels wide
|
|
||||||
|
|
||||||
int selected_text_width;
|
int selected_text_width;
|
||||||
dc.GetTextExtent(capitalize(itemText(selected_index)), &selected_text_width, nullptr);
|
dc.GetTextExtent(capitalize(itemText(selected_index)), &selected_text_width, nullptr);
|
||||||
dc.DrawText(capitalize(itemText(selected_index)), slider_pos - selected_text_width/2, 44);
|
dc.DrawText(capitalize(itemText(selected_index)), slider_pos - selected_text_width/2, 44);
|
||||||
|
|
||||||
dc.SetFont(*wxNORMAL_FONT);
|
dc.SetFont(*wxNORMAL_FONT);
|
||||||
} else {
|
} else {
|
||||||
// If it's not a slider, draw the list of items
|
// If it's not a slider, draw the list of items
|
||||||
int y = marginH - visible_start;
|
int y = marginH - visible_start;
|
||||||
for (size_t i = 0; i < count; ++i) {
|
for (size_t i = 0; i < count; ++i) {
|
||||||
@@ -424,21 +427,24 @@ void DropDownList::onMotion(wxMouseEvent& ev) {
|
|||||||
ev.Skip();
|
ev.Skip();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// find selected item
|
// find selected item
|
||||||
size_t count = itemCount();
|
size_t count = itemCount();
|
||||||
if (is_slider) {
|
if (is_slider) {
|
||||||
|
String first_item = capitalize(itemText(0));
|
||||||
|
if (first_item == _("Default")) first_item = capitalize(itemText(1));
|
||||||
|
String last_item = capitalize(itemText(count-1));
|
||||||
int first_text_width;
|
int first_text_width;
|
||||||
GetTextExtent(capitalize(itemText(0)), &first_text_width, nullptr);
|
|
||||||
int last_text_width;
|
int last_text_width;
|
||||||
GetTextExtent(capitalize(itemText(count - 1)), &last_text_width, nullptr);
|
GetTextExtent(first_item, &first_text_width, nullptr);
|
||||||
int slider_start = first_text_width + marginW + 16;
|
GetTextExtent(last_item, &last_text_width, nullptr);
|
||||||
int slider_end = cs.x - (last_text_width + marginW + 16);
|
int slider_start = first_text_width + marginW + 20;
|
||||||
int slider_pos = ev.GetX();
|
int slider_end = cs.x - last_text_width - marginW - 20;
|
||||||
if (slider_pos < slider_start) slider_pos = slider_start;
|
int slider_pos = ev.GetX();
|
||||||
if (slider_pos > slider_end) slider_pos = slider_end;
|
if (slider_pos < slider_start) slider_pos = slider_start;
|
||||||
int selected_item = round(((double)(slider_pos - slider_start)) / (slider_end - slider_start) * (count - 1));
|
if (slider_pos > slider_end) slider_pos = slider_end;
|
||||||
|
int selected_item = round(((double)(slider_pos - slider_start)) / (slider_end - slider_start) * (count-1));
|
||||||
selectItem(selected_item);
|
selectItem(selected_item);
|
||||||
} else {
|
} else {
|
||||||
int startY = marginH - visible_start;
|
int startY = marginH - visible_start;
|
||||||
for (size_t i = 0; i < count; ++i) {
|
for (size_t i = 0; i < count; ++i) {
|
||||||
int endY = startY + (int)item_size.height;
|
int endY = startY + (int)item_size.height;
|
||||||
@@ -570,4 +576,4 @@ BEGIN_EVENT_TABLE(DropDownList,wxPopupWindow)
|
|||||||
EVT_LEAVE_WINDOW (DropDownList::onMouseLeave)
|
EVT_LEAVE_WINDOW (DropDownList::onMouseLeave)
|
||||||
EVT_MOUSEWHEEL (DropDownList::onMouseWheel)
|
EVT_MOUSEWHEEL (DropDownList::onMouseWheel)
|
||||||
EVT_SCROLLWIN (DropDownList::onScroll)
|
EVT_SCROLLWIN (DropDownList::onScroll)
|
||||||
END_EVENT_TABLE ()
|
END_EVENT_TABLE ()
|
||||||
|
|||||||
+15
-13
@@ -200,28 +200,30 @@ END_EVENT_TABLE()
|
|||||||
|
|
||||||
DropDownChoiceList::DropDownChoiceList(Window* parent, bool is_submenu, ValueViewer& cve, ChoiceField::ChoiceP group)
|
DropDownChoiceList::DropDownChoiceList(Window* parent, bool is_submenu, ValueViewer& cve, ChoiceField::ChoiceP group)
|
||||||
: DropDownChoiceListBase(parent, is_submenu, cve, group)
|
: DropDownChoiceListBase(parent, is_submenu, cve, group)
|
||||||
{
|
{
|
||||||
// determine if slider
|
// determine if slider
|
||||||
size_t count = itemCount();
|
size_t count = itemCount();
|
||||||
if (count > 2) {
|
if (count > 3) {
|
||||||
int value;
|
int value;
|
||||||
try {
|
try {
|
||||||
value = std::stoi(itemText(0).ToStdString());
|
String first_item = capitalize(itemText(0));
|
||||||
|
if (first_item != _("Default")) value = std::stoi(first_item.ToStdString());
|
||||||
value = std::stoi(itemText(1).ToStdString());
|
value = std::stoi(itemText(1).ToStdString());
|
||||||
value = std::stoi(itemText(count - 1).ToStdString());
|
value = std::stoi(itemText(count - 2).ToStdString());
|
||||||
// the choices are numbers, use a slider
|
value = std::stoi(itemText(count - 1).ToStdString());
|
||||||
is_slider = true;
|
// the choices are numbers, use a slider
|
||||||
// load slider images if needed
|
is_slider = true;
|
||||||
if (!slider_loaded) {
|
// load slider images if needed
|
||||||
|
if (!slider_loaded) {
|
||||||
slider_loaded = true;
|
slider_loaded = true;
|
||||||
slider_left = load_resource_image(_("slider_left"));
|
slider_left = load_resource_image(_("slider_left"));
|
||||||
slider_right = load_resource_image(_("slider_right"));
|
slider_right = load_resource_image(_("slider_right"));
|
||||||
slider_center = load_resource_image(_("slider_center"));
|
slider_center = load_resource_image(_("slider_center"));
|
||||||
slider_tick = load_resource_image(_("slider_tick"));
|
slider_tick = load_resource_image(_("slider_tick"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (...) {}
|
catch (...) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DropDownChoiceList::onShow() {
|
void DropDownChoiceList::onShow() {
|
||||||
|
|||||||
Reference in New Issue
Block a user