From 303595689f43aaf356a7b683777f223d339e1461 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 9 Aug 2014 21:45:07 -0300 Subject: [PATCH] Use generated widget app::gen::NewSprite in NewFileCommand --- data/widgets/new_sprite.xml | 6 ++--- src/app/commands/cmd_new_file.cpp | 43 ++++++++++++++----------------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/data/widgets/new_sprite.xml b/data/widgets/new_sprite.xml index af4b19e59..a74f6b9f6 100644 --- a/data/widgets/new_sprite.xml +++ b/data/widgets/new_sprite.xml @@ -15,12 +15,12 @@ - + - - + + diff --git a/src/app/commands/cmd_new_file.cpp b/src/app/commands/cmd_new_file.cpp index c6618c2e0..0045e1ce6 100644 --- a/src/app/commands/cmd_new_file.cpp +++ b/src/app/commands/cmd_new_file.cpp @@ -45,6 +45,8 @@ #include "raster/stock.h" #include "ui/ui.h" +#include "generated_new_sprite.h" + #include #include @@ -87,15 +89,7 @@ void NewFileCommand::onExecute(Context* context) }; // Load the window widget - base::UniquePtr window(app::load_widget("new_sprite.xml", "new_sprite")); - Widget* width = app::find_widget(window, "width"); - Widget* height = app::find_widget(window, "height"); - Widget* radio1 = app::find_widget(window, "radio1"); - Widget* radio2 = app::find_widget(window, "radio2"); - Widget* radio3 = app::find_widget(window, "radio3"); - // Widget* colors = app::find_widget(window, "colors"); - ListBox* bg_box = app::find_widget(window, "bg_box"); - Widget* ok = app::find_widget(window, "ok_button"); + app::gen::NewSprite window; // Default values: Indexed, 320x240, Background color format = static_cast(get_config_int("NewSprite", "Type", IMAGE_INDEXED)); @@ -116,35 +110,38 @@ void NewFileCommand::onExecute(Context* context) h = clipboardSize.h; } - width->setTextf("%d", MAX(1, w)); - height->setTextf("%d", MAX(1, h)); + window.width()->setTextf("%d", MAX(1, w)); + window.height()->setTextf("%d", MAX(1, h)); // colors->setTextf("%d", MID(2, ncolors, 256)); // Select image-type switch (format) { - case IMAGE_RGB: radio1->setSelected(true); break; - case IMAGE_GRAYSCALE: radio2->setSelected(true); break; - case IMAGE_INDEXED: radio3->setSelected(true); break; + case IMAGE_RGB: window.rgbMode()->setSelected(true); break; + case IMAGE_GRAYSCALE: window.grayscaleMode()->setSelected(true); break; + case IMAGE_INDEXED: window.indexedMode()->setSelected(true); break; } // Select background color - bg_box->selectIndex(bg); + window.bgBox()->selectIndex(bg); // Open the window - window->openWindowInForeground(); + window.openWindowInForeground(); - if (window->getKiller() == ok) { + if (window.getKiller() == window.okButton()) { bool ok = false; // Get the options - if (radio1->isSelected()) format = IMAGE_RGB; - else if (radio2->isSelected()) format = IMAGE_GRAYSCALE; - else if (radio3->isSelected()) format = IMAGE_INDEXED; + if (window.rgbMode()->isSelected()) + format = IMAGE_RGB; + else if (window.grayscaleMode()->isSelected()) + format = IMAGE_GRAYSCALE; + else if (window.indexedMode()->isSelected()) + format = IMAGE_INDEXED; - w = width->getTextInt(); - h = height->getTextInt(); + w = window.width()->getTextInt(); + h = window.height()->getTextInt(); // ncolors = colors->getTextInt(); - bg = bg_box->getSelectedIndex(); + bg = window.bgBox()->getSelectedIndex(); w = MID(1, w, 65535); h = MID(1, h, 65535);