Added the number of colors in "New Sprite" dialog for Indexed sprites.

This commit is contained in:
David Capello 2010-06-01 20:35:13 -03:00
parent 81bafa3595
commit 0a5746bf3b
2 changed files with 60 additions and 55 deletions

View File

@ -1,51 +1,51 @@
<!-- ASE - Allegro Sprite Editor -->
<!-- Copyright (C) 2001-2010 by David Capello -->
<jinete>
<window text="New Sprite" name="new_sprite">
<box vertical="true">
<box horizontal="true">
<window text="New Sprite" name="new_sprite">
<box vertical="true">
<box vertical="true" expansive="true">
<separator text="Size:" left="true" horizontal="true" />
<box vertical="true" expansive="true">
<box horizontal="true">
<box vertical="true" homogeneous="true">
<label text="Width:" />
<label text="Height:" />
</box>
<box vertical="true" homogeneous="true" expansive="true">
<entry expansive="true" name="width" maxsize="8" magnetic="true" tooltip="Width of the new sprite (in pixels)" />
<entry expansive="true" name="height" maxsize="8" tooltip="Height of the new sprite (in pixels)" />
</box>
</box>
</box>
</box>
<box vertical="true">
<separator text="Color Mode:" left="true" horizontal="true" />
<box vertical="true" homogeneous="true">
<radio name="radio1" text="&amp;RGB Color" group="1" tooltip="RGBA color mode&#10;(32 bits per pixel)" />
<radio name="radio2" text="&amp;Grayscale" group="1" tooltip="Value and Alpha&#10;(16 bits per pixel)" />
<radio name="radio3" text="&amp;Indexed" group="1" tooltip="Using a palette of 256 colors&#10;(8 bits per pixel)" />
<separator text="Size:" left="true" horizontal="true" />
<box vertical="true" expansive="true">
<grid columns="2">
<label text="Width:" />
<entry name="width" maxsize="8" magnetic="true" cell_align="horizontal" tooltip="Width of the new sprite&#10;(in pixels)" />
<label text="Height:" />
<entry name="height" maxsize="8" cell_align="horizontal" tooltip="Height of the new sprite&#10;(in pixels)" />
</grid>
</box>
</box>
</box>
<separator text="Background:" left="true" horizontal="true" />
<view maxsize="true" expansive="true">
<listbox name="bg_box">
<listitem text="Transparent" />
<listitem text="Black" />
<listitem text="White" />
<listitem text="Magenta" />
<listitem text="Background Color" />
</listbox>
</view>
<box horizontal="true">
<box horizontal="true" expansive="true" />
<box horizontal="true" homogeneous="true">
<button text="&amp;OK" name="ok_button" magnetic="true" width="60" />
<button text="&amp;Cancel" />
<separator text="Color Mode:" left="true" horizontal="true" />
<box vertical="true" homogeneous="true" childspacing="0">
<box horizontal="true">
<radio name="radio3" text="&amp;Indexed with " group="1" tooltip="Using a palette of 256 colors&#10;(8 bits per pixel)" />
<entry name="colors" maxsize="8" tooltip="Maximum number of colors&#10;(only for Indexed images)" />
<label text="Colors" />
</box>
<radio name="radio1" text="&amp;RGB Color" group="1" tooltip="RGBA color mode&#10;(32 bits per pixel)" />
<radio name="radio2" text="&amp;Grayscale" group="1" tooltip="Value and Alpha&#10;(16 bits per pixel)" />
</box>
<separator text="Background:" left="true" horizontal="true" />
<view maxsize="true">
<listbox name="bg_box">
<listitem text="Transparent" />
<listitem text="Black" />
<listitem text="White" />
<listitem text="Magenta" />
<listitem text="Background Color" />
</listbox>
</view>
<box horizontal="true">
<box horizontal="true" expansive="true" />
<box horizontal="true" homogeneous="true">
<button text="&amp;OK" name="ok_button" magnetic="true" width="60" />
<button text="&amp;Cancel" />
</box>
</box>
</box>
</box>
</window>
</window>
</jinete>

View File

@ -68,8 +68,8 @@ NewFileCommand::NewFileCommand()
*/
void NewFileCommand::execute(Context* context)
{
JWidget width, height, radio1, radio2, radio3, ok, bg_box;
int imgtype, w, h, bg;
JWidget width, height, radio1, radio2, radio3, colors, ok, bg_box;
int imgtype, w, h, bg, ncolors;
char buf[1024];
Sprite *sprite;
color_t color;
@ -80,18 +80,18 @@ void NewFileCommand::execute(Context* context)
color_rgb(255, 0, 255),
app_get_colorbar()->getBgColor()
};
int ncolors = 256;
// Load the window widget
FramePtr window(load_widget("new_sprite.xml", "new_sprite"));
width = jwidget_find_name(window, "width");
height = jwidget_find_name(window, "height");
radio1 = jwidget_find_name(window, "radio1");
radio2 = jwidget_find_name(window, "radio2");
radio3 = jwidget_find_name(window, "radio3");
ok = jwidget_find_name(window, "ok_button");
bg_box = jwidget_find_name(window, "bg_box");
get_widgets(window,
"width", &width,
"height", &height,
"radio1", &radio1,
"radio2", &radio2,
"radio3", &radio3,
"colors", &colors,
"ok_button", &ok,
"bg_box", &bg_box, NULL);
// Default values: Indexed, 320x240, Background color
imgtype = get_config_int("NewSprite", "Type", IMAGE_INDEXED);
@ -99,9 +99,11 @@ void NewFileCommand::execute(Context* context)
w = get_config_int("NewSprite", "Width", 320);
h = get_config_int("NewSprite", "Height", 240);
bg = get_config_int("NewSprite", "Background", 4); // Default = Background color
ncolors = get_config_int("NewSprite", "Colors", 256);
width->setTextf("%d", w);
height->setTextf("%d", h);
width->setTextf("%d", MAX(1, w));
height->setTextf("%d", MAX(1, h));
colors->setTextf("%d", MID(2, ncolors, 256));
// Select image-type
switch (imgtype) {
@ -126,10 +128,12 @@ void NewFileCommand::execute(Context* context)
w = width->getTextInt();
h = height->getTextInt();
ncolors = colors->getTextInt();
bg = jlistbox_get_selected_index(bg_box);
w = MID(1, w, 9999);
h = MID(1, h, 9999);
ncolors = MID(2, ncolors, 256);
// Select the color
color = color_mask();
@ -147,7 +151,8 @@ void NewFileCommand::execute(Context* context)
set_config_int("NewSprite", "Background", bg);
// Create the new sprite
sprite = new_sprite(UIContext::instance(), imgtype, w, h, ncolors);
sprite = new_sprite(UIContext::instance(), imgtype, w, h,
imgtype == IMAGE_INDEXED ? ncolors: 256);
if (!sprite) {
Console console;
console.printf("Not enough memory to allocate the sprite\n");