mirror of
https://github.com/aseprite/aseprite.git
synced 2024-09-02 13:09:27 +00:00
Removed Context::getFg/BgColor member functions.
Modified color_get_*() so they do not need "imgtype" parameter. ColorBar class is public (defined in colbar.h). Added ColorBar::Fg/BgColorChange signals. Converted palette editor widget to a C++ class (PalEdit derived from Widget). Modified the "Palette Editor" (F4 key) to be non-modal (still WIP).
This commit is contained in:
parent
37e08c1a4a
commit
10781dcf5f
@ -67,7 +67,9 @@
|
||||
<!-- tools -->
|
||||
<key command="configure_tools" shortcut="C" />
|
||||
<key command="film_editor" shortcut="Tab" />
|
||||
<key command="palette_editor" shortcut="F4" />
|
||||
<key command="palette_editor" shortcut="F4">
|
||||
<param name="switch" value="true" />
|
||||
</key>
|
||||
<key command="convolution_matrix" shortcut="F9" />
|
||||
<key command="color_curve" shortcut="Ctrl+M" />
|
||||
<key command="color_curve" shortcut="F10" />
|
||||
@ -289,7 +291,9 @@
|
||||
<item command="configure_tools" text="&Configure" />
|
||||
<separator />
|
||||
<item command="film_editor" text="&Animation Editor" />
|
||||
<item command="palette_editor" text="&Palette Editor" />
|
||||
<item command="palette_editor" text="&Palette Editor">
|
||||
<param name="switch" value="true" />
|
||||
</item>
|
||||
<separator />
|
||||
<menu text="F&X" id="fx_popup">
|
||||
<item command="convolution_matrix" text="Convolution &Matrix" />
|
||||
|
@ -5,63 +5,80 @@
|
||||
<box vertical="true">
|
||||
<box horizontal="true" expansive="true">
|
||||
<box vertical="true">
|
||||
<view name="palette_editor" expansive="true" /> <!-- custom-widget -->
|
||||
<slider min="1" max="256" name="columns" />
|
||||
<view name="palette_editor" /> <!-- custom-widget -->
|
||||
</box>
|
||||
<box vertical="true" expansive="true">
|
||||
<box horizontal="true">
|
||||
<box vertical="true" homogeneous="true">
|
||||
<label text="R" />
|
||||
<label text="G" />
|
||||
<label text="B" />
|
||||
</box>
|
||||
<box vertical="true" homogeneous="true" expansive="true">
|
||||
<slider min="0" max="255" name="red" />
|
||||
<slider min="0" max="255" name="green" />
|
||||
<slider min="0" max="255" name="blue" />
|
||||
</box>
|
||||
<box vertical="true" homogeneous="true">
|
||||
<label text="H" />
|
||||
<label text="S" />
|
||||
<label text="V" />
|
||||
</box>
|
||||
<box vertical="true" homogeneous="true" expansive="true">
|
||||
<slider min="0" max="255" name="hue" />
|
||||
<slider min="0" max="255" name="saturation" />
|
||||
<slider min="0" max="255" name="value" />
|
||||
</box>
|
||||
<box horizontal="true" childspacing="0" noborders="true">
|
||||
<radio group="1" text="RGB" name="select_rgb" looklike="button" selected="true" />
|
||||
<radio group="1" text="HSV" name="select_hsv" looklike="button" />
|
||||
<box horizontal="true" expansive="true" />
|
||||
<button text="+" name="make_bigger" tooltip="More options" />
|
||||
</box>
|
||||
<box name="colorviewer" expansive="true" /> <!-- custom-widget -->
|
||||
<button text="Select &All" name="select_all" />
|
||||
<box vertical="true">
|
||||
<box horizontal="true" homogeneous="true">
|
||||
<button text="&Undo" name="undo" />
|
||||
<button text="&Redo" name="redo" />
|
||||
</box>
|
||||
<box horizontal="true" homogeneous="true">
|
||||
<button text="&Load" name="load" />
|
||||
<button text="&Save" name="save" />
|
||||
</box>
|
||||
<box horizontal="true" homogeneous="true">
|
||||
<button text="&Ramp" name="ramp" />
|
||||
<button text="&Quantize" name="quantize" />
|
||||
</box>
|
||||
</box>
|
||||
</box>
|
||||
</box>
|
||||
<box horizontal="true">
|
||||
<label text="Frame:" />
|
||||
<slider min="0" max="1" name="frame" expansive="true" />
|
||||
</box>
|
||||
|
||||
<box horizontal="true">
|
||||
<check name="all_frames" text="All frames the same palette" />
|
||||
<box horizontal="true" expansive="true" />
|
||||
<box horizontal="true" homogeneous="true">
|
||||
<button text="&OK" name="button_ok" magnetic="true" width="60" />
|
||||
<button text="&Cancel" />
|
||||
<grid columns="3" childspacing="0">
|
||||
|
||||
<label name="R_label" text="R" />
|
||||
<slider name="R_slider" min="0" max="255" cell_align="horizontal" />
|
||||
<entry name="R_entry" maxsize="3" />
|
||||
|
||||
<label name="G_label" text="G" />
|
||||
<slider name="G_slider" min="0" max="255" cell_align="horizontal" />
|
||||
<entry name="G_entry" maxsize="3" />
|
||||
|
||||
<label name="B_label" text="B" />
|
||||
<slider name="B_slider" min="0" max="255" cell_align="horizontal" />
|
||||
<entry name="B_entry" maxsize="3" />
|
||||
|
||||
<label name="H_label" text="H" />
|
||||
<slider name="H_slider" min="0" max="255" cell_align="horizontal" />
|
||||
<entry name="H_entry" maxsize="3" />
|
||||
|
||||
<label name="S_label" text="S" />
|
||||
<slider name="S_slider" min="0" max="255" cell_align="horizontal" />
|
||||
<entry name="S_entry" maxsize="3" />
|
||||
|
||||
<label name="V_label" text="V" />
|
||||
<slider name="V_slider" min="0" max="255" cell_align="horizontal" />
|
||||
<entry name="V_entry" maxsize="3" />
|
||||
|
||||
<label name="hex_label" text="#" />
|
||||
<box horizontal="true" cell_hspan="2" >
|
||||
<entry name="hex_entry" maxsize="6" />
|
||||
</box>
|
||||
|
||||
</grid>
|
||||
|
||||
<!-- <box name="colorviewer_box" expansive="true" /> <\!-- custom-widget -\-> -->
|
||||
<!-- <button text="Select &All" name="select_all" /> -->
|
||||
<!-- <box vertical="true"> -->
|
||||
<!-- <box horizontal="true" homogeneous="true"> -->
|
||||
<!-- <button text="&Undo" name="undo" /> -->
|
||||
<!-- <button text="&Redo" name="redo" /> -->
|
||||
<!-- </box> -->
|
||||
<!-- <box horizontal="true" homogeneous="true"> -->
|
||||
<!-- <button text="&Load" name="load" /> -->
|
||||
<!-- <button text="&Save" name="save" /> -->
|
||||
<!-- </box> -->
|
||||
<!-- <box horizontal="true" homogeneous="true"> -->
|
||||
<!-- <button text="&Ramp" name="ramp" /> -->
|
||||
<!-- <button text="&Quantize" name="quantize" /> -->
|
||||
<!-- </box> -->
|
||||
<!-- </box> -->
|
||||
</box>
|
||||
</box>
|
||||
<!-- <box horizontal="true"> -->
|
||||
<!-- <label text="Frame:" /> -->
|
||||
<!-- <slider min="0" max="1" name="frame" expansive="true" /> -->
|
||||
<!-- </box> -->
|
||||
|
||||
<!-- <box horizontal="true"> -->
|
||||
<!-- <\!-- <check name="all_frames" text="All frames the same palette" /> -\-> -->
|
||||
<!-- <box horizontal="true" expansive="true" /> -->
|
||||
<!-- <box horizontal="true" homogeneous="true"> -->
|
||||
<!-- <button text="&OK" name="button_ok" magnetic="true" width="60" /> -->
|
||||
<!-- <button text="&Cancel" /> -->
|
||||
<!-- </box> -->
|
||||
<!-- </box> -->
|
||||
</box>
|
||||
</window>
|
||||
</jinete>
|
||||
|
14
src/app.cpp
14
src/app.cpp
@ -100,8 +100,8 @@ static Widget* box_toolbar = NULL; /* box where the tools bar is */
|
||||
static Widget* box_statusbar = NULL; /* box where the status bar is */
|
||||
static Widget* box_tabsbar = NULL; /* box where the tabs bar is */
|
||||
static Widget* menubar = NULL; /* the menu bar widget */
|
||||
static StatusBar* statusbar = NULL; /* the status bar widget */
|
||||
static Widget* colorbar = NULL; /* the color bar widget */
|
||||
static StatusBar* statusbar = NULL; /* the status bar widget */
|
||||
static ColorBar* colorbar = NULL; /* the color bar widget */
|
||||
static Widget* toolbar = NULL; /* the tool bar widget */
|
||||
static Widget* tabsbar = NULL; /* the tabs bar widget */
|
||||
|
||||
@ -168,7 +168,7 @@ int App::run()
|
||||
|
||||
menubar = jmenubar_new();
|
||||
statusbar = new StatusBar();
|
||||
colorbar = colorbar_new(box_colorbar->getAlign());
|
||||
colorbar = new ColorBar(box_colorbar->getAlign());
|
||||
toolbar = toolbar_new();
|
||||
tabsbar = tabs_new(tabsbar_select_callback);
|
||||
view = editor_view_new();
|
||||
@ -430,7 +430,7 @@ int app_get_current_image_type()
|
||||
Frame* app_get_top_window() { return top_window; }
|
||||
Widget* app_get_menubar() { return menubar; }
|
||||
StatusBar* app_get_statusbar() { return statusbar; }
|
||||
Widget* app_get_colorbar() { return colorbar; }
|
||||
ColorBar* app_get_colorbar() { return colorbar; }
|
||||
Widget* app_get_toolbar() { return toolbar; }
|
||||
Widget* app_get_tabsbar() { return tabsbar; }
|
||||
|
||||
@ -442,7 +442,7 @@ void app_default_statusbar_message()
|
||||
|
||||
int app_get_fg_color(Sprite *sprite)
|
||||
{
|
||||
color_t c = colorbar_get_fg_color(colorbar);
|
||||
color_t c = colorbar->getFgColor();
|
||||
assert(sprite != NULL);
|
||||
|
||||
if (sprite->getCurrentLayer() != NULL)
|
||||
@ -453,7 +453,7 @@ int app_get_fg_color(Sprite *sprite)
|
||||
|
||||
int app_get_bg_color(Sprite *sprite)
|
||||
{
|
||||
color_t c = colorbar_get_bg_color(colorbar);
|
||||
color_t c = colorbar->getBgColor();
|
||||
assert(sprite != NULL);
|
||||
|
||||
if (sprite->getCurrentLayer() != NULL)
|
||||
@ -469,7 +469,7 @@ int app_get_color_to_clear_layer(Layer *layer)
|
||||
|
||||
/* the `Background' is erased with the `Background Color' */
|
||||
if (layer != NULL && layer->is_background())
|
||||
color = colorbar_get_bg_color(colorbar);
|
||||
color = colorbar->getBgColor();
|
||||
|
||||
return get_color_for_layer(layer, color);
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ class LegacyModules;
|
||||
class Params;
|
||||
class Sprite;
|
||||
class ToolBox;
|
||||
class ColorBar;
|
||||
class StatusBar;
|
||||
|
||||
class App
|
||||
@ -70,7 +71,7 @@ int app_get_current_image_type();
|
||||
Frame* app_get_top_window();
|
||||
Widget* app_get_menubar();
|
||||
StatusBar* app_get_statusbar();
|
||||
Widget* app_get_colorbar();
|
||||
ColorBar* app_get_colorbar();
|
||||
Widget* app_get_toolbar();
|
||||
Widget* app_get_tabsbar();
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "app.h"
|
||||
#include "core/cfg.h"
|
||||
#include "modules/gui.h"
|
||||
#include "widgets/colbar.h"
|
||||
#include "widgets/statebar.h"
|
||||
|
||||
class AdvancedModeCommand : public Command
|
||||
|
@ -62,7 +62,8 @@ void BackgroundFromLayerCommand::execute(Context* context)
|
||||
|
||||
// each frame of the layer to be converted as `Background' must be
|
||||
// cleared using the selected background color in the color-bar
|
||||
int bgcolor = context->getBgColor();
|
||||
int bgcolor = get_color_for_image(sprite->getImgType(),
|
||||
context->getSettings()->getBgColor());
|
||||
bgcolor = fixup_color_for_background(sprite->getImgType(), bgcolor);
|
||||
|
||||
{
|
||||
|
@ -108,7 +108,10 @@ void CanvasSizeCommand::execute(Context* context)
|
||||
|
||||
{
|
||||
Undoable undoable(sprite, "Canvas Size");
|
||||
int bgcolor = context->getBgColor();
|
||||
int bgcolor = get_color_for_image(sprite->getImgType(),
|
||||
context->getSettings()->getBgColor());
|
||||
bgcolor = fixup_color_for_background(sprite->getImgType(), bgcolor);
|
||||
|
||||
undoable.crop_sprite(x1, y1, x2-x1, y2-y1, bgcolor);
|
||||
undoable.commit();
|
||||
}
|
||||
|
@ -70,10 +70,9 @@ void ChangeColorCommand::load_params(Params* params)
|
||||
|
||||
void ChangeColorCommand::execute(Context* context)
|
||||
{
|
||||
JWidget colorbar = app_get_colorbar();
|
||||
color_t color = m_background ? colorbar_get_bg_color(colorbar):
|
||||
colorbar_get_fg_color(colorbar);
|
||||
int imgtype = app_get_current_image_type();
|
||||
ColorBar* colorbar = app_get_colorbar();
|
||||
color_t color = m_background ? colorbar->getBgColor():
|
||||
colorbar->getFgColor();
|
||||
|
||||
switch (m_change) {
|
||||
case None:
|
||||
@ -81,7 +80,7 @@ void ChangeColorCommand::execute(Context* context)
|
||||
break;
|
||||
case IncrementIndex:
|
||||
if (color_type(color) == COLOR_TYPE_INDEX) {
|
||||
int index = color_get_index(imgtype, color);
|
||||
int index = color_get_index(color);
|
||||
if (index < 255) // TODO use sprite palette limit
|
||||
color = color_index(index+1);
|
||||
}
|
||||
@ -90,7 +89,7 @@ void ChangeColorCommand::execute(Context* context)
|
||||
break;
|
||||
case DecrementIndex:
|
||||
if (color_type(color) == COLOR_TYPE_INDEX) {
|
||||
int index = color_get_index(imgtype, color);
|
||||
int index = color_get_index(color);
|
||||
if (index > 0)
|
||||
color = color_index(index-1);
|
||||
}
|
||||
@ -100,9 +99,9 @@ void ChangeColorCommand::execute(Context* context)
|
||||
}
|
||||
|
||||
if (m_background)
|
||||
colorbar_set_bg_color(colorbar, color);
|
||||
colorbar->setBgColor(color);
|
||||
else
|
||||
colorbar_set_fg_color(colorbar, color);
|
||||
colorbar->setFgColor(color);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -67,7 +67,7 @@ void CropSpriteCommand::execute(Context* context)
|
||||
{
|
||||
Undoable undoable(sprite, "Sprite Crop");
|
||||
int bgcolor = get_color_for_image(sprite->getImgType(),
|
||||
colorbar_get_bg_color(app_get_colorbar()));
|
||||
app_get_colorbar()->getBgColor());
|
||||
undoable.crop_sprite(sprite->getMask()->x,
|
||||
sprite->getMask()->y,
|
||||
sprite->getMask()->w,
|
||||
@ -111,7 +111,7 @@ void AutocropSpriteCommand::execute(Context* context)
|
||||
CurrentSpriteWriter sprite(context);
|
||||
{
|
||||
Undoable undoable(sprite, "Sprite Autocrop");
|
||||
undoable.autocrop_sprite(colorbar_get_bg_color(app_get_colorbar()));
|
||||
undoable.autocrop_sprite(app_get_colorbar()->getBgColor());
|
||||
undoable.commit();
|
||||
}
|
||||
sprite->generateMaskBoundaries();
|
||||
|
@ -89,9 +89,9 @@ void EyedropperCommand::execute(Context* context)
|
||||
|
||||
// set the color of the color-bar
|
||||
if (m_background)
|
||||
colorbar_set_bg_color(app_get_colorbar(), color);
|
||||
app_get_colorbar()->setBgColor(color);
|
||||
else
|
||||
colorbar_set_fg_color(app_get_colorbar(), color);
|
||||
app_get_colorbar()->setFgColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ void FlattenLayersCommand::execute(Context* context)
|
||||
{
|
||||
CurrentSpriteWriter sprite(context);
|
||||
int bgcolor = get_color_for_image(sprite->getImgType(),
|
||||
colorbar_get_bg_color(app_get_colorbar()));
|
||||
app_get_colorbar()->getBgColor());
|
||||
{
|
||||
Undoable undoable(sprite, "Flatten Layers");
|
||||
undoable.flatten_layers(bgcolor);
|
||||
|
@ -78,7 +78,7 @@ void NewFileCommand::execute(Context* context)
|
||||
color_rgb(0, 0, 0),
|
||||
color_rgb(255, 255, 255),
|
||||
color_rgb(255, 0, 255),
|
||||
colorbar_get_bg_color(app_get_colorbar())
|
||||
app_get_colorbar()->getBgColor()
|
||||
};
|
||||
int ncolors = 256;
|
||||
|
||||
|
@ -24,22 +24,44 @@
|
||||
#include <assert.h>
|
||||
#include <vector>
|
||||
|
||||
#include "Vaca/Bind.h"
|
||||
#include "jinete/jinete.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "commands/command.h"
|
||||
#include "commands/params.h"
|
||||
#include "core/cfg.h"
|
||||
#include "core/color.h"
|
||||
#include "dialogs/filesel.h"
|
||||
#include "modules/gui.h"
|
||||
#include "modules/editors.h"
|
||||
#include "modules/palettes.h"
|
||||
#include "raster/image.h"
|
||||
#include "raster/palette.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/stock.h"
|
||||
#include "util/quantize.h"
|
||||
#include "widgets/colbar.h"
|
||||
#include "widgets/colview.h"
|
||||
#include "widgets/editor.h"
|
||||
#include "widgets/paledit.h"
|
||||
#include "sprite_wrappers.h"
|
||||
#include "ui_context.h"
|
||||
|
||||
static Frame* window = NULL;
|
||||
static int redraw_timer_id = -1;
|
||||
static bool redraw_all = false;
|
||||
|
||||
// Slot for App::Exit signal
|
||||
static void on_exit_delete_this_widget()
|
||||
{
|
||||
assert(window != NULL);
|
||||
|
||||
jmanager_remove_timer(redraw_timer_id);
|
||||
redraw_timer_id = -1;
|
||||
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// palette_editor
|
||||
@ -51,21 +73,30 @@ public:
|
||||
Command* clone() { return new PaletteEditorCommand(*this); }
|
||||
|
||||
protected:
|
||||
void load_params(Params* params);
|
||||
void execute(Context* context);
|
||||
|
||||
private:
|
||||
bool m_open;
|
||||
bool m_close;
|
||||
bool m_switch;
|
||||
bool m_background;
|
||||
};
|
||||
|
||||
#define get_sprite(wgt) (*(const SpriteReader*)(wgt->getRoot())->user_data[0])
|
||||
// #define get_sprite(wgt) (*(const SpriteReader*)(wgt->getRoot())->user_data[0])
|
||||
|
||||
static std::vector<Palette*> palettes;
|
||||
static Widget *R_label, *G_label, *B_label;
|
||||
static Widget *H_label, *S_label, *V_label;
|
||||
static Widget *R_slider, *G_slider, *B_slider;
|
||||
static Widget *H_slider, *S_slider, *V_slider;
|
||||
static Widget *R_entry, *G_entry, *B_entry;
|
||||
static Widget *H_entry, *S_entry, *V_entry;
|
||||
static Widget *hex_entry;
|
||||
static PalEdit* palette_editor;
|
||||
static bool disable_colorbar_signals = false;
|
||||
|
||||
static JWidget slider_R, slider_G, slider_B;
|
||||
static JWidget slider_H, slider_S, slider_V;
|
||||
static JWidget colorviewer;
|
||||
static JWidget palette_editor;
|
||||
static JWidget slider_frame;
|
||||
static JWidget check_all_frames;
|
||||
|
||||
static void select_all_command(JWidget widget);
|
||||
static bool window_msg_proc(JWidget widget, JMessage msg);
|
||||
static bool window_close_hook(JWidget widget, void *data);
|
||||
static void load_command(JWidget widget);
|
||||
static void save_command(JWidget widget);
|
||||
static void ramp_command(JWidget widget);
|
||||
@ -73,10 +104,19 @@ static void quantize_command(JWidget widget);
|
||||
|
||||
static bool sliderRGB_change_hook(JWidget widget, void *data);
|
||||
static bool sliderHSV_change_hook(JWidget widget, void *data);
|
||||
static bool slider_columns_change_hook(JWidget widget, void *data);
|
||||
static bool slider_frame_change_hook(JWidget widget, void *data);
|
||||
static bool check_all_frames_change_hook(JWidget widget, void *data);
|
||||
static bool entryRGB_change_hook(JWidget widget, void *data);
|
||||
static bool entryHSV_change_hook(JWidget widget, void *data);
|
||||
static bool hex_entry_change_hook(JWidget widget, void *data);
|
||||
static void update_entries_from_sliders();
|
||||
static void update_sliders_from_entries();
|
||||
static void update_hex_entry();
|
||||
static void update_current_sprite_palette();
|
||||
static void update_colorbar();
|
||||
static bool palette_editor_change_hook(JWidget widget, void *data);
|
||||
static bool select_rgb_hook(JWidget widget, void *data);
|
||||
static bool select_hsv_hook(JWidget widget, void *data);
|
||||
static void modify_all_selected_entries_in_palette(int r, int g, int b);
|
||||
static void on_color_changed(color_t color);
|
||||
|
||||
static void set_new_palette(Palette *palette);
|
||||
|
||||
@ -85,217 +125,201 @@ PaletteEditorCommand::PaletteEditorCommand()
|
||||
"PaletteEditor",
|
||||
CmdRecordableFlag)
|
||||
{
|
||||
m_open = true;
|
||||
m_close = false;
|
||||
m_switch = false;
|
||||
m_background = false;
|
||||
}
|
||||
|
||||
void PaletteEditorCommand::load_params(Params* params)
|
||||
{
|
||||
std::string target = params->get("target");
|
||||
if (target == "foreground") m_background = false;
|
||||
else if (target == "background") m_background = true;
|
||||
|
||||
std::string open_str = params->get("open");
|
||||
if (open_str == "true") m_open = true;
|
||||
else m_open = false;
|
||||
|
||||
std::string close_str = params->get("close");
|
||||
if (close_str == "true") m_close = true;
|
||||
else m_close = false;
|
||||
|
||||
std::string switch_str = params->get("switch");
|
||||
if (switch_str == "true") m_switch = true;
|
||||
else m_switch = false;
|
||||
}
|
||||
|
||||
void PaletteEditorCommand::execute(Context* context)
|
||||
{
|
||||
JWidget colorviewer_box, palette_editor_view;
|
||||
JWidget slider_columns, button_ok;
|
||||
JWidget button_select_all;
|
||||
JWidget button_undo, button_redo;
|
||||
JWidget button_load, button_save;
|
||||
JWidget button_ramp, button_quantize;
|
||||
int frame, columns;
|
||||
Palette *palette = NULL;
|
||||
const CurrentSpriteReader sprite(context);
|
||||
int imgtype = sprite ? sprite->getImgType(): IMAGE_INDEXED;
|
||||
int frame_bak = sprite ? sprite->getCurrentFrame() : 0;
|
||||
bool all_frames_same_palette = true;
|
||||
Widget* palette_editor_view;
|
||||
Widget* select_rgb;
|
||||
Widget* select_hsv;
|
||||
bool first_time = false;
|
||||
|
||||
if (imgtype == IMAGE_GRAYSCALE) {
|
||||
jalert(_("Error<<You can't edit grayscale palette||&OK"));
|
||||
// If the window was never loaded yet, load it
|
||||
if (!window) {
|
||||
if (m_close)
|
||||
return; // Do nothing (the user want to close and inexistent window)
|
||||
|
||||
// Load the palette editor window
|
||||
window = static_cast<Frame*>(load_widget("palette_editor.xml", "palette_editor"));
|
||||
redraw_timer_id = jmanager_add_timer(window, 250);
|
||||
|
||||
first_time = true;
|
||||
|
||||
// Append hooks
|
||||
window->Close.connect(Vaca::Bind<bool>(&window_close_hook, (JWidget)window, (void*)0));
|
||||
|
||||
// Hook fg/bg color changes (by eyedropper mainly)
|
||||
app_get_colorbar()->FgColorChange.connect(&on_color_changed);
|
||||
app_get_colorbar()->BgColorChange.connect(&on_color_changed);
|
||||
|
||||
// Hook App::Exit signal
|
||||
App::instance()->Exit.connect(&on_exit_delete_this_widget);
|
||||
}
|
||||
// If the window is opened, close it (only in "switch" mode)
|
||||
else if (jwidget_is_visible(window) && (m_switch || m_close)) {
|
||||
window->closeWindow(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
/* load widgets */
|
||||
FramePtr window(load_widget("palette_editor.xml", "palette_editor"));
|
||||
get_widgets(window,
|
||||
"red", &slider_R,
|
||||
"green", &slider_G,
|
||||
"blue", &slider_B,
|
||||
"hue", &slider_H,
|
||||
"saturation", &slider_S,
|
||||
"value", &slider_V,
|
||||
"columns", &slider_columns,
|
||||
"frame", &slider_frame,
|
||||
"select_all", &button_select_all,
|
||||
"undo", &button_undo,
|
||||
"redo", &button_redo,
|
||||
"load", &button_load,
|
||||
"save", &button_save,
|
||||
"ramp", &button_ramp,
|
||||
"quantize", &button_quantize,
|
||||
"button_ok", &button_ok,
|
||||
"colorviewer", &colorviewer_box,
|
||||
"palette_editor", &palette_editor_view,
|
||||
"all_frames", &check_all_frames, NULL);
|
||||
"R_label", &R_label,
|
||||
"R_slider", &R_slider,
|
||||
"R_entry", &R_entry,
|
||||
"G_label", &G_label,
|
||||
"G_slider", &G_slider,
|
||||
"G_entry", &G_entry,
|
||||
"B_label", &B_label,
|
||||
"B_slider", &B_slider,
|
||||
"B_entry", &B_entry,
|
||||
"H_label", &H_label,
|
||||
"H_slider", &H_slider,
|
||||
"H_entry", &H_entry,
|
||||
"S_label", &S_label,
|
||||
"S_slider", &S_slider,
|
||||
"S_entry", &S_entry,
|
||||
"V_label", &V_label,
|
||||
"V_slider", &V_slider,
|
||||
"V_entry", &V_entry,
|
||||
"hex_entry", &hex_entry,
|
||||
"select_rgb", &select_rgb,
|
||||
"select_hsv", &select_hsv,
|
||||
// "load", &button_load,
|
||||
// "save", &button_save,
|
||||
// "ramp", &button_ramp,
|
||||
// "quantize", &button_quantize,
|
||||
// "button_ok", &button_ok,
|
||||
// "colorviewer_box", &colorviewer_box,
|
||||
"palette_editor", &palette_editor_view, NULL);
|
||||
|
||||
window->user_data[0] = (void*)&sprite;
|
||||
|
||||
/* create current_sprite->frames palettes */
|
||||
if (sprite) {
|
||||
palettes.resize(sprite->getTotalFrames());
|
||||
|
||||
for (frame=0; frame<sprite->getTotalFrames(); ++frame) {
|
||||
const Palette* orig = sprite->getPalette(frame);
|
||||
|
||||
palettes[frame] = new Palette(frame, orig->size());
|
||||
orig->copyColorsTo(palettes[frame]);
|
||||
// window->user_data[0] = (void*)&sprite;
|
||||
|
||||
if (frame > 0 &&
|
||||
palettes[frame-1]->countDiff(palettes[frame], NULL, NULL) > 0) {
|
||||
all_frames_same_palette = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
palettes.clear();
|
||||
jwidget_disable(check_all_frames);
|
||||
}
|
||||
// Custom widgets
|
||||
if (first_time) {
|
||||
// colorviewer = colorviewer_new(color_index(0), IMAGE_INDEXED);
|
||||
palette_editor = new PalEdit(true);
|
||||
palette_editor->setBoxSize(4);
|
||||
|
||||
/* get current palette */
|
||||
palette = new Palette(*get_current_palette());
|
||||
// jwidget_expansive(colorviewer, true);
|
||||
// jwidget_add_child(colorviewer_box, colorviewer);
|
||||
|
||||
/* get configuration */
|
||||
columns = get_config_int("PaletteEditor", "Columns", 16);
|
||||
columns = MID(1, columns, 256);
|
||||
// jwidget_disable(button_undo);
|
||||
// jwidget_disable(button_redo);
|
||||
|
||||
/* custom widgets */
|
||||
colorviewer = colorviewer_new(color_index(0), IMAGE_INDEXED);
|
||||
palette_editor = paledit_new(palette, true, 6);
|
||||
jview_attach(palette_editor_view, palette_editor);
|
||||
jview_maxsize(palette_editor_view);
|
||||
|
||||
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_maxsize(palette_editor_view);
|
||||
|
||||
/* set columns */
|
||||
jslider_set_value(slider_columns, columns);
|
||||
paledit_set_columns(palette_editor, columns);
|
||||
|
||||
/* all frames */
|
||||
if (all_frames_same_palette)
|
||||
jwidget_select(check_all_frames);
|
||||
else
|
||||
jwidget_deselect(check_all_frames);
|
||||
// Set palette editor columns
|
||||
palette_editor->setColumns(16);
|
||||
|
||||
/* frame */
|
||||
if (sprite) {
|
||||
jslider_set_range(slider_frame, 0, sprite->getTotalFrames()-1);
|
||||
jslider_set_value(slider_frame, sprite->getCurrentFrame());
|
||||
|
||||
if (jwidget_is_selected(check_all_frames))
|
||||
jwidget_disable(slider_frame);
|
||||
}
|
||||
else {
|
||||
jwidget_disable(slider_frame);
|
||||
jwidget_disable(button_quantize);
|
||||
// Hook signals
|
||||
jwidget_add_hook(window, -1, window_msg_proc, NULL);
|
||||
HOOK(R_slider, JI_SIGNAL_SLIDER_CHANGE, sliderRGB_change_hook, 0);
|
||||
HOOK(G_slider, JI_SIGNAL_SLIDER_CHANGE, sliderRGB_change_hook, 0);
|
||||
HOOK(B_slider, JI_SIGNAL_SLIDER_CHANGE, sliderRGB_change_hook, 0);
|
||||
HOOK(H_slider, JI_SIGNAL_SLIDER_CHANGE, sliderHSV_change_hook, 0);
|
||||
HOOK(S_slider, JI_SIGNAL_SLIDER_CHANGE, sliderHSV_change_hook, 0);
|
||||
HOOK(V_slider, JI_SIGNAL_SLIDER_CHANGE, sliderHSV_change_hook, 0);
|
||||
HOOK(R_entry, JI_SIGNAL_ENTRY_CHANGE, entryRGB_change_hook, 0);
|
||||
HOOK(G_entry, JI_SIGNAL_ENTRY_CHANGE, entryRGB_change_hook, 0);
|
||||
HOOK(B_entry, JI_SIGNAL_ENTRY_CHANGE, entryRGB_change_hook, 0);
|
||||
HOOK(H_entry, JI_SIGNAL_ENTRY_CHANGE, entryHSV_change_hook, 0);
|
||||
HOOK(S_entry, JI_SIGNAL_ENTRY_CHANGE, entryHSV_change_hook, 0);
|
||||
HOOK(V_entry, JI_SIGNAL_ENTRY_CHANGE, entryHSV_change_hook, 0);
|
||||
HOOK(hex_entry, JI_SIGNAL_ENTRY_CHANGE, hex_entry_change_hook, 0);
|
||||
HOOK(palette_editor, SIGNAL_PALETTE_EDITOR_CHANGE, palette_editor_change_hook, 0);
|
||||
HOOK(select_rgb, JI_SIGNAL_RADIO_CHANGE, select_rgb_hook, 0);
|
||||
HOOK(select_hsv, JI_SIGNAL_RADIO_CHANGE, select_hsv_hook, 0);
|
||||
|
||||
setup_mini_look(select_rgb);
|
||||
setup_mini_look(select_hsv);
|
||||
|
||||
// jbutton_add_command(button_load, load_command);
|
||||
// jbutton_add_command(button_save, save_command);
|
||||
// jbutton_add_command(button_ramp, ramp_command);
|
||||
// jbutton_add_command(button_quantize, quantize_command);
|
||||
|
||||
select_rgb_hook(NULL, NULL);
|
||||
}
|
||||
|
||||
/* hook signals */
|
||||
HOOK(slider_R, JI_SIGNAL_SLIDER_CHANGE, sliderRGB_change_hook, 0);
|
||||
HOOK(slider_G, JI_SIGNAL_SLIDER_CHANGE, sliderRGB_change_hook, 0);
|
||||
HOOK(slider_B, JI_SIGNAL_SLIDER_CHANGE, sliderRGB_change_hook, 0);
|
||||
HOOK(slider_H, JI_SIGNAL_SLIDER_CHANGE, sliderHSV_change_hook, 0);
|
||||
HOOK(slider_S, JI_SIGNAL_SLIDER_CHANGE, sliderHSV_change_hook, 0);
|
||||
HOOK(slider_V, JI_SIGNAL_SLIDER_CHANGE, sliderHSV_change_hook, 0);
|
||||
HOOK(slider_columns, JI_SIGNAL_SLIDER_CHANGE, slider_columns_change_hook, 0);
|
||||
HOOK(slider_frame, JI_SIGNAL_SLIDER_CHANGE, slider_frame_change_hook, 0);
|
||||
HOOK(check_all_frames, JI_SIGNAL_CHECK_CHANGE, check_all_frames_change_hook, 0);
|
||||
HOOK(palette_editor, SIGNAL_PALETTE_EDITOR_CHANGE, palette_editor_change_hook, 0);
|
||||
// Show the specified target color
|
||||
{
|
||||
int imgtype = app_get_current_image_type();
|
||||
color_t color =
|
||||
(m_background ? context->getSettings()->getBgColor():
|
||||
context->getSettings()->getFgColor());
|
||||
|
||||
jbutton_add_command(button_select_all, select_all_command);
|
||||
jbutton_add_command(button_load, load_command);
|
||||
jbutton_add_command(button_save, save_command);
|
||||
jbutton_add_command(button_ramp, ramp_command);
|
||||
jbutton_add_command(button_quantize, quantize_command);
|
||||
on_color_changed(color);
|
||||
}
|
||||
|
||||
/* default position */
|
||||
window->remap_window();
|
||||
window->center_window();
|
||||
if (m_switch || m_open) {
|
||||
if (!jwidget_is_visible(window)) {
|
||||
// Default position
|
||||
window->remap_window();
|
||||
window->center_window();
|
||||
|
||||
/* load window configuration */
|
||||
load_window_pos(window, "PaletteEditor");
|
||||
|
||||
/* open and run the window */
|
||||
window->open_window_fg();
|
||||
|
||||
/* check the killer widget */
|
||||
if (window->get_killer() == button_ok) {
|
||||
if (sprite) {
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
sprite_writer->resetPalettes();
|
||||
|
||||
/* one palette */
|
||||
if (jwidget_is_selected(check_all_frames)) {
|
||||
// Copy the current palette in the first frame
|
||||
get_current_palette()->copyColorsTo(palettes[0]);
|
||||
|
||||
sprite_writer->setPalette(palettes[0], true);
|
||||
}
|
||||
/* various palettes */
|
||||
else {
|
||||
frame = jslider_get_value(slider_frame);
|
||||
get_current_palette()->copyColorsTo(palettes[frame]);
|
||||
|
||||
for (frame=0; frame<sprite_writer->getTotalFrames(); ++frame) {
|
||||
if (frame == 0 ||
|
||||
palettes[frame]->countDiff(palettes[frame-1], NULL, NULL) > 0) {
|
||||
sprite_writer->setPalette(palettes[frame], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Load window configuration
|
||||
load_window_pos(window, "PaletteEditor");
|
||||
}
|
||||
/* change the system palette */
|
||||
else
|
||||
set_default_palette(palette);
|
||||
|
||||
set_current_palette(palette, true);
|
||||
// Run the window in background
|
||||
window->open_window_bg();
|
||||
}
|
||||
/* cancel or ESC */
|
||||
else {
|
||||
/* restore the system palette */
|
||||
if (sprite) {
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
sprite_writer->setCurrentFrame(frame_bak);
|
||||
|
||||
set_current_palette(sprite->getPalette(frame_bak), true);
|
||||
}
|
||||
else {
|
||||
set_current_palette(NULL, true);
|
||||
}
|
||||
}
|
||||
|
||||
/* redraw the entire screen */
|
||||
jmanager_refresh_screen();
|
||||
|
||||
/* save columns configuration */
|
||||
columns = jslider_get_value(slider_columns);
|
||||
set_config_int("PaletteEditors", "Columns", MID(1, columns, 256));
|
||||
|
||||
/* save window configuration */
|
||||
save_window_pos(window, "PaletteEditor");
|
||||
|
||||
if (!palettes.empty()) {
|
||||
assert(sprite);
|
||||
|
||||
for (frame=0; frame<sprite->getTotalFrames(); ++frame)
|
||||
delete palettes[frame];
|
||||
|
||||
palettes.clear();
|
||||
}
|
||||
|
||||
delete palette;
|
||||
}
|
||||
|
||||
static void select_all_command(JWidget widget)
|
||||
static bool window_msg_proc(JWidget widget, JMessage msg)
|
||||
{
|
||||
paledit_select_range(palette_editor, 0, 255,
|
||||
PALETTE_EDITOR_RANGE_LINEAL);
|
||||
if (msg->type == JM_TIMER &&
|
||||
msg->timer.timer_id == redraw_timer_id) {
|
||||
// Redraw all editors
|
||||
if (redraw_all) {
|
||||
redraw_all = false;
|
||||
jmanager_stop_timer(redraw_timer_id);
|
||||
|
||||
try {
|
||||
const CurrentSpriteReader sprite(UIContext::instance());
|
||||
update_editors_with_sprite(sprite);
|
||||
}
|
||||
catch (...) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
// Redraw just the current editor
|
||||
else {
|
||||
redraw_all = true;
|
||||
current_editor->editor_update();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool window_close_hook(JWidget widget, void *data)
|
||||
{
|
||||
// Save window configuration
|
||||
save_window_pos(window, "PaletteEditor");
|
||||
return false;
|
||||
}
|
||||
|
||||
static void load_command(JWidget widget)
|
||||
@ -335,22 +359,24 @@ static void save_command(JWidget widget)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!paledit_get_palette(palette_editor)->save(filename.c_str())) {
|
||||
jalert(_("Error<<Saving palette file||&Close"));
|
||||
}
|
||||
// TODO
|
||||
// if (!palette_editor->getPalette()->save(filename.c_str())) {
|
||||
// jalert(_("Error<<Saving palette file||&Close"));
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
static void ramp_command(JWidget widget)
|
||||
{
|
||||
int range_type = paledit_get_range_type(palette_editor);
|
||||
int i1 = paledit_get_1st_color(palette_editor);
|
||||
int i2 = paledit_get_2nd_color(palette_editor);
|
||||
#if 0
|
||||
int range_type = palette_editor->getRangeType();
|
||||
int i1 = palette_editor->get1stColor();
|
||||
int i2 = palette_editor->get2ndColor();
|
||||
Palette* palette = new Palette(0, 256);
|
||||
bool array[256];
|
||||
|
||||
paledit_get_selected_entries(palette_editor, array);
|
||||
paledit_get_palette(palette_editor)->copyColorsTo(palette);
|
||||
palette_editor->getSelectedEntries(array);
|
||||
palette_editor->getPalette()->copyColorsTo(palette);
|
||||
|
||||
if ((i1 >= 0) && (i2 >= 0)) {
|
||||
/* make the ramp */
|
||||
@ -366,181 +392,348 @@ static void ramp_command(JWidget widget)
|
||||
|
||||
set_new_palette(palette);
|
||||
delete palette;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void quantize_command(JWidget widget)
|
||||
{
|
||||
const SpriteReader& sprite = get_sprite(widget);
|
||||
assert(sprite != NULL);
|
||||
// const SpriteReader& sprite = get_sprite(widget);
|
||||
// assert(sprite != NULL);
|
||||
|
||||
Palette* palette = new Palette(0, 256);
|
||||
bool array[256];
|
||||
// Palette* palette = new Palette(0, 256);
|
||||
// bool array[256];
|
||||
|
||||
paledit_get_selected_entries(palette_editor, array);
|
||||
paledit_get_palette(palette_editor)->copyColorsTo(palette);
|
||||
// paledit_get_selected_entries(palette_editor, array);
|
||||
// paledit_get_palette(palette_editor)->copyColorsTo(palette);
|
||||
|
||||
if (sprite->getImgType() == IMAGE_RGB) {
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
sprite_quantize_ex(sprite_writer, palette);
|
||||
}
|
||||
else {
|
||||
jalert(_("Error<<You can use this command only for RGB sprites||&OK"));
|
||||
}
|
||||
// if (sprite->getImgType() == IMAGE_RGB) {
|
||||
// SpriteWriter sprite_writer(sprite);
|
||||
// sprite_quantize_ex(sprite_writer, palette);
|
||||
// }
|
||||
// else {
|
||||
// jalert(_("Error<<You can use this command only for RGB sprites||&OK"));
|
||||
// }
|
||||
|
||||
set_new_palette(palette);
|
||||
delete palette;
|
||||
// set_new_palette(palette);
|
||||
// delete palette;
|
||||
}
|
||||
|
||||
static bool sliderRGB_change_hook(JWidget widget, void *data)
|
||||
{
|
||||
Palette *palette = paledit_get_palette(palette_editor);
|
||||
int r = jslider_get_value(slider_R);
|
||||
int g = jslider_get_value(slider_G);
|
||||
int b = jslider_get_value(slider_B);
|
||||
float h, s, v;
|
||||
bool array[256];
|
||||
int c;
|
||||
Palette* palette = get_current_palette();
|
||||
int r = jslider_get_value(R_slider);
|
||||
int g = jslider_get_value(G_slider);
|
||||
int b = jslider_get_value(B_slider);
|
||||
color_t color = color_rgb(r, g, b);
|
||||
|
||||
rgb_to_hsv(r, g, b, &h, &s, &v);
|
||||
jslider_set_value(H_slider, color_get_hue(color));
|
||||
jslider_set_value(V_slider, color_get_value(color));
|
||||
jslider_set_value(S_slider, color_get_saturation(color));
|
||||
|
||||
paledit_get_selected_entries(palette_editor, array);
|
||||
for (c=0; c<256; c++) {
|
||||
if (array[c]) {
|
||||
palette->setEntry(c, _rgba(r, g, b, 255));
|
||||
set_current_color(c, r, g, b);
|
||||
}
|
||||
}
|
||||
modify_all_selected_entries_in_palette(r, g, b);
|
||||
|
||||
jslider_set_value(slider_H, 255.0 * h / 360.0);
|
||||
jslider_set_value(slider_V, 255.0 * v);
|
||||
jslider_set_value(slider_S, 255.0 * s);
|
||||
|
||||
jwidget_dirty(palette_editor);
|
||||
update_entries_from_sliders();
|
||||
update_hex_entry();
|
||||
update_current_sprite_palette();
|
||||
update_colorbar();
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool sliderHSV_change_hook(JWidget widget, void *data)
|
||||
{
|
||||
Palette *palette = paledit_get_palette(palette_editor);
|
||||
int h = jslider_get_value(slider_H);
|
||||
int s = jslider_get_value(slider_S);
|
||||
int v = jslider_get_value(slider_V);
|
||||
Palette* palette = get_current_palette();
|
||||
int h = jslider_get_value(H_slider);
|
||||
int s = jslider_get_value(S_slider);
|
||||
int v = jslider_get_value(V_slider);
|
||||
color_t color = color_hsv(h, s, v);
|
||||
int r, g, b;
|
||||
|
||||
jslider_set_value(R_slider, r = color_get_red(color));
|
||||
jslider_set_value(G_slider, g = color_get_green(color));
|
||||
jslider_set_value(B_slider, b = color_get_blue(color));
|
||||
|
||||
modify_all_selected_entries_in_palette(r, g, b);
|
||||
|
||||
update_entries_from_sliders();
|
||||
update_hex_entry();
|
||||
update_current_sprite_palette();
|
||||
update_colorbar();
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool entryRGB_change_hook(JWidget widget, void *data)
|
||||
{
|
||||
int r = R_entry->getTextInt();
|
||||
int g = G_entry->getTextInt();
|
||||
int b = B_entry->getTextInt();
|
||||
r = MID(0, r, 255);
|
||||
g = MID(0, g, 255);
|
||||
b = MID(0, b, 255);
|
||||
color_t color = color_rgb(r, g, b);
|
||||
|
||||
H_entry->setTextf("%d", color_get_hue(color));
|
||||
V_entry->setTextf("%d", color_get_value(color));
|
||||
S_entry->setTextf("%d", color_get_saturation(color));
|
||||
|
||||
modify_all_selected_entries_in_palette(r, g, b);
|
||||
|
||||
update_sliders_from_entries();
|
||||
update_hex_entry();
|
||||
update_current_sprite_palette();
|
||||
update_colorbar();
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool entryHSV_change_hook(JWidget widget, void *data)
|
||||
{
|
||||
Palette* palette = get_current_palette();
|
||||
int h = H_entry->getTextInt();
|
||||
int s = S_entry->getTextInt();
|
||||
int v = V_entry->getTextInt();
|
||||
color_t color = color_hsv(h, s, v);
|
||||
int r, g, b;
|
||||
|
||||
R_entry->setTextf("%d", r = color_get_red(color));
|
||||
G_entry->setTextf("%d", g = color_get_green(color));
|
||||
B_entry->setTextf("%d", b = color_get_blue(color));
|
||||
|
||||
modify_all_selected_entries_in_palette(r, g, b);
|
||||
|
||||
update_sliders_from_entries();
|
||||
update_hex_entry();
|
||||
update_current_sprite_palette();
|
||||
update_colorbar();
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool hex_entry_change_hook(JWidget widget, void *data)
|
||||
{
|
||||
Palette* palette = get_current_palette();
|
||||
std::string text = hex_entry->getText();
|
||||
int r, g, b;
|
||||
float h, s, v;
|
||||
bool array[256];
|
||||
int c, r, g, b;
|
||||
int c;
|
||||
|
||||
hsv_to_rgb(360.0 * h / 255.0, s / 255.0, v / 255.0, &r, &g, &b);
|
||||
// Fill with zeros at the end of the text
|
||||
while (text.size() < 6)
|
||||
text.push_back('0');
|
||||
|
||||
paledit_get_selected_entries(palette_editor, array);
|
||||
// Convert text (Base 16) to integer
|
||||
int hex = strtol(text.c_str(), NULL, 16);
|
||||
|
||||
jslider_set_value(R_slider, r = ((hex & 0xff0000) >> 16));
|
||||
jslider_set_value(G_slider, g = ((hex & 0xff00) >> 8));
|
||||
jslider_set_value(B_slider, b = ((hex & 0xff)));
|
||||
|
||||
rgb_to_hsv(r, g, b, &h, &s, &v);
|
||||
|
||||
palette_editor->getSelectedEntries(array);
|
||||
for (c=0; c<256; c++) {
|
||||
if (array[c]) {
|
||||
palette->setEntry(c, _rgba(r, g, b, 255));
|
||||
set_current_color(c, r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
jslider_set_value(slider_R, r);
|
||||
jslider_set_value(slider_G, g);
|
||||
jslider_set_value(slider_B, b);
|
||||
jslider_set_value(H_slider, 255.0 * h / 360.0);
|
||||
jslider_set_value(V_slider, 255.0 * v);
|
||||
jslider_set_value(S_slider, 255.0 * s);
|
||||
|
||||
update_entries_from_sliders();
|
||||
update_current_sprite_palette();
|
||||
update_colorbar();
|
||||
return false;
|
||||
}
|
||||
|
||||
static void update_entries_from_sliders()
|
||||
{
|
||||
R_entry->setTextf("%d", jslider_get_value(R_slider));
|
||||
G_entry->setTextf("%d", jslider_get_value(G_slider));
|
||||
B_entry->setTextf("%d", jslider_get_value(B_slider));
|
||||
|
||||
H_entry->setTextf("%d", jslider_get_value(H_slider));
|
||||
S_entry->setTextf("%d", jslider_get_value(S_slider));
|
||||
V_entry->setTextf("%d", jslider_get_value(V_slider));
|
||||
}
|
||||
|
||||
static void update_sliders_from_entries()
|
||||
{
|
||||
jslider_set_value(R_slider, R_entry->getTextInt());
|
||||
jslider_set_value(G_slider, G_entry->getTextInt());
|
||||
jslider_set_value(B_slider, B_entry->getTextInt());
|
||||
|
||||
jslider_set_value(H_slider, H_entry->getTextInt());
|
||||
jslider_set_value(S_slider, S_entry->getTextInt());
|
||||
jslider_set_value(V_slider, V_entry->getTextInt());
|
||||
}
|
||||
|
||||
static void update_hex_entry()
|
||||
{
|
||||
hex_entry->setTextf("%02x%02x%02x",
|
||||
jslider_get_value(R_slider),
|
||||
jslider_get_value(G_slider),
|
||||
jslider_get_value(B_slider));
|
||||
}
|
||||
|
||||
static void update_current_sprite_palette()
|
||||
{
|
||||
if (UIContext::instance()->get_current_sprite()) {
|
||||
try {
|
||||
CurrentSpriteWriter sprite(UIContext::instance());
|
||||
sprite->setPalette(get_current_palette(), false);
|
||||
}
|
||||
catch (...) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
jwidget_dirty(palette_editor);
|
||||
return false;
|
||||
|
||||
if (!jmanager_timer_is_running(redraw_timer_id))
|
||||
jmanager_start_timer(redraw_timer_id);
|
||||
redraw_all = false;
|
||||
}
|
||||
|
||||
static bool slider_columns_change_hook(JWidget widget, void *data)
|
||||
static void update_colorbar()
|
||||
{
|
||||
paledit_set_columns(palette_editor,
|
||||
(int)jslider_get_value(widget));
|
||||
return false;
|
||||
app_get_colorbar()->dirty();
|
||||
}
|
||||
|
||||
static bool slider_frame_change_hook(JWidget widget, void *data)
|
||||
static void update_sliders_from_color(color_t color)
|
||||
{
|
||||
const SpriteReader& sprite = get_sprite(widget);
|
||||
assert(sprite != NULL);
|
||||
|
||||
int old_frame = sprite->getCurrentFrame();
|
||||
int new_frame = jslider_get_value(slider_frame);
|
||||
|
||||
get_current_palette()->copyColorsTo(palettes[old_frame]);
|
||||
{
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
sprite_writer->setCurrentFrame(new_frame);
|
||||
}
|
||||
set_new_palette(palettes[new_frame]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool check_all_frames_change_hook(JWidget widget, void *data)
|
||||
{
|
||||
const SpriteReader& sprite = get_sprite(widget);
|
||||
assert(sprite != NULL);
|
||||
|
||||
int frame = jslider_get_value(slider_frame);
|
||||
|
||||
get_current_palette()->copyColorsTo(palettes[frame]);
|
||||
|
||||
if (jwidget_is_selected(check_all_frames)) {
|
||||
bool has_two_or_more_palettes = false;
|
||||
int c;
|
||||
|
||||
for (c=1; c<sprite->getTotalFrames(); c++) {
|
||||
if (palettes[c-1]->countDiff(palettes[c], NULL, NULL) > 0) {
|
||||
has_two_or_more_palettes = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (has_two_or_more_palettes) {
|
||||
if (jalert(PACKAGE
|
||||
"<<There are more than one palette. Only the"
|
||||
"<<current palette will be kept (for all frames)."
|
||||
"<<Do you want to continue?"
|
||||
"||&Yes||&No") != 1) {
|
||||
jwidget_deselect(check_all_frames);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
jwidget_disable(slider_frame);
|
||||
}
|
||||
else
|
||||
jwidget_enable(slider_frame);
|
||||
|
||||
return false;
|
||||
jslider_set_value(R_slider, color_get_red(color));
|
||||
jslider_set_value(G_slider, color_get_green(color));
|
||||
jslider_set_value(B_slider, color_get_blue(color));
|
||||
jslider_set_value(H_slider, color_get_hue(color));
|
||||
jslider_set_value(S_slider, color_get_saturation(color));
|
||||
jslider_set_value(V_slider, color_get_hue(color));
|
||||
}
|
||||
|
||||
static bool palette_editor_change_hook(JWidget widget, void *data)
|
||||
{
|
||||
int imgtype = colorviewer_get_imgtype(colorviewer);
|
||||
color_t color = color_index(paledit_get_2nd_color(palette_editor));
|
||||
int r = color_get_red(imgtype, color);
|
||||
int g = color_get_green(imgtype, color);
|
||||
int b = color_get_blue(imgtype, color);
|
||||
int imgtype = app_get_current_image_type();
|
||||
color_t color = color_index(palette_editor->get2ndColor());
|
||||
int r = color_get_red(color);
|
||||
int g = color_get_green(color);
|
||||
int b = color_get_blue(color);
|
||||
float h, s, v;
|
||||
|
||||
rgb_to_hsv(r, g, b, &h, &s, &v);
|
||||
|
||||
colorviewer_set_color(colorviewer, color);
|
||||
// colorviewer_set_color(colorviewer, color);
|
||||
|
||||
jslider_set_value(slider_R, r);
|
||||
jslider_set_value(slider_G, g);
|
||||
jslider_set_value(slider_B, b);
|
||||
jslider_set_value(slider_H, 255.0 * h / 360.0);
|
||||
jslider_set_value(slider_V, 255.0 * v);
|
||||
jslider_set_value(slider_S, 255.0 * s);
|
||||
{
|
||||
disable_colorbar_signals = true;
|
||||
|
||||
if (jmouse_b(0) & 2)
|
||||
app_get_colorbar()->setBgColor(color);
|
||||
else
|
||||
app_get_colorbar()->setFgColor(color);
|
||||
|
||||
disable_colorbar_signals = false;
|
||||
}
|
||||
|
||||
jslider_set_value(R_slider, r);
|
||||
jslider_set_value(G_slider, g);
|
||||
jslider_set_value(B_slider, b);
|
||||
jslider_set_value(H_slider, 255.0 * h / 360.0);
|
||||
jslider_set_value(V_slider, 255.0 * v);
|
||||
jslider_set_value(S_slider, 255.0 * s);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool select_rgb_hook(JWidget widget, void *data)
|
||||
{
|
||||
jwidget_show(R_label);
|
||||
jwidget_show(R_slider);
|
||||
jwidget_show(R_entry);
|
||||
jwidget_show(G_label);
|
||||
jwidget_show(G_slider);
|
||||
jwidget_show(G_entry);
|
||||
jwidget_show(B_label);
|
||||
jwidget_show(B_slider);
|
||||
jwidget_show(B_entry);
|
||||
|
||||
jwidget_hide(H_label);
|
||||
jwidget_hide(H_slider);
|
||||
jwidget_hide(H_entry);
|
||||
jwidget_hide(S_label);
|
||||
jwidget_hide(S_slider);
|
||||
jwidget_hide(S_entry);
|
||||
jwidget_hide(V_label);
|
||||
jwidget_hide(V_slider);
|
||||
jwidget_hide(V_entry);
|
||||
|
||||
window->setBounds(window->getBounds());
|
||||
window->dirty();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool select_hsv_hook(JWidget widget, void *data)
|
||||
{
|
||||
jwidget_hide(R_label);
|
||||
jwidget_hide(R_slider);
|
||||
jwidget_hide(R_entry);
|
||||
jwidget_hide(G_label);
|
||||
jwidget_hide(G_slider);
|
||||
jwidget_hide(G_entry);
|
||||
jwidget_hide(B_label);
|
||||
jwidget_hide(B_slider);
|
||||
jwidget_hide(B_entry);
|
||||
|
||||
jwidget_show(H_label);
|
||||
jwidget_show(H_slider);
|
||||
jwidget_show(H_entry);
|
||||
jwidget_show(S_label);
|
||||
jwidget_show(S_slider);
|
||||
jwidget_show(S_entry);
|
||||
jwidget_show(V_label);
|
||||
jwidget_show(V_slider);
|
||||
jwidget_show(V_entry);
|
||||
|
||||
window->setBounds(window->getBounds());
|
||||
window->dirty();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void modify_all_selected_entries_in_palette(int r, int g, int b)
|
||||
{
|
||||
bool array[256];
|
||||
palette_editor->getSelectedEntries(array);
|
||||
|
||||
Palette* palette = get_current_palette();
|
||||
for (int c=0; c<256; c++)
|
||||
if (array[c])
|
||||
palette->setEntry(c, _rgba(r, g, b, 255));
|
||||
}
|
||||
|
||||
static void on_color_changed(color_t color)
|
||||
{
|
||||
if (disable_colorbar_signals)
|
||||
return;
|
||||
|
||||
int imgtype = app_get_current_image_type();
|
||||
int index = color_get_index(color);
|
||||
palette_editor->selectColor(index);
|
||||
|
||||
update_sliders_from_color(color); // Update sliders
|
||||
update_entries_from_sliders(); // Update entries
|
||||
update_hex_entry(); // Update hex field
|
||||
|
||||
jwidget_flush_redraw(window);
|
||||
}
|
||||
|
||||
static void set_new_palette(Palette* palette)
|
||||
{
|
||||
/* copy the palette */
|
||||
palette->copyColorsTo(paledit_get_palette(palette_editor));
|
||||
// Copy the palette
|
||||
palette->copyColorsTo(get_current_palette());
|
||||
|
||||
/* set the palette calling the hooks */
|
||||
// Set the palette calling the hooks
|
||||
set_current_palette(palette, false);
|
||||
|
||||
/* redraw the entire screen */
|
||||
// Redraw the entire screen
|
||||
jmanager_refresh_screen();
|
||||
}
|
||||
|
||||
|
@ -44,12 +44,12 @@ SwitchColorsCommand::SwitchColorsCommand()
|
||||
|
||||
void SwitchColorsCommand::execute(Context* context)
|
||||
{
|
||||
JWidget colorbar = app_get_colorbar();
|
||||
color_t fg = colorbar_get_fg_color(colorbar);
|
||||
color_t bg = colorbar_get_bg_color(colorbar);
|
||||
ColorBar* colorbar = app_get_colorbar();
|
||||
color_t fg = colorbar->getFgColor();
|
||||
color_t bg = colorbar->getBgColor();
|
||||
|
||||
colorbar_set_fg_color(colorbar, bg);
|
||||
colorbar_set_bg_color(colorbar, fg);
|
||||
colorbar->setFgColor(bg);
|
||||
colorbar->setBgColor(fg);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -103,12 +103,12 @@ void ReplaceColorCommand::execute(Context* context)
|
||||
|
||||
button_color1 = colorbutton_new
|
||||
(get_config_color("ReplaceColor", "Color1",
|
||||
colorbar_get_fg_color(app_get_colorbar())),
|
||||
app_get_colorbar()->getFgColor()),
|
||||
sprite->getImgType());
|
||||
|
||||
button_color2 = colorbutton_new
|
||||
(get_config_color("ReplaceColor", "Color2",
|
||||
colorbar_get_bg_color(app_get_colorbar())),
|
||||
app_get_colorbar()->getBgColor()),
|
||||
sprite->getImgType());
|
||||
|
||||
target_button = target_button_new(sprite->getImgType(), false);
|
||||
|
@ -49,8 +49,6 @@ public:
|
||||
virtual bool is_executing_script() const { return false; }
|
||||
|
||||
ISettings* getSettings() { return m_settings; }
|
||||
int getFgColor() { return m_settings->getFgColor(); }
|
||||
int getBgColor() { return m_settings->getBgColor(); }
|
||||
|
||||
const SpriteList& get_sprite_list() const;
|
||||
Sprite* get_first_sprite() const;
|
||||
|
@ -177,15 +177,12 @@ color_t color_index(int index)
|
||||
return MAKE_COLOR(COLOR_TYPE_INDEX, index & 0xff);
|
||||
}
|
||||
|
||||
int color_get_red(int imgtype, color_t color)
|
||||
int color_get_red(color_t color)
|
||||
{
|
||||
switch (GET_COLOR_TYPE(color)) {
|
||||
|
||||
case COLOR_TYPE_MASK:
|
||||
if (imgtype == IMAGE_INDEXED)
|
||||
return _rgba_getr(get_current_palette()->getEntry(0));
|
||||
else
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
case COLOR_TYPE_RGB:
|
||||
return GET_DATA_C1(GET_COLOR_DATA_RGB(color));
|
||||
@ -211,15 +208,12 @@ int color_get_red(int imgtype, color_t color)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int color_get_green(int imgtype, color_t color)
|
||||
int color_get_green(color_t color)
|
||||
{
|
||||
switch (GET_COLOR_TYPE(color)) {
|
||||
|
||||
case COLOR_TYPE_MASK:
|
||||
if (imgtype == IMAGE_INDEXED)
|
||||
return _rgba_getg(get_current_palette()->getEntry(0));
|
||||
else
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
case COLOR_TYPE_RGB:
|
||||
return GET_DATA_C2(GET_COLOR_DATA_RGB(color));
|
||||
@ -245,15 +239,12 @@ int color_get_green(int imgtype, color_t color)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int color_get_blue(int imgtype, color_t color)
|
||||
int color_get_blue(color_t color)
|
||||
{
|
||||
switch (GET_COLOR_TYPE(color)) {
|
||||
|
||||
case COLOR_TYPE_MASK:
|
||||
if (imgtype == IMAGE_INDEXED)
|
||||
return _rgba_getb(get_current_palette()->getEntry(0));
|
||||
else
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
case COLOR_TYPE_RGB:
|
||||
return GET_DATA_C3(GET_COLOR_DATA_RGB(color));
|
||||
@ -279,7 +270,7 @@ int color_get_blue(int imgtype, color_t color)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int color_get_hue(int imgtype, color_t color)
|
||||
int color_get_hue(color_t color)
|
||||
{
|
||||
switch (GET_COLOR_TYPE(color)) {
|
||||
|
||||
@ -316,7 +307,7 @@ int color_get_hue(int imgtype, color_t color)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int color_get_saturation(int imgtype, color_t color)
|
||||
int color_get_saturation(color_t color)
|
||||
{
|
||||
switch (GET_COLOR_TYPE(color)) {
|
||||
|
||||
@ -353,7 +344,7 @@ int color_get_saturation(int imgtype, color_t color)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int color_get_value(int imgtype, color_t color)
|
||||
int color_get_value(color_t color)
|
||||
{
|
||||
switch (GET_COLOR_TYPE(color)) {
|
||||
|
||||
@ -390,7 +381,7 @@ int color_get_value(int imgtype, color_t color)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int color_get_index(int imgtype, color_t color)
|
||||
int color_get_index(color_t color)
|
||||
{
|
||||
switch (GET_COLOR_TYPE(color)) {
|
||||
|
||||
|
@ -46,13 +46,14 @@ color_t color_rgb(int r, int g, int b);
|
||||
color_t color_hsv(int h, int s, int v);
|
||||
color_t color_gray(int g);
|
||||
color_t color_index(int index);
|
||||
int color_get_red(int imgtype, color_t color);
|
||||
int color_get_green(int imgtype, color_t color);
|
||||
int color_get_blue(int imgtype, color_t color);
|
||||
int color_get_hue(int imgtype, color_t color);
|
||||
int color_get_saturation(int imgtype, color_t color);
|
||||
int color_get_value(int imgtype, color_t color);
|
||||
int color_get_index(int imgtype, color_t color);
|
||||
int color_get_red(color_t color);
|
||||
int color_get_green(color_t color);
|
||||
int color_get_blue(color_t color);
|
||||
int color_get_hue(color_t color);
|
||||
int color_get_saturation(color_t color);
|
||||
int color_get_value(color_t color);
|
||||
int color_get_index(color_t color);
|
||||
|
||||
color_t color_from_image(int imgtype, int c);
|
||||
|
||||
int blackandwhite(int r, int g, int b);
|
||||
|
@ -74,7 +74,7 @@ void dialogs_mask_color(Sprite* sprite)
|
||||
label_color = jlabel_new(_("Color:"));
|
||||
button_color = colorbutton_new
|
||||
(get_config_color("MaskColor", "Color",
|
||||
colorbar_get_fg_color(app_get_colorbar())),
|
||||
app_get_colorbar()->getFgColor()),
|
||||
sprite->getImgType());
|
||||
button_1 = jbutton_new("1");
|
||||
button_2 = jbutton_new("2");
|
||||
@ -156,15 +156,13 @@ void dialogs_mask_color(Sprite* sprite)
|
||||
|
||||
static void button_1_command(JWidget widget)
|
||||
{
|
||||
colorbutton_set_color(button_color,
|
||||
colorbar_get_fg_color(app_get_colorbar()));
|
||||
colorbutton_set_color(button_color, app_get_colorbar()->getFgColor());
|
||||
mask_preview((Sprite*)widget->user_data[1]);
|
||||
}
|
||||
|
||||
static void button_2_command(JWidget widget)
|
||||
{
|
||||
colorbutton_set_color(button_color,
|
||||
colorbar_get_bg_color(app_get_colorbar()));
|
||||
colorbutton_set_color(button_color, app_get_colorbar()->getBgColor());
|
||||
mask_preview((Sprite*)widget->user_data[1]);
|
||||
}
|
||||
|
||||
|
@ -430,10 +430,10 @@ void draw_color(BITMAP* bmp, const Rect& rc, int imgtype, color_t color)
|
||||
BITMAP* graph;
|
||||
|
||||
if (type == COLOR_TYPE_INDEX) {
|
||||
data = color_get_index(imgtype, color);
|
||||
data = color_get_index(color);
|
||||
rectfill(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1,
|
||||
/* get_color_for_allegro(bitmap_color_depth(bmp), color)); */
|
||||
palette_color[data]);
|
||||
get_color_for_allegro(bitmap_color_depth(bmp), color));
|
||||
// palette_color[data]);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -441,7 +441,9 @@ void draw_color(BITMAP* bmp, const Rect& rc, int imgtype, color_t color)
|
||||
|
||||
case IMAGE_INDEXED:
|
||||
rectfill(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1,
|
||||
palette_color[get_color_for_image(imgtype, color)]);
|
||||
get_color_for_allegro(imgtype, color_index(get_color_for_image(imgtype, color))));
|
||||
// get_color_for_allegro(bitmap_color_depth(bmp), color));
|
||||
// palette_color[get_color_for_image(imgtype, color)]);
|
||||
break;
|
||||
|
||||
case IMAGE_RGB:
|
||||
|
@ -65,12 +65,12 @@ UISettingsImpl::~UISettingsImpl()
|
||||
|
||||
color_t UISettingsImpl::getFgColor()
|
||||
{
|
||||
return colorbar_get_fg_color(app_get_colorbar());
|
||||
return app_get_colorbar()->getFgColor();
|
||||
}
|
||||
|
||||
color_t UISettingsImpl::getBgColor()
|
||||
{
|
||||
return colorbar_get_bg_color(app_get_colorbar());
|
||||
return app_get_colorbar()->getBgColor();
|
||||
}
|
||||
|
||||
Tool* UISettingsImpl::getCurrentTool()
|
||||
@ -88,12 +88,12 @@ TiledMode UISettingsImpl::getTiledMode()
|
||||
|
||||
void UISettingsImpl::setFgColor(color_t color)
|
||||
{
|
||||
colorbar_set_fg_color(app_get_colorbar(), color);
|
||||
app_get_colorbar()->setFgColor(color);
|
||||
}
|
||||
|
||||
void UISettingsImpl::setBgColor(color_t color)
|
||||
{
|
||||
colorbar_set_fg_color(app_get_colorbar(), color);
|
||||
app_get_colorbar()->setFgColor(color);
|
||||
}
|
||||
|
||||
void UISettingsImpl::setCurrentTool(Tool* tool)
|
||||
|
@ -57,54 +57,6 @@ using Vaca::Rect;
|
||||
#define FGBUTTON_SIZE (16*jguiscale())
|
||||
#define BGBUTTON_SIZE (18*jguiscale())
|
||||
|
||||
typedef enum {
|
||||
HOTCOLOR_NONE = -3,
|
||||
HOTCOLOR_FGCOLOR = -2,
|
||||
HOTCOLOR_BGCOLOR = -1,
|
||||
} hotcolor_t;
|
||||
|
||||
class ColorBar : public Widget
|
||||
{
|
||||
size_t m_firstIndex;
|
||||
size_t m_columns;
|
||||
size_t m_colorsPerColum;
|
||||
int m_entrySize;
|
||||
color_t m_fgcolor;
|
||||
color_t m_bgcolor;
|
||||
hotcolor_t m_hot;
|
||||
hotcolor_t m_hot_editing;
|
||||
// Drag & drop colors
|
||||
hotcolor_t m_hot_drag;
|
||||
hotcolor_t m_hot_drop;
|
||||
|
||||
public:
|
||||
ColorBar(int align);
|
||||
~ColorBar();
|
||||
|
||||
color_t getFgColor() const { return m_fgcolor; }
|
||||
color_t getBgColor() const { return m_bgcolor; }
|
||||
void setFgColor(color_t color);
|
||||
void setBgColor(color_t color);
|
||||
|
||||
void setColor(int index, color_t color);
|
||||
color_t getColorByPosition(int x, int y);
|
||||
|
||||
protected:
|
||||
virtual bool msg_proc(JMessage msg);
|
||||
|
||||
private:
|
||||
int getEntriesCount() const { return m_columns*m_colorsPerColum; }
|
||||
color_t getEntryColor(size_t i) const { return color_index(i+m_firstIndex); }
|
||||
|
||||
color_t getHotColor(hotcolor_t hot);
|
||||
void setHotColor(hotcolor_t hot, color_t color);
|
||||
Rect getColumnBounds(size_t column) const;
|
||||
Rect getEntryBounds(size_t index) const;
|
||||
Rect getFgBounds() const;
|
||||
Rect getBgBounds() const;
|
||||
void updateStatusBar(color_t color, int msecs);
|
||||
};
|
||||
|
||||
int colorbar_type()
|
||||
{
|
||||
static int type = 0;
|
||||
@ -113,46 +65,6 @@ int colorbar_type()
|
||||
return type;
|
||||
}
|
||||
|
||||
Widget* colorbar_new(int align)
|
||||
{
|
||||
return new ColorBar(align);
|
||||
}
|
||||
|
||||
void colorbar_set_size(JWidget widget, int size)
|
||||
{
|
||||
// TODO remove this
|
||||
}
|
||||
|
||||
color_t colorbar_get_fg_color(JWidget widget)
|
||||
{
|
||||
return ((ColorBar*)widget)->getFgColor();
|
||||
}
|
||||
|
||||
color_t colorbar_get_bg_color(JWidget widget)
|
||||
{
|
||||
return ((ColorBar*)widget)->getBgColor();
|
||||
}
|
||||
|
||||
void colorbar_set_fg_color(JWidget widget, color_t color)
|
||||
{
|
||||
((ColorBar*)widget)->setFgColor(color);
|
||||
}
|
||||
|
||||
void colorbar_set_bg_color(JWidget widget, color_t color)
|
||||
{
|
||||
((ColorBar*)widget)->setBgColor(color);
|
||||
}
|
||||
|
||||
void colorbar_set_color(JWidget widget, int index, color_t color)
|
||||
{
|
||||
((ColorBar*)widget)->setColor(index, color);
|
||||
}
|
||||
|
||||
color_t colorbar_get_color_by_position(JWidget widget, int x, int y)
|
||||
{
|
||||
return ((ColorBar*)widget)->getColorByPosition(x, y);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// ColorBar class
|
||||
|
||||
@ -204,6 +116,7 @@ void ColorBar::setFgColor(color_t color)
|
||||
dirty();
|
||||
|
||||
updateStatusBar(m_fgcolor, 100);
|
||||
FgColorChange(m_fgcolor);
|
||||
}
|
||||
|
||||
void ColorBar::setBgColor(color_t color)
|
||||
@ -212,11 +125,7 @@ void ColorBar::setBgColor(color_t color)
|
||||
dirty();
|
||||
|
||||
updateStatusBar(m_bgcolor, 100);
|
||||
}
|
||||
|
||||
void ColorBar::setColor(int index, color_t color)
|
||||
{
|
||||
// TODO remove me
|
||||
BgColorChange(m_bgcolor);
|
||||
}
|
||||
|
||||
color_t ColorBar::getColorByPosition(int x, int y)
|
||||
@ -500,22 +409,25 @@ bool ColorBar::msg_proc(JMessage msg)
|
||||
/* pick the color */
|
||||
else if (m_hot != HOTCOLOR_NONE) {
|
||||
switch (m_hot) {
|
||||
|
||||
case HOTCOLOR_FGCOLOR:
|
||||
case HOTCOLOR_BGCOLOR: {
|
||||
Command* paledit_cmd =
|
||||
CommandsModule::instance()->get_command_by_name(CommandId::palette_editor);
|
||||
Command* paledit_cmd = CommandsModule::instance()->get_command_by_name(CommandId::palette_editor);
|
||||
Params params;
|
||||
params.set("target", (m_hot == HOTCOLOR_FGCOLOR ? "foreground": "background"));
|
||||
params.set("open", "true");
|
||||
|
||||
UIContext::instance()->execute_command(paledit_cmd, ¶ms);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
color_t color = getHotColor(m_hot);
|
||||
if (msg->mouse.left) {
|
||||
colorbar_set_fg_color(this, color);
|
||||
this->setFgColor(color);
|
||||
}
|
||||
if (msg->mouse.right) {
|
||||
colorbar_set_bg_color(this, color);
|
||||
this->setBgColor(color);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -564,10 +476,10 @@ void ColorBar::setHotColor(hotcolor_t hot, color_t color)
|
||||
assert(false);
|
||||
break;
|
||||
case HOTCOLOR_FGCOLOR:
|
||||
m_fgcolor = color;
|
||||
setFgColor(color);
|
||||
break;
|
||||
case HOTCOLOR_BGCOLOR:
|
||||
m_bgcolor = color;
|
||||
setBgColor(color);
|
||||
break;
|
||||
default:
|
||||
assert(hot >= 0 && hot < getEntriesCount());
|
||||
|
@ -19,23 +19,64 @@
|
||||
#ifndef WIDGETS_COLBAR_H_INCLUDED
|
||||
#define WIDGETS_COLBAR_H_INCLUDED
|
||||
|
||||
#include "jinete/jbase.h"
|
||||
#include "Vaca/Signal.h"
|
||||
#include "jinete/jwidget.h"
|
||||
|
||||
#include "core/color.h"
|
||||
|
||||
JWidget colorbar_new(int align);
|
||||
class ColorBar : public Widget
|
||||
{
|
||||
typedef enum {
|
||||
HOTCOLOR_NONE = -3,
|
||||
HOTCOLOR_FGCOLOR = -2,
|
||||
HOTCOLOR_BGCOLOR = -1,
|
||||
} hotcolor_t;
|
||||
|
||||
public:
|
||||
ColorBar(int align);
|
||||
~ColorBar();
|
||||
|
||||
color_t getFgColor() const { return m_fgcolor; }
|
||||
color_t getBgColor() const { return m_bgcolor; }
|
||||
void setFgColor(color_t color);
|
||||
void setBgColor(color_t color);
|
||||
|
||||
color_t getColorByPosition(int x, int y);
|
||||
|
||||
// Signals
|
||||
Vaca::Signal1<void, color_t> FgColorChange;
|
||||
Vaca::Signal1<void, color_t> BgColorChange;
|
||||
|
||||
protected:
|
||||
virtual bool msg_proc(JMessage msg);
|
||||
|
||||
private:
|
||||
int getEntriesCount() const { return m_columns*m_colorsPerColum; }
|
||||
color_t getEntryColor(size_t i) const { return color_index(i+m_firstIndex); }
|
||||
|
||||
color_t getHotColor(hotcolor_t hot);
|
||||
void setHotColor(hotcolor_t hot, color_t color);
|
||||
Rect getColumnBounds(size_t column) const;
|
||||
Rect getEntryBounds(size_t index) const;
|
||||
Rect getFgBounds() const;
|
||||
Rect getBgBounds() const;
|
||||
void updateStatusBar(color_t color, int msecs);
|
||||
|
||||
size_t m_firstIndex;
|
||||
size_t m_columns;
|
||||
size_t m_colorsPerColum;
|
||||
int m_entrySize;
|
||||
color_t m_fgcolor;
|
||||
color_t m_bgcolor;
|
||||
hotcolor_t m_hot;
|
||||
hotcolor_t m_hot_editing;
|
||||
|
||||
// Drag & drop colors
|
||||
hotcolor_t m_hot_drag;
|
||||
hotcolor_t m_hot_drop;
|
||||
|
||||
};
|
||||
|
||||
int colorbar_type();
|
||||
|
||||
void colorbar_set_size(JWidget widget, int size);
|
||||
|
||||
color_t colorbar_get_fg_color(JWidget widget);
|
||||
color_t colorbar_get_bg_color(JWidget widget);
|
||||
|
||||
void colorbar_set_fg_color(JWidget widget, color_t color);
|
||||
void colorbar_set_bg_color(JWidget widget, color_t color);
|
||||
|
||||
void colorbar_set_color(JWidget widget, int index, color_t color);
|
||||
|
||||
color_t colorbar_get_color_by_position(JWidget widget, int x, int y);
|
||||
|
||||
#endif
|
||||
|
@ -161,9 +161,7 @@ static bool colorbutton_msg_proc(JWidget widget, JMessage msg)
|
||||
}
|
||||
/* pick a color from the color-bar */
|
||||
else if (picked->type == colorbar_type()) {
|
||||
color = colorbar_get_color_by_position(picked,
|
||||
msg->mouse.x,
|
||||
msg->mouse.y);
|
||||
color = ((ColorBar*)picked)->getColorByPosition(msg->mouse.x, msg->mouse.y);
|
||||
}
|
||||
/* pick a color from a editor */
|
||||
else if (picked->type == editor_type()) {
|
||||
|
@ -92,7 +92,7 @@ Frame* colorselector_new(bool editable_palette)
|
||||
JWidget grid1 = jgrid_new(3, false);
|
||||
JWidget grid2 = jgrid_new(5, false);
|
||||
JWidget tabs = tabs_new(select_tab_callback);
|
||||
JWidget pal = paledit_new(get_current_palette(), false, 1);
|
||||
PalEdit* pal = new PalEdit(false);
|
||||
JWidget idx = jlabel_new("None");
|
||||
JWidget lock = jbutton_new("");
|
||||
JWidget child;
|
||||
@ -275,13 +275,13 @@ static bool colorselector_msg_proc(JWidget widget, JMessage msg)
|
||||
|
||||
case JM_SIGNAL:
|
||||
if (msg->signal.num == JI_SIGNAL_INIT_THEME) {
|
||||
JWidget idx = jwidget_find_name(widget, "idx");
|
||||
JWidget pal = jwidget_find_name(widget, "pal");
|
||||
JWidget grid2 = jwidget_find_name(widget, "grid2");
|
||||
Widget* idx = widget->findChild("idx");
|
||||
PalEdit* pal = static_cast<PalEdit*>(widget->findChild("pal"));
|
||||
Widget* grid2 = widget->findChild("grid2");
|
||||
int idxlen = ji_font_text_len(idx->getFont(), "Index=888");
|
||||
|
||||
jwidget_set_min_size(idx, idxlen, 0);
|
||||
paledit_set_boxsize(pal, 4*jguiscale());
|
||||
pal->setBoxSize(4*jguiscale());
|
||||
jwidget_set_min_size(grid2, 200*jguiscale(), 0);
|
||||
}
|
||||
break;
|
||||
@ -326,17 +326,17 @@ static void colorselector_set_color2(JWidget widget, color_t color,
|
||||
colorselector->color = color;
|
||||
|
||||
if (exclude_this_model != models+MODEL_RGB) {
|
||||
jslider_set_value(rgb_rslider, color_get_red(imgtype, color));
|
||||
jslider_set_value(rgb_gslider, color_get_green(imgtype, color));
|
||||
jslider_set_value(rgb_bslider, color_get_blue(imgtype, color));
|
||||
jslider_set_value(rgb_rslider, color_get_red(color));
|
||||
jslider_set_value(rgb_gslider, color_get_green(color));
|
||||
jslider_set_value(rgb_bslider, color_get_blue(color));
|
||||
}
|
||||
if (exclude_this_model != models+MODEL_HSV) {
|
||||
jslider_set_value(hsv_hslider, color_get_hue(imgtype, color));
|
||||
jslider_set_value(hsv_sslider, color_get_saturation(imgtype, color));
|
||||
jslider_set_value(hsv_vslider, color_get_value(imgtype, color));
|
||||
jslider_set_value(hsv_hslider, color_get_hue(color));
|
||||
jslider_set_value(hsv_sslider, color_get_saturation(color));
|
||||
jslider_set_value(hsv_vslider, color_get_value(color));
|
||||
}
|
||||
if (exclude_this_model != models+MODEL_GRAY) {
|
||||
jslider_set_value(gray_vslider, color_get_value(imgtype, color));
|
||||
jslider_set_value(gray_vslider, color_get_value(color));
|
||||
}
|
||||
|
||||
switch (color_type(color)) {
|
||||
@ -368,16 +368,15 @@ static void colorselector_set_color2(JWidget widget, color_t color,
|
||||
if (update_index_entry) {
|
||||
switch (color_type(color)) {
|
||||
case COLOR_TYPE_INDEX:
|
||||
colorselector_set_paledit_index(widget, color_get_index(IMAGE_INDEXED, color),
|
||||
select_index_entry);
|
||||
colorselector_set_paledit_index(widget, color_get_index(color), select_index_entry);
|
||||
break;
|
||||
case COLOR_TYPE_MASK:
|
||||
colorselector_set_paledit_index(widget, 0, true);
|
||||
break;
|
||||
default: {
|
||||
int r = color_get_red (IMAGE_RGB, color);
|
||||
int g = color_get_green(IMAGE_RGB, color);
|
||||
int b = color_get_blue (IMAGE_RGB, color);
|
||||
int r = color_get_red (color);
|
||||
int g = color_get_green(color);
|
||||
int b = color_get_blue (color);
|
||||
int i = get_current_palette()->findBestfit(r, g, b);
|
||||
if (i >= 0 && i < 256)
|
||||
colorselector_set_paledit_index(widget, i, true);
|
||||
@ -392,14 +391,14 @@ static void colorselector_set_color2(JWidget widget, color_t color,
|
||||
static void colorselector_set_paledit_index(JWidget widget, int index, bool select_index_entry)
|
||||
{
|
||||
ColorSelector* colorselector = colorselector_data(widget);
|
||||
JWidget pal = jwidget_find_name(widget, "pal");
|
||||
JWidget idx = jwidget_find_name(widget, "idx");
|
||||
JWidget lock = jwidget_find_name(widget, "lock");
|
||||
PalEdit* pal = static_cast<PalEdit*>(widget->findChild("pal"));
|
||||
Widget* idx = widget->findChild("idx");
|
||||
Widget* lock = widget->findChild("lock");
|
||||
char buf[256];
|
||||
|
||||
if (index >= 0) {
|
||||
if (select_index_entry)
|
||||
paledit_select_color(pal, index);
|
||||
pal->selectColor(index);
|
||||
|
||||
sprintf(buf, "Index=%d", index);
|
||||
|
||||
@ -410,7 +409,7 @@ static void colorselector_set_paledit_index(JWidget widget, int index, bool sele
|
||||
}
|
||||
else {
|
||||
if (select_index_entry)
|
||||
paledit_select_range(pal, -1, -1, PALETTE_EDITOR_RANGE_NONE);
|
||||
pal->selectRange(-1, -1, PALETTE_EDITOR_RANGE_NONE);
|
||||
|
||||
sprintf(buf, "None");
|
||||
|
||||
@ -454,7 +453,7 @@ static bool slider_change_hook(JWidget widget, void* data)
|
||||
Frame* window = static_cast<Frame*>(widget->getRoot());
|
||||
ColorSelector* colorselector = colorselector_data(window);
|
||||
JWidget tabs = jwidget_find_name(window, "tabs");
|
||||
JWidget pal = jwidget_find_name(window, "pal");
|
||||
PalEdit* pal = static_cast<PalEdit*>(window->findChild("pal"));
|
||||
Model* m = reinterpret_cast<Model*>(tabs_get_selected_tab(tabs));
|
||||
color_t color = colorselector->color;
|
||||
int i, r, g, b;
|
||||
@ -488,9 +487,9 @@ static bool slider_change_hook(JWidget widget, void* data)
|
||||
}
|
||||
}
|
||||
|
||||
r = color_get_red (IMAGE_RGB, color);
|
||||
g = color_get_green(IMAGE_RGB, color);
|
||||
b = color_get_blue (IMAGE_RGB, color);
|
||||
r = color_get_red (color);
|
||||
g = color_get_green(color);
|
||||
b = color_get_blue (color);
|
||||
|
||||
/* if the palette is locked then we have to search for the closest
|
||||
color to the RGB values */
|
||||
@ -503,14 +502,14 @@ static bool slider_change_hook(JWidget widget, void* data)
|
||||
else {
|
||||
bool array[256];
|
||||
|
||||
paledit_get_selected_entries(pal, array);
|
||||
pal->getSelectedEntries(array);
|
||||
for (i=0; i<256; ++i)
|
||||
if (array[i])
|
||||
set_current_color(i, r, g, b);
|
||||
|
||||
jwidget_dirty(pal);
|
||||
|
||||
i = paledit_get_2nd_color(pal);
|
||||
i = pal->get2ndColor();
|
||||
if (i >= 0)
|
||||
color = color_index(i);
|
||||
}
|
||||
@ -528,14 +527,15 @@ static bool button_mask_select_hook(JWidget widget, void* data)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool paledit_change_hook(JWidget widget, void* data)
|
||||
static bool paledit_change_hook(Widget* widget, void* data)
|
||||
{
|
||||
Frame* window = static_cast<Frame*>(widget->getRoot());
|
||||
PalEdit* paledit = static_cast<PalEdit*>(widget);
|
||||
bool array[256];
|
||||
color_t color = colorselector_get_color(window);
|
||||
int i;
|
||||
|
||||
paledit_get_selected_entries(widget, array);
|
||||
paledit->getSelectedEntries(array);
|
||||
for (i=0; i<256; ++i)
|
||||
if (array[i]) {
|
||||
color = color_index(i);
|
||||
|
@ -1799,9 +1799,9 @@ IToolLoop* Editor::createToolLoopImpl(Context* context, JMessage msg)
|
||||
}
|
||||
|
||||
// Get fg/bg colors
|
||||
JWidget colorbar = app_get_colorbar();
|
||||
color_t fg = colorbar_get_fg_color(colorbar);
|
||||
color_t bg = colorbar_get_bg_color(colorbar);
|
||||
ColorBar* colorbar = app_get_colorbar();
|
||||
color_t fg = colorbar->getFgColor();
|
||||
color_t bg = colorbar->getBgColor();
|
||||
|
||||
// Create the new tool loop
|
||||
ToolLoopImpl* tool_loop = new ToolLoopImpl(this,
|
||||
|
@ -40,49 +40,9 @@
|
||||
#include "widgets/paledit.h"
|
||||
|
||||
/* #define COLOR_SIZE 6 */
|
||||
#define COLOR_SIZE (paledit->boxsize)
|
||||
#define COLOR_SIZE (m_boxsize)
|
||||
|
||||
typedef struct PalEdit
|
||||
{
|
||||
JWidget widget;
|
||||
Palette *palette;
|
||||
bool editable;
|
||||
unsigned range_type;
|
||||
unsigned columns;
|
||||
int boxsize;
|
||||
int color[2];
|
||||
} PalEdit;
|
||||
|
||||
static PalEdit *paledit_data(JWidget widget);
|
||||
static bool paledit_msg_proc(JWidget widget, JMessage msg);
|
||||
static void paledit_request_size(JWidget widget, int *w, int *h);
|
||||
static void paledit_update_scroll(JWidget widget, int color);
|
||||
|
||||
JWidget paledit_new(Palette *palette, bool editable, int boxsize)
|
||||
{
|
||||
Widget* widget = new Widget(paledit_type());
|
||||
PalEdit *paledit = jnew(PalEdit, 1);
|
||||
|
||||
paledit->widget = widget;
|
||||
paledit->palette = palette;
|
||||
paledit->editable = editable;
|
||||
paledit->range_type = PALETTE_EDITOR_RANGE_NONE;
|
||||
paledit->columns = 16;
|
||||
paledit->boxsize = boxsize;
|
||||
paledit->color[0] = -1;
|
||||
paledit->color[1] = -1;
|
||||
|
||||
jwidget_add_hook(widget, paledit_type(), paledit_msg_proc, paledit);
|
||||
jwidget_focusrest(widget, true);
|
||||
|
||||
widget->border_width.l = widget->border_width.r = 1 * jguiscale();
|
||||
widget->border_width.t = widget->border_width.b = 1 * jguiscale();
|
||||
widget->child_spacing = 1 * jguiscale();
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
int paledit_type()
|
||||
static int paledit_type()
|
||||
{
|
||||
static int type = 0;
|
||||
if (!type)
|
||||
@ -90,87 +50,86 @@ int paledit_type()
|
||||
return type;
|
||||
}
|
||||
|
||||
Palette *paledit_get_palette(JWidget widget)
|
||||
PalEdit::PalEdit(bool editable)
|
||||
: Widget(paledit_type())
|
||||
{
|
||||
PalEdit *paledit = paledit_data(widget);
|
||||
m_editable = editable;
|
||||
m_range_type = PALETTE_EDITOR_RANGE_NONE;
|
||||
m_columns = 16;
|
||||
m_boxsize = 6;
|
||||
m_color[0] = -1;
|
||||
m_color[1] = -1;
|
||||
|
||||
return paledit->palette;
|
||||
jwidget_focusrest(this, true);
|
||||
|
||||
this->border_width.l = this->border_width.r = 1 * jguiscale();
|
||||
this->border_width.t = this->border_width.b = 1 * jguiscale();
|
||||
this->child_spacing = 1 * jguiscale();
|
||||
}
|
||||
|
||||
int paledit_get_range_type(JWidget widget)
|
||||
int PalEdit::getRangeType()
|
||||
{
|
||||
PalEdit *paledit = paledit_data(widget);
|
||||
|
||||
return paledit->range_type;
|
||||
return m_range_type;
|
||||
}
|
||||
|
||||
int paledit_get_columns(JWidget widget)
|
||||
int PalEdit::getColumns()
|
||||
{
|
||||
PalEdit *paledit = paledit_data(widget);
|
||||
|
||||
return paledit->columns;
|
||||
return m_columns;
|
||||
}
|
||||
|
||||
void paledit_set_columns(JWidget widget, int columns)
|
||||
void PalEdit::setColumns(int columns)
|
||||
{
|
||||
PalEdit *paledit = paledit_data(widget);
|
||||
int old_columns = paledit->columns;
|
||||
int old_columns = m_columns;
|
||||
|
||||
assert(columns >= 1 && columns <= 256);
|
||||
paledit->columns = columns;
|
||||
m_columns = columns;
|
||||
|
||||
if (paledit->columns != old_columns) {
|
||||
JWidget view = jwidget_get_view(widget);
|
||||
if (m_columns != old_columns) {
|
||||
Widget* view = jwidget_get_view(this);
|
||||
if (view)
|
||||
jview_update(view);
|
||||
|
||||
jwidget_dirty(widget);
|
||||
jwidget_dirty(this);
|
||||
}
|
||||
}
|
||||
|
||||
void paledit_set_boxsize(JWidget widget, int boxsize)
|
||||
void PalEdit::setBoxSize(int boxsize)
|
||||
{
|
||||
PalEdit *paledit = paledit_data(widget);
|
||||
|
||||
paledit->boxsize = boxsize;
|
||||
m_boxsize = boxsize;
|
||||
}
|
||||
|
||||
void paledit_select_color(JWidget widget, int index)
|
||||
void PalEdit::selectColor(int index)
|
||||
{
|
||||
PalEdit *paledit = paledit_data(widget);
|
||||
|
||||
assert(index >= 0 && index <= 255);
|
||||
|
||||
if ((paledit->color[0] != index) ||
|
||||
(paledit->color[1] != index) ||
|
||||
(paledit->range_type != PALETTE_EDITOR_RANGE_NONE)) {
|
||||
paledit->color[0] = index;
|
||||
paledit->color[1] = index;
|
||||
paledit->range_type = PALETTE_EDITOR_RANGE_NONE;
|
||||
if ((m_color[0] != index) ||
|
||||
(m_color[1] != index) ||
|
||||
(m_range_type != PALETTE_EDITOR_RANGE_NONE)) {
|
||||
m_color[0] = index;
|
||||
m_color[1] = index;
|
||||
m_range_type = PALETTE_EDITOR_RANGE_NONE;
|
||||
|
||||
if ((index >= 0) && (index <= 255))
|
||||
paledit_update_scroll(widget, index);
|
||||
update_scroll(index);
|
||||
|
||||
jwidget_dirty(widget);
|
||||
jwidget_dirty(this);
|
||||
}
|
||||
}
|
||||
|
||||
void paledit_select_range(JWidget widget, int begin, int end, int range_type)
|
||||
void PalEdit::selectRange(int begin, int end, int range_type)
|
||||
{
|
||||
PalEdit *paledit = paledit_data(widget);
|
||||
|
||||
/* assert(begin >= 0 && begin <= 255); */
|
||||
/* assert(end >= 0 && end <= 255); */
|
||||
|
||||
paledit->color[0] = begin;
|
||||
paledit->color[1] = end;
|
||||
paledit->range_type = range_type;
|
||||
m_color[0] = begin;
|
||||
m_color[1] = end;
|
||||
m_range_type = range_type;
|
||||
|
||||
paledit_update_scroll(widget, end);
|
||||
jwidget_dirty(widget);
|
||||
update_scroll(end);
|
||||
jwidget_dirty(this);
|
||||
}
|
||||
|
||||
static void swap_color(Palette *palette, int i1, int i2)
|
||||
static void swap_color(Palette* palette, int i1, int i2)
|
||||
{
|
||||
ase_uint32 c1 = palette->getEntry(i1);
|
||||
ase_uint32 c2 = palette->getEntry(i2);
|
||||
@ -179,38 +138,36 @@ static void swap_color(Palette *palette, int i1, int i2)
|
||||
palette->setEntry(i1, c2);
|
||||
}
|
||||
|
||||
void paledit_move_selection(JWidget widget, int x, int y)
|
||||
void PalEdit::moveSelection(int x, int y)
|
||||
{
|
||||
PalEdit *paledit = paledit_data(widget);
|
||||
|
||||
if (!paledit->editable)
|
||||
if (!m_editable)
|
||||
return;
|
||||
|
||||
switch (paledit->range_type) {
|
||||
switch (m_range_type) {
|
||||
|
||||
case PALETTE_EDITOR_RANGE_LINEAL: {
|
||||
int c1 = MIN(paledit->color[0], paledit->color[1]);
|
||||
int c2 = MAX(paledit->color[0], paledit->color[1]);
|
||||
int c1 = MIN(m_color[0], m_color[1]);
|
||||
int c2 = MAX(m_color[0], m_color[1]);
|
||||
int c;
|
||||
|
||||
/* left */
|
||||
if (x < 0) {
|
||||
if (c1 > 0) {
|
||||
for (c=c1; c<=c2; c++)
|
||||
swap_color(paledit->palette, c, c-1);
|
||||
swap_color(get_current_palette(), c, c-1);
|
||||
|
||||
paledit->color[0]--;
|
||||
paledit->color[1]--;
|
||||
m_color[0]--;
|
||||
m_color[1]--;
|
||||
}
|
||||
}
|
||||
/* right */
|
||||
else if (x > 0) {
|
||||
if (c2 < 255) {
|
||||
for (c=c2; c>=c1; c--)
|
||||
swap_color(paledit->palette, c, c+1);
|
||||
swap_color(get_current_palette(), c, c+1);
|
||||
|
||||
paledit->color[0]++;
|
||||
paledit->color[1]++;
|
||||
m_color[0]++;
|
||||
m_color[1]++;
|
||||
}
|
||||
}
|
||||
/* up */
|
||||
@ -226,9 +183,9 @@ void paledit_move_selection(JWidget widget, int x, int y)
|
||||
|
||||
case PALETTE_EDITOR_RANGE_NONE:
|
||||
case PALETTE_EDITOR_RANGE_RECTANGULAR: {
|
||||
int cols = paledit->columns;
|
||||
int index1 = paledit->color[0];
|
||||
int index2 = paledit->color[1];
|
||||
int cols = m_columns;
|
||||
int index1 = m_color[0];
|
||||
int index2 = m_color[1];
|
||||
int c, u, v, x1, y1, x2, y2;
|
||||
|
||||
/* swap */
|
||||
@ -251,12 +208,12 @@ void paledit_move_selection(JWidget widget, int x, int y)
|
||||
if ((x1 > 0) && ((y1*cols+x1-1) >= 0)) {
|
||||
for (v=y1; v<=y2; v++)
|
||||
for (u=x1; u<=x2; u++)
|
||||
swap_color(paledit->palette,
|
||||
swap_color(get_current_palette(),
|
||||
(v*cols + u),
|
||||
(v*cols + (u-1)));
|
||||
|
||||
paledit->color[0]--;
|
||||
paledit->color[1]--;
|
||||
m_color[0]--;
|
||||
m_color[1]--;
|
||||
}
|
||||
}
|
||||
/* right */
|
||||
@ -264,12 +221,12 @@ void paledit_move_selection(JWidget widget, int x, int y)
|
||||
if ((x2 < cols-1) && ((y2*cols+x2+1) <= 255)) {
|
||||
for (v=y1; v<=y2; v++)
|
||||
for (u=x2; u>=x1; u--)
|
||||
swap_color(paledit->palette,
|
||||
swap_color(get_current_palette(),
|
||||
(v*cols + u),
|
||||
(v*cols + (u+1)));
|
||||
|
||||
paledit->color[0]++;
|
||||
paledit->color[1]++;
|
||||
m_color[0]++;
|
||||
m_color[1]++;
|
||||
}
|
||||
}
|
||||
/* up */
|
||||
@ -277,12 +234,12 @@ void paledit_move_selection(JWidget widget, int x, int y)
|
||||
if (((y1-1)*cols+x1) >= 0) {
|
||||
for (v=y1; v<=y2; v++)
|
||||
for (u=x1; u<=x2; u++)
|
||||
swap_color(paledit->palette,
|
||||
swap_color(get_current_palette(),
|
||||
(v*cols + u),
|
||||
((v-1)*cols + u));
|
||||
|
||||
paledit->color[0] -= cols;
|
||||
paledit->color[1] -= cols;
|
||||
m_color[0] -= cols;
|
||||
m_color[1] -= cols;
|
||||
}
|
||||
}
|
||||
/* down */
|
||||
@ -290,12 +247,12 @@ void paledit_move_selection(JWidget widget, int x, int y)
|
||||
if (((y2+1)*cols+x2) <= 255) {
|
||||
for (v=y2; v>=y1; v--)
|
||||
for (u=x1; u<=x2; u++)
|
||||
swap_color(paledit->palette,
|
||||
swap_color(get_current_palette(),
|
||||
(v*cols + u),
|
||||
((v+1)*cols + u));
|
||||
|
||||
paledit->color[0] += cols;
|
||||
paledit->color[1] += cols;
|
||||
m_color[0] += cols;
|
||||
m_color[1] += cols;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -303,43 +260,39 @@ void paledit_move_selection(JWidget widget, int x, int y)
|
||||
}
|
||||
|
||||
/* fixup the scroll */
|
||||
paledit_update_scroll(widget, paledit->color[1]);
|
||||
update_scroll(m_color[1]);
|
||||
|
||||
/* set the palette */
|
||||
set_current_palette(paledit->palette, false);
|
||||
//set_current_palette(m_palette, false);
|
||||
|
||||
/* refresh the screen */
|
||||
jmanager_refresh_screen();
|
||||
}
|
||||
|
||||
int paledit_get_1st_color(JWidget widget)
|
||||
int PalEdit::get1stColor()
|
||||
{
|
||||
PalEdit *paledit = paledit_data(widget);
|
||||
return paledit->color[0];
|
||||
return m_color[0];
|
||||
}
|
||||
|
||||
int paledit_get_2nd_color(JWidget widget)
|
||||
int PalEdit::get2ndColor()
|
||||
{
|
||||
PalEdit *paledit = paledit_data(widget);
|
||||
return paledit->color[1];
|
||||
return m_color[1];
|
||||
}
|
||||
|
||||
void paledit_get_selected_entries(JWidget widget, bool array[256])
|
||||
void PalEdit::getSelectedEntries(bool array[256])
|
||||
{
|
||||
PalEdit *paledit = paledit_data(widget);
|
||||
|
||||
memset(array, false, sizeof(bool)*256);
|
||||
|
||||
switch (paledit->range_type) {
|
||||
switch (m_range_type) {
|
||||
|
||||
case PALETTE_EDITOR_RANGE_NONE:
|
||||
if (paledit->color[1] >= 0)
|
||||
array[paledit->color[1]] = true;
|
||||
if (m_color[1] >= 0)
|
||||
array[m_color[1]] = true;
|
||||
break;
|
||||
|
||||
case PALETTE_EDITOR_RANGE_LINEAL: {
|
||||
int c1 = MIN(paledit->color[0], paledit->color[1]);
|
||||
int c2 = MAX(paledit->color[0], paledit->color[1]);
|
||||
int c1 = MIN(m_color[0], m_color[1]);
|
||||
int c2 = MAX(m_color[0], m_color[1]);
|
||||
int c;
|
||||
|
||||
for (c=c1; c<=c2; c++)
|
||||
@ -348,9 +301,9 @@ void paledit_get_selected_entries(JWidget widget, bool array[256])
|
||||
}
|
||||
|
||||
case PALETTE_EDITOR_RANGE_RECTANGULAR: {
|
||||
int cols = paledit->columns;
|
||||
int index1 = paledit->color[0];
|
||||
int index2 = paledit->color[1];
|
||||
int cols = m_columns;
|
||||
int index1 = m_color[0];
|
||||
int index2 = m_color[1];
|
||||
int c, x, y, x1, y1, x2, y2;
|
||||
|
||||
/* swap */
|
||||
@ -376,64 +329,49 @@ void paledit_get_selected_entries(JWidget widget, bool array[256])
|
||||
}
|
||||
}
|
||||
|
||||
static PalEdit *paledit_data(JWidget widget)
|
||||
bool PalEdit::msg_proc(JMessage msg)
|
||||
{
|
||||
return reinterpret_cast<PalEdit*>(jwidget_get_data(widget, paledit_type()));
|
||||
}
|
||||
|
||||
static bool paledit_msg_proc(JWidget widget, JMessage msg)
|
||||
{
|
||||
PalEdit *paledit = paledit_data(widget);
|
||||
|
||||
switch (msg->type) {
|
||||
|
||||
case JM_DESTROY:
|
||||
jfree (paledit);
|
||||
break;
|
||||
|
||||
case JM_REQSIZE:
|
||||
paledit_request_size(widget, &msg->reqsize.w, &msg->reqsize.h);
|
||||
request_size(&msg->reqsize.w, &msg->reqsize.h);
|
||||
return true;
|
||||
|
||||
case JM_KEYPRESSED:
|
||||
if (jwidget_has_focus(widget)) {
|
||||
/* other keys */
|
||||
if ((paledit->color[1] >= 0) &&
|
||||
(paledit->color[1] <= 255)) {
|
||||
switch (msg->key.scancode) {
|
||||
case KEY_LEFT: paledit_move_selection(widget, -1, 0); break;
|
||||
case KEY_RIGHT: paledit_move_selection(widget, +1, 0); break;
|
||||
case KEY_UP: paledit_move_selection(widget, 0, -1); break;
|
||||
case KEY_DOWN: paledit_move_selection(widget, 0, +1); break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
// case JM_KEYPRESSED:
|
||||
// if (jwidget_has_focus(this)) {
|
||||
// /* other keys */
|
||||
// if ((m_color[1] >= 0) && (m_color[1] <= 255)) {
|
||||
// switch (msg->key.scancode) {
|
||||
// case KEY_LEFT: moveSelection(-1, 0); return true;
|
||||
// case KEY_RIGHT: moveSelection(+1, 0); return true;
|
||||
// case KEY_UP: moveSelection(0, -1); return true;
|
||||
// case KEY_DOWN: moveSelection(0, +1); return true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
|
||||
case JM_DRAW: {
|
||||
div_t d = div(256, paledit->columns);
|
||||
int cols = paledit->columns;
|
||||
div_t d = div(256, m_columns);
|
||||
int cols = m_columns;
|
||||
int rows = d.quot + ((d.rem)? 1: 0);
|
||||
int x1, y1, x2, y2;
|
||||
int x, y, u, v;
|
||||
int c, color;
|
||||
BITMAP *bmp;
|
||||
Palette* palette = get_current_palette();
|
||||
|
||||
bmp = create_bitmap (jrect_w(widget->rc), jrect_h(widget->rc));
|
||||
clear_to_color (bmp, makecol(0 , 0, 0));
|
||||
bmp = create_bitmap(jrect_w(this->rc), jrect_h(this->rc));
|
||||
clear_to_color(bmp, makecol(0 , 0, 0));
|
||||
|
||||
y = widget->border_width.t;
|
||||
y = this->border_width.t;
|
||||
c = 0;
|
||||
|
||||
for (v=0; v<rows; v++) {
|
||||
x = widget->border_width.l;
|
||||
x = this->border_width.l;
|
||||
|
||||
for (u=0; u<cols; u++) {
|
||||
if (c >= 256)
|
||||
if (c >= palette->size())
|
||||
break;
|
||||
|
||||
if (bitmap_color_depth(ji_screen) == 8)
|
||||
@ -441,26 +379,26 @@ static bool paledit_msg_proc(JWidget widget, JMessage msg)
|
||||
else
|
||||
color = makecol_depth
|
||||
(bitmap_color_depth(ji_screen),
|
||||
_rgba_getr(paledit->palette->getEntry(c)),
|
||||
_rgba_getg(paledit->palette->getEntry(c)),
|
||||
_rgba_getb(paledit->palette->getEntry(c)));
|
||||
_rgba_getr(palette->getEntry(c)),
|
||||
_rgba_getg(palette->getEntry(c)),
|
||||
_rgba_getb(palette->getEntry(c)));
|
||||
|
||||
rectfill(bmp, x, y, x+COLOR_SIZE-1, y+COLOR_SIZE-1, color);
|
||||
|
||||
x += COLOR_SIZE+widget->child_spacing;
|
||||
x += COLOR_SIZE+this->child_spacing;
|
||||
c++;
|
||||
}
|
||||
|
||||
y += COLOR_SIZE+widget->child_spacing;
|
||||
y += COLOR_SIZE+this->child_spacing;
|
||||
}
|
||||
|
||||
/* draw the edges in the selected color */
|
||||
if (paledit->color[0] >= 0) {
|
||||
int index1 = paledit->color[0];
|
||||
int index2 = paledit->color[1];
|
||||
int bl = widget->border_width.l;
|
||||
int bt = widget->border_width.t;
|
||||
int cs = widget->child_spacing;
|
||||
if (m_color[0] >= 0) {
|
||||
int index1 = m_color[0];
|
||||
int index2 = m_color[1];
|
||||
int bl = this->border_width.l;
|
||||
int bt = this->border_width.t;
|
||||
int cs = this->child_spacing;
|
||||
int color = makecol (255, 255, 255);
|
||||
|
||||
/* swap */
|
||||
@ -479,7 +417,7 @@ static bool paledit_msg_proc(JWidget widget, JMessage msg)
|
||||
if (y2 < y1) { c = y2; y2 = y1; y1 = c; }
|
||||
|
||||
/* draw the rectangular gamma or just the cursor */
|
||||
if (paledit->range_type != PALETTE_EDITOR_RANGE_LINEAL) {
|
||||
if (m_range_type != PALETTE_EDITOR_RANGE_LINEAL) {
|
||||
if (x2 < x1) { c = x2; x2 = x1; x1 = c; }
|
||||
|
||||
rect(bmp,
|
||||
@ -548,32 +486,33 @@ static bool paledit_msg_proc(JWidget widget, JMessage msg)
|
||||
}
|
||||
|
||||
blit(bmp, ji_screen,
|
||||
0, 0, widget->rc->x1, widget->rc->y1, bmp->w, bmp->h);
|
||||
0, 0, this->rc->x1, this->rc->y1, bmp->w, bmp->h);
|
||||
destroy_bitmap(bmp);
|
||||
break;
|
||||
}
|
||||
|
||||
case JM_BUTTONPRESSED:
|
||||
jwidget_hard_capture_mouse(widget);
|
||||
jwidget_hard_capture_mouse(this);
|
||||
/* continue... */
|
||||
|
||||
case JM_MOTION:
|
||||
if (jwidget_has_capture(widget)) {
|
||||
JRect cpos = jwidget_get_child_rect(widget);
|
||||
div_t d = div (256, paledit->columns);
|
||||
int cols = paledit->columns;
|
||||
if (jwidget_has_capture(this)) {
|
||||
JRect cpos = jwidget_get_child_rect(this);
|
||||
div_t d = div(256, m_columns);
|
||||
int cols = m_columns;
|
||||
int rows = d.quot + ((d.rem)? 1: 0);
|
||||
int mouse_x, mouse_y;
|
||||
int req_w, req_h;
|
||||
int x, y, u, v;
|
||||
int c;
|
||||
Palette* palette = get_current_palette();
|
||||
|
||||
paledit_request_size(widget, &req_w, &req_h);
|
||||
request_size(&req_w, &req_h);
|
||||
|
||||
mouse_x = MID(cpos->x1, msg->mouse.x,
|
||||
cpos->x1+req_w-widget->border_width.r-1);
|
||||
cpos->x1+req_w-this->border_width.r-1);
|
||||
mouse_y = MID(cpos->y1, msg->mouse.y,
|
||||
cpos->y1+req_h-widget->border_width.b-1);
|
||||
cpos->y1+req_h-this->border_width.b-1);
|
||||
|
||||
y = cpos->y1;
|
||||
c = 0;
|
||||
@ -582,35 +521,31 @@ static bool paledit_msg_proc(JWidget widget, JMessage msg)
|
||||
x = cpos->x1;
|
||||
|
||||
for (u=0; u<cols; u++) {
|
||||
if (c >= 256)
|
||||
if (c >= palette->size())
|
||||
break;
|
||||
|
||||
if ((mouse_x >= x) && (mouse_x <= x+COLOR_SIZE) &&
|
||||
(mouse_y >= y) && (mouse_y <= y+COLOR_SIZE) &&
|
||||
(c != paledit->color[1])) {
|
||||
(c != m_color[1])) {
|
||||
if (msg->any.shifts & KB_SHIFT_FLAG)
|
||||
paledit_select_range(widget,
|
||||
paledit->color[0], c,
|
||||
PALETTE_EDITOR_RANGE_LINEAL);
|
||||
selectRange(m_color[0], c, PALETTE_EDITOR_RANGE_LINEAL);
|
||||
else if (msg->any.shifts & KB_CTRL_FLAG)
|
||||
paledit_select_range(widget,
|
||||
paledit->color[0], c,
|
||||
PALETTE_EDITOR_RANGE_RECTANGULAR);
|
||||
selectRange(m_color[0], c, PALETTE_EDITOR_RANGE_RECTANGULAR);
|
||||
else
|
||||
paledit_select_color(widget, c);
|
||||
selectColor(c);
|
||||
|
||||
paledit_update_scroll(widget, c);
|
||||
update_scroll(c);
|
||||
|
||||
jwidget_emit_signal(widget, SIGNAL_PALETTE_EDITOR_CHANGE);
|
||||
jwidget_emit_signal(this, SIGNAL_PALETTE_EDITOR_CHANGE);
|
||||
c = 256;
|
||||
break;
|
||||
}
|
||||
|
||||
x += COLOR_SIZE+widget->child_spacing;
|
||||
x += COLOR_SIZE+this->child_spacing;
|
||||
c++;
|
||||
}
|
||||
|
||||
y += COLOR_SIZE+widget->child_spacing;
|
||||
y += COLOR_SIZE+this->child_spacing;
|
||||
}
|
||||
|
||||
jrect_free(cpos);
|
||||
@ -619,32 +554,30 @@ static bool paledit_msg_proc(JWidget widget, JMessage msg)
|
||||
break;
|
||||
|
||||
case JM_BUTTONRELEASED:
|
||||
jwidget_release_mouse(widget);
|
||||
jwidget_release_mouse(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return Widget::msg_proc(msg);
|
||||
}
|
||||
|
||||
static void paledit_request_size(JWidget widget, int *w, int *h)
|
||||
void PalEdit::request_size(int* w, int* h)
|
||||
{
|
||||
PalEdit *paledit = paledit_data(widget);
|
||||
div_t d = div(256, paledit->columns);
|
||||
int cols = paledit->columns;
|
||||
div_t d = div(256, m_columns);
|
||||
int cols = m_columns;
|
||||
int rows = d.quot + ((d.rem)? 1: 0);
|
||||
|
||||
*w = widget->border_width.l + widget->border_width.r +
|
||||
+ cols*COLOR_SIZE + (cols-1)*widget->child_spacing;
|
||||
*w = this->border_width.l + this->border_width.r +
|
||||
+ cols*COLOR_SIZE + (cols-1)*this->child_spacing;
|
||||
|
||||
*h = widget->border_width.t + widget->border_width.b +
|
||||
+ rows*COLOR_SIZE + (rows-1)*widget->child_spacing;
|
||||
*h = this->border_width.t + this->border_width.b +
|
||||
+ rows*COLOR_SIZE + (rows-1)*this->child_spacing;
|
||||
}
|
||||
|
||||
static void paledit_update_scroll(JWidget widget, int color)
|
||||
void PalEdit::update_scroll(int color)
|
||||
{
|
||||
JWidget view = jwidget_get_view(widget);
|
||||
Widget* view = jwidget_get_view(this);
|
||||
if (view != NULL) {
|
||||
PalEdit *paledit = paledit_data(widget);
|
||||
JRect vp = jview_get_viewport_position(view);
|
||||
int scroll_x, scroll_y;
|
||||
int x, y, cols;
|
||||
@ -652,11 +585,11 @@ static void paledit_update_scroll(JWidget widget, int color)
|
||||
|
||||
jview_get_scroll(view, &scroll_x, &scroll_y);
|
||||
|
||||
d = div(256, paledit->columns);
|
||||
cols = paledit->columns;
|
||||
d = div(256, m_columns);
|
||||
cols = m_columns;
|
||||
|
||||
y = (COLOR_SIZE+widget->child_spacing) * (color / cols);
|
||||
x = (COLOR_SIZE+widget->child_spacing) * (color % cols);
|
||||
y = (COLOR_SIZE+this->child_spacing) * (color / cols);
|
||||
x = (COLOR_SIZE+this->child_spacing) * (color % cols);
|
||||
|
||||
if (scroll_x > x)
|
||||
scroll_x = x;
|
||||
|
@ -21,11 +21,9 @@
|
||||
|
||||
#include <allegro/color.h>
|
||||
|
||||
#include "jinete/jbase.h"
|
||||
#include "jinete/jwidget.h"
|
||||
|
||||
class Palette;
|
||||
|
||||
/* TODO use some JI_SIGNAL_USER */
|
||||
// TODO use some JI_SIGNAL_USER
|
||||
#define SIGNAL_PALETTE_EDITOR_CHANGE 0x10005
|
||||
|
||||
enum {
|
||||
@ -34,23 +32,38 @@ enum {
|
||||
PALETTE_EDITOR_RANGE_RECTANGULAR,
|
||||
};
|
||||
|
||||
JWidget paledit_new(Palette* palette, bool editable, int boxsize);
|
||||
int paledit_type();
|
||||
class PalEdit : public Widget
|
||||
{
|
||||
public:
|
||||
PalEdit(bool editable);
|
||||
|
||||
Palette* paledit_get_palette(JWidget widget);
|
||||
int paledit_get_range_type(JWidget widget);
|
||||
int getRangeType();
|
||||
|
||||
int paledit_get_columns(JWidget widget);
|
||||
void paledit_set_columns(JWidget widget, int columns);
|
||||
void paledit_set_boxsize(JWidget widget, int boxsize);
|
||||
int getColumns();
|
||||
void setColumns(int columns);
|
||||
void setBoxSize(int boxsize);
|
||||
|
||||
void paledit_select_color(JWidget widget, int index);
|
||||
void paledit_select_range(JWidget widget, int begin, int end, int range_type);
|
||||
void selectColor(int index);
|
||||
void selectRange(int begin, int end, int range_type);
|
||||
|
||||
void paledit_move_selection(JWidget widget, int x, int y);
|
||||
void moveSelection(int x, int y);
|
||||
|
||||
int paledit_get_1st_color(JWidget widget);
|
||||
int paledit_get_2nd_color(JWidget widget);
|
||||
void paledit_get_selected_entries(JWidget widget, bool array[256]);
|
||||
int get1stColor();
|
||||
int get2ndColor();
|
||||
void getSelectedEntries(bool array[256]);
|
||||
|
||||
protected:
|
||||
virtual bool msg_proc(JMessage msg);
|
||||
|
||||
private:
|
||||
void request_size(int* w, int* h);
|
||||
void update_scroll(int color);
|
||||
|
||||
bool m_editable;
|
||||
unsigned m_range_type;
|
||||
unsigned m_columns;
|
||||
int m_boxsize;
|
||||
int m_color[2];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user