Added the missing palette commands: ramp, quantize, load, and save.

This commit is contained in:
David Capello 2010-06-13 20:04:38 -03:00
parent a0fabbfe18
commit 91174456cd
2 changed files with 63 additions and 82 deletions

View File

@ -47,40 +47,18 @@
</box> </box>
</grid> </grid>
<!-- <box name="colorviewer_box" expansive="true" /> <\!-- custom-widget -\-> -->
<!-- <button text="Select &amp;All" name="select_all" /> -->
<!-- <box vertical="true"> -->
<!-- <box horizontal="true" homogeneous="true"> -->
<!-- <button text="&amp;Undo" name="undo" /> -->
<!-- <button text="&amp;Redo" name="redo" /> -->
<!-- </box> -->
<!-- <box horizontal="true" homogeneous="true"> -->
<!-- <button text="&amp;Load" name="load" /> -->
<!-- <button text="&amp;Save" name="save" /> -->
<!-- </box> -->
<!-- <box horizontal="true" homogeneous="true"> -->
<!-- <button text="&amp;Ramp" name="ramp" /> -->
<!-- <button text="&amp;Quantize" name="quantize" /> -->
<!-- </box> -->
<!-- </box> -->
</box> </box>
</box> </box>
<!-- <box horizontal="true"> --> <box horizontal="true" name="more_options">
<!-- <label text="Frame:" /> --> <button text="&amp;Ramp" name="ramp" />
<!-- <slider min="0" max="1" name="frame" expansive="true" /> --> <box horizontal="true" name="more_options" childspacing="0">
<!-- </box> --> <button text="&amp;Sort" name="sort" />
<button text="&amp;Quantize" name="quantize" />
<!-- <box horizontal="true"> --> </box>
<!-- <\!-- <check name="all_frames" text="All frames the same palette" /> -\-> --> <box horizontal="true" name="more_options" childspacing="0">
<!-- <box horizontal="true" expansive="true" /> --> <button text="&amp;Load" name="load" />
<!-- <box horizontal="true" homogeneous="true"> --> <button text="&amp;Save" name="save" />
<!-- <button text="&amp;OK" name="button_ok" magnetic="true" width="60" /> --> </box>
<!-- <button text="&amp;Cancel" /> -->
<!-- </box> -->
<!-- </box> -->
<box vertical="true" name="more_options">
<label text="more options" />
</box> </box>
</box> </box>
</window> </window>

View File

@ -102,6 +102,7 @@ static bool window_close_hook(JWidget widget, void *data);
static void load_command(JWidget widget); static void load_command(JWidget widget);
static void save_command(JWidget widget); static void save_command(JWidget widget);
static void ramp_command(JWidget widget); static void ramp_command(JWidget widget);
static void sort_command(JWidget widget);
static void quantize_command(JWidget widget); static void quantize_command(JWidget widget);
static bool sliderRGB_change_hook(JWidget widget, void *data); static bool sliderRGB_change_hook(JWidget widget, void *data);
@ -159,6 +160,11 @@ void PaletteEditorCommand::execute(Context* context)
Widget* select_rgb; Widget* select_rgb;
Widget* select_hsv; Widget* select_hsv;
Widget* expand_button; Widget* expand_button;
Widget* button_load;
Widget* button_save;
Widget* button_ramp;
Widget* button_sort;
Widget* button_quantize;
bool first_time = false; bool first_time = false;
// If the window was never loaded yet, load it // If the window was never loaded yet, load it
@ -212,28 +218,18 @@ void PaletteEditorCommand::execute(Context* context)
"select_hsv", &select_hsv, "select_hsv", &select_hsv,
"expand", &expand_button, "expand", &expand_button,
"more_options", &more_options, "more_options", &more_options,
// "load", &button_load, "load", &button_load,
// "save", &button_save, "save", &button_save,
// "ramp", &button_ramp, "ramp", &button_ramp,
// "quantize", &button_quantize, "sort", &button_sort,
// "button_ok", &button_ok, "quantize", &button_quantize,
// "colorviewer_box", &colorviewer_box,
"palette_editor", &palette_editor_view, NULL); "palette_editor", &palette_editor_view, NULL);
// window->user_data[0] = (void*)&sprite;
// Custom widgets // Custom widgets
if (first_time) { if (first_time) {
// colorviewer = colorviewer_new(color_index(0), IMAGE_INDEXED);
palette_editor = new PalEdit(true); palette_editor = new PalEdit(true);
palette_editor->setBoxSize(4*jguiscale()); palette_editor->setBoxSize(4*jguiscale());
// jwidget_expansive(colorviewer, true);
// jwidget_add_child(colorviewer_box, colorviewer);
// jwidget_disable(button_undo);
// jwidget_disable(button_redo);
jview_attach(palette_editor_view, palette_editor); jview_attach(palette_editor_view, palette_editor);
jview_maxsize(palette_editor_view); jview_maxsize(palette_editor_view);
@ -265,10 +261,11 @@ void PaletteEditorCommand::execute(Context* context)
jwidget_hide(more_options); jwidget_hide(more_options);
// jbutton_add_command(button_load, load_command); jbutton_add_command(button_load, load_command);
// jbutton_add_command(button_save, save_command); jbutton_add_command(button_save, save_command);
// jbutton_add_command(button_ramp, ramp_command); jbutton_add_command(button_ramp, ramp_command);
// jbutton_add_command(button_quantize, quantize_command); jbutton_add_command(button_sort, sort_command);
jbutton_add_command(button_quantize, quantize_command);
select_rgb_hook(NULL, NULL); select_rgb_hook(NULL, NULL);
} }
@ -371,63 +368,66 @@ static void save_command(JWidget widget)
return; return;
} }
// TODO Palette* palette = get_current_palette();
// if (!palette_editor->getPalette()->save(filename.c_str())) { if (!palette->save(filename.c_str())) {
// jalert(_("Error<<Saving palette file||&Close")); jalert(_("Error<<Saving palette file||&Close"));
// } }
} }
} }
static void ramp_command(JWidget widget) static void ramp_command(JWidget widget)
{ {
#if 0
int range_type = palette_editor->getRangeType(); int range_type = palette_editor->getRangeType();
int i1 = palette_editor->get1stColor(); int i1 = palette_editor->get1stColor();
int i2 = palette_editor->get2ndColor(); int i2 = palette_editor->get2ndColor();
Palette* palette = new Palette(0, 256); Palette* src_palette = get_current_palette();
Palette* dst_palette = new Palette(0, 256);
bool array[256]; bool array[256];
palette_editor->getSelectedEntries(array); palette_editor->getSelectedEntries(array);
palette_editor->getPalette()->copyColorsTo(palette); src_palette->copyColorsTo(dst_palette);
if ((i1 >= 0) && (i2 >= 0)) { if ((i1 >= 0) && (i2 >= 0)) {
/* make the ramp */ // Make the ramp
if (range_type == PALETTE_EDITOR_RANGE_LINEAL) { if (range_type == PALETTE_EDITOR_RANGE_LINEAL) {
/* lineal ramp */ // Lineal ramp
palette->makeHorzRamp(i1, i2); dst_palette->makeHorzRamp(i1, i2);
} }
else if (range_type == PALETTE_EDITOR_RANGE_RECTANGULAR) { else if (range_type == PALETTE_EDITOR_RANGE_RECTANGULAR) {
/* rectangular ramp */ // Rectangular ramp
palette->makeRectRamp(i1, i2, paledit_get_columns(palette_editor)); dst_palette->makeRectRamp(i1, i2, palette_editor->getColumns());
} }
} }
set_new_palette(palette); set_new_palette(dst_palette);
delete palette; delete dst_palette;
#endif }
static void sort_command(JWidget widget)
{
} }
static void quantize_command(JWidget widget) static void quantize_command(JWidget widget)
{ {
// const SpriteReader& sprite = get_sprite(widget); const CurrentSpriteReader& sprite(UIContext::instance());
// assert(sprite != NULL);
// Palette* palette = new Palette(0, 256); if (sprite == NULL) {
// bool array[256]; jalert(_("Error<<There is no sprite selected to quantize.||&OK"));
return;
}
// paledit_get_selected_entries(palette_editor, array); if (sprite->getImgType() != IMAGE_RGB) {
// paledit_get_palette(palette_editor)->copyColorsTo(palette); jalert(_("Error<<You can use this command only for RGB sprites||&OK"));
return;
}
// if (sprite->getImgType() == IMAGE_RGB) { Palette* palette = new Palette(0, 256);
// SpriteWriter sprite_writer(sprite); {
// sprite_quantize_ex(sprite_writer, palette); SpriteWriter sprite_writer(sprite);
// } sprite_quantize_ex(sprite_writer, palette);
// else { set_new_palette(palette);
// jalert(_("Error<<You can use this command only for RGB sprites||&OK")); }
// } delete palette;
// set_new_palette(palette);
// delete palette;
} }
static bool sliderRGB_change_hook(JWidget widget, void *data) static bool sliderRGB_change_hook(JWidget widget, void *data)
@ -782,6 +782,9 @@ static void set_new_palette(Palette* palette)
// Set the palette calling the hooks // Set the palette calling the hooks
set_current_palette(palette, false); set_current_palette(palette, false);
// Update the sprite palette
update_current_sprite_palette();
// Redraw the entire screen // Redraw the entire screen
jmanager_refresh_screen(); jmanager_refresh_screen();
} }