Merge pull request #6 from haganbmj/stored_image_resolution

misc: change storage size of image slices
This commit is contained in:
Brendan Hagan
2022-07-04 16:08:21 -04:00
committed by GitHub
8 changed files with 141 additions and 27 deletions
+12 -4
View File
@@ -487,12 +487,18 @@ label:
windows : Open sets windows : Open sets
app language : Language of the user interface : app language : Language of the user interface :
card display : Card Display card display : Card Display
zoom : &Zoom : storage : Storage
export : &Export : zoom : &Zoom:
export : &Export:
scale : &Internal Scale:
percent of normal: % of normal size percent of normal: % of normal size
external programs: External programs external programs: External programs
apprentice: &Apprentice: apprentice: &Apprentice:
apprentice exe: Apprentice Executable apprentice exe: Apprentice Executable
internal scale desc:
Scale to internally store card images at.
Changing this may impact how Sharpening looks.
Does not retroactively apply to existing images.
check at startup: Check for new versions at startup check at startup: Check for new versions at startup
checking requires internet: checking requires internet:
Checking for updates requires an internet connection. Checking for updates requires an internet connection.
@@ -521,8 +527,8 @@ label:
html export options:Export options html export options:Export options
# Image slicer # Image slicer
original: Original: original: Original (%s x %s):
result: Result: result: Result (%s x %s):
size: Size size: Size
original size: &Original Size original size: &Original Size
size to fit: Size to &Fit size to fit: Size to &Fit
@@ -614,6 +620,7 @@ button:
always: Always always: Always
if internet connection exists: If internet connection exists if internet connection exists: If internet connection exists
never: Never never: Never
internal image extension: Store images internally with extension
# Column select # Column select
move up: Move &Up move up: Move &Up
@@ -676,6 +683,7 @@ title:
global: Global global: Global
display: Display display: Display
directories: Directories directories: Directories
internal: Internal
updates: Updates updates: Updates
update check: Update Check update check: Update Check
locate apprentice: Locate Apprentice locate apprentice: Locate Apprentice
+4
View File
@@ -172,6 +172,8 @@ Settings::Settings()
, symbol_grid (true) , symbol_grid (true)
, symbol_grid_snap (false) , symbol_grid_snap (false)
, print_layout (LAYOUT_NO_SPACE) , print_layout (LAYOUT_NO_SPACE)
, internal_scale (1.0)
, internal_image_extension(true)
#if USE_OLD_STYLE_UPDATE_CHECKER #if USE_OLD_STYLE_UPDATE_CHECKER
, updates_url (_("http://magicseteditor.sourceforge.net/updates")) , updates_url (_("http://magicseteditor.sourceforge.net/updates"))
#endif #endif
@@ -258,6 +260,8 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(Settings) {
REFLECT(default_game); REFLECT(default_game);
REFLECT(print_layout); REFLECT(print_layout);
REFLECT(apprentice_location); REFLECT(apprentice_location);
REFLECT(internal_scale);
REFLECT(internal_image_extension);
#if USE_OLD_STYLE_UPDATE_CHECKER #if USE_OLD_STYLE_UPDATE_CHECKER
REFLECT(updates_url); REFLECT(updates_url);
#else #else
+4
View File
@@ -193,6 +193,10 @@ public:
// --------------------------------------------------- : Special game stuff // --------------------------------------------------- : Special game stuff
String apprentice_location; String apprentice_location;
// --------------------------------------------------- : Internal settings
double internal_scale;
bool internal_image_extension;
// --------------------------------------------------- : Update checking // --------------------------------------------------- : Update checking
#if USE_OLD_STYLE_UPDATE_CHECKER #if USE_OLD_STYLE_UPDATE_CHECKER
String updates_url; String updates_url;
+20 -4
View File
@@ -133,11 +133,11 @@ ImageSliceWindow::ImageSliceWindow(Window* parent, const Image& source, const wx
// top row: image editors // top row: image editors
wxSizer* s2 = new wxBoxSizer(wxHORIZONTAL); wxSizer* s2 = new wxBoxSizer(wxHORIZONTAL);
wxSizer* s3 = new wxBoxSizer(wxVERTICAL); wxSizer* s3 = new wxBoxSizer(wxVERTICAL);
s3->Add(new wxStaticText(this, wxID_ANY, _LABEL_("original"))); s3->Add(new wxStaticText(this, wxID_ANY, _LABEL_2_("original", to_string(slice.source.GetWidth()), to_string(slice.source.GetHeight()))));
s3->Add(selector, 1, wxEXPAND | wxTOP, 4); s3->Add(selector, 1, wxEXPAND | wxTOP, 4);
s2->Add(s3, 1, wxEXPAND | wxALL, 4); s2->Add(s3, 1, wxEXPAND | wxALL, 4);
wxSizer* s4 = new wxBoxSizer(wxVERTICAL); wxSizer* s4 = new wxBoxSizer(wxVERTICAL);
s4->Add(new wxStaticText(this, wxID_ANY, _LABEL_("result"))); s4->Add(new wxStaticText(this, wxID_ANY, _LABEL_2_("result", to_string(slice.target_size.GetWidth()), to_string(slice.target_size.GetHeight()))));
s4->Add(preview, 0, wxTOP, 4); s4->Add(preview, 0, wxTOP, 4);
s2->Add(s4, 0, wxALL, 4); s2->Add(s4, 0, wxALL, 4);
s->Add(s2, 1, wxEXPAND); s->Add(s2, 1, wxEXPAND);
@@ -389,7 +389,13 @@ void ImageSlicePreview::update() {
wxSize ImageSlicePreview::DoGetBestSize() const { wxSize ImageSlicePreview::DoGetBestSize() const {
// We know the client size we want, calculate the size that goes with that // We know the client size we want, calculate the size that goes with that
wxSize ws = GetSize(), cs = GetClientSize(); wxSize ws = GetSize(), cs = GetClientSize();
return slice.target_size + ws - cs;
float target_ratio = ((float)slice.target_size.GetWidth()) / ((float)slice.target_size.GetHeight());
if (target_ratio > 1.0) {
return wxSize(500, 500 / target_ratio);
} else {
return wxSize(500 * target_ratio, 500);
}
} }
void ImageSlicePreview::onPaint(wxPaintEvent&) { void ImageSlicePreview::onPaint(wxPaintEvent&) {
@@ -414,6 +420,10 @@ void ImageSlicePreview::draw(DC& dc) {
} else { } else {
bitmap = Bitmap(image); bitmap = Bitmap(image);
} }
// Rescale the bitmap based on the available size.
auto available_size = DoGetBestSize();
bitmap = wxBitmap(bitmap.ConvertToImage().Scale(available_size.GetWidth(), available_size.GetHeight()));
} }
if (bitmap.Ok()) { if (bitmap.Ok()) {
dc.DrawBitmap(bitmap, 0, 0); dc.DrawBitmap(bitmap, 0, 0);
@@ -468,7 +478,13 @@ ImageSliceSelector::ImageSliceSelector(Window* parent, int id, ImageSlice& slice
, slice(slice) , slice(slice)
, mouse_down(false) , mouse_down(false)
{ {
SetMinSize(wxSize(400, 300));
float target_ratio = ((float) slice.source.GetWidth()) / ((float) slice.source.GetHeight());
if (target_ratio > 1.0) {
SetMinSize(wxSize(500, 500 / target_ratio));
} else {
SetMinSize(wxSize(500 * target_ratio, 500));
}
SetBackgroundStyle(wxBG_STYLE_PAINT); SetBackgroundStyle(wxBG_STYLE_PAINT);
} }
+72
View File
@@ -67,6 +67,23 @@ private:
void updateExportZoom(); void updateExportZoom();
}; };
class InternalPreferencesPage : public PreferencesPage {
public:
InternalPreferencesPage(Window* parent);
void store() override;
private:
DECLARE_EVENT_TABLE();
wxCheckBox* internal_image_extension;
wxComboBox* internal_scale;
int internal_scale_int;
void onInternalScaleChange(wxCommandEvent&);
void updateInternalScale();
};
// Preferences page for directories of programs // Preferences page for directories of programs
// i.e. Apprentice, Magic Workstation // i.e. Apprentice, Magic Workstation
// perhaps in the future also directories for packages? // perhaps in the future also directories for packages?
@@ -108,6 +125,7 @@ PreferencesWindow::PreferencesWindow(Window* parent)
wxNotebook* nb = new wxNotebook(this, ID_NOTEBOOK); wxNotebook* nb = new wxNotebook(this, ID_NOTEBOOK);
nb->AddPage(new GlobalPreferencesPage (nb), _TITLE_("global")); nb->AddPage(new GlobalPreferencesPage (nb), _TITLE_("global"));
nb->AddPage(new DisplayPreferencesPage(nb), _TITLE_("display")); nb->AddPage(new DisplayPreferencesPage(nb), _TITLE_("display"));
nb->AddPage(new InternalPreferencesPage(nb), _TITLE_("internal"));
nb->AddPage(new DirsPreferencesPage (nb), _TITLE_("directories")); nb->AddPage(new DirsPreferencesPage (nb), _TITLE_("directories"));
nb->AddPage(new UpdatePreferencesPage (nb), _TITLE_("updates")); nb->AddPage(new UpdatePreferencesPage (nb), _TITLE_("updates"));
@@ -294,6 +312,60 @@ BEGIN_EVENT_TABLE(DisplayPreferencesPage, wxPanel)
EVT_TEXT_ENTER(ID_EXPORT_ZOOM, DisplayPreferencesPage::onExportZoomChange) EVT_TEXT_ENTER(ID_EXPORT_ZOOM, DisplayPreferencesPage::onExportZoomChange)
END_EVENT_TABLE () END_EVENT_TABLE ()
// ----------------------------------------------------------------------------- : Preferences page : internal
InternalPreferencesPage::InternalPreferencesPage(Window* parent) : PreferencesPage(parent) {
internal_image_extension = new wxCheckBox(this, wxID_ANY, _BUTTON_("internal image extension"));
internal_scale = new wxComboBox(this, ID_INTERNAL_SCALE);
internal_image_extension->SetValue(settings.internal_image_extension);
internal_scale_int = static_cast<int>(settings.internal_scale * 100);
internal_scale->SetValue(String::Format(_("%d%%"), internal_scale_int));
int choices[] = { 100,200 };
for (unsigned int i = 0; i < sizeof(choices) / sizeof(choices[0]); ++i) {
internal_scale->Append(String::Format(_("%d%%"), choices[i]));
}
wxSizer* s = new wxBoxSizer(wxVERTICAL);
wxSizer* s2 = new wxStaticBoxSizer(wxVERTICAL, this, _LABEL_("storage"));
wxSizer* s3 = new wxBoxSizer(wxHORIZONTAL);
s3->Add(new wxStaticText(this, wxID_ANY, _LABEL_("scale")), 0, wxALL & ~wxLEFT, 4);
s3->AddSpacer(2);
s3->Add(internal_scale);
s3->Add(new wxStaticText(this, wxID_ANY, _LABEL_("percent of normal")), 1, wxALL & ~wxRIGHT, 4);
s2->Add(s3);
s2->Add(new wxStaticText(this, wxID_ANY, _LABEL_("internal scale desc")), 0, wxALL & ~wxLEFT, 4);
s2->Add(internal_image_extension, 0, wxEXPAND | wxALL, 4);
s->Add(s2, 0, wxEXPAND | wxALL, 8);
s->SetSizeHints(this);
SetSizer(s);
}
void InternalPreferencesPage::store() {
settings.internal_image_extension = internal_image_extension->GetValue();
updateInternalScale();
settings.internal_scale = internal_scale_int / 100.0;
}
void InternalPreferencesPage::onInternalScaleChange(wxCommandEvent&) {
updateInternalScale();
}
void InternalPreferencesPage::updateInternalScale() {
String s = internal_scale->GetValue();
int i = internal_scale_int;
if (wxSscanf(s.c_str(), _("%u"), &i)) {
internal_scale_int = min(max(i, 1), 1000);
}
internal_scale->SetValue(String::Format(_("%d%%"), (int)internal_scale_int));
}
BEGIN_EVENT_TABLE(InternalPreferencesPage, wxPanel)
EVT_COMBOBOX(ID_INTERNAL_SCALE, InternalPreferencesPage::onInternalScaleChange)
END_EVENT_TABLE()
// ----------------------------------------------------------------------------- : Preferences page : directories // ----------------------------------------------------------------------------- : Preferences page : directories
+6 -2
View File
@@ -41,11 +41,15 @@ void ImageValueEditor::sliceImage(const Image& image) {
AlphaMask mask; AlphaMask mask;
style().mask.getNoCache(options,mask); style().mask.getNoCache(options,mask);
// slice // slice
ImageSliceWindow s(wxGetTopLevelParent(&editor()), image, style().getSize(), mask); // Specify a desired size based on the stylesheet and a scale multiplier defined within the user's settings.
// Storing at a greater than 100% resolution allows for better exports >100%, but may change how images look when filters (sharpen) are applied.
// Additionally, this bloats the set file size as even under-resolution images are upscaled to the new minimum size.
RealSize desired_slice_size = RealSize(style().getSize().width * settings.internal_scale, style().getSize().height * settings.internal_scale);
ImageSliceWindow s(wxGetTopLevelParent(&editor()), image, desired_slice_size, mask);
// clicked ok? // clicked ok?
if (s.ShowModal() == wxID_OK) { if (s.ShowModal() == wxID_OK) {
// store the image into the set // store the image into the set
LocalFileName new_image_file = getLocalPackage().newFileName(field().name,_(".png")); // a new unique name in the package LocalFileName new_image_file = getLocalPackage().newFileName(field().name, settings.internal_image_extension ? _(".png") : _("")); // a new unique name in the package
Image img = s.getImage(); Image img = s.getImage();
img.SaveFile(getLocalPackage().nameOut(new_image_file), wxBITMAP_TYPE_PNG); // always use PNG images, see #69. Disk space is cheap anyway. img.SaveFile(getLocalPackage().nameOut(new_image_file), wxBITMAP_TYPE_PNG); // always use PNG images, see #69. Disk space is cheap anyway.
addAction(value_action(valueP(), new_image_file)); addAction(value_action(valueP(), new_image_file));
+5 -1
View File
@@ -87,7 +87,11 @@ String tr(const Package&, const String& subcat, const String& key, DefaultLocale
#define _TOOLTIP_1_(s,a) format_string(_TOOLTIP_(s), a) #define _TOOLTIP_1_(s,a) format_string(_TOOLTIP_(s), a)
/// A localized string for tooltip labels, with 1 argument (printf style) /// A localized string for tooltip labels, with 1 argument (printf style)
#define _LABEL_1_(s,a) format_string(_LABEL_(s), a) #define _LABEL_1_(s,a) format_string(_LABEL_(s), a)
/// A localized string for tooltip labels, with 2 argument (printf style)
#define _LABEL_2_(s,a,b) format_string(_LABEL_(s), a, b)
/// A localized string for tooltip labels, with 3 argument (printf style)
#define _LABEL_3_(s,a,b,c) format_string(_LABEL_(s), a, b, c)
/// A localized string for button text, with 1 argument (printf style) /// A localized string for button text, with 1 argument (printf style)
#define _BUTTON_1_(s,a) format_string(_BUTTON_(s), a) #define _BUTTON_1_(s,a) format_string(_BUTTON_(s), a)
+2
View File
@@ -282,6 +282,8 @@ enum ControlID {
ID_EXPORT_ZOOM_Y, ID_EXPORT_ZOOM_Y,
ID_SHARPEN, ID_SHARPEN,
ID_SHARPEN_AMOUNT, ID_SHARPEN_AMOUNT,
// Internal window
ID_INTERNAL_SCALE,
// Updates window // Updates window
ID_PACKAGE_LIST, ID_PACKAGE_LIST,
ID_KEEP, ID_KEEP,