Use generated widget app::gen::NewSprite in NewFileCommand

This commit is contained in:
David Capello 2014-08-09 21:45:07 -03:00
parent df0d39ed87
commit 303595689f
2 changed files with 23 additions and 26 deletions

View File

@ -15,12 +15,12 @@
<separator text="Color Mode:" left="true" horizontal="true" />
<box vertical="true" homogeneous="true" childspacing="0">
<box horizontal="true">
<radio id="radio3" text="&amp;Indexed color" group="1" tooltip="Using a palette of 256 colors&#10;(8 bits per pixel)" />
<radio id="indexed_mode" text="&amp;Indexed color" group="1" tooltip="Using a palette of 256 colors&#10;(8 bits per pixel)" />
<!-- <entry id="colors" maxsize="8" tooltip="Maximum number of colors&#10;(only for Indexed images)&#10;&#10;This field cannot be modified in this beta version." disabled="true" /> -->
<!-- <label text="Colors" /> -->
</box>
<radio id="radio1" text="&amp;RGB color" group="1" tooltip="RGBA color mode&#10;(32 bits per pixel)" />
<radio id="radio2" text="&amp;Grayscale" group="1" tooltip="Value and Alpha&#10;(16 bits per pixel)" />
<radio id="rgb_mode" text="&amp;RGB color" group="1" tooltip="RGBA color mode&#10;(32 bits per pixel)" />
<radio id="grayscale_mode" text="&amp;Grayscale" group="1" tooltip="Value and Alpha&#10;(16 bits per pixel)" />
</box>
<separator text="Background:" left="true" horizontal="true" />

View File

@ -45,6 +45,8 @@
#include "raster/stock.h"
#include "ui/ui.h"
#include "generated_new_sprite.h"
#include <allegro/config.h>
#include <allegro/unicode.h>
@ -87,15 +89,7 @@ void NewFileCommand::onExecute(Context* context)
};
// Load the window widget
base::UniquePtr<Window> window(app::load_widget<Window>("new_sprite.xml", "new_sprite"));
Widget* width = app::find_widget<Widget>(window, "width");
Widget* height = app::find_widget<Widget>(window, "height");
Widget* radio1 = app::find_widget<Widget>(window, "radio1");
Widget* radio2 = app::find_widget<Widget>(window, "radio2");
Widget* radio3 = app::find_widget<Widget>(window, "radio3");
// Widget* colors = app::find_widget<Widget>(window, "colors");
ListBox* bg_box = app::find_widget<ListBox>(window, "bg_box");
Widget* ok = app::find_widget<Widget>(window, "ok_button");
app::gen::NewSprite window;
// Default values: Indexed, 320x240, Background color
format = static_cast<PixelFormat>(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);