+ Added Editor::space_pressed to move the scroll with the space key.

+ Renamed Editor::cursor_eyedropper to Editor::alt_pressed.
+ Added statusbar_show_tip.
+ Added AppHooks.
+ Renamed color_button_* to colorbutton_*
+ Renamed GfxObj*Layer::parent to Layer*Layer::parent_layer.
+ Added Palette gfxobj and refactored a lot of code to this new Palette
  instead of Allegro's RGB/PALETTE.
+ Now jfile.c uses jxml.c.
+ New signature for callbacks in 'hook_signal' of modules/gui.c:
  bool hook(JWidget, void *);
- Removed colsel and minipal from dialogs.
+ Fixed mouse bounds in sliders.
This commit is contained in:
David Capello 2008-03-22 18:43:56 +00:00
parent ef28731b5a
commit 19e8083256
140 changed files with 3151 additions and 3342 deletions

View File

@ -1,3 +1,72 @@
2008-03-22 David A. Capello <dacap@users.sourceforge.net>
* src/commands/cmd_new_file.c (cmd_new_file_execute): Removed the
'Custom' background-color option.
* src/widgets/colbut.c (ColorButton): Rewritten to use the new
colorselector tooltip window, and added a new eyedropper feature
pressing the button.
* src/jinete/jmanager.c (jmanager_remove_msg_filter_for): Added.
* src/widgets/statebar.c (statusbar_show_tip): Added.
* src/jinete/jmanager.c (jmanager_set_timer_interval): Added.
2008-03-21 David A. Capello <dacap@users.sourceforge.net>
* src/raster/sprite.c (general_copy): Fixed a problem calling with
sprite_set_frames(..., src_sprite->frame) instead of src_sprite->frames.
* src/raster/layer.c (layer_new_copy): Added dst_sprite.
2008-03-20 David A. Capello <dacap@users.sourceforge.net>
* src/raster/layer.c (layer_flatten): Fixed a problem where the
flatten layer was added in other sprite. For this the new "sprite"
parameter was added. Renamed to layer_new_flatten_copy.
* src/widgets/editor/editor.c (editor_msg_proc): Fixed an annoying
flickering effect when the mouse button was released in
editor->state == EDIT_DRAWING.
2008-03-19 David A. Capello <dacap@users.sourceforge.net>
* src/jinete/jmanager.c (jmanager_generate_messages): Now the
mouse events are enqueue even if mouse_widget = NULL, because
maybe a msg_filter is added in "jmanager_enqueue_message".
2008-03-16 David A. Capello <dacap@users.sourceforge.net>
* src/raster/undo.c (chunk_dirty_invert): Fixed a bug with
dirty->rows == 0 (for example, when you use floodfill and it
doesn't fill nothing).
* src/raster/palette.h (struct Palette): Added. A lot of code was
passed from Allegro's RGB and PALETTE to this new Palette
structure.
2008-03-15 David A. Capello <dacap@users.sourceforge.net>
* src/core/app.c (app_add_hook): Added.
(app_trigger_event): Added.
* src/jinete/jtooltips.c (tipwindow_msg_proc): Fixed a memory leak
of a JRect in JM_DRAW.
* src/jinete/jmenu.c (window_msg_proc): Added to call
jwidget_free_deferred in JM_CLOSE of a menubox-window. This fix a
memory leak (the menuboxes' windows were not freed).
* src/jinete/jtooltips.c (jtooltip_window_set_hotregion): Fixed a
memory leak (was called jfree instead of jregion_free).
* src/commands/cmd_grid.c (cmd_snap_to_grid_checked)
(cmd_show_grid_checked): Added.
* src/jinete/jslider.c (slider_msg_proc): Fixed the mouse limits
in the slider widget.
2008-03-09 David A. Capello <dacap@users.sourceforge.net>
* src/widgets/colbar.c: A lot of work was done for the lock/idx

View File

@ -19,20 +19,21 @@ NEWS
+ Enhanced GUI:
+ more borders for windows and more spacing between widgets.
+ better mouse behavior (now in Windows the mouse is captured).
+ Finally screen scaling supported (with double-buffering). This means
+ added tooltips.
+ Added pixel-scaling support (with double-buffering). This means
that you can use a screen of 320x240 between a window of 640x480
(screen-scaling x2).
(pixel-scaling x2).
+ Fixed other minor problems when you drawn in 'tiled mode' or 'paste'
the clipboard.
+ New XML format for the menus and keyboard shortcuts.
- Removed a lot of complex functionality:
- Removed a lot of "complex" functionality:
- Removed mask-repositories (you can use .msk files instead).
- Removed menu scripting customization.
- Removed screen saver.
- Removed sessions.
- Removed draw-text (it'll return in next versions).
- Removed layer-sets (the Film-Editor can't handle them right at the
moment)
moment).
- Removed mapgen.
- Removed linked-cels (were complex for the end-user).
- Also the scripting support is broken, next versions of ASE will

View File

@ -1,32 +1,34 @@
Next beta
---------
- slider limits
- Palette gfxobj
- color module a "jcolor"?
- tooltips for color-bar.
- add two DrawClick2:
- DrawClick2FreeHand
- DrawClick2Shape
- the user_data of hook_signal should be void*.
- remove src/dialogs/colsel.[ch]
- remove src/dialogs/minipal.[ch]
+ faltan opciones para los rangos de paleta
+ agregar soporte para UNDO al cambiar los colores de la paleta.
- si está activado el cuatro para configurar herramientas las teclas G
y H deben actualizarlo
+ Solución: con hooks y Options (agregar core/options.[ch])
- fix this bug:
+ Create a RGB image,
+ change color mode to Indexed,
+ Undo (with the mouse).
High priority work
------------------
- search for TODO;
- rewrite tools-inks-drawingmode stuff;
- new animation editor (remove the film editor)
- drag & drop files in Windows.
- add core/options & the Options structure.
- add two DrawClick2:
- DrawClick2FreeHand
- DrawClick2Shape
- remove the jfilesel.c
- fix the sprite-properties dialog when select the constant
frame length.
- fix copyright years (2001-2008)
- fix a bug in the film editor when move the separator (panel) outside
the screen (to left or right)
+ rewrite the film editor.
- 'jfile.c' should use 'jxml.c', because there are duplicate code:
two (precarious) XML parsers.
- ver por el nuevo load_font de Allegro.
- complete palette operations, and palette editor (it needs a slider
or something to move between palette changes);

View File

@ -25,7 +25,7 @@
/* general information */
#define PACKAGE "ase"
#define VERSION "0.6-beta2"
#define VERSION "0.6b2"
#define WEBSITE "http://www.aseprite.org/"
#define COPYRIGHT "Copyright (C) 2001-2008 David A. Capello"

View File

@ -30,10 +30,10 @@
<key command="new_layer" shortcut="Shift+N" />
<!-- frame -->
<key command="new_frame" shortcut="N" />
<key command="goto_first_frame" shortcut="Down" />
<key command="goto_first_frame" shortcut="Home" />
<key command="goto_previous_frame" shortcut="Left" />
<key command="goto_next_frame" shortcut="Right" />
<key command="goto_last_frame" shortcut="Up" />
<key command="goto_last_frame" shortcut="End" />
<key command="play_animation" shortcut="Enter" />
<!-- cel -->
<key command="cel_properties" shortcut="Shift+Ctrl+P" />

View File

@ -8,7 +8,7 @@
<box vertical homogeneous>
<label text="Resolution:" />
<label text="Color depth:" />
<label text="Pixel scale:" />
<label text="Pixel scaling:" />
<check text="Fullscreen" name="fullscreen" />
</box>
<box vertical homogeneous expansive>

View File

@ -11,7 +11,7 @@
</box>
<box vertical homogeneous expansive>
<label text="" name="src_name" />
<entry maxsize="256" name="dst_name" />
<entry maxsize="256" name="dst_name" magnetic />
</box>
</box>
<check text="Duplicate merged layers only" name="flatten" />

View File

@ -32,11 +32,10 @@
<separator text="Background:" left horizontal />
<view maxsize expansive>
<listbox name="bg_box">
<listitem text="Transparent (mask color)" />
<listitem text="Transparent" />
<listitem text="Black" />
<listitem text="White" />
<listitem text="Magenta" />
<listitem text="Custom" />
</listbox>
</view>

View File

@ -7,22 +7,10 @@
<box vertical expansive>
<box horizontal expansive>
<box vertical homogeneous>
<label text="Get:" />
<label text="Put:" />
</box>
<box vertical homogeneous expansive>
<box horizontal expansive>
<box vertical homogeneous expansive name="color_buttons_box" />
<box vertical homogeneous>
<button text="1" name="button1_1" />
<button text="1" name="button2_1" />
</box>
<box vertical homogeneous>
<button text="2" name="button1_2" />
<button text="2" name="button2_2" />
</box>
</box>
<label text="From:" />
<label text="To:" />
</box>
<box vertical homogeneous expansive name="color_buttons_box" />
</box>
<label text="Fuzziness:" />
<slider min=0 max=255 name="fuzziness" />

BIN
data/tips/anicontrols.pcx Normal file

Binary file not shown.

BIN
data/tips/eyedropper.pcx Normal file

Binary file not shown.

View File

@ -14,52 +14,56 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Website: http://www.aseprite.org/
http://www.aseprite.org/
**********************************************************************
\image zoom.pcx
Use the <1>, <2>, <3>, <4>, <5> and <6> keys to set the zoom in the
current editor's viewport.
\image zoom.pcx
**********************************************************************
You can get a color from the sprite using the <9> or <0> keys to
set the left or right color respectively.
\image eyedropper.pcx
You can pick a color from the sprite using the <I> key or <Alt+Left
click>. This replaces the ``Tool Foreground Color''.
<Alt+Right click> replaces the ``Tool Background Color'' and the <X>
switches the Foreground and Background colors.
**********************************************************************
\image sprprop.pcx
You can modify the quantity of sprite's animation frames using the
"Sprite/Properties" menu or pressing <Ctrl+P>.
``Sprite/Properties'' menu or pressing <Ctrl+P>.
**********************************************************************
\image anicontrols.pcx
Move through the frames with the arrows keys
\split
Left = go to previous frame
<Left> = go to previous frame
Down = go to first frame
<Home> = go to first frame
\next
Right = go to next frame
<Right> = go to next frame
Up = go to last frame
<End> = go to last frame
\done
Enter = play animation
<Enter> = play animation
**********************************************************************
You can add new animation frames pressing <Ctrl+Shift+N> or using
"Frame/New" menu.
You can add new animation frames pressing N-key or using
``Frame/New'' menu.
**********************************************************************
Do you want edit layers, frames and cels? Use the film editor:
\image filmedit.pcx
Go to "Tools/Film Editor" menu or press TAB when you are
editing a sprite.
**********************************************************************
You can use the onionskin feature to edit animations (press <C> key to
see the "Tools Setup" window):
Do you want edit layers, frames and cels? Use the film editor:
Go to ``Tools/Film Editor'' menu or press <Tab> key when you are editing
a sprite.
**********************************************************************
\image onion.pcx
Remember that only the current layer is used as onionskin, also, it's
useful only when this layer has the mask color as background.
You can use the onion-skinning feature to edit animations (press <C> key to
see the ``Tools Setup'' window):
**********************************************************************
When you apply some effect (like Convolution Matrix, or Color Curves),
you can choose the target channels:
@ -99,9 +103,9 @@ All frames in all layers
**********************************************************************
\image colcurv.pcx
In the "Color Curve" window, you can use the <Ins> and <Del> keys to
In the ``Color Curve'' window, you can use the <Ins> and <Del> keys to
insert or remove vertices respectively. Also, if you press in a
vertex with the right mouse button, the "Point Properties" window (to
vertex with the right mouse button, the ``Point Properties'' window (to
change the coordinates manually) will be appears.
**********************************************************************
\image minipal.pcx
@ -117,13 +121,13 @@ A RGB image without dithering.
Ordered dithering method.
\done
See "Tool/Options" menu or press <Ctrl+Shift+O>.
See ``Tool/Options'' menu or press <Ctrl+Shift+O>.
**********************************************************************
\image lua.pcx
Do you want to write Lua scripts to generate images or create
repetitive tasks? You can find the documentation in
"docs/scripts/README.txt". Also you can look for "data/scripts/gens/"
``docs/scripts/README.txt''. Also you can look for ``data/scripts/gens/''
directory for some examples.
**********************************************************************
\palette sprite.pcx

View File

@ -1,120 +0,0 @@
# Allegro Sprite Editor tips
# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007 David A. Capello
**********************************************************************
\palette ase.pcx
\image ase.pcx
Bienvenido a ASE 0.6
Puede encontrar ayuda en la Wiki de ASE:
http://www.aseprite.org/wiki/
Reporte bugs y errores a:
ase-help@lists.sourceforge.net
**********************************************************************
\split
\image nodither.pcx
Este es el viejo método para graficar imágenes RGB. Sin fusionado.
\next
\image dither.pcx
Ahora, puede configurar para usar este nuevo método de fusionado de
colores.
\done
Vea el menú "Tool/Opciones" o presione <Ctrl+Shift+O>.
**********************************************************************
Utilice las teclas <1>, <2>, <3>, <4>, <5> y <6> para cambiar el zoom
del editor activo.
\image zoom.pcx
**********************************************************************
Puede obtener un color desde el sprite usando las teclas <9> y <0>
para cambiar los colores izquierdo o derecho respectivamente.
**********************************************************************
\image sprprop.pcx
Puede modificar la cantidad de cuadros de animación del sprite usando
el menú "Sprite/Propiedades" o presionando <Ctrl+P>.
**********************************************************************
Puede agregar cuadros de animación presionando <Ctrl+Shift+N> o
utilizando el menú "Frame/Nuevo".
**********************************************************************
¿Quiere editar los capas, cuadros y cels? Use el "Film Editor":
\image filmedit.pcx
Vaya al menú "Tools/Film Editor" o presione TAB cuando esté
editando un sprite.
**********************************************************************
Puede usar el papel cebolla (onionskin) para editar animaciones
(presione <C> para ver la ventana de "Tools Setup"):
\image onion.pcx
Recuerde que solo la capa activa es utilizada como papel cebolla,
además, es útil solo cuando la capa usa el color máscara de fondo.
**********************************************************************
Cuando aplica algún efecto (como la Matriz de Convolución, o la
Curva de Color), puede elegir los canales objetivos:
\split
\image tar_rgb.pcx
* R: Canal Rojo
* G: Canal Verde
* B: Canal Azul
* A: Canal Alpha
\next
\image tar_gray.pcx
* K: Canal Negro
* A: Canal Alpha
\next
\image tar_indx.pcx
* R: Canal Rojo
* G: Canal Verde
* B: Canal Azul
* Index: Utilizar directamente el índice
\done
También puede especificar a que imágenes le desea aplicar el efecto:
\split
\image tar_1.pcx
Cuadro actual de la capa actual
\next
\image tar_2.pcx
Todos los cuadros de la capa actual
\next
\image tar_3.pcx
Cuadros actuales de todas las capas
\next
\image tar_4.pcx
Todos los cuadros de todas las capas
\done
**********************************************************************
\image colcurv.pcx
En la ventana de "Curva de Color", puede usar las teclas <Ins>
(insertar) y <Del> (suprimir) para insertar o borrar vértices
respectivamentes. También, si presiona en uno de estos puntos con el
botón derecho del mouse, la venta "Propiedades del Punto" aparecera
(para cambiar las coordenadas manualmente).
**********************************************************************
\image minipal.pcx
Seleccionando un color en la barra-de-colores usando la tecla <Ctrl>
le mostrará esta mini-paleta.
**********************************************************************
\image lua.pcx
¿Desea escribir scripts (guiones) en Lua para generar imágenes o crear
tareas repetitivas? Puede buscar la documentación en
"docs/scripts/README.txt". También puede ver el directorio
"data/scripts/gens/" para algunos ejemplos.
**********************************************************************
\palette sprite.pcx
\image sprite.pcx
Y recuerde buscar actualizaciones en:
http://www.aseprite.org/
Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007 por David A. Capello

View File

@ -35,8 +35,8 @@ and differents chunks. Also, the color depth can be 8, 16 or 32 for
Indexed, Grayscale and RGB respectively, and the images are more easy
to read (there aren't differences with old frames). The palette isn't
included for color depths more than 8, but when the sprite is 8 bpp,
the palette is in an old FLI color chunk (type=11). See fli.txt for
details.
the palette is in a FLI color chunk (it could be type=11 or type=4).
See fli.txt for details.
To read the sprite, just do this:
* Read the ASE header (section 3)

View File

@ -4,6 +4,7 @@ Format for .jid files
General format:
<jinete>
<widget_type [id="..."]
[expansive]
[width="percentage of screen width"]
@ -13,6 +14,7 @@ Format for .jid files
...>
widgets children...
</widget_type>
</jinete>
======================================================================
Supported widget types

View File

@ -85,8 +85,6 @@ COMMON_SOURCES = \
src/core/file_system.c \
src/core/modules.c \
src/dialogs/canvasze.c \
src/dialogs/colsel.c \
src/dialogs/dpaledit.c \
src/dialogs/drawtext.c \
src/dialogs/filesel.c \
src/dialogs/filmedit.c \
@ -162,7 +160,7 @@ COMMON_SOURCES = \
src/modules/editors.c \
src/modules/gfx.c \
src/modules/gui.c \
src/modules/palette.c \
src/modules/palettes.c \
src/modules/recent.c \
src/modules/rootmenu.c \
src/modules/sprites.c \
@ -178,6 +176,7 @@ COMMON_SOURCES = \
src/raster/image.c \
src/raster/layer.c \
src/raster/mask.c \
src/raster/palette.c \
src/raster/path.c \
src/raster/quant.c \
src/raster/rotate.c \

View File

@ -24,7 +24,7 @@
#include "core/app.h"
#include "core/cfg.h"
#include "modules/gui.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "modules/sprites.h"
#include "raster/image.h"
#include "raster/quant.h"

View File

@ -26,7 +26,7 @@
#include "console/console.h"
#include "core/app.h"
#include "modules/gui.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#define DEPTH_TO_INDEX(bpp) \
((bpp == 8)? 0: \
@ -193,7 +193,7 @@ static bool try_new_gfx_mode(void)
gui_setup_screen();
/* set to a black palette */
set_current_palette(black_palette, TRUE);
set_black_palette();
/* restore palette all screen stuff */
app_refresh_screen();
@ -209,7 +209,7 @@ static bool try_new_gfx_mode(void)
gui_setup_screen();
/* set to a black palette */
set_current_palette(black_palette, TRUE);
set_black_palette();
/* restore palette all screen stuff */
app_refresh_screen();

View File

@ -43,21 +43,21 @@ static JWidget window = NULL;
static bool brush_preview_msg_proc(JWidget widget, JMessage msg);
static int window_close_hook(JWidget widget, int user_data);
static int brush_size_slider_change_hook(JWidget widget, int user_data);
static int brush_angle_slider_change_hook(JWidget widget, int user_data);
static int brush_type_change_hook(JWidget widget, int user_data);
static int brush_mode_change_hook(JWidget widget, int user_data);
static int glass_dirty_slider_change_hook(JWidget widget, int user_data);
static int spray_width_slider_change_hook(JWidget widget, int user_data);
static int air_speed_slider_change_hook(JWidget widget, int user_data);
static int filled_check_change_hook(JWidget widget, int user_data);
static int tiled_check_change_hook(JWidget widget, int user_data);
static int use_grid_check_change_hook(JWidget widget, int user_data);
static int view_grid_check_change_hook(JWidget widget, int user_data);
static int set_grid_button_select_hook(JWidget widget, int user_data);
static int cursor_button_change_hook(JWidget widget, int user_data);
static int onionskin_check_change_hook(JWidget widget, int user_data);
static bool window_close_hook(JWidget widget, void *data);
static bool brush_size_slider_change_hook(JWidget widget, void *data);
static bool brush_angle_slider_change_hook(JWidget widget, void *data);
static bool brush_type_change_hook(JWidget widget, void *data);
static bool brush_mode_change_hook(JWidget widget, void *data);
static bool glass_dirty_slider_change_hook(JWidget widget, void *data);
static bool spray_width_slider_change_hook(JWidget widget, void *data);
static bool air_speed_slider_change_hook(JWidget widget, void *data);
static bool filled_check_change_hook(JWidget widget, void *data);
static bool tiled_check_change_hook(JWidget widget, void *data);
static bool use_grid_check_change_hook(JWidget widget, void *data);
static bool view_grid_check_change_hook(JWidget widget, void *data);
static bool set_grid_button_select_hook(JWidget widget, void *data);
static bool cursor_button_change_hook(JWidget widget, void *data);
static bool onionskin_check_change_hook(JWidget widget, void *data);
static void cmd_configure_tools_execute(const char *argument)
{
@ -108,7 +108,7 @@ static void cmd_configure_tools_execute(const char *argument)
/* cursor-color */
if (first_time) {
cursor_color = color_button_new(get_cursor_color(), IMAGE_INDEXED);
cursor_color = colorbutton_new(get_cursor_color(), IMAGE_INDEXED);
jwidget_set_name(cursor_color, "cursor_color");
}
else {
@ -187,10 +187,10 @@ static void cmd_configure_tools_execute(const char *argument)
HOOK(glass_dirty, JI_SIGNAL_SLIDER_CHANGE, glass_dirty_slider_change_hook, 0);
HOOK(air_speed, JI_SIGNAL_SLIDER_CHANGE, air_speed_slider_change_hook, 0);
HOOK(spray_width, JI_SIGNAL_SLIDER_CHANGE, spray_width_slider_change_hook, 0);
HOOK(cursor_color, SIGNAL_COLOR_BUTTON_CHANGE, cursor_button_change_hook, 0);
HOOK(cursor_color, SIGNAL_COLORBUTTON_CHANGE, cursor_button_change_hook, 0);
HOOK(check_onionskin, JI_SIGNAL_CHECK_CHANGE, onionskin_check_change_hook, 0);
add_gui_exit_hook(jwidget_free, window);
app_add_hook(APP_EXIT, jwidget_free, window);
}
/* default position */
@ -226,7 +226,7 @@ static bool brush_preview_msg_proc(JWidget widget, JMessage msg)
return FALSE;
}
static int window_close_hook(JWidget widget, int user_data)
static bool window_close_hook(JWidget widget, void *data)
{
/* isn't running anymore */
/* window = NULL; */
@ -237,26 +237,26 @@ static int window_close_hook(JWidget widget, int user_data)
return FALSE;
}
static int brush_size_slider_change_hook(JWidget widget, int user_data)
static bool brush_size_slider_change_hook(JWidget widget, void *data)
{
set_brush_size(jslider_get_value(widget));
jwidget_dirty((JWidget)user_data);
jwidget_dirty((JWidget)data);
return FALSE;
}
static int brush_angle_slider_change_hook(JWidget widget, int user_data)
static bool brush_angle_slider_change_hook(JWidget widget, void *data)
{
set_brush_angle(jslider_get_value(widget));
jwidget_dirty((JWidget)user_data);
jwidget_dirty((JWidget)data);
return FALSE;
}
static int brush_type_change_hook(JWidget widget, int user_data)
static bool brush_type_change_hook(JWidget widget, void *data)
{
int type = group_button_get_selected(widget);
set_brush_type(type);
jwidget_dirty((JWidget)user_data);
jwidget_dirty((JWidget)data);
statusbar_set_text(app_get_statusbar(), 250,
"Brush type: %s",
@ -267,7 +267,7 @@ static int brush_type_change_hook(JWidget widget, int user_data)
return TRUE;
}
static int brush_mode_change_hook(JWidget widget, int user_data)
static bool brush_mode_change_hook(JWidget widget, void *data)
{
int mode = group_button_get_selected(widget);
@ -281,50 +281,50 @@ static int brush_mode_change_hook(JWidget widget, int user_data)
return TRUE;
}
static int glass_dirty_slider_change_hook(JWidget widget, int user_data)
static bool glass_dirty_slider_change_hook(JWidget widget, void *data)
{
set_glass_dirty(jslider_get_value(widget));
return FALSE;
}
static int spray_width_slider_change_hook(JWidget widget, int user_data)
static bool spray_width_slider_change_hook(JWidget widget, void *data)
{
set_spray_width(jslider_get_value(widget));
return FALSE;
}
static int air_speed_slider_change_hook(JWidget widget, int user_data)
static bool air_speed_slider_change_hook(JWidget widget, void *data)
{
set_air_speed(jslider_get_value(widget));
return FALSE;
}
static int filled_check_change_hook(JWidget widget, int user_data)
static bool filled_check_change_hook(JWidget widget, void *data)
{
set_filled_mode(jwidget_is_selected(widget));
return FALSE;
}
static int tiled_check_change_hook(JWidget widget, int user_data)
static bool tiled_check_change_hook(JWidget widget, void *data)
{
set_tiled_mode(jwidget_is_selected(widget));
return FALSE;
}
static int use_grid_check_change_hook(JWidget widget, int user_data)
static bool use_grid_check_change_hook(JWidget widget, void *data)
{
set_use_grid(jwidget_is_selected(widget));
return FALSE;
}
static int view_grid_check_change_hook(JWidget widget, int user_data)
static bool view_grid_check_change_hook(JWidget widget, void *data)
{
set_view_grid(jwidget_is_selected(widget));
refresh_all_editors();
return FALSE;
}
static int set_grid_button_select_hook(JWidget widget, int user_data)
static bool set_grid_button_select_hook(JWidget widget, void *data)
{
Sprite *sprite = current_sprite;
@ -349,20 +349,19 @@ static int set_grid_button_select_hook(JWidget widget, int user_data)
return TRUE;
}
static int cursor_button_change_hook(JWidget widget, int user_data)
static bool cursor_button_change_hook(JWidget widget, void *data)
{
set_cursor_color(color_button_get_color(widget));
set_cursor_color(colorbutton_get_color(widget));
return TRUE;
}
static int onionskin_check_change_hook(JWidget widget, int user_data)
static bool onionskin_check_change_hook(JWidget widget, void *data)
{
set_onionskin(jwidget_is_selected(widget));
refresh_all_editors();
return FALSE;
}
Command cmd_configure_tools = {
CMD_CONFIGURE_TOOLS,
NULL,

View File

@ -57,7 +57,7 @@ static Layer *duplicate_layer(void)
if (undo_is_enabled(sprite->undo))
undo_open(sprite->undo);
layer_copy = layer_new_copy(sprite->layer);
layer_copy = layer_new_copy(sprite, sprite->layer);
if (!layer_copy) {
if (undo_is_enabled(sprite->undo))
undo_close(sprite->undo);
@ -71,9 +71,9 @@ static Layer *duplicate_layer(void)
/* add the new layer in the sprite */
if (undo_is_enabled(sprite->undo))
undo_add_layer(sprite->undo, (Layer *)sprite->layer->parent, layer_copy);
undo_add_layer(sprite->undo, sprite->layer->parent_layer, layer_copy);
layer_add_layer((Layer *)sprite->layer->parent, layer_copy);
layer_add_layer(sprite->layer->parent_layer, layer_copy);
if (undo_is_enabled(sprite->undo)) {
undo_move_layer(sprite->undo, layer_copy);
@ -81,7 +81,7 @@ static Layer *duplicate_layer(void)
undo_close(sprite->undo);
}
layer_move_layer((Layer *)sprite->layer->parent, layer_copy, sprite->layer);
layer_move_layer(sprite->layer->parent_layer, layer_copy, sprite->layer);
sprite_set_layer(sprite, layer_copy);
return layer_copy;

View File

@ -26,12 +26,30 @@
#include "modules/tools.h"
#include "widgets/statebar.h"
/* ======================== */
/* show_grid */
/* ======================== */
static bool cmd_show_grid_checked(const char *argument)
{
return get_view_grid();
}
static void cmd_show_grid_execute(const char *argument)
{
set_view_grid(get_view_grid() ? FALSE: TRUE);
refresh_all_editors();
}
/* ======================== */
/* snap_to_grid */
/* ======================== */
static bool cmd_snap_to_grid_checked(const char *argument)
{
return get_use_grid();
}
static void cmd_snap_to_grid_execute(const char *argument)
{
char buf[512];
@ -49,7 +67,7 @@ static void cmd_snap_to_grid_execute(const char *argument)
Command cmd_show_grid = {
CMD_SHOW_GRID,
NULL,
NULL,
cmd_show_grid_checked,
cmd_show_grid_execute,
NULL
};
@ -57,7 +75,7 @@ Command cmd_show_grid = {
Command cmd_snap_to_grid = {
CMD_SNAP_TO_GRID,
NULL,
NULL,
cmd_snap_to_grid_checked,
cmd_snap_to_grid_execute,
NULL
};

View File

@ -140,7 +140,7 @@ static void cmd_merge_down_layer_execute(const char *argument)
}
sprite_set_layer(sprite, dst_layer);
layer_remove_layer((Layer *)src_layer->parent, src_layer);
layer_remove_layer(src_layer->parent_layer, src_layer);
layer_free(src_layer);
update_screen_for_sprite(sprite);

View File

@ -29,7 +29,6 @@
#include "core/app.h"
#include "core/cfg.h"
#include "core/color.h"
#include "dialogs/colsel.h"
#include "modules/gui.h"
#include "modules/sprites.h"
#include "raster/image.h"
@ -115,16 +114,6 @@ static void cmd_new_file_execute(const char *argument)
color = bg_table[bg];
ok = TRUE;
}
else {
color = get_config_color("NewSprite",
"BackgroundCustom",
color_rgb(0, 0, 0, 255));
if (ji_color_select(imgtype, &color)) {
set_config_color("NewSprite", "BackgroundCustom", color);
ok = TRUE;
}
}
if (ok) {
/* save the configuration */

View File

@ -23,6 +23,7 @@
#include "commands/commands.h"
#include "console/console.h"
#include "core/color.h"
#include "core/app.h"
#include "modules/gui.h"
#include "modules/sprites.h"
#include "raster/cel.h"
@ -31,6 +32,7 @@
#include "raster/sprite.h"
#include "raster/stock.h"
#include "raster/undo.h"
#include "widgets/statebar.h"
static bool new_frame_for_layer(Sprite *sprite, Layer *layer, int frame);
static bool copy_cel_in_next_frame(Sprite *sprite, Layer *layer, int frame);
@ -67,6 +69,10 @@ static void cmd_new_frame_execute(const char *argument)
/* close undo & refresh the screen */
undo_close(sprite->undo);
update_screen_for_sprite(sprite);
statusbar_show_tip(app_get_statusbar(), 1000,
_("New frame %d/%d"),
sprite->frame+1, sprite->frames);
}
static bool new_frame_for_layer(Sprite *sprite, Layer *layer, int frame)

View File

@ -18,15 +18,438 @@
#include "config.h"
#include "jinete/jbase.h"
#include <allegro.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "jinete/jinete.h"
#include "commands/commands.h"
#include "dialogs/dpaledit.h"
#include "core/cfg.h"
#include "core/color.h"
#include "dialogs/filesel.h"
#include "modules/gui.h"
#include "modules/palettes.h"
#include "modules/sprites.h"
#include "modules/sprites.h"
#include "raster/image.h"
#include "raster/palette.h"
#include "raster/sprite.h"
#include "raster/stock.h"
#include "util/quantize.h"
#include "widgets/colview.h"
#include "widgets/paledit.h"
static Palette **palettes;
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 void select_all_command(JWidget widget);
static void load_command(JWidget widget);
static void save_command(JWidget widget);
static void ramp_command(JWidget widget);
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 palette_editor_change_hook(JWidget widget, void *data);
static void set_new_palette(Palette *palette);
static void cmd_palette_editor_execute(const char *argument)
{
dialogs_palette_editor();
JWidget window, 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;
int imgtype = current_sprite ? current_sprite->imgtype: IMAGE_INDEXED;
int frame_bak = current_sprite ? current_sprite->frame : 0;
if (imgtype == IMAGE_GRAYSCALE) {
jalert(_("Error<<You can't edit grayscale palette||&OK"));
return;
}
/* load widgets */
window = load_widget("paledit.jid", "palette_editor");
if (!window)
return;
if (!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, NULL)) {
jwidget_free(window);
return;
}
/* create current_sprite->frames palettes */
if (current_sprite) {
palettes = jmalloc(sizeof(Palette *) * current_sprite->frames);
if (!palettes) {
jalert(_("Error<<Not enough memory||&OK"));
return;
}
for (frame=0; frame<current_sprite->frames; ++frame) {
palettes[frame] = palette_new(frame, MAX_PALETTE_COLORS);
palette_copy_colors(palettes[frame],
sprite_get_palette(current_sprite, frame));
}
}
else
palettes = NULL;
/* get current palette */
palette = palette_new_copy(get_current_palette());
/* get configuration */
columns = get_config_int("PaletteEditor", "Columns", 16);
columns = MID(1, columns, 256);
/* custom widgets */
colorviewer = colorviewer_new(color_index(0), IMAGE_INDEXED);
palette_editor = paledit_new(palette, TRUE, 6);
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);
/* frame */
if (current_sprite) {
jslider_set_range(slider_frame, 0, current_sprite->frames-1);
jslider_set_value(slider_frame, current_sprite->frame);
}
else
jwidget_disable(slider_frame);
/* 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(palette_editor, SIGNAL_PALETTE_EDITOR_CHANGE, palette_editor_change_hook, 0);
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);
/* default position */
jwindow_remap(window);
jwindow_center(window);
/* load window configuration */
load_window_pos(window, "PaletteEditor");
/* open and run the window */
jwindow_open_fg(window);
/* check the killer widget */
if (jwindow_get_killer(window) == button_ok) {
if (current_sprite) {
palette_copy_colors(palettes[jslider_get_value(slider_frame)],
get_current_palette());
sprite_reset_palettes(current_sprite);
for (frame=0; frame<current_sprite->frames; ++frame) {
if (frame == 0 ||
palette_count_diff(palettes[frame],
palettes[frame-1], NULL, NULL) > 0) {
sprite_set_palette(current_sprite, palettes[frame], TRUE);
}
}
}
/* change the system palette */
else
set_default_palette(palette);
set_current_palette(palette, TRUE);
}
/* cancel or ESC */
else {
/* restore the system palette */
if (current_sprite) {
current_sprite->frame = frame_bak;
set_current_palette(sprite_get_palette(current_sprite, 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");
jwidget_free(window);
if (palettes) {
assert(current_sprite);
for (frame=0; frame<current_sprite->frames; ++frame)
palette_free(palettes[frame]);
jfree(palettes);
}
palette_free(palette);
}
static void select_all_command(JWidget widget)
{
paledit_select_range(palette_editor, 0, 255,
PALETTE_EDITOR_RANGE_LINEAL);
}
static void load_command(JWidget widget)
{
Palette *palette;
char *filename;
filename = ase_file_selector(_("Load Palette"), "", "pcx,bmp,tga,lbm,col");
if (filename) {
palette = palette_load(filename);
if (!palette) {
jalert(_("Error<<Loading palette file||&Close"));
}
else {
set_new_palette(palette);
jfree(palette);
}
jfree(filename);
}
}
static void save_command(JWidget widget)
{
char *filename;
int ret;
again:
filename = ase_file_selector(_("Save Palette"), "", "pcx,bmp,tga,col");
if (filename) {
if (exists(filename)) {
ret = jalert("%s<<%s<<%s||%s",
_("Warning"),
_("File exists, overwrite it?"),
get_filename(filename),
_("&Yes||&No||&Cancel"));
if (ret == 2) {
jfree(filename);
goto again;
}
else if (ret != 1) {
jfree(filename);
return;
}
}
if (palette_save(paledit_get_palette(palette_editor), filename))
jalert(_("Error<<Saving palette file||&Close"));
jfree(filename);
}
}
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);
Palette *palette = palette_new(0, MAX_PALETTE_COLORS);
bool array[256];
paledit_get_selected_entries(palette_editor, array);
palette_copy_colors(palette, paledit_get_palette(palette_editor));
if ((i1 >= 0) && (i2 >= 0)) {
/* make the ramp */
if (range_type == PALETTE_EDITOR_RANGE_LINEAL) {
/* lineal ramp */
palette_make_horz_ramp(palette, i1, i2);
}
else if (range_type == PALETTE_EDITOR_RANGE_RECTANGULAR) {
/* rectangular ramp */
palette_make_rect_ramp(palette, i1, i2, paledit_get_columns(palette_editor));
}
}
set_new_palette(palette);
palette_free(palette);
}
static void quantize_command(JWidget widget)
{
Palette *palette = palette_new(0, MAX_PALETTE_COLORS);
bool array[256];
paledit_get_selected_entries(palette_editor, array);
palette_copy_colors(palette, paledit_get_palette(palette_editor));
if (current_sprite && current_sprite->imgtype == IMAGE_RGB) {
sprite_quantize_ex(current_sprite, palette);
}
else {
jalert(_("Error<<You can use this command only for RGB sprites||&OK"));
}
set_new_palette(palette);
palette_free(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;
rgb_to_hsv(r, g, b, &h, &s, &v);
paledit_get_selected_entries(palette_editor, array);
for (c=0; c<256; c++) {
if (array[c]) {
palette->color[c] = _rgba(r, g, b, 255);
set_current_color(c, 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);
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);
bool array[256];
int c, r, g, b;
hsv_to_rgb(360.0 * h / 255.0, s / 255.0, v / 255.0, &r, &g, &b);
paledit_get_selected_entries(palette_editor, array);
for (c=0; c<256; c++) {
if (array[c]) {
palette->color[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);
jwidget_dirty(palette_editor);
return FALSE;
}
static bool slider_columns_change_hook(JWidget widget, void *data)
{
paledit_set_columns(palette_editor,
(int)jslider_get_value(widget));
return FALSE;
}
static bool slider_frame_change_hook(JWidget widget, void *data)
{
int old_frame = current_sprite->frame;
int new_frame = jslider_get_value(slider_frame);
palette_copy_colors(palettes[old_frame], get_current_palette());
current_sprite->frame = new_frame;
set_new_palette(palettes[new_frame]);
return FALSE;
}
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);
float h, s, v;
rgb_to_hsv(r, g, b, &h, &s, &v);
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);
return FALSE;
}
static void set_new_palette(Palette *palette)
{
/* copy the palette */
palette_copy_colors(paledit_get_palette(palette_editor), palette);
/* set the palette calling the hooks */
set_current_palette(palette, FALSE);
/* redraw the entire screen */
jmanager_refresh_screen();
}
Command cmd_palette_editor = {

View File

@ -25,9 +25,10 @@
#include "commands/commands.h"
#include "modules/editors.h"
#include "modules/gui.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "modules/sprites.h"
#include "modules/tools.h"
#include "raster/palette.h"
#include "raster/sprite.h"
#include "widgets/editor.h"
@ -51,6 +52,8 @@ static void cmd_play_animation_execute(const char *argument)
int old_frame, msecs;
bool done = FALSE;
bool onionskin = get_onionskin();
Palette *oldpal, *newpal;
PALETTE rgbpal;
if (sprite->frames < 2)
return;
@ -71,12 +74,18 @@ static void cmd_play_animation_execute(const char *argument)
clear_bitmap(ji_screen);
/* do animation */
oldpal = NULL;
speed_timer = 0;
while (!done) {
msecs = sprite_get_frlen(sprite, sprite->frame);
install_int_ex(speed_timer_callback, MSEC_TO_TIMER(msecs));
set_palette(sprite_get_palette(sprite, sprite->frame));
newpal = sprite_get_palette(sprite, sprite->frame);
if (oldpal != newpal) {
set_palette(palette_to_allegro(newpal, rgbpal));
oldpal = newpal;
}
editor_draw_sprite_safe(current_editor, 0, 0, sprite->w, sprite->h);
do {
@ -105,7 +114,8 @@ static void cmd_play_animation_execute(const char *argument)
sprite->frame = old_frame;
/* refresh all */
set_current_palette(sprite_get_palette(sprite, sprite->frame), TRUE);
newpal = sprite_get_palette(sprite, sprite->frame);
set_current_palette(newpal, TRUE);
jmanager_refresh_screen();
gui_feedback();

View File

@ -19,10 +19,12 @@
#include "config.h"
#include "commands/commands.h"
#include "core/app.h"
#include "modules/gui.h"
#include "modules/sprites.h"
#include "raster/sprite.h"
#include "raster/undo.h"
#include "widgets/statebar.h"
static bool cmd_redo_enabled(const char *argument)
{
@ -31,6 +33,10 @@ static bool cmd_redo_enabled(const char *argument)
static void cmd_redo_execute(const char *argument)
{
statusbar_show_tip(app_get_statusbar(), 1000,
_("Redid %s"),
undo_get_next_redo_label(current_sprite->undo));
undo_redo(current_sprite->undo);
sprite_generate_mask_boundaries(current_sprite);
update_screen_for_sprite(current_sprite);

View File

@ -46,7 +46,7 @@ static void cmd_save_mask_execute(const char *argument)
int ret;
for (;;) {
char *filename = ase_file_selector(_("Save .msk File"), filename, "msk");
filename = ase_file_selector(_("Save .msk File"), filename, "msk");
if (!filename)
return;
@ -74,7 +74,7 @@ static void cmd_save_mask_execute(const char *argument)
if (save_msk_file(sprite->mask, filename) != 0)
jalert("%s<<%s<<%s||%s",
_("Error"), _("Error saving .msk file"),
_(filename), _("&Close"));
filename, _("&Close"));
}
Command cmd_save_mask = {

View File

@ -95,9 +95,9 @@ static void cmd_sprite_properties_execute(const char *argument)
jwidget_set_text(frames, buf);
/* background color */
bgcolor_button = color_button_new(color_from_image(sprite->imgtype,
sprite->bgcolor),
current_sprite->imgtype);
bgcolor_button = colorbutton_new(color_from_image(sprite->imgtype,
sprite->bgcolor),
current_sprite->imgtype);
jwidget_add_child(bgcolor_box, bgcolor_button);
@ -116,7 +116,7 @@ static void cmd_sprite_properties_execute(const char *argument)
/* the background color changes */
new_bgcolor = get_color_for_image(sprite->imgtype,
color_button_get_color(bgcolor_button));
colorbutton_get_color(bgcolor_button));
/* set frames */
if (sprite->bgcolor != new_bgcolor) {

View File

@ -19,10 +19,12 @@
#include "config.h"
#include "commands/commands.h"
#include "core/app.h"
#include "modules/gui.h"
#include "modules/sprites.h"
#include "raster/sprite.h"
#include "raster/undo.h"
#include "widgets/statebar.h"
static bool cmd_undo_enabled(const char *argument)
{
@ -31,6 +33,10 @@ static bool cmd_undo_enabled(const char *argument)
static void cmd_undo_execute(const char *argument)
{
statusbar_show_tip(app_get_statusbar(), 1000,
_("Undid %s"),
undo_get_next_undo_label(current_sprite->undo));
undo_undo(current_sprite->undo);
sprite_generate_mask_boundaries(current_sprite);
update_screen_for_sprite(current_sprite);

View File

@ -22,6 +22,7 @@
#include "commands/commands.h"
#include "console/console.h"
#include "core/app.h"
#include "core/cfg.h"
#include "core/color.h"
#include "core/core.h"
@ -63,6 +64,8 @@ static void cmd_color_curve_execute(const char *argument)
the_curve = curve_new(CURVE_LINEAR);
curve_add_point(the_curve, curve_point_new(0, 0));
curve_add_point(the_curve, curve_point_new(255, 255));
app_add_hook(APP_EXIT, curve_free, the_curve);
}
image = GetImage(current_sprite);

View File

@ -58,13 +58,13 @@ static JWidget listbox_generate_convmatg(void);
static void listbox_fill_convmatg(JWidget listbox);
static void listbox_select_current_convmatr(JWidget listbox);
static int reload_select_hook(JWidget widget, int user_data);
static int generate_select_hook(JWidget widget, int user_data);
static bool reload_select_hook(JWidget widget, void *data);
static bool generate_select_hook(JWidget widget, void *data);
static int list_change_hook(JWidget widget, int user_data);
static int target_change_hook(JWidget widget, int user_data);
static int preview_change_hook(JWidget widget, int user_data);
static int tiled_change_hook(JWidget widget, int user_data);
static bool list_change_hook(JWidget widget, void *data);
static bool target_change_hook(JWidget widget, void *data);
static bool preview_change_hook(JWidget widget, void *data);
static bool tiled_change_hook(JWidget widget, void *data);
static void make_preview(void);
static bool cmd_convolution_matrix_enabled(const char *argument)
@ -210,9 +210,9 @@ static void listbox_select_current_convmatr(JWidget listbox)
}
}
static int reload_select_hook(JWidget widget, int user_data)
static bool reload_select_hook(JWidget widget, void *data)
{
JWidget listbox = (JWidget)user_data;
JWidget listbox = (JWidget)data;
JWidget listitem;
JLink link, next;
@ -234,7 +234,7 @@ static int reload_select_hook(JWidget widget, int user_data)
return TRUE; /* do not close */
}
static int generate_select_hook(JWidget widget, int user_data)
static bool generate_select_hook(JWidget widget, void *data)
{
JWidget window;
JWidget view_x;
@ -300,7 +300,7 @@ static int generate_select_hook(JWidget widget, int user_data)
return TRUE; /* do not close */
}
static int list_change_hook(JWidget widget, int user_data)
static bool list_change_hook(JWidget widget, void *data)
{
JWidget selected = jlistbox_get_selected_child(widget);
ConvMatr *convmatr = selected->user_data[0];
@ -312,14 +312,14 @@ static int list_change_hook(JWidget widget, int user_data)
return FALSE;
}
static int target_change_hook(JWidget widget, int user_data)
static bool target_change_hook(JWidget widget, void *data)
{
effect_load_target(preview_get_effect(preview));
make_preview();
return FALSE;
}
static int preview_change_hook(JWidget widget, int user_data)
static bool preview_change_hook(JWidget widget, void *data)
{
set_config_bool("ConvolutionMatrix", "Preview",
jwidget_is_selected(widget));
@ -327,7 +327,7 @@ static int preview_change_hook(JWidget widget, int user_data)
return FALSE;
}
static int tiled_change_hook(JWidget widget, int user_data)
static bool tiled_change_hook(JWidget widget, void *data)
{
set_tiled_mode(jwidget_is_selected(widget));
make_preview();

View File

@ -47,11 +47,11 @@ static JWidget entry_width, entry_height;
static JWidget check_preview, preview;
static JWidget check_tiled;
static int width_change_hook(JWidget widget, int user_data);
static int height_change_hook(JWidget widget, int user_data);
static int target_change_hook(JWidget widget, int user_data);
static int preview_change_hook(JWidget widget, int user_data);
static int tiled_change_hook(JWidget widget, int user_data);
static bool width_change_hook(JWidget widget, void *data);
static bool height_change_hook(JWidget widget, void *data);
static bool target_change_hook(JWidget widget, void *data);
static bool preview_change_hook(JWidget widget, void *data);
static bool tiled_change_hook(JWidget widget, void *data);
static void make_preview(void);
static bool cmd_despeckle_enabled(const char *argument)
@ -144,7 +144,7 @@ static void cmd_despeckle_execute(const char *argument)
jwidget_free(window);
}
static int width_change_hook(JWidget widget, int user_data)
static bool width_change_hook(JWidget widget, void *data)
{
set_config_int("Median", "Width",
strtol(jwidget_get_text(widget), NULL, 10));
@ -152,7 +152,7 @@ static int width_change_hook(JWidget widget, int user_data)
return TRUE;
}
static int height_change_hook(JWidget widget, int user_data)
static bool height_change_hook(JWidget widget, void *data)
{
set_config_int("Median", "Height",
strtol(jwidget_get_text(widget), NULL, 10));
@ -160,21 +160,21 @@ static int height_change_hook(JWidget widget, int user_data)
return TRUE;
}
static int target_change_hook(JWidget widget, int user_data)
static bool target_change_hook(JWidget widget, void *data)
{
effect_load_target(preview_get_effect(preview));
make_preview();
return FALSE;
}
static int preview_change_hook(JWidget widget, int user_data)
static bool preview_change_hook(JWidget widget, void *data)
{
set_config_bool("Median", "Preview", jwidget_is_selected(widget));
make_preview();
return FALSE;
}
static int tiled_change_hook(JWidget widget, int user_data)
static bool tiled_change_hook(JWidget widget, void *data)
{
set_tiled_mode(jwidget_is_selected(widget));
make_preview();

View File

@ -44,8 +44,8 @@
static JWidget check_preview, preview;
static int target_change_hook(JWidget widget, int user_data);
static int preview_change_hook(JWidget widget, int user_data);
static bool target_change_hook(JWidget widget, void *data);
static bool preview_change_hook(JWidget widget, void *data);
static void make_preview(void);
static bool cmd_invert_color_enabled(const char *argument)
@ -123,14 +123,14 @@ static void cmd_invert_color_execute(const char *argument)
jwidget_free(window);
}
static int target_change_hook(JWidget widget, int user_data)
static bool target_change_hook(JWidget widget, void *data)
{
effect_load_target(preview_get_effect(preview));
make_preview();
return FALSE;
}
static int preview_change_hook(JWidget widget, int user_data)
static bool preview_change_hook(JWidget widget, void *data)
{
set_config_bool("InvertColor", "Preview", jwidget_is_selected(widget));
make_preview();

View File

@ -45,12 +45,10 @@ static JWidget button_color1, button_color2;
static JWidget slider_fuzziness, check_preview;
static JWidget preview;
static int button_1_select_hook(JWidget widget, int user_data);
static int button_2_select_hook(JWidget widget, int user_data);
static int color_change_hook(JWidget widget, int user_data);
static int target_change_hook(JWidget widget, int user_data);
static int slider_change_hook(JWidget widget, int user_data);
static int preview_change_hook(JWidget widget, int user_data);
static bool color_change_hook(JWidget widget, void *data);
static bool target_change_hook(JWidget widget, void *data);
static bool slider_change_hook(JWidget widget, void *data);
static bool preview_change_hook(JWidget widget, void *data);
static void make_preview(void);
static bool cmd_replace_color_enabled(const char *argument)
@ -62,8 +60,6 @@ static void cmd_replace_color_execute(const char *argument)
{
JWidget window = NULL;
JWidget color_buttons_box;
JWidget button1_1, button1_2;
JWidget button2_1, button2_2;
JWidget box_target, target_button;
JWidget button_ok;
Image *image;
@ -84,10 +80,6 @@ static void cmd_replace_color_execute(const char *argument)
if (!get_widgets(window,
"color_buttons_box", &color_buttons_box,
"button1_1", &button1_1,
"button1_2", &button1_2,
"button2_1", &button2_1,
"button2_2", &button2_2,
"preview", &check_preview,
"fuzziness", &slider_fuzziness,
"target", &box_target,
@ -103,12 +95,12 @@ static void cmd_replace_color_execute(const char *argument)
preview = preview_new(effect);
button_color1 = color_button_new
button_color1 = colorbutton_new
(get_config_color("ReplaceColor", "Color1",
colorbar_get_fg_color(app_get_colorbar())),
current_sprite->imgtype);
button_color2 = color_button_new
button_color2 = colorbutton_new
(get_config_color("ReplaceColor", "Color2",
colorbar_get_bg_color(app_get_colorbar())),
current_sprite->imgtype);
@ -125,12 +117,8 @@ static void cmd_replace_color_execute(const char *argument)
jwidget_add_child(box_target, target_button);
jwidget_add_child(window, preview);
HOOK(button1_1, JI_SIGNAL_BUTTON_SELECT, button_1_select_hook, 1);
HOOK(button1_2, JI_SIGNAL_BUTTON_SELECT, button_2_select_hook, 1);
HOOK(button2_1, JI_SIGNAL_BUTTON_SELECT, button_1_select_hook, 2);
HOOK(button2_2, JI_SIGNAL_BUTTON_SELECT, button_2_select_hook, 2);
HOOK(button_color1, SIGNAL_COLOR_BUTTON_CHANGE, color_change_hook, 1);
HOOK(button_color2, SIGNAL_COLOR_BUTTON_CHANGE, color_change_hook, 2);
HOOK(button_color1, SIGNAL_COLORBUTTON_CHANGE, color_change_hook, 1);
HOOK(button_color2, SIGNAL_COLORBUTTON_CHANGE, color_change_hook, 2);
HOOK(target_button, SIGNAL_TARGET_BUTTON_CHANGE, target_change_hook, 0);
HOOK(slider_fuzziness, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0);
HOOK(check_preview, JI_SIGNAL_CHECK_CHANGE, preview_change_hook, 0);
@ -167,52 +155,32 @@ done:;
sprite_unlock(sprite);
}
static int button_1_select_hook(JWidget widget, int user_data)
{
JWidget w = user_data == 1 ? button_color1: button_color2;
color_button_set_color(w, colorbar_get_fg_color(app_get_colorbar()));
color_change_hook(w, user_data);
return TRUE;
}
static int button_2_select_hook(JWidget widget, int user_data)
{
JWidget w = user_data == 1 ? button_color1: button_color2;
color_button_set_color(w, colorbar_get_bg_color(app_get_colorbar()));
color_change_hook(w, user_data);
return TRUE;
}
static int color_change_hook(JWidget widget, int user_data)
static bool color_change_hook(JWidget widget, void *data)
{
char buf[64];
sprintf(buf, "Color%d", user_data);
set_config_color("ReplaceColor", buf, color_button_get_color(widget));
sprintf(buf, "Color%d", (int)data);
set_config_color("ReplaceColor", buf, colorbutton_get_color(widget));
make_preview();
return FALSE;
}
static int target_change_hook(JWidget widget, int user_data)
static bool target_change_hook(JWidget widget, void *data)
{
effect_load_target(preview_get_effect(preview));
make_preview();
return FALSE;
}
static int slider_change_hook(JWidget widget, int user_data)
static bool slider_change_hook(JWidget widget, void *data)
{
set_config_int("ReplaceColor", "Fuzziness", jslider_get_value(widget));
make_preview();
return FALSE;
}
static int preview_change_hook(JWidget widget, int user_data)
static bool preview_change_hook(JWidget widget, void *data)
{
set_config_bool("ReplaceColor", "Preview", jwidget_is_selected(widget));
make_preview();

View File

@ -148,8 +148,10 @@ void console_printf(const char *format, ...)
jwidget_set_text(wid_textbox, final);
jfree(final);
}
else
else {
printf(buf);
fflush(stdout);
}
}
void user_printf(const char *format, ...)

View File

@ -44,13 +44,15 @@
#include "modules/editors.h"
#include "modules/gfx.h"
#include "modules/gui.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "modules/recent.h"
#include "modules/rootmenu.h"
#include "modules/sprites.h"
#include "raster/image.h"
#include "raster/palette.h"
#include "raster/sprite.h"
#include "script/script.h"
#include "util/boundary.h"
#include "util/recscr.h"
#include "widgets/colbar.h"
#include "widgets/editor.h"
@ -72,16 +74,24 @@ typedef struct Option
char *data;
} Option;
typedef struct AppHook
{
void (*proc)(void *);
void *data;
} AppHook;
static char *exe_name; /* name of the program */
static JList apphooks[APP_EVENTS];
static JWidget top_window = NULL; /* top level window (the desktop) */
static JWidget box_menubar = NULL; /* box where the menu bar is */
static JWidget box_menubar = NULL; /* box where the menu bar is */
static JWidget box_colorbar = NULL; /* box where the color bar is */
static JWidget box_toolbar = NULL; /* box where the tools bar is */
static JWidget box_statusbar = NULL; /* box where the status bar is */
static JWidget box_tabsbar = NULL; /* box where the tabs bar is */
static JWidget box_toolbar = NULL; /* box where the tools bar is */
static JWidget box_statusbar = NULL; /* box where the status bar is */
static JWidget box_tabsbar = NULL; /* box where the tabs bar is */
static JWidget menubar = NULL; /* the menu bar widget */
static JWidget statusbar = NULL; /* the status bar widget */
static JWidget statusbar = NULL; /* the status bar widget */
static JWidget colorbar = NULL; /* the color bar widget */
static JWidget toolbar = NULL; /* the tool bar widget */
static JWidget tabsbar = NULL; /* the tabs bar widget */
@ -97,6 +107,9 @@ static void usage(int status);
static Option *option_new(int type, const char *data);
static void option_free(Option *option);
static AppHook *apphook_new(void (*proc)(void *), void *data);
static void apphook_free(AppHook *apphook);
/**
* Initializes the application loading the modules, setting the
* graphics mode, loading the configuration and resources, etc.
@ -105,7 +118,14 @@ bool app_init(int argc, char *argv[])
{
exe_name = argv[0];
/* Initialize language suppport. */
/* initialize application hooks */
{
int c;
for (c=0; c<APP_EVENTS; ++c)
apphooks[c] = NULL;
}
/* initialize language suppport */
intl_init();
/* install the `core' of ASE application */
@ -146,22 +166,20 @@ bool app_init(int argc, char *argv[])
/* custom default palette? */
if (palette_filename) {
PALETTE pal;
BITMAP *bmp;
Palette *pal;
PRINTF("Loading custom palette file: %s\n", palette_filename);
bmp = load_bitmap(palette_filename, pal);
if (!bmp) {
pal = palette_load(palette_filename);
if (pal == NULL) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
console_printf(_("Error loading default palette from `%s'\n"),
palette_filename);
return FALSE;
}
destroy_bitmap(bmp);
set_default_palette(pal);
palette_free(pal);
}
/* set system palette to the default one */
@ -349,11 +367,30 @@ void app_loop(void)
*/
void app_exit(void)
{
JLink link;
int c;
/* remove ase handlers */
PRINTF("Uninstalling ASE\n");
app_trigger_event(APP_EXIT);
/* destroy application hooks */
for (c=0; c<APP_EVENTS; ++c) {
if (apphooks[c] != NULL) {
JI_LIST_FOR_EACH(apphooks[c], link) {
apphook_free(link->data);
}
jlist_free(apphooks[c]);
apphooks[c] = NULL;
}
}
/* finalize modules, configuration and core */
modules_exit();
editor_cursor_exit();
boundary_exit();
gfxobj_exit();
ase_config_exit();
file_system_exit();
@ -363,6 +400,31 @@ void app_exit(void)
intl_exit();
}
void app_add_hook(int app_event, void (*proc)(void *data), void *data)
{
assert(app_event >= 0 && app_event < APP_EVENTS);
if (apphooks[app_event] == NULL)
apphooks[app_event] = jlist_new();
jlist_append(apphooks[app_event], apphook_new(proc, data));
}
void app_trigger_event(int app_event)
{
assert(app_event >= 0 && app_event < APP_EVENTS);
if (apphooks[app_event] != NULL) {
JList list = apphooks[app_event];
JLink link;
JI_LIST_FOR_EACH(list, link) {
AppHook *h = (AppHook *)link->data;
(h->proc)(h->data);
}
}
}
/**
* Updates palette and redraw the screen.
*/
@ -370,7 +432,7 @@ void app_refresh_screen(void)
{
if (ase_mode & MODE_GUI) {
/* update the color palette */
set_current_palette(current_sprite ?
set_current_palette(current_sprite != NULL ?
sprite_get_palette(current_sprite,
current_sprite->frame): NULL,
FALSE);
@ -455,8 +517,10 @@ int app_get_current_image_type(void)
{
if (current_sprite)
return current_sprite->imgtype;
else
else if (screen != NULL && bitmap_color_depth(screen) == 8)
return IMAGE_INDEXED;
else
return IMAGE_RGB;
}
JWidget app_get_top_window(void) { return top_window; }
@ -657,3 +721,20 @@ static void option_free(Option *option)
jfree(option->data);
jfree(option);
}
static AppHook *apphook_new(void (*proc)(void *), void *data)
{
AppHook *apphook = jnew(AppHook, 1);
if (!apphook)
return NULL;
apphook->proc = proc;
apphook->data = data;
return apphook;
}
static void apphook_free(AppHook *apphook)
{
jfree(apphook);
}

View File

@ -21,10 +21,20 @@
#include "jinete/jbase.h"
/* enumeration of ASE events in the highest application level */
enum {
APP_EXIT,
APP_PALETTE_CHANGE,
APP_EVENTS
};
bool app_init(int argc, char *argv[]);
void app_loop(void);
void app_exit(void);
void app_add_hook(int app_event, void (*proc)(void *data), void *data);
void app_trigger_event(int app_event);
void app_refresh_screen(void);
void app_realloc_sprite_list(void);

View File

@ -27,9 +27,10 @@
#include "core/color.h"
#include "core/core.h"
#include "modules/gfx.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "raster/blend.h"
#include "raster/image.h"
#include "raster/palette.h"
#include "widgets/colbar.h"
#define _hsva_geth _rgba_getr
@ -147,6 +148,13 @@ int color_type(color_t color)
return GET_COLOR_TYPE(color);
}
bool color_equals(color_t c1, color_t c2)
{
return
GET_COLOR_TYPE(c1) == GET_COLOR_TYPE(c2) &&
GET_COLOR_DATA(c1) == GET_COLOR_DATA(c2);
}
color_t color_mask(void)
{
color_t c = { COLOR_TYPE_MASK, 0 };
@ -193,7 +201,10 @@ int color_get_red(int imgtype, color_t color)
switch (GET_COLOR_TYPE(color)) {
case COLOR_TYPE_MASK:
return imgtype == IMAGE_INDEXED ? _rgb_scale_6[current_palette[0].r]: 0;
if (imgtype == IMAGE_INDEXED)
return _rgba_getr(palette_get_entry(get_current_palette(), 0));
else
return 0;
case COLOR_TYPE_RGB:
return _rgba_getr(GET_COLOR_RGB(color));
@ -211,7 +222,8 @@ int color_get_red(int imgtype, color_t color)
return _graya_getv(GET_COLOR_GRAY(color));
case COLOR_TYPE_INDEX:
return _rgb_scale_6[current_palette[GET_COLOR_INDEX(color)].r];
return _rgba_getr(palette_get_entry(get_current_palette(),
GET_COLOR_INDEX(color)));
}
@ -224,7 +236,10 @@ int color_get_green(int imgtype, color_t color)
switch (GET_COLOR_TYPE(color)) {
case COLOR_TYPE_MASK:
return imgtype == IMAGE_INDEXED ? _rgb_scale_6[current_palette[0].g]: 0;
if (imgtype == IMAGE_INDEXED)
return _rgba_getg(palette_get_entry(get_current_palette(), 0));
else
return 0;
case COLOR_TYPE_RGB:
return _rgba_getg(GET_COLOR_RGB(color));
@ -242,7 +257,8 @@ int color_get_green(int imgtype, color_t color)
return _graya_getv(GET_COLOR_GRAY(color));
case COLOR_TYPE_INDEX:
return _rgb_scale_6[current_palette[GET_COLOR_INDEX(color)].g];
return _rgba_getg(palette_get_entry(get_current_palette(),
GET_COLOR_INDEX(color)));
}
@ -255,7 +271,10 @@ int color_get_blue(int imgtype, color_t color)
switch (GET_COLOR_TYPE(color)) {
case COLOR_TYPE_MASK:
return imgtype == IMAGE_INDEXED ? _rgb_scale_6[current_palette[0].b]: 0;
if (imgtype == IMAGE_INDEXED)
return _rgba_getb(palette_get_entry(get_current_palette(), 0));
else
return 0;
case COLOR_TYPE_RGB:
return _rgba_getb(GET_COLOR_RGB(color));
@ -273,7 +292,8 @@ int color_get_blue(int imgtype, color_t color)
return _graya_getv(GET_COLOR_GRAY(color));
case COLOR_TYPE_INDEX:
return _rgb_scale_6[current_palette[GET_COLOR_INDEX(color)].b];
return _rgba_getb(palette_get_entry(get_current_palette(),
GET_COLOR_INDEX(color)));
}
@ -304,10 +324,11 @@ int color_get_hue(int imgtype, color_t color)
return 0;
case COLOR_TYPE_INDEX: {
int c = GET_COLOR_INDEX(color);
int r = _rgb_scale_6[current_palette[c].r];
int g = _rgb_scale_6[current_palette[c].g];
int b = _rgb_scale_6[current_palette[c].b];
ase_uint32 c = palette_get_entry(get_current_palette(),
GET_COLOR_INDEX(color));
int r = _rgba_getr(c);
int g = _rgba_getg(c);
int b = _rgba_getb(c);
rgb_to_hsv_int(&r, &g, &b);
return r;
}
@ -341,10 +362,11 @@ int color_get_saturation(int imgtype, color_t color)
return 0;
case COLOR_TYPE_INDEX: {
int c = GET_COLOR_INDEX(color);
int r = _rgb_scale_6[current_palette[c].r];
int g = _rgb_scale_6[current_palette[c].g];
int b = _rgb_scale_6[current_palette[c].b];
ase_uint32 c = palette_get_entry(get_current_palette(),
GET_COLOR_INDEX(color));
int r = _rgba_getr(c);
int g = _rgba_getg(c);
int b = _rgba_getb(c);
rgb_to_hsv_int(&r, &g, &b);
return g;
}
@ -378,10 +400,11 @@ int color_get_value(int imgtype, color_t color)
return _graya_getv(GET_COLOR_GRAY(color));
case COLOR_TYPE_INDEX: {
int c = GET_COLOR_INDEX(color);
int r = _rgb_scale_6[current_palette[c].r];
int g = _rgb_scale_6[current_palette[c].g];
int b = _rgb_scale_6[current_palette[c].b];
ase_uint32 c = palette_get_entry(get_current_palette(),
GET_COLOR_INDEX(color));
int r = _rgba_getr(c);
int g = _rgba_getg(c);
int b = _rgba_getb(c);
rgb_to_hsv_int(&r, &g, &b);
return b;
}
@ -568,11 +591,13 @@ int get_color_for_allegro(int depth, color_t color)
case COLOR_TYPE_INDEX:
c = GET_COLOR_INDEX(color);
if (depth != 8)
if (depth != 8) {
ase_uint32 _c = palette_get_entry(get_current_palette(), c);
c = makeacol_depth(depth,
_rgb_scale_6[current_palette[c].r],
_rgb_scale_6[current_palette[c].g],
_rgb_scale_6[current_palette[c].b], 255);
_rgba_getr(_c),
_rgba_getg(_c),
_rgba_getb(_c), 255);
}
break;
}
@ -681,12 +706,13 @@ int get_color_for_image(int imgtype, color_t color)
case COLOR_TYPE_INDEX:
data = GET_COLOR_INDEX(color);
switch (imgtype) {
case IMAGE_RGB:
c = data;
c = _rgba(_rgb_scale_6[current_palette[c].r],
_rgb_scale_6[current_palette[c].g],
_rgb_scale_6[current_palette[c].b], 255);
case IMAGE_RGB: {
ase_uint32 _c = palette_get_entry(get_current_palette(), data);
c = _rgba(_rgba_getr(_c),
_rgba_getg(_c),
_rgba_getb(_c), 255);
break;
}
case IMAGE_GRAYSCALE:
c = _graya(data & 0xff, 255);
break;
@ -782,15 +808,17 @@ void color_to_formalstring(int imgtype, color_t color,
}
break;
case COLOR_TYPE_INDEX:
case COLOR_TYPE_INDEX: {
ase_uint32 _c = palette_get_entry(get_current_palette(), data & 0xff);
data = GET_COLOR_INDEX(color);
uszprintf(buf, size, "%s %d(RGB %d %d %d)",
_("Index"),
data & 0xff,
_rgb_scale_6[current_palette[data & 0xff].r],
_rgb_scale_6[current_palette[data & 0xff].g],
_rgb_scale_6[current_palette[data & 0xff].b]);
_rgba_getr(_c),
_rgba_getg(_c),
_rgba_getb(_c));
break;
}
default:
assert(FALSE);
@ -862,86 +890,6 @@ void color_to_formalstring(int imgtype, color_t color,
}
}
void draw_color(BITMAP *bmp, int x1, int y1, int x2, int y2,
int imgtype, color_t color)
{
int type = GET_COLOR_TYPE(color);
int data;
int w = x2 - x1 + 1;
int h = y2 - y1 + 1;
BITMAP *graph;
int grid;
grid = MIN(w, h) / 2;
grid += MIN(w, h) - grid*2;
if (type == COLOR_TYPE_INDEX) {
data = GET_COLOR_INDEX(color);
rectfill(bmp, x1, y1, x2, y2,
/* get_color_for_allegro(bitmap_color_depth(bmp), color)); */
palette_color[_index_cmap[data]]);
return;
}
switch (imgtype) {
case IMAGE_INDEXED:
rectfill(bmp, x1, y1, x2, y2,
palette_color[_index_cmap[get_color_for_image(imgtype, color)]]);
break;
case IMAGE_RGB:
graph = create_bitmap_ex(32, w, h);
if (!graph)
return;
rectgrid(graph, 0, 0, w-1, h-1, grid, grid);
drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
set_trans_blender(0, 0, 0, color_get_alpha(imgtype, color));
{
int rgb_bitmap_color = get_color_for_image(imgtype, color);
color_t color2 = color_rgb(_rgba_getr(rgb_bitmap_color),
_rgba_getg(rgb_bitmap_color),
_rgba_getb(rgb_bitmap_color),
_rgba_geta(rgb_bitmap_color));
rectfill(graph, 0, 0, w-1, h-1, get_color_for_allegro(32, color2));
}
drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
use_current_sprite_rgb_map();
blit(graph, bmp, 0, 0, x1, y1, w, h);
restore_rgb_map();
destroy_bitmap(graph);
break;
case IMAGE_GRAYSCALE:
graph = create_bitmap_ex(32, w, h);
if (!graph)
return;
rectgrid(graph, 0, 0, w-1, h-1, grid, grid);
drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
set_trans_blender(0, 0, 0, color_get_alpha(imgtype, color));
{
int gray_bitmap_color = get_color_for_image(imgtype, color);
color_t color2 = color_gray(_graya_getv(gray_bitmap_color),
_graya_geta(gray_bitmap_color));
rectfill(graph, 0, 0, w-1, h-1, get_color_for_allegro(32, color2));
}
drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
use_current_sprite_rgb_map();
blit(graph, bmp, 0, 0, x1, y1, w, h);
restore_rgb_map();
destroy_bitmap(graph);
break;
}
}
/* returns the same values of bitmap_mask_color() (this function *must*
returns the same values) */
static int get_mask_for_bitmap(int depth)

View File

@ -44,6 +44,8 @@ char *color_to_string(color_t color, char *buf, int size);
color_t string_to_color(const char *str);
int color_type(color_t color);
bool color_equals(color_t c1, color_t c2);
color_t color_mask(void);
color_t color_rgb(int r, int g, int b, int a);
color_t color_hsv(int h, int s, int v, int a);
@ -68,8 +70,6 @@ int get_color_for_image(int imgtype, color_t color);
color_t image_getpixel_color(struct Image *image, int x, int y);
void color_to_formalstring(int imgtype, color_t color, char *buf,
int size, bool long_format);
void draw_color(struct BITMAP *bmp, int x1, int y1, int x2, int y2,
int imgtype, color_t color);
#endif /* MODULES_COLOR_H */

View File

@ -39,7 +39,9 @@
# define NO_STDERR
#endif
/* ASE mode */
/**
* Current running mode of ASE.
*/
int ase_mode = 0;
#ifdef NEED_LOG

View File

@ -24,7 +24,7 @@
#include "modules/editors.h"
#include "modules/gfx.h"
#include "modules/gui.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "modules/recent.h"
#include "modules/rootmenu.h"
#include "modules/sprites.h"

View File

@ -1,344 +0,0 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <allegro.h>
#include <stdio.h>
#include <string.h>
#include "jinete/jinete.h"
#include "core/cfg.h"
#include "core/color.h"
#include "dialogs/filesel.h"
#include "modules/gui.h"
#include "modules/palette.h"
#include "modules/sprites.h"
#include "raster/image.h"
#include "raster/sprite.h"
#include "raster/stock.h"
#include "util/quantize.h"
#include "widgets/colview.h"
#include "widgets/paledit.h"
static JWidget slider_R, slider_G, slider_B, slider_A;
static JWidget slider_H, slider_S, slider_V;
static JWidget colorviewer;
static JWidget palette_editor;
static int sliderRGB_change_signal(JWidget widget, int user_data);
static int sliderHSV_change_signal(JWidget widget, int user_data);
static int sliderA_change_signal(JWidget widget, int user_data);
static int colorviewer_select_signal(JWidget widget, int user_data);
static int paledit_change_signal(JWidget widget, int user_data);
static int window_resize_signal(JWidget widget, int user_data);
bool ji_color_select(int imgtype, color_t *color)
{
JWidget window, colorviewer_box, palette_editor_view, button_ok;
char buf[256];
PALETTE palette;
bool ret = FALSE;
/* load the window */
window = load_widget("colsel.jid", "color_selection");
if (!window)
return ret;
/* get current palette */
get_palette(palette);
/* window title */
sprintf(buf, "%s (%s)", window->text,
imgtype == IMAGE_RGB ? "RGB":
imgtype == IMAGE_GRAYSCALE ? "Grayscale":
imgtype == IMAGE_INDEXED ? "Indexed": "Unknown");
jwidget_set_text(window, buf);
if (!get_widgets(window,
"red", &slider_R,
"green", &slider_G,
"blue", &slider_B,
"alpha", &slider_A,
"hue", &slider_H,
"saturation", &slider_S,
"value", &slider_V,
"button_ok", &button_ok,
"colorviewer", &colorviewer_box,
"palette_editor", &palette_editor_view, NULL)) {
jwidget_free(window);
return ret;
}
colorviewer = colorviewer_new(*color, imgtype);
palette_editor = paledit_new(palette, FALSE, 3);
paledit_set_columns(palette_editor, 32);
jwidget_expansive(colorviewer, TRUE);
jwidget_add_child(colorviewer_box, colorviewer);
jview_attach(palette_editor_view, palette_editor);
jview_maxsize(palette_editor_view);
jview_without_bars(palette_editor_view);
/* hook signals */
HOOK(slider_R, JI_SIGNAL_SLIDER_CHANGE, sliderRGB_change_signal, 0);
HOOK(slider_G, JI_SIGNAL_SLIDER_CHANGE, sliderRGB_change_signal, 0);
HOOK(slider_B, JI_SIGNAL_SLIDER_CHANGE, sliderRGB_change_signal, 0);
HOOK(slider_A, JI_SIGNAL_SLIDER_CHANGE, sliderA_change_signal, 0);
HOOK(slider_H, JI_SIGNAL_SLIDER_CHANGE, sliderHSV_change_signal, 0);
HOOK(slider_S, JI_SIGNAL_SLIDER_CHANGE, sliderHSV_change_signal, 0);
HOOK(slider_V, JI_SIGNAL_SLIDER_CHANGE, sliderHSV_change_signal, 0);
HOOK(colorviewer, SIGNAL_COLORVIEWER_SELECT, colorviewer_select_signal, 0);
HOOK(palette_editor, SIGNAL_PALETTE_EDITOR_CHANGE, paledit_change_signal, 0);
HOOK(window, JI_SIGNAL_WINDOW_RESIZE, window_resize_signal, palette_editor);
/* initial values */
switch (color_type(*color)) {
case COLOR_TYPE_MASK:
colorviewer_select_signal(NULL, 0);
break;
case COLOR_TYPE_RGB:
case COLOR_TYPE_GRAY:
jslider_set_value(slider_R, color_get_red(imgtype, *color));
jslider_set_value(slider_G, color_get_green(imgtype, *color));
jslider_set_value(slider_B, color_get_blue(imgtype, *color));
jslider_set_value(slider_A, color_get_alpha(imgtype, *color));
sliderRGB_change_signal(NULL, 0);
break;
case COLOR_TYPE_INDEX:
paledit_select_color(palette_editor, color_get_index(imgtype, *color));
paledit_change_signal(NULL, color_get_index(imgtype, *color));
break;
}
/* disable widgets */
if (imgtype != IMAGE_RGB) {
if (imgtype == IMAGE_GRAYSCALE) {
jwidget_disable(slider_R);
jwidget_disable(slider_G);
jwidget_disable(slider_B);
jwidget_disable(slider_H);
jwidget_disable(slider_S);
}
else if (imgtype == IMAGE_INDEXED) {
jwidget_disable(slider_A);
}
}
/* default position */
jwindow_remap(window);
jwindow_center(window);
/* load window configuration */
load_window_pos(window, "ColorSelection");
/* open and run the window */
jwindow_open(window);
jwidget_emit_signal(window, JI_SIGNAL_WINDOW_RESIZE);
jwindow_open_fg(window);
/* check the killer widget */
if (jwindow_get_killer(window) == button_ok) {
/* selected color */
*color = colorviewer_get_color(colorviewer);
ret = TRUE;
}
/* save window configuration */
save_window_pos(window, "ColorSelection");
jwidget_free(window);
return ret;
}
static int sliderRGB_change_signal(JWidget widget, int user_data)
{
int imgtype = colorviewer_get_imgtype(colorviewer);
int r = jslider_get_value(slider_R);
int g = jslider_get_value(slider_G);
int b = jslider_get_value(slider_B);
int a = jslider_get_value(slider_A);
float h, s, v;
color_t color;
rgb_to_hsv(r, g, b, &h, &s, &v);
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);
color = color_rgb(r, g, b, a);
if (imgtype == IMAGE_INDEXED) {
int i = get_color_for_image(imgtype, color);
paledit_select_color(palette_editor, i);
}
else if (imgtype == IMAGE_RGB) {
paledit_select_color(palette_editor, -1);
}
colorviewer_set_color(colorviewer, color);
return FALSE;
}
static int sliderHSV_change_signal(JWidget widget, int user_data)
{
int imgtype = colorviewer_get_imgtype(colorviewer);
int h = jslider_get_value(slider_H);
int s = jslider_get_value(slider_S);
int v = jslider_get_value(slider_V);
int a = jslider_get_value(slider_A);
int r, g, b;
color_t color;
hsv_to_rgb(360.0 * h / 255.0, s / 255.0, v / 255.0, &r, &g, &b);
jslider_set_value(slider_R, r);
jslider_set_value(slider_G, g);
jslider_set_value(slider_B, b);
color = color_rgb(r, g, b, a);
if (imgtype == IMAGE_INDEXED) {
int i = get_color_for_image(imgtype, color);
paledit_select_color(palette_editor, i);
}
else if (imgtype == IMAGE_RGB) {
paledit_select_color(palette_editor, -1);
}
colorviewer_set_color(colorviewer, color);
return FALSE;
}
static int sliderA_change_signal(JWidget widget, int user_data)
{
color_t input_color = colorviewer_get_color(colorviewer);
int imgtype = colorviewer_get_imgtype(colorviewer);
int r = color_get_red(imgtype, input_color);
int g = color_get_green(imgtype, input_color);
int b = color_get_blue(imgtype, input_color);
int a = jslider_get_value(slider_A);
int type = color_type(input_color);
color_t color;
switch (type) {
case COLOR_TYPE_MASK:
color = color_rgb(jslider_get_value(slider_R),
jslider_get_value(slider_G),
jslider_get_value(slider_B), a);
break;
case COLOR_TYPE_RGB:
case COLOR_TYPE_INDEX:
color = color_rgb(r, g, b, a);
break;
case COLOR_TYPE_GRAY:
{
float h, s, v;
rgb_to_hsv(r, g, b, &h, &s, &v);
color = color_gray(v * 255.0, a);
}
break;
}
colorviewer_set_color(colorviewer, color);
return FALSE;
}
static int colorviewer_select_signal(JWidget widget, int user_data)
{
int imgtype = colorviewer_get_imgtype(colorviewer);
color_t color = color_mask();
int r = color_get_red(imgtype, color);
int g = color_get_green(imgtype, color);
int b = color_get_blue(imgtype, color);
float h, s, v;
rgb_to_hsv(r, g, b, &h, &s, &v);
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_A, color_get_alpha(imgtype, color));
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);
if (imgtype == IMAGE_INDEXED) {
int i = get_color_for_image(imgtype, color);
paledit_select_color(palette_editor, i);
}
else if (imgtype == IMAGE_RGB) {
paledit_select_color(palette_editor, -1);
}
return FALSE;
}
static int paledit_change_signal(JWidget widget, int user_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);
float h, s, v;
rgb_to_hsv(r, g, b, &h, &s, &v);
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_A, color_get_alpha(imgtype, color));
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);
return FALSE;
}
static int window_resize_signal(JWidget widget, int user_data)
{
JWidget paledit = (JWidget)user_data;
JWidget view = jwidget_get_view(paledit);
JRect vp = jview_get_viewport_position(view);
int cols, box = 3;
do {
box++;
paledit_set_boxsize(paledit, box);
cols = (jrect_w(vp)-1) / (box+1);
paledit_set_columns(paledit, cols);
} while (((jrect_h(vp)-1) / (box+1))*cols > 256);
box--;
paledit_set_boxsize(paledit, box);
cols = (jrect_w(vp)-1) / (box+1);
paledit_set_columns(paledit, cols);
jwidget_dirty(paledit);
jrect_free(vp);
return FALSE;
}

View File

@ -1,27 +0,0 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef DIALOGS_COLSEL_H
#define DIALOGS_COLSEL_H
#include "core/color.h"
bool ji_color_select(int imgtype, color_t *color);
#endif /* DIALOGS_COLSEL_H */

View File

@ -1,447 +0,0 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <allegro.h>
#include <stdio.h>
#include <string.h>
#include "jinete/jinete.h"
#include "core/cfg.h"
#include "core/color.h"
#include "dialogs/filesel.h"
#include "modules/gui.h"
#include "modules/palette.h"
#include "modules/sprites.h"
#include "raster/image.h"
#include "raster/sprite.h"
#include "raster/stock.h"
#include "util/quantize.h"
#include "widgets/colview.h"
#include "widgets/paledit.h"
static PALETTE *palettes;
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 void select_all_command(JWidget widget);
static void load_command(JWidget widget);
static void save_command(JWidget widget);
static void ramp_command(JWidget widget);
static void quantize_command(JWidget widget);
static int sliderRGB_change_signal(JWidget widget, int user_data);
static int sliderHSV_change_signal(JWidget widget, int user_data);
static int slider_columns_change_signal(JWidget widget, int user_data);
static int slider_frame_change_signal(JWidget widget, int user_data);
static int palette_editor_change_signal(JWidget widget, int user_data);
static void set_new_palette(RGB *palette);
void dialogs_palette_editor(void)
{
JWidget window, 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;
int imgtype = current_sprite ? current_sprite->imgtype: IMAGE_INDEXED;
int frame_bak = current_sprite ? current_sprite->frame : 0;
if (imgtype == IMAGE_GRAYSCALE) {
jalert(_("Error<<You can't edit grayscale palette||&OK"));
return;
}
/* load widgets */
window = load_widget("paledit.jid", "palette_editor");
if (!window)
return;
if (!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, NULL)) {
jwidget_free(window);
return;
}
/* create current_sprite->frames palettes */
if (current_sprite) {
palettes = jmalloc(sizeof(PALETTE) * current_sprite->frames);
if (!palettes) {
jalert(_("Error<<Not enough memory||&OK"));
return;
}
for (frame=0; frame<current_sprite->frames; frame++)
memcpy(palettes[frame],
sprite_get_palette(current_sprite, frame), sizeof(PALETTE));
}
else
palettes = NULL;
/* get current palette */
palette_copy(palette, current_palette);
/* get configuration */
columns = get_config_int("PaletteEditor", "Columns", 16);
columns = MID(1, columns, 256);
/* custom widgets */
colorviewer = colorviewer_new(color_index(0), IMAGE_INDEXED);
palette_editor = paledit_new(palette, TRUE, 6);
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);
/* frame */
if (current_sprite) {
jslider_set_range(slider_frame, 0, current_sprite->frames-1);
jslider_set_value(slider_frame, current_sprite->frame);
}
else
jwidget_disable(slider_frame);
/* hook signals */
HOOK(slider_R, JI_SIGNAL_SLIDER_CHANGE, sliderRGB_change_signal, 0);
HOOK(slider_G, JI_SIGNAL_SLIDER_CHANGE, sliderRGB_change_signal, 0);
HOOK(slider_B, JI_SIGNAL_SLIDER_CHANGE, sliderRGB_change_signal, 0);
HOOK(slider_H, JI_SIGNAL_SLIDER_CHANGE, sliderHSV_change_signal, 0);
HOOK(slider_S, JI_SIGNAL_SLIDER_CHANGE, sliderHSV_change_signal, 0);
HOOK(slider_V, JI_SIGNAL_SLIDER_CHANGE, sliderHSV_change_signal, 0);
HOOK(slider_columns, JI_SIGNAL_SLIDER_CHANGE, slider_columns_change_signal, 0);
HOOK(slider_frame, JI_SIGNAL_SLIDER_CHANGE, slider_frame_change_signal, 0);
HOOK(palette_editor, SIGNAL_PALETTE_EDITOR_CHANGE, palette_editor_change_signal, 0);
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);
/* default position */
jwindow_remap(window);
jwindow_center(window);
/* load window configuration */
load_window_pos(window, "PaletteEditor");
/* open and run the window */
jwindow_open_fg(window);
/* check the killer widget */
if (jwindow_get_killer (window) == button_ok) {
if (current_sprite) {
palette_copy(palettes[jslider_get_value(slider_frame)],
current_palette);
sprite_reset_palettes(current_sprite);
for (frame=0; frame<current_sprite->frames; frame++) {
if (frame == 0 ||
palette_diff(palettes[frame], palettes[frame-1], NULL, NULL))
sprite_set_palette(current_sprite, palettes[frame], frame);
}
}
/* change the system palette */
else
set_default_palette(palette);
set_current_palette(palette, TRUE);
}
/* cancel or ESC */
else {
/* restore the system palette */
if (current_sprite) {
current_sprite->frame = frame_bak;
set_current_palette(sprite_get_palette(current_sprite, 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");
jwidget_free(window);
if (palettes)
jfree(palettes);
}
static void select_all_command(JWidget widget)
{
paledit_select_range(palette_editor, 0, 255,
PALETTE_EDITOR_RANGE_LINEAL);
}
static void load_command(JWidget widget)
{
RGB *palette;
char *filename;
filename = ase_file_selector(_("Load Palette"), "", "pcx,bmp,tga,lbm,col");
if (filename) {
palette = palette_load(filename);
if (!palette) {
jalert(_("Error<<Loading palette file||&Close"));
}
else {
set_new_palette(palette);
jfree(palette);
}
jfree(filename);
}
}
static void save_command(JWidget widget)
{
char *filename;
int ret;
again:
filename = ase_file_selector(_("Save Palette"), "", "pcx,bmp,tga,col");
if (filename) {
if (exists(filename)) {
ret = jalert("%s<<%s<<%s||%s",
_("Warning"),
_("File exists, overwrite it?"),
get_filename(filename),
_("&Yes||&No||&Cancel"));
if (ret == 2) {
jfree(filename);
goto again;
}
else if (ret != 1) {
jfree(filename);
return;
}
}
if (palette_save(paledit_get_palette(palette_editor), filename))
jalert(_("Error<<Saving palette file||&Close"));
jfree(filename);
}
}
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);
PALETTE palette;
bool array[256];
paledit_get_selected_entries(palette_editor, array);
palette_copy(palette, paledit_get_palette(palette_editor));
if ((i1 >= 0) && (i2 >= 0)) {
/* make the ramp */
if (range_type == PALETTE_EDITOR_RANGE_LINEAL) {
/* lineal ramp */
make_palette_ramp(palette, i1, i2);
}
else if (range_type == PALETTE_EDITOR_RANGE_RECTANGULAR) {
/* rectangular ramp */
make_palette_rect_ramp(palette, i1, i2, paledit_get_columns(palette_editor));
}
}
set_new_palette(palette);
}
static void quantize_command(JWidget widget)
{
PALETTE palette;
bool array[256];
paledit_get_selected_entries(palette_editor, array);
palette_copy(palette, paledit_get_palette(palette_editor));
if (current_sprite && current_sprite->imgtype == IMAGE_RGB) {
sprite_quantize_ex(current_sprite, palette);
}
else {
jalert("Error<<You can use this command only for RGB sprites||&OK");
}
set_new_palette(palette);
}
static int sliderRGB_change_signal(JWidget widget, int user_data)
{
RGB *palette = paledit_get_palette(palette_editor);
int r = jslider_get_value(slider_R)>>2;
int g = jslider_get_value(slider_G)>>2;
int b = jslider_get_value(slider_B)>>2;
float h, s, v;
bool array[256];
int c;
rgb_to_hsv(_rgb_scale_6[r],
_rgb_scale_6[g],
_rgb_scale_6[b], &h, &s, &v);
paledit_get_selected_entries(palette_editor, array);
for (c=0; c<256; c++) {
if (array[c]) {
palette[c].r = r;
palette[c].g = g;
palette[c].b = b;
set_current_color(c, 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);
return FALSE;
}
static int sliderHSV_change_signal(JWidget widget, int user_data)
{
RGB *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);
bool array[256];
int c, r, g, b;
hsv_to_rgb(360.0 * h / 255.0, s / 255.0, v / 255.0, &r, &g, &b);
r >>= 2;
g >>= 2;
b >>= 2;
paledit_get_selected_entries(palette_editor, array);
for (c=0; c<256; c++) {
if (array[c]) {
palette[c].r = r;
palette[c].g = g;
palette[c].b = b;
set_current_color(c, r, g, b);
}
}
jslider_set_value(slider_R, _rgb_scale_6[r]);
jslider_set_value(slider_G, _rgb_scale_6[g]);
jslider_set_value(slider_B, _rgb_scale_6[b]);
jwidget_dirty(palette_editor);
return FALSE;
}
static int slider_columns_change_signal(JWidget widget, int user_data)
{
paledit_set_columns(palette_editor,
(int)jslider_get_value(widget));
return FALSE;
}
static int slider_frame_change_signal(JWidget widget, int user_data)
{
int old_frame = current_sprite->frame;
int new_frame = jslider_get_value(slider_frame);
palette_copy(palettes[old_frame], current_palette);
current_sprite->frame = new_frame;
set_new_palette(palettes[new_frame]);
return FALSE;
}
static int palette_editor_change_signal(JWidget widget, int user_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);
float h, s, v;
rgb_to_hsv(r, g, b, &h, &s, &v);
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);
return FALSE;
}
static void set_new_palette(RGB *palette)
{
/* copy the palette */
palette_copy(paledit_get_palette(palette_editor), palette);
/* set the palette calling the hooks */
set_current_palette(palette, FALSE);
/* redraw the entire screen */
jmanager_refresh_screen();
}

View File

@ -1,25 +0,0 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef DIALOGS_DPALEDIT_H
#define DIALOGS_DPALEDIT_H
void dialogs_palette_editor(void);
#endif /* DIALOGS_DPALEDIT_H */

View File

@ -30,7 +30,7 @@
#include "core/dirs.h"
#include "dialogs/filesel.h"
#include "modules/gui.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "modules/sprites.h"
#include "raster/blend.h"
#include "raster/image.h"
@ -81,7 +81,7 @@ void dialogs_draw_text(void)
update_button_text();
/* color button */
color_but = color_button_new
color_but = colorbutton_new
(get_config_color("DrawText", "Color",
colorbar_get_fg_color(app_get_colorbar())),
current_sprite->imgtype);
@ -100,7 +100,7 @@ void dialogs_draw_text(void)
jwindow_open_fg(window);
if (jwindow_get_killer(window) == button_ok) {
color_t color_with_type = color_button_get_color(color_but);
color_t color_with_type = colorbutton_get_color(color_but);
const char *text = jwidget_get_text(entry_text);
const char *size_str = jwidget_get_text(entry_size);
const char *font_str = get_config_string("DrawText", "Font",

View File

@ -29,7 +29,7 @@
#include "core/core.h"
#include "modules/gfx.h"
#include "modules/gui.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "modules/rootmenu.h"
#include "modules/sprites.h"
#include "raster/cel.h"
@ -324,7 +324,7 @@ static bool layer_box_msg_proc(JWidget widget, JMessage msg)
int tabs = -2;
Layer *l = layer;
while (l->gfxobj.type != GFXOBJ_SPRITE) {
while (l != NULL) {
if (++tabs > 0) {
/* JList item = jlist_find(((Layer *)l->parent)->layers, l); */
int y1 = y_mid-LAYSIZE/2;
@ -332,7 +332,7 @@ static bool layer_box_msg_proc(JWidget widget, JMessage msg)
/* int y2 = item->prev ? y_mid+LAYSIZE/2 : y_mid; */
vline(bmp, tabs*16-1, y1, y2, makecol(0, 0, 0));
}
l = (Layer *)l->parent;
l = l->parent_layer;
}
/* draw the layer name */
@ -470,7 +470,7 @@ static bool layer_box_msg_proc(JWidget widget, JMessage msg)
}
/* move */
else if (layer_box->layer != current_sprite->layer) {
layer_move_layer((Layer *)layer_box->layer->parent,
layer_move_layer(layer_box->layer->parent_layer,
layer_box->layer, current_sprite->layer);
current_sprite->layer = layer_box->layer;
@ -632,7 +632,7 @@ static bool cel_box_msg_proc(JWidget widget, JMessage msg)
if (sprite->layer == layer)
rectfill(bmp, 0, y, bmp->w-1, y+h-1, makecol(44, 76, 145));
else if (layer->gfxobj.type == GFXOBJ_LAYER_SET)
else if (layer_is_set(layer))
rectfill(bmp, 0, y, bmp->w-1, y+h-1, makecol(128, 128, 128));
hline(bmp, 0, y, bmp->w-1, makecol(0, 0, 0));
@ -839,21 +839,21 @@ static bool cel_box_msg_proc(JWidget widget, JMessage msg)
static Layer *select_prev_layer(Layer *layer, int enter_in_sets)
{
GfxObj *parent = layer->parent;
Layer *parent = layer->parent_layer;
if (enter_in_sets && layer->gfxobj.type == GFXOBJ_LAYER_SET) {
if (enter_in_sets && layer_is_set(layer)) {
if (!jlist_empty(layer->layers))
layer = jlist_last_data(layer->layers);
}
else if (parent->type == GFXOBJ_LAYER_SET) {
JList list = ((Layer *)parent)->layers;
else if (parent != NULL) {
JList list = parent->layers;
JLink link = jlist_find(list, layer);
if (link != list->end) {
if (link->prev != list->end)
layer = link->prev->data;
else
layer = select_prev_layer((Layer *)parent, FALSE);
layer = select_prev_layer(parent, FALSE);
}
}
@ -862,21 +862,21 @@ static Layer *select_prev_layer(Layer *layer, int enter_in_sets)
static Layer *select_next_layer(Layer *layer, int enter_in_sets)
{
GfxObj *parent = layer->parent;
Layer *parent = layer->parent_layer;
if (enter_in_sets && layer->gfxobj.type == GFXOBJ_LAYER_SET) {
if (enter_in_sets && layer_is_set(layer)) {
if (!jlist_empty(layer->layers))
layer = jlist_first_data(layer->layers);
}
else if (parent->type == GFXOBJ_LAYER_SET) {
JList list = ((Layer *)parent)->layers;
else if (parent != NULL) {
JList list = parent->layers;
JLink link = jlist_find(list, layer);
if (link != list->end) {
if (link->next != list->end)
layer = link->next->data;
else
layer = select_next_layer((Layer *)parent, FALSE);
layer = select_next_layer(parent, FALSE);
}
}
@ -887,7 +887,7 @@ static int count_layers(Layer *layer)
{
int count;
if (layer->parent->type == GFXOBJ_SPRITE)
if (layer->parent_layer == NULL)
count = 0;
else
count = 1;
@ -903,13 +903,13 @@ static int count_layers(Layer *layer)
static int get_layer_pos(Layer *layer, Layer *current, int *pos)
{
if (layer->parent->type == GFXOBJ_SPRITE)
if (layer->parent_layer == NULL)
*pos = 0;
if (layer == current)
return TRUE;
if (layer->parent->type != GFXOBJ_SPRITE)
if (layer->parent_layer != NULL)
(*pos)++;
if (layer->gfxobj.type == GFXOBJ_LAYER_SET) {
@ -926,7 +926,7 @@ static Layer *get_layer_in_pos(Layer *layer, int pos)
{
static int internal_pos;
if (layer->parent->type == GFXOBJ_SPRITE)
if (layer->parent_layer == NULL)
internal_pos = 0;
else {
if (internal_pos == pos)

View File

@ -45,9 +45,9 @@ static JWidget button_color, slider_fuzziness, check_preview;
static void button_1_command(JWidget widget);
static void button_2_command(JWidget widget);
static int color_change_hook(JWidget widget, int user_data);
static int slider_change_hook(JWidget widget, int user_data);
static int preview_change_hook(JWidget widget, int user_data);
static bool color_change_hook(JWidget widget, void *data);
static bool slider_change_hook(JWidget widget, void *data);
static bool preview_change_hook(JWidget widget, void *data);
static Mask *gen_mask(void);
static void mask_preview(void);
@ -74,7 +74,7 @@ void dialogs_mask_color(void)
box3 = jbox_new(JI_HORIZONTAL);
box4 = jbox_new(JI_HORIZONTAL | JI_HOMOGENEOUS);
label_color = jlabel_new(_("Color:"));
button_color = color_button_new
button_color = colorbutton_new
(get_config_color("MaskColor", "Color",
colorbar_get_fg_color(app_get_colorbar())),
sprite->imgtype);
@ -93,7 +93,7 @@ void dialogs_mask_color(void)
jbutton_add_command(button_1, button_1_command);
jbutton_add_command(button_2, button_2_command);
HOOK(button_color, SIGNAL_COLOR_BUTTON_CHANGE, color_change_hook, 0);
HOOK(button_color, SIGNAL_COLORBUTTON_CHANGE, color_change_hook, 0);
HOOK(slider_fuzziness, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0);
HOOK(check_preview, JI_SIGNAL_CHECK_CHANGE, preview_change_hook, 0);
@ -134,7 +134,7 @@ void dialogs_mask_color(void)
mask_free(mask);
set_config_color("MaskColor", "Color",
color_button_get_color(button_color));
colorbutton_get_color(button_color));
set_config_int("MaskColor", "Fuzziness",
jslider_get_value(slider_fuzziness));
@ -155,31 +155,31 @@ void dialogs_mask_color(void)
static void button_1_command(JWidget widget)
{
color_button_set_color(button_color,
colorbar_get_fg_color(app_get_colorbar()));
colorbutton_set_color(button_color,
colorbar_get_fg_color(app_get_colorbar()));
mask_preview();
}
static void button_2_command(JWidget widget)
{
color_button_set_color(button_color,
colorbar_get_bg_color(app_get_colorbar()));
colorbutton_set_color(button_color,
colorbar_get_bg_color(app_get_colorbar()));
mask_preview();
}
static int color_change_hook(JWidget widget, int user_data)
static bool color_change_hook(JWidget widget, void *data)
{
mask_preview();
return FALSE;
}
static int slider_change_hook(JWidget widget, int user_data)
static bool slider_change_hook(JWidget widget, void *data)
{
mask_preview();
return FALSE;
}
static int preview_change_hook(JWidget widget, int user_data)
static bool preview_change_hook(JWidget widget, void *data)
{
mask_preview();
return FALSE;
@ -196,7 +196,7 @@ static Mask *gen_mask(void)
image = GetImage2(sprite, &xpos, &ypos, NULL);
color = get_color_for_image(sprite->imgtype,
color_button_get_color(button_color));
colorbutton_get_color(button_color));
fuzziness = jslider_get_value(slider_fuzziness);
mask = mask_new();

View File

@ -1,116 +0,0 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <assert.h>
#include <stdio.h>
#include "jinete/jinete.h"
#include "core/color.h"
#include "modules/gui.h"
#include "modules/palette.h"
#include "widgets/colbar.h"
#include "widgets/paledit.h"
static int paledit_change_signal(JWidget widget, int user_data);
static bool window_hook(JWidget widget, JMessage msg);
void ji_minipal_new(JWidget color_bar, int x, int y)
{
JWidget window, paledit;
window = jwindow_new("MiniPal");
paledit = palette_editor_new(current_palette, FALSE, 3);
HOOK(paledit, SIGNAL_PALETTE_EDITOR_CHANGE, paledit_change_signal, color_bar);
jwidget_add_hook(window, JI_USER_WIDGET, window_hook, paledit);
jwidget_expansive(paledit, TRUE);
jwidget_add_child(window, paledit);
jwindow_position(window, x, y);
jwindow_open_bg(window);
}
static int paledit_change_signal(JWidget widget, int user_data)
{
if (jmouse_b(0)) {
PaletteEditor *paledit = palette_editor_data(widget);
JWidget colorbar = (JWidget)user_data;
if (paledit->color[0] == paledit->color[1]) {
color_t color = color_index(paledit->color[1]);
colorbar_set_fg_color(colorbar, color);
}
else {
bool array[256];
int c, sel;
palette_editor_get_selected_entries(widget, array);
for (c=sel=0; c<256; c++)
if (array[c])
sel++;
colorbar_set_size(colorbar, sel);
for (c=sel=0; c<256; c++) {
if (array[c]) {
colorbar_set_color(colorbar, sel++,
color_index(c));
}
}
}
}
return FALSE;
}
static bool window_hook(JWidget widget, JMessage msg)
{
switch (msg->type) {
case JM_SIGNAL: {
if (msg->signal.num == JI_SIGNAL_WINDOW_RESIZE) {
JWidget paledit = jwidget_get_data(widget, JI_USER_WIDGET);
int cols, box = 3;
do {
box++;
palette_editor_data(paledit)->boxsize = box;
cols = (jrect_w(paledit->rc)-1) / (box+1);
palette_editor_set_columns(paledit, cols);
} while (((jrect_h(paledit->rc)-1) / (box+1))*cols > 256);
box--;
palette_editor_data(paledit)->boxsize = box;
cols = (jrect_w(paledit->rc)-1) / (box+1);
palette_editor_set_columns(paledit, cols);
jwidget_dirty(paledit);
}
else if (msg->signal.num == JI_SIGNAL_WINDOW_CLOSE) {
jwidget_free_deferred(widget);
}
break;
}
}
return FALSE;
}

View File

@ -1,27 +0,0 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef DIALOGS_MINIPAL_H
#define DIALOGS_MINIPAL_H
#include "jinete/jbase.h"
void ji_minipal_new(JWidget color_bar, int x, int y);
#endif /* DIALOGS_MINIPAL_H */

View File

@ -40,7 +40,7 @@ void dialogs_select_language(bool force)
static JWidget slider_x, slider_y, check_lockmouse;
static int slider_mouse_hook(JWidget widget, int user_data);
static bool slider_mouse_hook(JWidget widget, void *data);
/* shows option dialog */
void dialogs_options(void)
@ -121,7 +121,7 @@ void dialogs_options(void)
jwidget_free(window);
}
static int slider_mouse_hook(JWidget widget, int user_data)
static bool slider_mouse_hook(JWidget widget, void *data)
{
int x, y;

View File

@ -191,7 +191,7 @@ static void do_quick(int action)
sprite_set_layer(sprite, dst_layer);
/* remove the temporary created layer */
layer_remove_layer((Layer *)handle_layer->parent, handle_layer);
layer_remove_layer(handle_layer->parent_layer, handle_layer);
/* refresh the sprite */
update_screen_for_sprite(sprite);

View File

@ -30,7 +30,8 @@
#include "core/dirs.h"
#include "intl/intl.h"
#include "modules/gui.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "raster/palette.h"
static JWidget tips_new(void);
static int tips_type(void);
@ -49,7 +50,7 @@ static BITMAP *tips_load_image(const char *filename, PALETTE pal);
static void prev_command(JWidget widget, void *data);
static void next_command(JWidget widget, void *data);
static int check_signal(JWidget widget, int user_data);
static bool check_change_hook(JWidget widget, void *data);
void dialogs_tips(bool forced)
{
@ -57,7 +58,7 @@ void dialogs_tips(bool forced)
JWidget button_close, button_prev, button_next;
JWidget view, tips;
JWidget check;
PALETTE old_pal;
Palette *old_pal;
/* don't show it? */
if (!forced && !get_config_bool("Tips", "Show", TRUE))
@ -100,7 +101,7 @@ void dialogs_tips(bool forced)
jbutton_add_command_data(button_prev, prev_command, tips);
jbutton_add_command_data(button_next, next_command, tips);
HOOK(check, JI_SIGNAL_CHECK_CHANGE, check_signal, 0);
HOOK(check, JI_SIGNAL_CHECK_CHANGE, check_change_hook, 0);
if (get_config_bool("Tips", "Show", TRUE))
jwidget_select(check);
@ -131,7 +132,7 @@ void dialogs_tips(bool forced)
jwidget_set_min_size(window, 0, 0);
/* load first page */
memcpy(old_pal, current_palette, sizeof(PALETTE));
old_pal = palette_new_copy(get_current_palette());
tips_load_page(tips);
/* run the window */
@ -140,6 +141,8 @@ void dialogs_tips(bool forced)
/* restore the palette */
set_current_palette(old_pal, TRUE);
palette_free(old_pal);
jmanager_refresh_screen();
}
@ -406,13 +409,16 @@ static JWidget tips_load_box(FILE *f, char *buf, int sizeof_buf, int *take)
/* \palette filename */
else if (ustrncmp (buf+1, "palette", 7) == 0) {
char filename[1024];
PALETTE pal;
PALETTE rgbpal;
BITMAP *bmp;
sprintf(filename, "tips/%s", strchr(buf, ' ')+1);
bmp = tips_load_image(filename, pal);
bmp = tips_load_image(filename, rgbpal);
if (bmp) {
set_current_palette(pal, FALSE);
Palette *pal = palette_new(0, MAX_PALETTE_COLORS);
set_current_palette(palette_from_allegro(pal, rgbpal), FALSE);
palette_free(pal);
destroy_bitmap(bmp);
}
else {
@ -507,7 +513,7 @@ static void next_command(JWidget widget, void *data)
tips_load_page((JWidget)data);
}
static int check_signal(JWidget widget, int user_data)
static bool check_change_hook(JWidget widget, void *data)
{
set_config_bool("Tips", "Show", jwidget_is_selected(widget));
return TRUE;

View File

@ -22,8 +22,9 @@
#include "effect/colcurve.h"
#include "effect/effect.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "raster/image.h"
#include "raster/palette.h"
static struct {
Curve *curve;
@ -68,7 +69,7 @@ void curve_free(Curve *curve)
JLink link;
JI_LIST_FOR_EACH(curve->points, link)
jfree(link->data);
curve_point_free(link->data);
jlist_free(curve->points);
jfree(curve);
@ -329,6 +330,7 @@ void apply_color_curve2 (Effect *effect)
void apply_color_curve1(Effect *effect)
{
Palette *pal = get_current_palette();
ase_uint8 *src_address;
ase_uint8 *dst_address;
int x, c, r, g, b;
@ -353,9 +355,9 @@ void apply_color_curve1(Effect *effect)
if (effect->target.index)
c = data.cmap[c];
else {
r = _rgb_scale_6[current_palette[c].r];
g = _rgb_scale_6[current_palette[c].g];
b = _rgb_scale_6[current_palette[c].b];
r = _rgba_getr(pal->color[c]);
g = _rgba_getg(pal->color[c]);
b = _rgba_getb(pal->color[c]);
if (effect->target.r) r = data.cmap[r];
if (effect->target.g) g = data.cmap[g];

View File

@ -28,9 +28,10 @@
#include "core/dirs.h"
#include "effect/convmatr.h"
#include "effect/effect.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "modules/tools.h"
#include "raster/image.h"
#include "raster/palette.h"
#include "util/filetoks.h"
/* TODO warning: this number could be dangerous for big filters */
@ -57,6 +58,9 @@ void exit_convolution_matrix(void)
{
clean_matrices_stock();
jlist_free(data.matrices);
if (data.lines != NULL)
jfree(data.lines);
}
ConvMatr *convmatr_new(int w, int h)
@ -113,7 +117,7 @@ void set_convmatr(ConvMatr *convmatr)
data.convmatr = convmatr;
data.tiled = get_tiled_mode();
if (data.lines)
if (data.lines != NULL)
jfree(data.lines);
data.lines = jmalloc(sizeof(unsigned char *) * convmatr->h);
@ -458,6 +462,7 @@ void apply_convolution_matrix2(Effect *effect)
void apply_convolution_matrix1(Effect *effect)
{
Palette *pal = get_current_palette();
ConvMatr *matrix = data.convmatr;
Image *src = effect->src;
Image *dst = effect->dst;
@ -490,9 +495,9 @@ void apply_convolution_matrix1(Effect *effect)
GET_CONVMATR_DATA
(ase_uint8,
r += _rgb_scale_6[current_palette[color].r] * (*mdata);
g += _rgb_scale_6[current_palette[color].g] * (*mdata);
b += _rgb_scale_6[current_palette[color].b] * (*mdata);
r += _rgba_getr(pal->color[color]) * (*mdata);
g += _rgba_getg(pal->color[color]) * (*mdata);
b += _rgba_getb(pal->color[color]) * (*mdata);
index += color * (*mdata);
);
@ -508,21 +513,21 @@ void apply_convolution_matrix1(Effect *effect)
r = MID(0, r, 255);
}
else
r = _rgb_scale_6[current_palette[color].r];
r = _rgba_getr(pal->color[color]);
if (effect->target.g) {
g = g / div + matrix->bias;
g = MID(0, g, 255);
}
else
g = _rgb_scale_6[current_palette[color].g];
g = _rgba_getg(pal->color[color]);
if (effect->target.b) {
b = b / div + matrix->bias;
b = MID(0, b, 255);
}
else
b = _rgb_scale_6[current_palette[color].b];
b = _rgba_getb(pal->color[color]);
*(dst_address++) = orig_rgb_map->data[r>>3][g>>3][b>>3];
}

View File

@ -19,8 +19,9 @@
#include "config.h"
#include "effect/effect.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "raster/image.h"
#include "raster/palette.h"
void apply_invert_color4(Effect *effect)
{
@ -94,6 +95,7 @@ void apply_invert_color2(Effect *effect)
void apply_invert_color1(Effect *effect)
{
Palette *pal = get_current_palette();
ase_uint8 *src_address;
ase_uint8 *dst_address;
int x, c, r, g, b;
@ -118,9 +120,9 @@ void apply_invert_color1(Effect *effect)
if (effect->target.index)
c ^= 0xff;
else {
r = (current_palette[c].r>>1);
g = (current_palette[c].g>>1);
b = (current_palette[c].b>>1);
r = _rgba_getr(pal->color[c])>>3;
g = _rgba_getg(pal->color[c])>>3;
b = _rgba_getb(pal->color[c])>>3;
if (effect->target.r) r ^= 0x1f;
if (effect->target.g) g ^= 0x1f;

View File

@ -21,9 +21,10 @@
#include <allegro.h>
#include "effect/effect.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "modules/tools.h"
#include "raster/image.h"
#include "raster/palette.h"
static struct {
int tiled;
@ -178,6 +179,7 @@ void apply_median2(Effect *effect)
void apply_median1(Effect *effect)
{
Palette *pal = get_current_palette();
Image *src = effect->src;
Image *dst = effect->dst;
ase_uint8 *src_address;
@ -211,9 +213,9 @@ void apply_median1(Effect *effect)
data.channel[0][c] = color;
}
else {
data.channel[0][c] = _rgb_scale_6[current_palette[color].r];
data.channel[1][c] = _rgb_scale_6[current_palette[color].g];
data.channel[2][c] = _rgb_scale_6[current_palette[color].b];
data.channel[0][c] = _rgba_getr(pal->color[color]);
data.channel[1][c] = _rgba_getg(pal->color[color]);
data.channel[2][c] = _rgba_getb(pal->color[color]);
}
c++;
);
@ -234,17 +236,17 @@ void apply_median1(Effect *effect)
if (effect->target.r)
r = data.channel[0][data.ncolors/2];
else
r = _rgb_scale_6[current_palette[color].r];
r = _rgba_getr(pal->color[color]);
if (effect->target.g)
g = data.channel[1][data.ncolors/2];
else
g = _rgb_scale_6[current_palette[color].g];
g = _rgba_getg(pal->color[color]);
if (effect->target.b)
b = data.channel[2][data.ncolors/2];
else
b = _rgb_scale_6[current_palette[color].b];
b = _rgba_getb(pal->color[color]);
*(dst_address++) = orig_rgb_map->data[r>>3][g>>3][b>>3];
}

View File

@ -29,6 +29,7 @@
#define ASE_FILE_MAGIC 0xA5E0
#define ASE_FILE_FRAME_MAGIC 0xF1FA
#define ASE_FILE_CHUNK_FLI_COLOR2 4
#define ASE_FILE_CHUNK_FLI_COLOR 11
#define ASE_FILE_CHUNK_LAYER 0x2004
#define ASE_FILE_CHUNK_CEL 0x2005
@ -90,8 +91,9 @@ static void ase_file_write_string(FILE *f, const char *string);
static void ase_file_write_start_chunk(FILE *f, int type);
static void ase_file_write_close_chunk(FILE *f);
static void ase_file_read_color_chunk(FILE *f, RGB *pal);
static void ase_file_write_color_chunk(FILE *f, RGB *pal);
static Palette *ase_file_read_color_chunk(FILE *f, Sprite *sprite, int frame);
static Palette *ase_file_read_color2_chunk(FILE *f, Sprite *sprite, int frame);
static void ase_file_write_color2_chunk(FILE *f, Palette *pal);
static Layer *ase_file_read_layer_chunk(FILE *f, Sprite *sprite, Layer **previous_layer, int *current_level);
static void ase_file_write_layer_chunk(FILE *f, Layer *layer);
static Cel *ase_file_read_cel_chunk(FILE *f, Sprite *sprite, int frame, int imgtype, FileOp *fop, ASE_Header *header);
@ -208,10 +210,22 @@ static bool load_ASE(FileOp *fop)
/* fop_error(fop, "Color chunk\n"); */
if (sprite->imgtype == IMAGE_INDEXED) {
/* TODO fix to read palette-per-frame */
PALETTE palette;
ase_file_read_color_chunk(f, palette);
sprite_set_palette(sprite, palette, 0);
Palette *pal = ase_file_read_color_chunk(f, sprite, frame);
sprite_set_palette(sprite, pal, TRUE);
palette_free(pal);
}
else
fop_error(fop, _("Warning: was found a color chunk in non-8bpp file\n"));
break;
/* only for 8 bpp images */
case ASE_FILE_CHUNK_FLI_COLOR2:
/* fop_error(fop, "Color2 chunk\n"); */
if (sprite->imgtype == IMAGE_INDEXED) {
Palette *pal = ase_file_read_color2_chunk(f, sprite, frame);
sprite_set_palette(sprite, pal, TRUE);
palette_free(pal);
}
else
fop_error(fop, _("Warning: was found a color chunk in non-8bpp file\n"));
@ -302,13 +316,17 @@ static bool save_ASE(FileOp *fop)
/* frame duration */
frame_header.duration = sprite_get_frlen(sprite, frame);
/* the sprite is indexed and the palette changes? (or is the first frame) */
if (sprite->imgtype == IMAGE_INDEXED &&
(frame == 0 ||
palette_count_diff(sprite_get_palette(sprite, frame-1),
sprite_get_palette(sprite, frame), NULL, NULL) > 0)) {
/* write the color chunk */
ase_file_write_color2_chunk(f, sprite_get_palette(sprite, frame));
}
/* write extra chunks in the first frame */
if (frame == 0) {
/* color chunk */
if (sprite->imgtype == IMAGE_INDEXED)
/* TODO fix this to write palette per-frame */
ase_file_write_color_chunk(f, sprite_get_palette(sprite, 0));
/* write layer chunks */
JI_LIST_FOR_EACH(sprite->set->layers, link)
ase_file_write_layers(f, link->data);
@ -576,9 +594,11 @@ static void ase_file_write_close_chunk(FILE *f)
fseek(f, chunk_end, SEEK_SET);
}
static void ase_file_read_color_chunk(FILE *f, RGB *pal)
static Palette *ase_file_read_color_chunk(FILE *f, Sprite *sprite, int frame)
{
int i, c, packets, skip, size;
int i, c, r, g, b, packets, skip, size;
Palette *pal = palette_new(frame, MAX_PALETTE_COLORS);
palette_copy_colors(pal, sprite_get_palette(sprite, frame));
packets = fgetw(f); /* number of packets */
skip = 0;
@ -590,27 +610,61 @@ static void ase_file_read_color_chunk(FILE *f, RGB *pal)
if (!size) size = 256;
for (c=skip; c<skip+size; c++) {
pal[c].r = fgetc(f);
pal[c].g = fgetc(f);
pal[c].b = fgetc(f);
r = fgetc(f);
g = fgetc(f);
b = fgetc(f);
palette_set_entry(pal, c,
_rgba(_rgb_scale_6[r],
_rgb_scale_6[g],
_rgb_scale_6[b], 255));
}
}
return pal;
}
static Palette *ase_file_read_color2_chunk(FILE *f, Sprite *sprite, int frame)
{
int i, c, r, g, b, packets, skip, size;
Palette *pal = palette_new(frame, MAX_PALETTE_COLORS);
palette_copy_colors(pal, sprite_get_palette(sprite, frame));
packets = fgetw(f); /* number of packets */
skip = 0;
/* read all packets */
for (i=0; i<packets; i++) {
skip += fgetc(f);
size = fgetc(f);
if (!size) size = 256;
for (c=skip; c<skip+size; c++) {
r = fgetc(f);
g = fgetc(f);
b = fgetc(f);
palette_set_entry(pal, c, _rgba(r, g, b, 255));
}
}
return pal;
}
/* writes the original color chunk in FLI files for the entire palette "pal" */
static void ase_file_write_color_chunk(FILE *f, RGB *pal)
static void ase_file_write_color2_chunk(FILE *f, Palette *pal)
{
int c;
int c, color;
ase_file_write_start_chunk(f, ASE_FILE_CHUNK_FLI_COLOR);
ase_file_write_start_chunk(f, ASE_FILE_CHUNK_FLI_COLOR2);
fputw(1, f);
fputc(0, f);
fputc(0, f);
for (c=0; c<256; c++) {
fputc(pal[c].r, f);
fputc(pal[c].g, f);
fputc(pal[c].b, f);
for (c=0; c<MAX_PALETTE_COLORS; c++) {
color = palette_get_entry(pal, c);
fputc(_rgba_getr(color), f);
fputc(_rgba_getg(color), f);
fputc(_rgba_getb(color), f);
}
ase_file_write_close_chunk(f);
@ -653,17 +707,19 @@ static Layer *ase_file_read_layer_chunk(FILE *f, Sprite *sprite, Layer **previou
layer->writable = (flags & 2) ? TRUE: FALSE;
/* name */
if (name)
if (name) {
layer_set_name(layer, name);
jfree(name);
}
/* child level... */
if (child_level == *current_level)
layer_add_layer((Layer *)(*previous_layer)->parent, layer);
layer_add_layer((*previous_layer)->parent_layer, layer);
else if (child_level > *current_level)
layer_add_layer((*previous_layer), layer);
else if (child_level < *current_level)
layer_add_layer((Layer *)((Layer *)(*previous_layer)->parent)->parent, layer);
layer_add_layer((*previous_layer)->parent_layer->parent_layer, layer);
*previous_layer = layer;
*current_level = child_level;
@ -674,7 +730,7 @@ static Layer *ase_file_read_layer_chunk(FILE *f, Sprite *sprite, Layer **previou
static void ase_file_write_layer_chunk(FILE *f, Layer *layer)
{
GfxObj *parent;
Layer *parent;
int child_level;
ase_file_write_start_chunk(f, ASE_FILE_CHUNK_LAYER);
@ -688,10 +744,10 @@ static void ase_file_write_layer_chunk(FILE *f, Layer *layer)
/* layer child level */
child_level = -1;
parent = layer->parent;
while (parent && parent->type != GFXOBJ_SPRITE) {
parent = layer->parent_layer;
while (parent != NULL) {
child_level++;
parent = ((Layer *)parent)->parent;
parent = parent->parent_layer;
}
fputw(child_level, f);
@ -916,8 +972,10 @@ static Mask *ase_file_read_mask_chunk(FILE *f)
if (!mask)
return NULL;
if (name)
if (name) {
mask_set_name(mask, name);
jfree(name);
}
mask_replace(mask, x, y, w, h);

View File

@ -161,9 +161,9 @@ static void read_bmicolors(FileOp *fop, int ncols, FILE *f,int win_flag)
int i, r, g, b;
for (i=0; i<ncols; i++) {
b = fgetc(f) / 4;
g = fgetc(f) / 4;
r = fgetc(f) / 4;
b = fgetc(f);
g = fgetc(f);
r = fgetc(f);
fop_sequence_set_color(fop, i, r, g, b);
if (win_flag)
fgetc(f);
@ -676,9 +676,9 @@ static bool save_BMP(FileOp *fop)
/* palette */
for (i=0; i<256; i++) {
fop_sequence_get_color(fop, i, &r, &g, &b);
fputc(_rgb_scale_6[b], f);
fputc(_rgb_scale_6[g], f);
fputc(_rgb_scale_6[r], f);
fputc(b, f);
fputc(g, f);
fputc(r, f);
fputc(0, f);
}
}

View File

@ -31,7 +31,7 @@
#include "core/core.h"
#include "file/file.h"
#include "modules/gui.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "raster/raster.h"
#include "widgets/statebar.h"
@ -441,7 +441,7 @@ void fop_operate(FileOp *fop)
bool loadres;
/* default palette */
memcpy(fop->seq.palette, default_palette, sizeof(PALETTE));
palette_black(fop->seq.palette);
/* TODO set_palette for each frame??? */
#define SEQUENCE_IMAGE() \
@ -453,7 +453,11 @@ void fop_operate(FileOp *fop)
\
layer_add_cel(fop->seq.layer, fop->seq.last_cel); \
\
sprite_set_palette(fop->sprite, fop->seq.palette, frame); \
if (palette_count_diff(sprite_get_palette(fop->sprite, frame), \
fop->seq.palette, NULL, NULL) > 0) { \
fop->seq.palette->frame = frame; \
sprite_set_palette(fop->sprite, fop->seq.palette, TRUE); \
} \
\
old_image = fop->seq.image; \
fop->seq.image = NULL; \
@ -585,11 +589,10 @@ void fop_operate(FileOp *fop)
image_clear(fop->seq.image, 0);
sprite_render(fop->sprite, fop->seq.image, 0, 0);
/* setup the palette */
palette_copy(fop->seq.palette,
sprite_get_palette(fop->sprite,
fop->sprite->frame));
palette_copy_colors(fop->seq.palette,
sprite_get_palette(fop->sprite,
fop->sprite->frame));
/* setup the filename to be used */
fop->filename = jlist_nth_data(fop->seq.filename_list,
@ -670,28 +673,24 @@ void fop_free(FileOp *fop)
jlist_free(fop->seq.filename_list);
}
if (fop->seq.palette)
jfree(fop->seq.palette);
if (fop->seq.palette != NULL)
palette_free(fop->seq.palette);
jfree(fop);
}
void fop_sequence_set_color(FileOp *fop, int index, int r, int g, int b)
{
assert(fop->seq.palette != NULL);
fop->seq.palette[index].r = r;
fop->seq.palette[index].g = g;
fop->seq.palette[index].b = b;
palette_set_entry(fop->seq.palette, index, _rgba(r, g, b, 255));
}
void fop_sequence_get_color(FileOp *fop, int index, int *r, int *g, int *b)
{
assert(fop->seq.palette != NULL);
ase_uint32 c = palette_get_entry(fop->seq.palette, index);
*r = fop->seq.palette[index].r;
*g = fop->seq.palette[index].g;
*b = fop->seq.palette[index].b;
*r = _rgba_getr(c);
*g = _rgba_getg(c);
*b = _rgba_getb(c);
}
Image *fop_sequence_image(FileOp *fop, int imgtype, int w, int h)
@ -867,7 +866,7 @@ static FileOp *fop_new(FileOpType type)
static void fop_prepare_for_sequence(FileOp *fop)
{
fop->seq.filename_list = jlist_new();
fop->seq.palette = jmalloc(sizeof(RGB) * 256);
fop->seq.palette = palette_new(0, MAX_PALETTE_COLORS);
}
static FileFormat *get_fileformat(const char *extension)

View File

@ -20,7 +20,6 @@
#define FILE_H
#include "jinete/jbase.h"
#include <allegro/color.h>
#include <stdio.h>
#define FILE_SUPPORT_RGB (1<<0)
@ -40,9 +39,10 @@
#define FILE_LOAD_SEQUENCE_YES (1<<2)
#define FILE_LOAD_ONE_FRAME (1<<3)
struct Image;
struct Cel;
struct Image;
struct Layer;
struct Palette;
struct Sprite;
struct FileFormat;
@ -84,7 +84,7 @@ typedef struct FileOp
/* data for sequences */
struct {
JList filename_list; /* all file names to load/save */
RGB *palette; /* palette of the sequence */
struct Palette *palette; /* palette of the sequence */
struct Image *image; /* image to be saved/loaded */
/* for the progress bar */
float progress_offset; /* progress offset from the current frame */

View File

@ -23,7 +23,7 @@
#include "file/file.h"
#include "file/fli/fli.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "raster/raster.h"
static bool load_FLI(FileOp *fop);
@ -45,14 +45,15 @@ FileFormat format_fli =
/* loads a FLI/FLC file */
static bool load_FLI(FileOp *fop)
{
#define SETPAL() \
do { \
for (c=0; c<256; c++) { \
pal[c].r = cmap[c*3]>>2; \
pal[c].g = cmap[c*3+1]>>2; \
pal[c].b = cmap[c*3+2]>>2; \
} \
sprite_set_palette(sprite, pal, frpos_out); \
#define SETPAL() \
do { \
for (c=0; c<256; c++) { \
palette_set_entry(pal, c, _rgba(cmap[c*3], \
cmap[c*3+1], \
cmap[c*3+2], 255)); \
} \
pal->frame = frpos_out; \
sprite_set_palette(sprite, pal, TRUE); \
} while (0)
unsigned char cmap[768];
@ -61,7 +62,7 @@ static bool load_FLI(FileOp *fop)
Image *bmp, *old, *image;
Sprite *sprite;
Layer *layer;
PALETTE pal;
Palette *pal;
int c, w, h;
int frpos_in;
int frpos_out;
@ -90,10 +91,12 @@ static bool load_FLI(FileOp *fop)
/* create the bitmaps */
bmp = image_new(IMAGE_INDEXED, w, h);
old = image_new(IMAGE_INDEXED, w, h);
if ((!bmp) || (!old)) {
pal = palette_new(0, MAX_PALETTE_COLORS);
if (!bmp || !old || !pal) {
fop_error(fop, _("Not enough memory.\n"));
if (bmp) image_free(bmp);
if (old) image_free(old);
if (pal) palette_free(pal);
fclose(f);
return FALSE;
}
@ -199,6 +202,7 @@ static bool load_FLI(FileOp *fop)
/* destroy the bitmaps */
image_free(bmp);
image_free(old);
palette_free(pal);
fop->sprite = sprite;
return TRUE;
@ -213,7 +217,7 @@ static bool save_FLI(FileOp *fop)
s_fli_header fli_header;
int c, frpos, times;
Image *bmp, *old;
PALETTE pal;
Palette *pal;
FILE *f;
/* prepare fli header */
@ -259,11 +263,11 @@ static bool save_FLI(FileOp *fop)
frpos<sprite->frames;
frpos++) {
/* get color map */
palette_copy(pal, sprite_get_palette(sprite, frpos));
pal = sprite_get_palette(sprite, frpos);
for (c=0; c<256; c++) {
cmap[3*c] = _rgb_scale_6[pal[c].r];
cmap[3*c+1] = _rgb_scale_6[pal[c].g];
cmap[3*c+2] = _rgb_scale_6[pal[c].b];
cmap[3*c ] = _rgba_getr(pal->color[c]);
cmap[3*c+1] = _rgba_getg(pal->color[c]);
cmap[3*c+2] = _rgba_getb(pal->color[c]);
}
/* render the frame in the bitmap */

View File

@ -31,7 +31,7 @@
#include "file/file.h"
#include "file/gif/format.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "raster/raster.h"
#include "util/autocrop.h"
@ -82,43 +82,38 @@ static bool load_GIF(FileOp *fop)
Image *image = NULL;
Image *current_image_old = NULL;
Image *current_image = NULL;
PALETTE opal, npal;
Palette *opal = NULL;
Palette *npal = NULL;
bool ret = FALSE;
int i, c;
gif = gif_load_animation(fop->filename, fop_progress, fop);
if (!gif) {
fop_error(fop, _("Error loading GIF file.\n"));
return FALSE;
goto error;
}
current_image = image_new(IMAGE_INDEXED, gif->width, gif->height);
current_image_old = image_new(IMAGE_INDEXED, gif->width, gif->height);
if (!current_image || !current_image_old) {
if (current_image) image_free(current_image);
if (current_image_old) image_free(current_image_old);
gif_destroy_animation(gif);
opal = palette_new(0, MAX_PALETTE_COLORS);
npal = palette_new(0, MAX_PALETTE_COLORS);
if (!current_image || !current_image_old || !opal || !npal) {
fop_error(fop, _("Error creating temporary image.\n"));
return FALSE;
goto error;
}
sprite = sprite_new(IMAGE_INDEXED, gif->width, gif->height);
if (!sprite) {
gif_destroy_animation(gif);
image_free(current_image);
fop_error(fop, _("Error creating sprite.\n"));
return FALSE;
goto error;
}
sprite_set_frames(sprite, gif->frames_count);
layer = layer_new(sprite);
if (!layer) {
gif_destroy_animation(gif);
image_free(current_image);
sprite_free(sprite);
fop_error(fop, _("Error creating main layer.\n"));
return FALSE;
goto error;
}
layer_add_layer(sprite->set, layer);
@ -139,26 +134,26 @@ static bool load_GIF(FileOp *fop)
/* make the palette */
for (c=0; c<pal->colors_count; c++) {
npal[c].r = pal->colors[c].r>>2;
npal[c].g = pal->colors[c].g>>2;
npal[c].b = pal->colors[c].b>>2;
palette_set_entry(npal, c, _rgba(pal->colors[c].r,
pal->colors[c].g,
pal->colors[c].b, 255));
}
if (i == 0)
for (; c<256; c++)
npal[c].r = npal[c].g = npal[c].b = 0;
palette_set_entry(npal, c, _rgba(0, 0, 0, 255));
else
for (; c<256; c++) {
npal[c].r = opal[c].r;
npal[c].g = opal[c].g;
npal[c].b = opal[c].b;
palette_set_entry(npal, c, palette_get_entry(opal, c));
}
/* first frame or palette changes */
if (i == 0 || palette_diff(opal, npal, NULL, NULL))
sprite_set_palette(sprite, npal, i);
if (i == 0 || palette_count_diff(opal, npal, NULL, NULL)) {
npal->frame = i;
sprite_set_palette(sprite, npal, TRUE);
}
/* copy new palette to old palette */
palette_copy(opal, npal);
palette_copy_colors(opal, npal);
cel = cel_new(i, 0);
image = image_new(IMAGE_INDEXED,
@ -248,12 +243,18 @@ static bool load_GIF(FileOp *fop)
#endif
}
gif_destroy_animation(gif);
image_free(current_image);
image_free(current_image_old);
fop->sprite = sprite;
return TRUE;
sprite = NULL;
ret = TRUE;
error:;
if (gif) gif_destroy_animation(gif);
if (current_image) image_free(current_image);
if (current_image_old) image_free(current_image_old);
if (npal) palette_free(npal);
if (opal) palette_free(opal);
if (sprite) sprite_free(sprite);
return ret;
}
/* TODO: find the colors that are used and resort the palette */
@ -284,7 +285,7 @@ static bool save_GIF(FileOp *fop)
int u1, v1, u2, v2;
int i1, j1, i2, j2;
Image *bmp, *old;
PALETTE opal, npal;
Palette *opal, *npal;
int c, i, x, y;
int w, h;
int ret;
@ -321,9 +322,10 @@ static bool save_GIF(FileOp *fop)
/* avoid compilation warnings */
x1 = y1 = x2 = y2 = 0;
for (i = 0; i < sprite->frames; i++) {
opal = NULL;
for (i=0; i<sprite->frames; ++i) {
/* frame palette */
palette_copy(npal, sprite_get_palette(sprite, i));
npal = sprite_get_palette(sprite, i);
/* render the frame in the bitmap */
image_clear(bmp, 0);
@ -333,10 +335,10 @@ static bool save_GIF(FileOp *fop)
if (i == 0) {
/* TODO: don't use 256 colors, but only as much as needed. */
gif->palette.colors_count = max_used_index(bmp)+1;
for (c = 0; c < gif->palette.colors_count; c++) {
gif->palette.colors[c].r = _rgb_scale_6[npal[c].r];
gif->palette.colors[c].g = _rgb_scale_6[npal[c].g];
gif->palette.colors[c].b = _rgb_scale_6[npal[c].b];
for (c=0; c<gif->palette.colors_count; ++c) {
gif->palette.colors[c].r = _rgba_getr(npal->color[c]);
gif->palette.colors[c].g = _rgba_getg(npal->color[c]);
gif->palette.colors[c].b = _rgba_getb(npal->color[c]);
}
/* render all */
@ -401,12 +403,12 @@ static bool save_GIF(FileOp *fop)
#endif
/* palette changes */
if (palette_diff(opal, npal, NULL, NULL) > 0) {
if (opal != npal) {
gif->frames[i].palette.colors_count = max_used_index(bmp)+1;
for (c = 0; c < gif->frames[i].palette.colors_count; c++) {
gif->frames[i].palette.colors[c].r = _rgb_scale_6[npal[c].r];
gif->frames[i].palette.colors[c].g = _rgb_scale_6[npal[c].g];
gif->frames[i].palette.colors[c].b = _rgb_scale_6[npal[c].b];
for (c=0; c<gif->frames[i].palette.colors_count; ++c) {
gif->frames[i].palette.colors[c].r = _rgba_getr(npal->color[c]);
gif->frames[i].palette.colors[c].g = _rgba_getg(npal->color[c]);
gif->frames[i].palette.colors[c].b = _rgba_getb(npal->color[c]);
}
}
}
@ -433,7 +435,7 @@ static bool save_GIF(FileOp *fop)
/* update the old image and color-map to the new ones to compare later */
image_copy(old, bmp, 0, 0);
palette_copy(opal, npal);
opal = npal;
}
ret = gif_save_animation(fop->filename, gif, fop_progress, fop);

View File

@ -64,7 +64,7 @@ static bool save_ICO(FileOp *fop)
fputw(1, f); /* resource type: ICON */
fputw(num, f); /* number of icons */
for(n = 0; n < num; n++) {
for (n=0; n<num; ++n) {
depth = 8;/* bitmap_color_depth(bmp[n]); */
bpp = (depth == 8) ? 8 : 24;
bw = (((fop->sprite->w * bpp / 8) + 3) / 4) * 4;
@ -91,7 +91,7 @@ static bool save_ICO(FileOp *fop)
fop->sprite->w,
fop->sprite->h);
for (n = 0; n < num; n++) {
for (n=0; n<num; ++n) {
image_clear(bmp, 0);
layer_render(fop->sprite->set, bmp, 0, 0, n);
@ -119,21 +119,21 @@ static bool save_ICO(FileOp *fop)
/* PALETTE */
if (bpp == 8) {
RGB *pal = sprite_get_palette(fop->sprite, n);
Palette *pal = sprite_get_palette(fop->sprite, n);
fputl(0, f); /* color 0 is black, so the XOR mask works */
for (i = 1; i<256; i++) {
fputc(_rgb_scale_6[pal[i].b], f);
fputc(_rgb_scale_6[pal[i].g], f);
fputc(_rgb_scale_6[pal[i].r], f);
for (i=1; i<256; i++) {
fputc(_rgba_getb(pal->color[i]), f);
fputc(_rgba_getg(pal->color[i]), f);
fputc(_rgba_getr(pal->color[i]), f);
fputc(0, f);
}
}
/* XOR MASK */
for (y = bmp->h - 1; y >= 0; y--) {
for (x = 0; x < bmp->w; x++) {
for (y=bmp->h-1; y>=0; --y) {
for (x=0; x<bmp->w; ++x) {
if (bpp == 8) {
fputc(image_getpixel(bmp, x, y), f);
}
@ -146,20 +146,20 @@ static bool save_ICO(FileOp *fop)
}
/* every scanline must be 32-bit aligned */
while (x&3) {
while (x & 3) {
fputc(0, f);
x++;
}
}
/* AND MASK */
for (y = bmp->h - 1; y >= 0; y--) {
for (x = 0; x < (bmp->w + 7)/8; x++) {
for (y=bmp->h-1; y>=0; --y) {
for (x=0; x<(bmp->w+7)/8; ++x) {
m = 0;
v = 128;
for (b = 0; b < 8; b++) {
c = image_getpixel(bmp, x * 8 + b, y);
for (b=0; b<8; b++) {
c = image_getpixel(bmp, x*8+b, y);
if (c == 0/* bitmap_mask_color(bmp) */)
m += v;
v /= 2;
@ -169,7 +169,7 @@ static bool save_ICO(FileOp *fop)
}
/* every scanline must be 32-bit aligned */
while (x&3) {
while (x & 3) {
fputc(0, f);
x++;
}

View File

@ -160,7 +160,7 @@ static bool load_JPEG(FileOp *fop)
/* generate a grayscale palette if is necessary */
if (image->imgtype == IMAGE_GRAYSCALE)
for (c=0; c<256; c++)
fop_sequence_set_color(fop, c, c >> 2, c >> 2, c >> 2);
fop_sequence_set_color(fop, c, c, c, c);
/* read each scan line */
while (cinfo.output_scanline < cinfo.output_height) {

View File

@ -73,9 +73,9 @@ static bool load_PCX(FileOp *fop)
fgetl(f); /* skip DPI values */
for (c=0; c<16; c++) { /* read the 16 color palette */
r = fgetc(f) / 4;
g = fgetc(f) / 4;
b = fgetc(f) / 4;
r = fgetc(f);
g = fgetc(f);
b = fgetc(f);
fop_sequence_set_color(fop, c, r, g, b);
}
@ -153,9 +153,9 @@ static bool load_PCX(FileOp *fop)
while ((c = fgetc(f)) != EOF) {
if (c == 12) {
for (c=0; c<256; c++) {
r = fgetc(f) / 4;
g = fgetc(f) / 4;
b = fgetc(f) / 4;
r = fgetc(f);
g = fgetc(f);
b = fgetc(f);
fop_sequence_set_color(fop, c, r, g, b);
}
break;
@ -214,9 +214,9 @@ static bool save_PCX(FileOp *fop)
for (c=0; c<16; c++) {
fop_sequence_get_color(fop, c, &r, &g, &b);
fputc(_rgb_scale_6[r], f);
fputc(_rgb_scale_6[g], f);
fputc(_rgb_scale_6[b], f);
fputc(r, f);
fputc(g, f);
fputc(b, f);
}
fputc(0, f); /* reserved */
@ -284,9 +284,9 @@ static bool save_PCX(FileOp *fop)
for (c=0; c<256; c++) {
fop_sequence_get_color(fop, c, &r, &g, &b);
fputc(_rgb_scale_6[r], f);
fputc(_rgb_scale_6[g], f);
fputc(_rgb_scale_6[b], f);
fputc(r, f);
fputc(g, f);
fputc(b, f);
}
}

View File

@ -189,9 +189,9 @@ static bool load_PNG(FileOp *fop)
for (c = 0; c < num_palette; c++) {
fop_sequence_set_color(fop, c,
palette[c].red / 4,
palette[c].green / 4,
palette[c].blue / 4);
palette[c].red,
palette[c].green,
palette[c].blue);
}
for (; c < 256; c++) {
fop_sequence_set_color(fop, c, 0, 0, 0);
@ -381,9 +381,9 @@ static bool save_PNG(FileOp *fop)
/* ... set palette colors ... */
for (c = 0; c < PNG_MAX_PALETTE_LENGTH; c++) {
fop_sequence_get_color(fop, c, &r, &g, &b);
palette[c].red = _rgb_scale_6[r];
palette[c].green = _rgb_scale_6[g];
palette[c].blue = _rgb_scale_6[b];
palette[c].red = r;
palette[c].green = g;
palette[c].blue = b;
}
png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH);

View File

@ -267,9 +267,9 @@ static bool load_TGA(FileOp *fop)
for (i=0; i<palette_colors; i++) {
fop_sequence_set_color(fop, i,
image_palette[i][2] >> 2,
image_palette[i][1] >> 2,
image_palette[i][0] >> 2);
image_palette[i][2],
image_palette[i][1],
image_palette[i][0]);
}
type = IMAGE_INDEXED;
@ -295,7 +295,7 @@ static bool load_TGA(FileOp *fop)
}
for (i=0; i<256; i++)
fop_sequence_set_color(fop, i, i>>2, i>>2, i>>2);
fop_sequence_set_color(fop, i, i, i, i);
type = IMAGE_GRAYSCALE;
break;
@ -431,9 +431,9 @@ static bool save_TGA(FileOp *fop)
if (need_pal) {
for (y=0; y<256; y++) {
fop_sequence_get_color(fop, y, &r, &g, &b);
image_palette[y][2] = _rgb_scale_6[r];
image_palette[y][1] = _rgb_scale_6[g];
image_palette[y][0] = _rgb_scale_6[b];
image_palette[y][2] = r;
image_palette[y][1] = g;
image_palette[y][0] = b;
}
fwrite(image_palette, 1, 768, f);
}

View File

@ -402,6 +402,8 @@ static bool button_msg_proc(JWidget widget, JMessage msg)
case JM_BUTTONRELEASED:
if (jwidget_has_capture(widget)) {
jwidget_release_mouse(widget);
if (jwidget_has_mouse(widget)) {
switch (widget->type) {
@ -421,7 +423,6 @@ static bool button_msg_proc(JWidget widget, JMessage msg)
break;
}
}
jwidget_release_mouse(widget);
return TRUE;
}
break;

View File

@ -113,13 +113,14 @@ static JWidget convert_tag_to_widget(JXmlElem elem)
bool right = jxmlelem_has_attr(elem, "right");
bool top = jxmlelem_has_attr(elem, "top");
bool bottom = jxmlelem_has_attr(elem, "bottom");
char *bevel = jxmlelem_get_attr(elem, "bevel");
const char *_bevel = jxmlelem_get_attr(elem, "bevel");
jwidget_set_align(widget,
(left ? JI_LEFT: (right ? JI_RIGHT: JI_CENTER)) |
(top ? JI_TOP: (bottom ? JI_BOTTOM: JI_MIDDLE)));
if (bevel != NULL) {
if (_bevel != NULL) {
char *bevel = jstrdup(_bevel);
int c, b[4];
char *tok;
@ -132,6 +133,8 @@ static JWidget convert_tag_to_widget(JXmlElem elem)
if (c < 4)
b[c] = ustrtol(tok, NULL, 10);
}
jfree(bevel);
jbutton_set_bevel(widget, b[0], b[1], b[2], b[3]);
}
}

View File

@ -153,6 +153,13 @@ static bool grid_msg_proc(JWidget widget, JMessage msg)
jfree(grid->cells[row]);
jfree(grid->cells);
}
if (grid->colstrip != NULL)
jfree(grid->colstrip);
if (grid->rowstrip != NULL)
jfree(grid->rowstrip);
jfree(grid);
break;

View File

@ -125,17 +125,23 @@ void _ji_set_font_of_all_widgets(struct FONT *f)
{
int c;
/* first of all, we have to set the font to all the widgets */
for (c=0; c<nwidgets; c++)
if (_ji_is_valid_widget(widgets[c])) {
if (_ji_is_valid_widget(widgets[c]))
jwidget_set_font(widgets[c], f);
jwidget_init_theme(widgets[c]);
}
/* then we can reinitialize the theme of each widget */
for (c=0; c<nwidgets; c++)
if (_ji_is_valid_widget(widgets[c]))
jwidget_init_theme(widgets[c]);
/* remap the windows */
for (c=0; c<nwidgets; c++)
if (_ji_is_valid_widget(widgets[c])) {
if (widgets[c]->type == JI_WINDOW)
jwindow_remap(widgets[c]);
}
/* refresh the screen */
jmanager_refresh_screen();
}

View File

@ -221,14 +221,14 @@ void jmanager_free(JWidget widget)
/* no more cursor */
jmouse_set_cursor(JI_CURSOR_NULL);
/* destroy filters */
for (c=0; c<NFILTERS; ++c) {
JI_LIST_FOR_EACH(msg_filters[c], link) {
filter_free(link->data);
}
jlist_free(msg_filters[c]);
msg_filters[c] = NULL;
}
/* finish theme */
ji_set_theme(NULL);
/* destroy clipboard */
jclipboard_set_text(NULL);
/* destroy this widget */
jwidget_free(widget);
/* destroy timers */
if (timers != NULL) {
@ -239,14 +239,14 @@ void jmanager_free(JWidget widget)
n_timers = 0;
}
/* finish theme */
ji_set_theme(NULL);
/* destroy clipboard */
jclipboard_set_text(NULL);
/* destroy this widget */
jwidget_free(widget);
/* destroy filters */
for (c=0; c<NFILTERS; ++c) {
JI_LIST_FOR_EACH(msg_filters[c], link) {
filter_free(link->data);
}
jlist_free(msg_filters[c]);
msg_filters[c] = NULL;
}
/* no more default manager */
default_manager = NULL;
@ -374,118 +374,114 @@ bool jmanager_generate_messages(JWidget manager)
destination = mouse_widget;
/* send the mouse movement message */
if (destination) {
msg = new_mouse_msg(JM_MOTION, destination);
jmanager_enqueue_message(msg);
}
msg = new_mouse_msg(JM_MOTION, destination);
jmanager_enqueue_message(msg);
generate_setcursor_message();
}
}
/* mouse wheel */
if (jmouse_z(0) != jmouse_z(1)) {
if (capture_widget || mouse_widget) {
msg = new_mouse_msg(JM_WHEEL,
capture_widget ? capture_widget:
mouse_widget);
jmanager_enqueue_message(msg);
}
msg = new_mouse_msg(JM_WHEEL,
capture_widget ? capture_widget:
mouse_widget);
jmanager_enqueue_message(msg);
}
/* mouse clicks */
if ((jmouse_b(0) != jmouse_b(1)) &&
((!jmouse_b(0)) || (!jmouse_b(1)))) {
if (capture_widget || mouse_widget) {
int current_ticks = ji_clock;
int current_ticks = ji_clock;
msg = new_mouse_msg(!jmouse_b(1) ? JM_BUTTONPRESSED:
JM_BUTTONRELEASED,
capture_widget ? capture_widget:
mouse_widget);
msg = new_mouse_msg(!jmouse_b(1) ? JM_BUTTONPRESSED:
JM_BUTTONRELEASED,
capture_widget ? capture_widget:
mouse_widget);
/**********************************************************************/
/* Double Click */
if (msg->type == JM_BUTTONPRESSED) {
if (double_click_level != DOUBLE_CLICK_NONE) {
/* time out, back to NONE */
if (current_ticks - double_click_ticks > DOUBLE_CLICK_TIMEOUT_MSECS) {
double_click_level = DOUBLE_CLICK_NONE;
/**********************************************************************/
/* Double Click */
if (msg->type == JM_BUTTONPRESSED) {
if (double_click_level != DOUBLE_CLICK_NONE) {
/* time out, back to NONE */
if (current_ticks - double_click_ticks > DOUBLE_CLICK_TIMEOUT_MSECS) {
double_click_level = DOUBLE_CLICK_NONE;
}
else if (double_click_buttons == msg->mouse.flags) {
if (double_click_level == DOUBLE_CLICK_UP) {
msg->type = JM_DOUBLECLICK;
}
else if (double_click_buttons == msg->mouse.flags) {
if (double_click_level == DOUBLE_CLICK_UP) {
msg->type = JM_DOUBLECLICK;
}
else {
double_click_level = DOUBLE_CLICK_NONE;
}
}
/* press other button, back to NONE */
else {
double_click_level = DOUBLE_CLICK_NONE;
}
}
/* this could be the beginning of the state */
if (double_click_level == DOUBLE_CLICK_NONE) {
double_click_level = DOUBLE_CLICK_DOWN;
double_click_buttons = msg->mouse.flags;
double_click_ticks = current_ticks;
}
}
else if (msg->type == JM_BUTTONRELEASED) {
if (double_click_level != DOUBLE_CLICK_NONE) {
/* time out, back to NONE */
if (current_ticks - double_click_ticks > DOUBLE_CLICK_TIMEOUT_MSECS) {
double_click_level = DOUBLE_CLICK_NONE;
}
else if (double_click_buttons == msg->mouse.flags) {
if (double_click_level == DOUBLE_CLICK_DOWN) {
double_click_level = DOUBLE_CLICK_UP;
double_click_ticks = current_ticks;
}
}
/* press other button, back to NONE */
else {
double_click_level = DOUBLE_CLICK_NONE;
}
/* press other button, back to NONE */
else {
double_click_level = DOUBLE_CLICK_NONE;
}
}
/* Z-Order:
Send the window to top (only when you click in a window
that aren't the desktop) */
if (!capture_widget && msg->type == JM_BUTTONPRESSED) {
JWidget window = jwidget_get_window(mouse_widget);
JWidget win_manager = window ? jwidget_get_manager(window): NULL;
if ((window) &&
(!jwindow_is_desktop(window)) &&
(window != TOPWND(win_manager))) {
/* put it in the top of the list */
jlist_remove(win_manager->children, window);
if (jwindow_is_ontop(window))
jlist_prepend(win_manager->children, window);
else {
int pos = jlist_length(win_manager->children);
JI_LIST_FOR_EACH_BACK(win_manager->children, link) {
if (jwindow_is_ontop((JWidget)link->data))
break;
pos--;
}
jlist_insert(win_manager->children, window, pos);
}
generate_proc_windows_list();
jwidget_dirty(window);
}
/* put the focus */
jmanager_set_focus(mouse_widget);
/* this could be the beginning of the state */
if (double_click_level == DOUBLE_CLICK_NONE) {
double_click_level = DOUBLE_CLICK_DOWN;
double_click_buttons = msg->mouse.flags;
double_click_ticks = current_ticks;
}
jmanager_enqueue_message(msg);
}
else if (msg->type == JM_BUTTONRELEASED) {
if (double_click_level != DOUBLE_CLICK_NONE) {
/* time out, back to NONE */
if (current_ticks - double_click_ticks > DOUBLE_CLICK_TIMEOUT_MSECS) {
double_click_level = DOUBLE_CLICK_NONE;
}
else if (double_click_buttons == msg->mouse.flags) {
if (double_click_level == DOUBLE_CLICK_DOWN) {
double_click_level = DOUBLE_CLICK_UP;
double_click_ticks = current_ticks;
}
}
/* press other button, back to NONE */
else {
double_click_level = DOUBLE_CLICK_NONE;
}
}
}
/* Z-Order:
Send the window to top (only when you click in a window
that aren't the desktop) */
if (msg->type == JM_BUTTONPRESSED &&
!capture_widget && mouse_widget) {
JWidget window = jwidget_get_window(mouse_widget);
JWidget win_manager = window ? jwidget_get_manager(window): NULL;
if ((window) &&
(!jwindow_is_desktop(window)) &&
(window != TOPWND(win_manager))) {
/* put it in the top of the list */
jlist_remove(win_manager->children, window);
if (jwindow_is_ontop(window))
jlist_prepend(win_manager->children, window);
else {
int pos = jlist_length(win_manager->children);
JI_LIST_FOR_EACH_BACK(win_manager->children, link) {
if (jwindow_is_ontop((JWidget)link->data))
break;
pos--;
}
jlist_insert(win_manager->children, window, pos);
}
generate_proc_windows_list();
jwidget_dirty(window);
}
/* put the focus */
jmanager_set_focus(mouse_widget);
}
jmanager_enqueue_message(msg);
}
/* generate JM_CHAR/JM_KEYPRESSED messages */
@ -654,6 +650,14 @@ void jmanager_stop_timer(int timer_id)
timers[timer_id]->last_time = -1;
}
void jmanager_set_timer_interval(int timer_id, int interval)
{
assert(timer_id >= 0 && timer_id < n_timers);
assert(timers[timer_id] != NULL);
timers[timer_id]->interval = interval;
}
/**
* @param msg You can't use the this message after calling this
* routine. The message will be automatically freed through
@ -681,8 +685,12 @@ void jmanager_enqueue_message(JMessage msg)
jmessage_add_pre_dest(msg, filter->widget);
}
}
jlist_append(msg_queue, msg);
/* there are a destination widget at least? */
if (!jlist_empty(msg->any.widgets))
jlist_append(msg_queue, msg);
else
jmessage_free(msg);
}
JWidget jmanager_get_focus(void)
@ -945,6 +953,22 @@ void jmanager_remove_msg_filter(int message, JWidget widget)
}
}
void jmanager_remove_msg_filter_for(JWidget widget)
{
JLink link, next;
int c;
for (c=0; c<NFILTERS; ++c) {
JI_LIST_FOR_EACH_SAFE(msg_filters[c], link, next) {
Filter *filter = link->data;
if (filter->widget == widget) {
filter_free(filter);
jlist_delete_link(msg_filters[c], link);
}
}
}
}
/* configures the window for begin the loop */
void _jmanager_open_window(JWidget manager, JWidget window)
{
@ -1371,7 +1395,8 @@ static void generate_proc_windows_list2(JWidget widget)
JI_LIST_FOR_EACH(widget->children, link) {
window = link->data;
jlist_append(proc_windows_list, window);
if (jwindow_is_foreground(window) || jwindow_is_desktop(window))
if (jwindow_is_foreground(window) ||
jwindow_is_desktop(window))
break;
}
}
@ -1423,8 +1448,8 @@ static JMessage new_mouse_msg(int type, JWidget widget)
msg->mouse.right = msg->mouse.flags & 2 ? TRUE: FALSE;
msg->mouse.middle = msg->mouse.flags & 4 ? TRUE: FALSE;
assert(widget != NULL);
jmessage_add_dest(msg, widget);
if (widget != NULL)
jmessage_add_dest(msg, widget);
return msg;
}

View File

@ -51,6 +51,7 @@ int jmanager_add_timer(JWidget widget, int interval);
void jmanager_remove_timer(int timer_id);
void jmanager_start_timer(int timer_id);
void jmanager_stop_timer(int timer_id);
void jmanager_set_timer_interval(int timer_id, int interval);
/* routines that uses the ji_get_default_manager() */
@ -75,6 +76,7 @@ void jmanager_refresh_screen(void);
void jmanager_add_msg_filter(int message, JWidget widget);
void jmanager_remove_msg_filter(int message, JWidget widget);
void jmanager_remove_msg_filter_for(JWidget widget);
JI_END_DECLS

View File

@ -225,7 +225,7 @@ char *jstrdup(const char *string)
mem = ustrdup(string);
if (mem != NULL)
addslot(mem, strlen(mem));
addslot(mem, ustrsizez(mem));
return mem;
}

View File

@ -141,6 +141,7 @@ static void close_menuitem(JWidget menuitem, bool last_of_close_chain);
static void close_popup(JWidget menubox);
static void close_all(JWidget menu);
static void exe_menuitem(JWidget menuitem);
static bool window_msg_proc(JWidget widget, JMessage msg);
static JWidget check_for_letter(JWidget menu, int ascii);
static JWidget check_for_accel(JWidget menu, JMessage msg);
@ -329,10 +330,8 @@ void jmenu_popup(JWidget menu, int x, int y)
menubox = jmenubox_new();
base = create_base(menubox);
base->was_clicked = TRUE;
base->is_filtering = TRUE;
jmanager_add_msg_filter(JM_BUTTONPRESSED, menubox);
jwindow_moveable(window, FALSE); /* can't move the window */
@ -355,10 +354,10 @@ void jmenu_popup(JWidget menu, int x, int y)
/* open the window */
jwindow_open_fg(window);
/* free focus */
/* free the keyboard focus */
jmanager_free_focus();
/* fetch the "menu" */
/* fetch the "menu" so it isn't destroyed */
jmenubox_set_menu(menubox, NULL);
/* destroy the window */
@ -492,7 +491,7 @@ static bool menubox_msg_proc(JWidget widget, JMessage msg)
if (!msg->mouse.flags && !get_base(widget)->was_clicked)
break;
/* fall through */
/* fall though */
case JM_BUTTONPRESSED:
if (menu) {
@ -841,6 +840,8 @@ static bool menuitem_msg_proc(JWidget widget, JMessage msg)
/* new window and new menu-box */
window = jwindow_new(NULL);
jwidget_add_hook(window, -1, window_msg_proc, NULL);
menubox = jmenubox_new();
menuitem->submenu_menubox = menubox;
@ -966,7 +967,7 @@ static bool menuitem_msg_proc(JWidget widget, JMessage msg)
else
jmanager_set_focus(widget->parent->parent);
/* isn't necessary to free this window because it's
/* is not necessary to free this window because it's
automatically destroyed by the manager
... jwidget_free(window);
*/
@ -1018,8 +1019,7 @@ static void menuitem_request_size(JWidget widget, int *w, int *h)
}
/**
* Clims the hierarchy of menus to get the 'base' of the most-top
* menubox.
* Clims the hierarchy of menus to get the most-top menubox.
*/
static JWidget get_base_menubox(JWidget widget)
{
@ -1305,6 +1305,19 @@ static void exe_menuitem(JWidget menuitem)
jmanager_enqueue_message(msg);
}
static bool window_msg_proc(JWidget widget, JMessage msg)
{
switch (msg->type) {
case JM_CLOSE:
jwidget_free_deferred(widget);
break;
}
return FALSE;
}
static JWidget check_for_letter(JWidget menu, int ascii)
{
JWidget menuitem;

View File

@ -147,23 +147,18 @@ static bool slider_msg_proc(JWidget widget, JMessage msg)
case JM_MOTION:
if (jwidget_has_capture(widget)) {
JRect rect = jrect_new(0, 0, JI_SCREEN_W, JI_SCREEN_H);
int value, accuracy, range;
int xbeg = widget->rc->x1
+ widget->border_width.l;
int width = jrect_w(widget->rc)
- widget->border_width.l
- widget->border_width.r;
JRect rc = jwidget_get_child_rect(widget);
range = slider->max - slider->min + 1;
/* with left click */
if (slider_press_left) {
value = slider->min + range * (msg->mouse.x - xbeg) / width;
value = slider->min + range * (msg->mouse.x - rc->x1) / jrect_w(rc);
}
/* with right click */
else {
accuracy = MID(1, width / range, width);
accuracy = MID(1, jrect_w(rc) / range, jrect_w(rc));
value = slider_press_value +
(msg->mouse.x - slider_press_x) / accuracy;
@ -180,21 +175,21 @@ static bool slider_msg_proc(JWidget widget, JMessage msg)
if (slider_press_left) {
int x = jmouse_x(0);
if (x < widget->rc->x1 + widget->border_width.l)
x = widget->rc->x1 + widget->border_width.l;
else if (x > widget->rc->x2 - widget->border_width.r)
x = widget->rc->x2 - widget->border_width.r;
if (x < rc->x1-1)
x = rc->x1-1;
else if (x > rc->x2)
x = rc->x2;
if (x != jmouse_x(0))
jmouse_set_position(x, jmouse_y(0));
}
/* for right click */
else if (jmouse_control_infinite_scroll(rect)) {
else if (jmouse_control_infinite_scroll(rc)) {
slider_press_x = jmouse_x(0);
slider_press_value = slider->value;
}
jrect_free(rect);
jrect_free(rc);
return TRUE;
}
break;

View File

@ -451,7 +451,7 @@ static void update_mouse_position(void)
RECT rc;
if (GetCursorPos(&pt) && GetClientRect(win_get_window(), &rc)) {
MapWindowPoints(win_get_window(), NULL, (POINT *)&rc, 2);
MapWindowPoints(win_get_window(), NULL, (LPPOINT)&rc, 2);
if (!PtInRect(&rc, pt)) {
/* if the mouse is free we can hide the cursor putting the

View File

@ -78,6 +78,11 @@ JWidget jtooltip_window_new(const char *text)
return window;
}
/**
* @param widget The tooltip window.
* @param region The new hot-region. This pointer is holded by the @a widget.
* So you can't destroy it after calling this routine.
*/
void jtooltip_window_set_hotregion(JWidget widget, JRegion region)
{
TipWindow *tipwindow = tipwindow_data(widget);
@ -85,11 +90,13 @@ void jtooltip_window_set_hotregion(JWidget widget, JRegion region)
assert(region != NULL);
if (tipwindow->hot_region != NULL)
jfree(tipwindow->hot_region);
jregion_free(tipwindow->hot_region);
if (!tipwindow->filtering) {
tipwindow->filtering = TRUE;
jmanager_add_msg_filter(JM_MOTION, widget);
jmanager_add_msg_filter(JM_BUTTONPRESSED, widget);
jmanager_add_msg_filter(JM_KEYPRESSED, widget);
}
tipwindow->hot_region = region;
}
@ -191,7 +198,6 @@ static JWidget tipwindow_new(const char *text, bool close_on_buttonpressed)
jwidget_add_hook(window, tipwindow_type(),
tipwindow_msg_proc, tipwindow);
jwidget_init_theme(window);
jwidget_set_bg_color(window, makecol(255, 255, 200));
return window;
}
@ -220,10 +226,18 @@ static bool tipwindow_msg_proc(JWidget widget, JMessage msg)
if (tipwindow->filtering) {
tipwindow->filtering = FALSE;
jmanager_remove_msg_filter(JM_MOTION, widget);
jmanager_remove_msg_filter(JM_BUTTONPRESSED, widget);
jmanager_remove_msg_filter(JM_KEYPRESSED, widget);
}
break;
case JM_DESTROY:
if (tipwindow->filtering) {
tipwindow->filtering = FALSE;
jmanager_remove_msg_filter(JM_MOTION, widget);
jmanager_remove_msg_filter(JM_BUTTONPRESSED, widget);
jmanager_remove_msg_filter(JM_KEYPRESSED, widget);
}
if (tipwindow->hot_region != NULL) {
jregion_free(tipwindow->hot_region);
}
@ -273,6 +287,9 @@ static bool tipwindow_msg_proc(JWidget widget, JMessage msg)
_ji_theme_textbox_draw(NULL, widget, &w, &h, 0, 0);
widget->border_width.t = h-3;
/* setup the background color */
jwidget_set_bg_color(widget, makecol(255, 255, 200));
return TRUE;
}
break;
@ -282,7 +299,23 @@ static bool tipwindow_msg_proc(JWidget widget, JMessage msg)
jwindow_close(widget, NULL);
break;
case JM_KEYPRESSED:
if (tipwindow->filtering && msg->key.scancode < KEY_MODIFIERS)
jwindow_close(widget, NULL);
break;
case JM_BUTTONPRESSED:
/* if the user click outside the window, we have to close the
tooltip window */
if (tipwindow->filtering) {
JWidget picked = jwidget_pick(widget, msg->mouse.x, msg->mouse.y);
if (!picked || jwidget_get_window(picked) != widget) {
jwindow_close(widget, NULL);
}
}
/* this is used when the user click inside a small text
tooltip */
if (tipwindow->close_on_buttonpressed)
jwindow_close(widget, NULL);
break;
@ -315,6 +348,8 @@ static bool tipwindow_msg_proc(JWidget widget, JMessage msg)
widget->bg_color,
ji_color_foreground());
widget->border_width.t = oldt;
jrect_free(pos);
return TRUE;
}

View File

@ -122,6 +122,7 @@ void jwidget_free(JWidget widget)
/* break relationship with the manager */
jmanager_free_widget(widget);
jmanager_remove_messages_for(widget);
jmanager_remove_msg_filter_for(widget);
/* remove from parent */
if (widget->parent)

View File

@ -325,7 +325,7 @@ static bool window_msg_proc(JWidget widget, JMessage msg)
if (!window->is_moveable)
break;
if (!click_pos)
if (click_pos == NULL)
click_pos = jrect_new_copy(widget->rc);
else
jrect_copy(click_pos, widget->rc);
@ -346,7 +346,7 @@ static bool window_msg_proc(JWidget widget, JMessage msg)
jwidget_release_mouse(widget);
jmouse_set_cursor(JI_CURSOR_NORMAL);
if (click_pos) {
if (click_pos != NULL) {
jrect_free(click_pos);
click_pos = NULL;
}

View File

@ -23,7 +23,7 @@
#include "core/app.h"
#include "modules/editors.h"
#include "modules/gui.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "modules/sprites.h"
#include "raster/image.h"
#include "raster/sprite.h"

View File

@ -23,14 +23,18 @@
#include "jinete/jintern.h"
#include "jinete/jsystem.h"
#include "jinete/jtheme.h"
#include "console/console.h"
#include "core/app.h"
#include "core/cfg.h"
#include "core/dirs.h"
#include "modules/gfx.h"
#include "modules/gui.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "modules/tools.h"
#include "raster/blend.h"
#include "raster/image.h"
#include "widgets/editor.h"
/* static BITMAP *icons_pcx; */
@ -64,12 +68,12 @@ static void convert_data_to_bitmap(DATA *data, BITMAP **bmp)
}
}
static void gen_gfx(void)
static void gen_gfx(void *data)
{
int c;
for(c=0; c<GFX_BITMAP_COUNT; c++) {
if(gfx_bmps[c])
for (c=0; c<GFX_BITMAP_COUNT; c++) {
if (gfx_bmps[c])
destroy_bitmap(gfx_bmps[c]);
gfx_bmps[c] = NULL;
@ -101,7 +105,7 @@ int init_module_graphics(void)
for(c=0; c<GFX_BITMAP_COUNT; c++)
gfx_bmps[c] = NULL;
hook_palette_changes(gen_gfx);
app_add_hook(APP_PALETTE_CHANGE, gen_gfx, NULL);
return 0;
}
@ -109,8 +113,6 @@ void exit_module_graphics(void)
{
int c;
unhook_palette_changes(gen_gfx);
for(c=0; c<GFX_BITMAP_COUNT; c++)
if(gfx_bmps[c]) {
destroy_bitmap(gfx_bmps[c]);
@ -465,8 +467,6 @@ void rectdiscard(void *_data)
jfree(data);
}
/**********************************************************************/
/* Rectangles */
@ -520,6 +520,9 @@ void rectgrid(BITMAP *bmp, int x1, int y1, int x2, int y2, int w, int h)
}
}
/**********************************************************************/
/* Specials */
void draw_emptyset_symbol(JRect rc, int color)
{
int cx, cy, x1, y1, x2, y2, size;
@ -538,8 +541,144 @@ void draw_emptyset_symbol(JRect rc, int color)
line(ji_screen, x1, y2, x2, y1, color);
}
void draw_color(BITMAP *bmp, int x1, int y1, int x2, int y2,
int imgtype, color_t color)
{
int type = color_type(color);
int data;
int w = x2 - x1 + 1;
int h = y2 - y1 + 1;
BITMAP *graph;
int grid;
grid = MIN(w, h) / 2;
grid += MIN(w, h) - grid*2;
if (type == COLOR_TYPE_INDEX) {
data = color_get_index(imgtype, color);
rectfill(bmp, x1, y1, x2, y2,
/* get_color_for_allegro(bitmap_color_depth(bmp), color)); */
palette_color[_index_cmap[data]]);
return;
}
switch (imgtype) {
case IMAGE_INDEXED:
rectfill(bmp, x1, y1, x2, y2,
palette_color[_index_cmap[get_color_for_image(imgtype, color)]]);
break;
case IMAGE_RGB:
graph = create_bitmap_ex(32, w, h);
if (!graph)
return;
rectgrid(graph, 0, 0, w-1, h-1, grid, grid);
drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
set_trans_blender(0, 0, 0, color_get_alpha(imgtype, color));
{
int rgb_bitmap_color = get_color_for_image(imgtype, color);
color_t color2 = color_rgb(_rgba_getr(rgb_bitmap_color),
_rgba_getg(rgb_bitmap_color),
_rgba_getb(rgb_bitmap_color),
_rgba_geta(rgb_bitmap_color));
rectfill(graph, 0, 0, w-1, h-1, get_color_for_allegro(32, color2));
}
drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
use_current_sprite_rgb_map();
blit(graph, bmp, 0, 0, x1, y1, w, h);
restore_rgb_map();
destroy_bitmap(graph);
break;
case IMAGE_GRAYSCALE:
graph = create_bitmap_ex(32, w, h);
if (!graph)
return;
rectgrid(graph, 0, 0, w-1, h-1, grid, grid);
drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
set_trans_blender(0, 0, 0, color_get_alpha(imgtype, color));
{
int gray_bitmap_color = get_color_for_image(imgtype, color);
color_t color2 = color_gray(_graya_getv(gray_bitmap_color),
_graya_geta(gray_bitmap_color));
rectfill(graph, 0, 0, w-1, h-1, get_color_for_allegro(32, color2));
}
drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
use_current_sprite_rgb_map();
blit(graph, bmp, 0, 0, x1, y1, w, h);
restore_rgb_map();
destroy_bitmap(graph);
break;
}
}
void draw_color_button(BITMAP *bmp,
int x1, int y1, int x2, int y2,
int b0, int b1, int b2, int b3,
int imgtype, color_t color,
bool hot)
{
int face = ji_color_face();
int fore = ji_color_foreground();
draw_color(bmp, x1, y1, x2, y2, imgtype, color);
hline(bmp, x1, y1, x2, fore);
if (b2 && b3)
hline(bmp, x1, y2, x2, fore);
vline(bmp, x1, y1, y2, fore);
vline(bmp, x2, y1, y2, fore);
if (!hot) {
int r = color_get_red(imgtype, color);
int g = color_get_green(imgtype, color);
int b = color_get_blue(imgtype, color);
int c = makecol(MIN(255, r+64),
MIN(255, g+64),
MIN(255, b+64));
rect(bmp, x1+1, y1+1, x2-1, y2-((b2 && b3)?1:0), c);
}
else {
rect(bmp, x1+1, y1+1, x2-1, y2-((b2 && b3)?1:0), fore);
bevel_box(bmp,
x1+1, y1+1, x2-1, y2-((b2 && b3)?1:0),
ji_color_facelight(), ji_color_faceshadow(), 1);
}
if (b0) {
hline(bmp, x1, y1, x1+1, face);
putpixel(bmp, x1, y1+1, face);
putpixel(bmp, x1+1, y1+1, fore);
}
if (b1) {
hline(bmp, x2-1, y1, x2, face);
putpixel(bmp, x2, y1+1, face);
putpixel(bmp, x2-1, y1+1, fore);
}
if (b2) {
putpixel(bmp, x1, y2-1, face);
hline(bmp, x1, y2, x1+1, face);
putpixel(bmp, x1+1, y2-1, fore);
}
if (b3) {
putpixel(bmp, x2, y2-1, face);
hline(bmp, x2-1, y2, x2, face);
putpixel(bmp, x2-1, y2-1, fore);
}
}
/************************************************************************/
/* Font related */

View File

@ -19,6 +19,7 @@
#ifndef MODULES_GFX_H
#define MODULES_GFX_H
#include "core/color.h"
#include "jinete/jbase.h"
struct FONT;
@ -114,6 +115,13 @@ void rectdotted(struct BITMAP *bmp, int x1, int y1, int x2, int y2, int fg, int
void rectgrid(struct BITMAP *bmp, int x1, int y1, int x2, int y2, int w, int h);
void draw_emptyset_symbol(JRect rc, int color);
void draw_color(struct BITMAP *bmp, int x1, int y1, int x2, int y2,
int imgtype, color_t color);
void draw_color_button(struct BITMAP *bmp,
int x1, int y1, int x2, int y2,
int b0, int b1, int b2, int b3,
int imgtype, color_t color,
bool hot);
int character_length(struct FONT *font, int chr);
void render_character(struct BITMAP *bmp, struct FONT *font, int chr, int x, int y, int fg, int bg);

View File

@ -41,7 +41,7 @@
#include "modules/editors.h"
#include "modules/gfx.h"
#include "modules/gui.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "modules/rootmenu.h"
#include "modules/sprites.h"
#include "raster/sprite.h"
@ -77,12 +77,6 @@ static int try_depths[] = { 32, 24, 16, 15, 8 };
/**************************************************************/
typedef struct ExitHook
{
void (*proc)(void *);
void *data;
} ExitHook;
struct Monitor
{
/* returns true when the job is done and the monitor can be removed */
@ -95,8 +89,6 @@ struct Monitor
static JWidget manager = NULL;
static JList exit_hooks;
static int monitor_timer = -1;
static JList monitors;
@ -109,9 +101,6 @@ static JList icon_buttons;
static bool double_buffering;
static int screen_scaling;
static ExitHook *exithook_new(void (*proc)(void *), void *data);
static void exithook_free(ExitHook *exithook);
static Monitor *monitor_new(void (*proc)(void *),
void (*free)(void *), void *data);
static void monitor_free(Monitor *monitor);
@ -123,7 +112,7 @@ static void save_gui_config(void);
static bool button_with_icon_msg_proc(JWidget widget, JMessage msg);
static bool manager_msg_proc(JWidget widget, JMessage msg);
static void regen_theme_and_fixup_icons(void);
static void regen_theme_and_fixup_icons(void *data);
/**
* Used by set_display_switch_callback(SWITCH_IN, ...).
@ -246,7 +235,6 @@ int init_module_gui(void)
}
gfx_done:;
exit_hooks = jlist_new();
monitors = jlist_new();
/* window title */
@ -278,7 +266,7 @@ int init_module_gui(void)
reload_default_font();
/* hook for palette change to regenerate the theme */
hook_palette_changes(regen_theme_and_fixup_icons);
app_add_hook(APP_PALETTE_CHANGE, regen_theme_and_fixup_icons, NULL);
/* icon buttons */
icon_buttons = jlist_new();
@ -293,15 +281,6 @@ void exit_module_gui(void)
{
JLink link;
/* call the ExitHooks */
JI_LIST_FOR_EACH(exit_hooks, link) {
ExitHook *exithook = link->data;
(*exithook->proc)(exithook->data);
exithook_free(link->data);
}
jlist_free(exit_hooks);
exit_hooks = NULL;
/* destroy monitors */
JI_LIST_FOR_EACH(monitors, link) {
monitor_free(link->data);
@ -319,8 +298,7 @@ void exit_module_gui(void)
}
jlist_free(icon_buttons);
unhook_palette_changes(regen_theme_and_fixup_icons);
icon_buttons = NULL;
jmanager_free(manager);
@ -329,23 +307,6 @@ void exit_module_gui(void)
remove_timer();
}
static ExitHook *exithook_new(void (*proc)(void *), void *data)
{
ExitHook *exithook = jnew(ExitHook, 1);
if (!exithook)
return NULL;
exithook->proc = proc;
exithook->data = data;
return exithook;
}
static void exithook_free(ExitHook *exithook)
{
jfree(exithook);
}
static Monitor *monitor_new(void (*proc)(void *),
void (*free)(void *), void *data)
{
@ -621,8 +582,8 @@ void rebuild_recent_list(void)
typedef struct HookData {
int signal_num;
int (*signal_handler)(JWidget widget, int user_data);
int user_data;
bool (*signal_handler)(JWidget widget, void *data);
void *data;
} HookData;
static int hook_type(void)
@ -644,7 +605,7 @@ static bool hook_handler(JWidget widget, JMessage msg)
case JM_SIGNAL: {
HookData *hook_data = jwidget_get_data(widget, hook_type());
if (hook_data->signal_num == msg->signal.num)
return (*hook_data->signal_handler)(widget, hook_data->user_data);
return (*hook_data->signal_handler)(widget, hook_data->data);
break;
}
}
@ -657,14 +618,14 @@ static bool hook_handler(JWidget widget, JMessage msg)
*/
void hook_signal(JWidget widget,
int signal_num,
int (*signal_handler)(JWidget widget, int user_data),
int user_data)
bool (*signal_handler)(JWidget widget, void *data),
void *data)
{
HookData *hook_data = jnew(HookData, 1);
hook_data->signal_num = signal_num;
hook_data->signal_handler = signal_handler;
hook_data->user_data = user_data;
hook_data->data = data;
jwidget_add_hook(widget, hook_type(), hook_handler, hook_data);
}
@ -765,17 +726,6 @@ JWidget check_button_new(const char *text, int b1, int b2, int b3, int b4)
return widget;
}
/**
* Adds a routine to be called when the @ref exit_module_gui is called.
*/
void add_gui_exit_hook(void (*proc)(void *data), void *data)
{
assert(proc != NULL);
assert(exit_hooks != NULL);
jlist_append(exit_hooks, exithook_new(proc, data));
}
/**
* Adds a routine to be called each 100 milliseconds to monitor
* whatever you want. It's mainly used to monitor the progress of a
@ -896,7 +846,7 @@ static bool manager_msg_proc(JWidget widget, JMessage msg)
/**********************************************************************/
/* graphics */
static void regen_theme_and_fixup_icons(void)
static void regen_theme_and_fixup_icons(void *data)
{
JWidget button;
JLink link;

View File

@ -21,8 +21,8 @@
#include "jinete/jbase.h"
#define HOOK(widget, signal, signal_handler, user_data) \
hook_signal((widget), (signal), (signal_handler), (int)(user_data))
#define HOOK(widget, signal, signal_handler, data) \
hook_signal((widget), (signal), (signal_handler), (void *)(data))
#define GUISCALE (JI_SCREEN_W > 512 ? 2: 1)
@ -54,8 +54,8 @@ void rebuild_recent_list(void);
void hook_signal(JWidget widget,
int signal_num,
int (*signal_handler)(JWidget widget, int user_data),
int user_data);
bool (*signal_handler)(JWidget widget, void *data),
void *data);
bool get_widgets(JWidget window, ...);
@ -66,11 +66,6 @@ JWidget radio_button_new(int radio_group, int b1, int b2, int b3, int b4);
JWidget check_button_new(const char *text, int b1, int b2, int b3, int b4);
/* void change_to_button_style(JWidget widget, int b1, int b2, int b3, int b4); */
/********************************************************************/
/* exit-hooks */
void add_gui_exit_hook(void (*proc)(void *data), void *data);
/********************************************************************/
/* monitors */

View File

@ -1,443 +0,0 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <assert.h>
#include <allegro.h>
#include <string.h>
#include "jinete/jlist.h"
#include "modules/palette.h"
#include "raster/blend.h"
#include "raster/sprite.h"
#include "util/col_file.h"
PALETTE current_palette; /* current original palette (you can
use _current_palette from Allegro
to refer to the current system
"fake-palette") */
RGB_MAP *orig_rgb_map = NULL; /* color map for the original palette
(not for the system palette) */
COLOR_MAP *orig_trans_map = NULL;
/* current rgb map */
static RGB_MAP *my_rgb_map = NULL;
/* hook's information (for the `ase_set_palette' routine) */
static JList hooks;
/* system color (in order of importance) */
static RGB system_color[] =
{
{ 255/4, 255/4, 255/4, 0 }, /* background */
{ 0/4, 0/4, 0/4, 0 }, /* foreground */
{ 128/4, 128/4, 128/4, 0 }, /* disabled */
{ 210/4, 200/4, 190/4, 0 }, /* face */
{ 44/4, 76/4, 145/4, 0 }, /* selected */
{ 250/4, 240/4, 230/4, 0 }, /* hotface */
{ 255/4, 255/4, 0/4, 0 }, /* yellow */
{ 0/4, 0/4, 255/4, 0 } /* blue */
};
#define SYSTEM_COLORS (sizeof(system_color) / sizeof(RGB))
int init_module_palette(void)
{
orig_rgb_map = jnew(RGB_MAP, 1);
orig_trans_map = jnew(COLOR_MAP, 1);
my_rgb_map = jnew(RGB_MAP, 1);
hooks = jlist_new();
rgb_map = my_rgb_map;
color_map = NULL;
palette_copy(current_palette, black_palette);
return 0;
}
void exit_module_palette(void)
{
rgb_map = NULL;
jlist_free(hooks);
jfree(my_rgb_map);
jfree(orig_trans_map);
jfree(orig_rgb_map);
}
void set_default_palette(RGB *palette)
{
palette_copy(default_palette, palette);
}
/* changes the current system palette, all hooks will be called, if
"palette" is NULL will be used the default one (ase_palette) */
bool set_current_palette(RGB *_palette, int forced)
{
PALETTE palette;
bool ret = FALSE;
/* if "palette" == NULL we must use "default_palette" */
if (!_palette)
palette_copy(palette, default_palette);
else
palette_copy(palette, _palette);
/* have changes */
if (forced || palette_diff(palette, current_palette, NULL, NULL)) {
int i, j, k;
/* copy current palette */
palette_copy(current_palette, palette);
/* create a RGB map for the original palette */
create_rgb_table(orig_rgb_map, palette, NULL);
/* create a transparency-map with the original palette */
rgb_map = orig_rgb_map;
create_trans_table(orig_trans_map, palette, 128, 128, 128, NULL);
rgb_map = my_rgb_map;
/* make the fake-palette and fixup the _index_cmap[]... */
/* fill maps with default values */
for (i=0; i<256; i++)
_index_cmap[i] = i;
/* fake palette system is only for 8 bpp screen */
if (screen && bitmap_color_depth(screen) == 8) {
char found[SYSTEM_COLORS];
for (i=0; i<SYSTEM_COLORS; i++) {
found[i] = FALSE;
for (j=1; j<256; j++) {
/* color found */
if ((system_color[i].r == palette[j].r) &&
(system_color[i].g == palette[j].g) &&
(system_color[i].b == palette[j].b)) {
found[i] = TRUE;
break;
}
}
}
for (i=0; i<SYSTEM_COLORS; i++) {
if (found[i])
continue;
for (j=255; j>1; j--) {
for (k=1; k<j; k++) {
if ((palette[j].r == palette[k].r) &&
(palette[j].g == palette[k].g) &&
(palette[j].b == palette[k].b)) {
_index_cmap[j] = k;
palette[j].r = system_color[i].r;
palette[j].g = system_color[i].g;
palette[j].b = system_color[i].b;
j = 0;
break;
}
}
}
}
}
/* create a map for the fake-palette */
create_rgb_table(my_rgb_map, palette, NULL);
/* change system color palette */
set_palette(palette);
/* call hooks */
call_palette_hooks();
ret = TRUE;
}
return ret;
}
/* changes a color of the current system palette */
void set_current_color(int index, int r, int g, int b)
{
assert(index >= 0 && index <= 255);
assert(r >= 0 && r < 64);
assert(g >= 0 && g < 64);
assert(b >= 0 && b < 64);
if (current_palette[index].r != r ||
current_palette[index].g != g ||
current_palette[index].b != b) {
RGB rgb = { r, g, b, 0 };
current_palette[index] = rgb;
if ((screen) && (bitmap_color_depth (screen) == 8) &&
(_index_cmap[index] != index))
_index_cmap[index] = index;
set_color(index, &rgb);
}
}
/* inserts a new palette-hook in the end of the list */
void hook_palette_changes(void (*proc)(void))
{
jlist_append(hooks, proc);
}
/* removes a palette-hook */
void unhook_palette_changes(void (*proc)(void))
{
jlist_remove(hooks, proc);
}
/* calls all hooks */
void call_palette_hooks(void)
{
JLink link;
/* call the hooks */
JI_LIST_FOR_EACH(hooks, link)
(*((void (*)())link->data))();
}
/**********************************************************************/
static int regen_rgb_map = FALSE;
void use_current_sprite_rgb_map(void)
{
rgb_map = orig_rgb_map;
}
void use_sprite_rgb_map(Sprite *sprite)
{
rgb_map = my_rgb_map;
regen_rgb_map = TRUE;
create_rgb_table(my_rgb_map,
sprite_get_palette(sprite, sprite->frame), NULL);
}
void restore_rgb_map(void)
{
rgb_map = my_rgb_map;
if (regen_rgb_map) {
regen_rgb_map = FALSE;
create_rgb_table(my_rgb_map, _current_palette, NULL);
}
}
/**********************************************************************/
/* creates a linear ramp in the palette */
void make_palette_ramp(RGB *p, int from, int to)
{
float rv, gv, bv;
float rd, gd, bd;
int i;
if (from > to) {
i = from;
from = to;
to = i;
}
if ((to - from) < 2)
return;
/* deltas */
rd = (float)(p[to].r - p[from].r) / (float)(to - from);
gd = (float)(p[to].g - p[from].g) / (float)(to - from);
bd = (float)(p[to].b - p[from].b) / (float)(to - from);
/* values */
rv = p[from].r;
gv = p[from].g;
bv = p[from].b;
for (i=from+1; i<to; i++) {
rv += rd;
gv += gd;
bv += bd;
p[i].r = rv;
p[i].g = gv;
p[i].b = bv;
}
}
/* creates a rectangular ramp in the palette */
void make_palette_rect_ramp(RGB *p, int from, int to, int cols)
{
float rv1, gv1, bv1, rv2, gv2, bv2;
float rd1, gd1, bd1, rd2, gd2, bd2;
int imin = MIN(from, to);
int imax = MAX(from, to);
int xmin = imin % cols;
int ymin = imin / cols;
int xmax = imax % cols;
int ymax = imax / cols;
int x1 = MIN(xmin, xmax);
int y1 = MIN(ymin, ymax);
int x2 = MAX(xmin, xmax);
int y2 = MAX(ymin, ymax);
int i, rows;
rows = y2 - y1;
/* left side */
from = y1*cols+x1;
to = y2*cols+x1;
/* deltas */
rd1 = (float)(p[to].r - p[from].r) / (float)rows;
gd1 = (float)(p[to].g - p[from].g) / (float)rows;
bd1 = (float)(p[to].b - p[from].b) / (float)rows;
/* values */
rv1 = p[from].r;
gv1 = p[from].g;
bv1 = p[from].b;
/* right side */
from = y1*cols+x2;
to = y2*cols+x2;
/* deltas */
rd2 = (float)(p[to].r - p[from].r) / (float)rows;
gd2 = (float)(p[to].g - p[from].g) / (float)rows;
bd2 = (float)(p[to].b - p[from].b) / (float)rows;
/* values */
rv2 = p[from].r;
gv2 = p[from].g;
bv2 = p[from].b;
for (i=y1; i<=y2; i++) {
/* left side */
p[i*cols+x1].r = rv1;
p[i*cols+x1].g = gv1;
p[i*cols+x1].b = bv1;
/* right side */
p[i*cols+x2].r = rv2;
p[i*cols+x2].g = gv2;
p[i*cols+x2].b = bv2;
/* ramp from left to right side */
make_palette_ramp(p, i*cols+x1, i*cols+x2);
rv1 += rd1;
gv1 += gd1;
bv1 += bd1;
rv2 += rd2;
gv2 += gd2;
bv2 += bd2;
}
}
/* counts differences between palettes */
int palette_diff(RGB *p1, RGB *p2, int *from, int *to)
{
register int c, diff = 0;
if (from) *from = -1;
if (to) *to = -1;
/* compare palettes */
for (c=0; c<256; c++) {
if ((p1[c].r != p2[c].r) ||
(p1[c].g != p2[c].g) ||
(p1[c].b != p2[c].b)) {
if (from && *from < 0) *from = c;
if (to) *to = c;
diff++;
}
}
return diff;
}
void palette_copy(RGB *dst, RGB *src)
{
memcpy(dst, src, sizeof(PALETTE));
}
RGB *palette_load(const char *filename)
{
RGB *palette = NULL;
char ext[64];
ustrcpy(ext, get_extension(filename));
if ((ustricmp(ext, "pcx") == 0) ||
(ustricmp(ext, "bmp") == 0) ||
(ustricmp(ext, "tga") == 0) ||
(ustricmp(ext, "lbm") == 0)) {
BITMAP *bmp;
palette = jmalloc(sizeof(PALETTE));
bmp = load_bitmap(filename, palette);
if (bmp)
destroy_bitmap(bmp);
else {
jfree(palette);
palette = NULL;
}
}
else if (ustricmp(ext, "col") == 0) {
palette = load_col_file(filename);
}
return palette;
}
int palette_save(RGB *palette, const char *filename)
{
int ret = -1;
char ext[64];
ustrcpy(ext, get_extension(filename));
if ((ustricmp(ext, "pcx") == 0) ||
(ustricmp(ext, "bmp") == 0) ||
(ustricmp(ext, "tga") == 0)) {
int c, x, y;
BITMAP *bmp;
bmp = create_bitmap_ex(8, 16, 16);
for (y=c=0; y<16; y++)
for (x=0; x<16; x++)
putpixel(bmp, x, y, c++);
ret = save_bitmap(filename, bmp, palette);
destroy_bitmap(bmp);
}
else if (ustricmp(ext, "col") == 0) {
ret = save_col_file(palette, filename);
}
return ret;
}

274
src/modules/palettes.c Normal file
View File

@ -0,0 +1,274 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <assert.h>
#include <allegro.h>
#include <string.h>
#include "jinete/jlist.h"
#include "core/app.h"
#include "modules/palettes.h"
#include "raster/blend.h"
#include "raster/image.h"
#include "raster/palette.h"
#include "raster/sprite.h"
RGB_MAP *orig_rgb_map = NULL; /* color map for the original palette
(not for the mapped-palette) */
COLOR_MAP *orig_trans_map = NULL;
/**
* The default color palette.
*/
static Palette *ase_default_palette = NULL;
/**
* Current original palette (you can use _current_palette from Allegro
* to refer to the current system "mapped-palette").
*/
static Palette *ase_current_palette = NULL;
/* current rgb map */
static RGB_MAP *my_rgb_map = NULL;
static int regen_my_rgb_map = FALSE;
/* system color (in order of importance) */
static ase_uint32 ase_system_color[] =
{
_rgba(255, 255, 255, 255), /* background */
_rgba(0, 0, 0, 255), /* foreground */
_rgba(128, 128, 128, 255), /* disabled */
_rgba(210, 200, 190, 255), /* face */
_rgba( 44, 76, 145, 255), /* selected */
_rgba(250, 240, 230, 255), /* hotface */
_rgba(255, 255, 0, 255), /* yellow */
_rgba( 0, 0, 255, 255), /* blue */
_rgba(255, 255, 200, 255), /* yellow for tooltips */
};
#define SYSTEM_COLORS (sizeof(ase_system_color) / sizeof(RGB))
int init_module_palette(void)
{
orig_rgb_map = jnew(RGB_MAP, 1);
orig_trans_map = jnew(COLOR_MAP, 1);
my_rgb_map = jnew(RGB_MAP, 1);
rgb_map = my_rgb_map;
color_map = NULL;
ase_default_palette = palette_new(0, MAX_PALETTE_COLORS);
palette_from_allegro(ase_default_palette, default_palette);
ase_current_palette = palette_new(0, MAX_PALETTE_COLORS);
palette_from_allegro(ase_current_palette, black_palette);
return 0;
}
void exit_module_palette(void)
{
rgb_map = NULL;
if (ase_default_palette != NULL)
jfree(ase_default_palette);
if (ase_current_palette != NULL)
jfree(ase_current_palette);
jfree(my_rgb_map);
jfree(orig_trans_map);
jfree(orig_rgb_map);
}
Palette *get_current_palette(void)
{
return ase_current_palette;
}
Palette *get_default_palette(void)
{
return ase_default_palette;
}
void set_default_palette(Palette *palette)
{
palette_copy_colors(ase_default_palette, palette);
}
/**
* Changes the current system palette. Triggers the APP_PALETTE_CHANGE event
*
* @param palette If "palette" is NULL will be used the default one
* (ase_default_palette)
*/
bool set_current_palette(Palette *_palette, int forced)
{
Palette *palette = _palette ? _palette: ase_default_palette;
bool ret = FALSE;
/* have changes */
if (forced ||
palette_count_diff(palette, ase_current_palette, NULL, NULL) > 0) {
PALETTE rgbpal;
int i, j, k;
/* copy current palette */
palette_copy_colors(ase_current_palette, palette);
/* create a RGB map for the original palette */
create_rgb_table(orig_rgb_map, palette_to_allegro(palette, rgbpal), NULL);
/* create a transparency-map with the original palette */
rgb_map = orig_rgb_map;
create_trans_table(orig_trans_map, rgbpal, 128, 128, 128, NULL);
rgb_map = my_rgb_map;
/* create the mapped-palette fixing up the _index_cmap[] to map
similar colors... */
/* fill maps with default values */
for (i=0; i<256; i++)
_index_cmap[i] = i;
/* a mapped-palette is only necessary for 8 bpp screen */
if (screen != NULL && bitmap_color_depth(screen) == 8) {
bool found[SYSTEM_COLORS];
/* first of all, we can search for system colors in the palette */
for (i=0; i<SYSTEM_COLORS; i++) {
found[i] = FALSE;
for (j=1; j<256; j++) {
if ((_rgba_getr(ase_system_color[i])>>2) == (_rgba_getr(palette->color[j])>>2) &&
(_rgba_getg(ase_system_color[i])>>2) == (_rgba_getg(palette->color[j])>>2) &&
(_rgba_getb(ase_system_color[i])>>2) == (_rgba_getb(palette->color[j])>>2)) {
found[i] = TRUE;
break;
}
}
}
/* after that, we can search for repeated colors in the system
palette, to make a mapping between two same colors */
for (i=0, j=255; i<SYSTEM_COLORS; i++) {
if (found[i])
continue;
for (; j>=1; j--) {
for (k=1; k<j; k++) {
/* if the "j" color is the same as "k" color... */
if (palette->color[j] == palette->color[k]) {
/* ...then we can paint "j" using "k" */
_index_cmap[j] = k;
rgbpal[j].r = _rgba_getr(ase_system_color[i]) >> 2;
rgbpal[j].g = _rgba_getg(ase_system_color[i]) >> 2;
rgbpal[j].b = _rgba_getb(ase_system_color[i]) >> 2;
--j;
goto next;
}
}
}
next:;
}
}
/* create a map for the mapped-palette */
create_rgb_table(my_rgb_map, rgbpal, NULL);
set_palette(rgbpal); /* change system color palette */
/* call hooks */
app_trigger_event(APP_PALETTE_CHANGE);
ret = TRUE;
}
return ret;
}
void set_black_palette(void)
{
Palette *p = palette_new(0, MAX_PALETTE_COLORS);
set_current_palette(p, TRUE);
palette_free(p);
}
/* changes a color of the current system palette */
void set_current_color(int index, int r, int g, int b)
{
register int c;
assert(index >= 0 && index <= 255);
assert(r >= 0 && r <= 255);
assert(g >= 0 && g <= 255);
assert(b >= 0 && b <= 255);
c = ase_current_palette->color[index];
if (_rgba_getr(c) != r ||
_rgba_getg(c) != g ||
_rgba_getb(c) != b) {
RGB rgb;
ase_current_palette->color[index] = _rgba(r, g, b, 255);
if (screen && bitmap_color_depth(screen) == 8 &&
/* this color is mapped? */
_index_cmap[index] != index) {
/* ok, restore the it to point to the original index */
_index_cmap[index] = index;
}
rgb.r = r>>2;
rgb.g = g>>2;
rgb.b = b>>2;
set_color(index, &rgb);
}
}
/**********************************************************************/
void use_current_sprite_rgb_map(void)
{
rgb_map = orig_rgb_map;
}
void use_sprite_rgb_map(Sprite *sprite)
{
Palette *pal = sprite_get_palette(sprite, sprite->frame);
PALETTE rgbpal;
rgb_map = my_rgb_map;
regen_my_rgb_map = TRUE;
create_rgb_table(my_rgb_map, palette_to_allegro(pal, rgbpal), NULL);
}
void restore_rgb_map(void)
{
rgb_map = my_rgb_map;
if (regen_my_rgb_map) {
regen_my_rgb_map = FALSE;
create_rgb_table(my_rgb_map, _current_palette, NULL);
}
}

View File

@ -16,40 +16,32 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef MODULES_PALETTE_H
#define MODULES_PALETTE_H
#ifndef MODULES_PALETTES_H
#define MODULES_PALETTES_H
#include "jinete/jbase.h"
#include <allegro/color.h>
struct Palette;
struct Sprite;
extern PALETTE current_palette;
extern RGB_MAP *orig_rgb_map;
extern COLOR_MAP *orig_trans_map;
int init_module_palette(void);
void exit_module_palette(void);
void set_default_palette(struct RGB *palette);
bool set_current_palette(struct RGB *palette, int forced);
void set_current_color(int index, int r, int g, int b);
struct Palette *get_default_palette(void);
struct Palette *get_current_palette(void);
void hook_palette_changes(void(*proc)(void));
void unhook_palette_changes(void(*proc)(void));
void call_palette_hooks(void);
void set_default_palette(struct Palette *palette);
bool set_current_palette(struct Palette *palette, int forced);
void set_black_palette(void);
void set_current_color(int index, int r, int g, int b);
void use_current_sprite_rgb_map(void);
void use_sprite_rgb_map(struct Sprite *sprite);
void restore_rgb_map(void);
void make_palette_ramp(RGB *palette, int from, int to);
void make_palette_rect_ramp(RGB *palette, int from, int to, int width);
int palette_diff(RGB *p1, RGB *p2, int *from, int *to);
void palette_copy(RGB *dst, RGB *src);
RGB *palette_load(const char *filename);
int palette_save(RGB *palette, const char *filename);
#endif /* MODULES_PALETTE_H */
#endif /* MODULES_PALETTES_H */

View File

@ -37,19 +37,10 @@
#include "modules/editors.h"
#include "modules/gfx.h"
#include "modules/gui.h"
#include "modules/palette.h"
#include "modules/palettes.h"
#include "modules/sprites.h"
#include "modules/tools.h"
#include "raster/algo.h"
#include "raster/blend.h"
#include "raster/brush.h"
#include "raster/dirty.h"
#include "raster/image.h"
#include "raster/layer.h"
#include "raster/mask.h"
#include "raster/sprite.h"
#include "raster/stock.h"
#include "raster/undo.h"
#include "raster/raster.h"
#include "util/misc.h"
#include "widgets/editor.h"
#include "widgets/statebar.h"
@ -76,7 +67,7 @@ static int _cursor_mask;
static Image *tool_image = NULL;
static int tool_color;
static void update_cursor_color(void)
static void update_cursor_color(void *data)
{
if (ji_screen)
_cursor_color = get_color_for_allegro(bitmap_color_depth(ji_screen),
@ -128,7 +119,7 @@ int init_module_tools(void)
air_speed = MID(1, air_speed, 100);
refresh_tools_names();
hook_palette_changes(update_cursor_color);
app_add_hook(APP_PALETTE_CHANGE, update_cursor_color, NULL);
return 0;
}
@ -153,8 +144,6 @@ void exit_module_tools(void)
jrect_free(grid);
brush_free(brush);
unhook_palette_changes(update_cursor_color);
}
void refresh_tools_names(void)
@ -262,7 +251,7 @@ color_t get_cursor_color(void)
void set_cursor_color(color_t color)
{
cursor_color = color;
update_cursor_color();
update_cursor_color(NULL);
}
/* returns the size which use the current tool */
@ -609,6 +598,16 @@ void control_tool(JWidget widget, Tool *tool, color_t _color)
const char *_size = _("Size");
bool click2 = get_config_bool("Options", "DrawClick2", FALSE);
/* First of all we have to dispatch the enqueue messages. Why is it
needed? To dispatch the JM_CLOSE and redrawing messages if a
color-selector was shown to the user before to click. This is
because the tooltips filter the JM_BUTTONPRESSED message, so when
the user click outside the window, it is closed, but the filtered
JM_BUTTONPRESSED message is not "eaten" so the editor receive it
anyway */
jmanager_dispatch_messages(jwidget_get_manager(widget));
jwidget_flush_redraw(jwidget_get_manager(widget));
/* get image information */
image = GetImage2(editor->sprite, &offset_x, &offset_y, NULL);
@ -1316,15 +1315,20 @@ static void my_image_hline1_glass(int x1, int y, int x2, void *data)
{
register ase_uint8 *address = ((ase_uint8 **)tool_image->line)[y]+x1;
register int x = x2 - x1 + 1;
int c, tc = _rgba(_rgb_scale_6[_current_palette[_index_cmap[tool_color]].r],
_rgb_scale_6[_current_palette[_index_cmap[tool_color]].g],
_rgb_scale_6[_current_palette[_index_cmap[tool_color]].b], 255);
Palette *pal = get_current_palette();
ase_uint32 c, tc;
tc = pal->color[tool_color];
/* tc = _rgba(_rgb_scale_6[_current_palette[_index_cmap[tool_color]].r], */
/* _rgb_scale_6[_current_palette[_index_cmap[tool_color]].g], */
/* _rgb_scale_6[_current_palette[_index_cmap[tool_color]].b], 255); */
while (x--) {
c = _rgba_blend_normal(_rgba(_rgb_scale_6[_current_palette[*address].r],
_rgb_scale_6[_current_palette[*address].g],
_rgb_scale_6[_current_palette[*address].b], 255),
tc, glass_dirty);
/* c = _rgba_blend_normal(_rgba(_rgb_scale_6[_current_palette[*address].r], */
/* _rgb_scale_6[_current_palette[*address].g], */
/* _rgb_scale_6[_current_palette[*address].b], 255), */
/* tc, glass_dirty); */
c = _rgba_blend_normal(pal->color[*address], tc, glass_dirty);
/* *(address++) = rgb_map->data[_rgba_getr(c)>>3] */
/* [_rgba_getg(c)>>3] */

View File

@ -41,7 +41,7 @@
BLEND_COLOR _rgba_blenders[] =
{
#ifdef USE_SSE_ASM
_rgba_blend_normal_sse
_rgba_blend_normal_sse,
#else
_rgba_blend_normal,
#endif
@ -86,6 +86,12 @@ BLEND_COLOR _graya_blenders[] =
_graya_blend_copy,
};
/**
* Mapped indexed colors. If you want to draw a color in the screen
* for the current sprite, you should pass through this map before:
*
* final_index = _index_cmap[sprite_getpixel(...)].
*/
unsigned char _index_cmap[256] =
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,

View File

@ -18,6 +18,7 @@
#include "config.h"
#include <assert.h>
#include <allegro.h>
/* #include <allegro/color.h> */
/* #include <allegro/gfx.h> */
@ -75,6 +76,7 @@ Image *image_new(int imgtype, int w, int h)
Image *image_new_copy(const Image *image)
{
assert(image != NULL);
return image_crop(image, 0, 0, image->w, image->h);
}

View File

@ -32,18 +32,18 @@
#define _rgba_getb(c) (((c) >> _rgba_b_shift) & 0xff)
#define _rgba_geta(c) (((c) >> _rgba_a_shift) & 0xff)
#define _rgba(r,g,b,a) \
(((r) << _rgba_r_shift) | \
((g) << _rgba_g_shift) | \
((b) << _rgba_b_shift) | \
((a) << _rgba_a_shift))
((ase_uint32)(((r) << _rgba_r_shift) | \
((g) << _rgba_g_shift) | \
((b) << _rgba_b_shift) | \
((a) << _rgba_a_shift)))
#define _graya_v_shift 0
#define _graya_a_shift 8
#define _graya_getv(c) (((c) >> _graya_v_shift) & 0xff)
#define _graya_geta(c) (((c) >> _graya_a_shift) & 0xff)
#define _graya(v,a) \
(((v) << _graya_v_shift) | \
((a) << _graya_a_shift))
((ase_uint16)(((v) << _graya_v_shift) | \
((a) << _graya_a_shift)))
#define _image_bitmap_next_bit(d, a) \
if (d.rem < 7) \

View File

@ -31,14 +31,15 @@
#include "raster/stock.h"
#include "raster/undo.h"
static bool has_cels(Layer *layer, int frame);
static bool has_cels(const Layer *layer, int frame);
static void layer_set_parent(Layer *layer, Layer *parent_set);
#define LAYER_INIT(name_string) \
do { \
layer_set_name(layer, name_string); \
\
layer->sprite = sprite; \
layer->parent = NULL; \
layer->parent_layer = NULL; \
layer->readable = TRUE; \
layer->writable = TRUE; \
\
@ -78,25 +79,27 @@ Layer *layer_set_new(Sprite *sprite)
return layer;
}
Layer *layer_new_copy(const Layer *layer)
Layer *layer_new_copy(Sprite *dst_sprite, const Layer *src_layer)
{
Layer *layer_copy = NULL;
switch (layer->gfxobj.type) {
assert(dst_sprite != NULL);
switch (src_layer->gfxobj.type) {
case GFXOBJ_LAYER_IMAGE: {
Cel *cel_copy, *cel;
Image *image_copy, *image;
JLink link;
layer_copy = layer_new(layer->sprite);
layer_copy = layer_new(dst_sprite);
if (!layer_copy)
break;
layer_set_blend_mode(layer_copy, layer->blend_mode);
layer_set_blend_mode(layer_copy, src_layer->blend_mode);
/* copy cels */
JI_LIST_FOR_EACH(layer->cels, link) {
JI_LIST_FOR_EACH(src_layer->cels, link) {
cel = (Cel *)link->data;
cel_copy = cel_new_copy(cel);
if (!cel_copy) {
@ -105,22 +108,17 @@ Layer *layer_new_copy(const Layer *layer)
}
assert((cel->image >= 0) &&
(cel->image < layer->sprite->stock->nimage));
(cel->image < src_layer->sprite->stock->nimage));
image = layer->sprite->stock->image[cel->image];
image = src_layer->sprite->stock->image[cel->image];
assert(image != NULL);
image_copy = image_new_copy(image);
if (layer->sprite != NULL &&
undo_is_enabled(layer->sprite->undo)) {
undo_add_image(layer->sprite->undo,
layer->sprite->stock,
image_copy);
}
if (undo_is_enabled(dst_sprite->undo))
undo_add_image(dst_sprite->undo, dst_sprite->stock, image_copy);
cel_copy->image = stock_add_image(layer->sprite->stock,
image_copy);
cel_copy->image = stock_add_image(dst_sprite->stock, image_copy);
layer_add_cel(layer_copy, cel_copy);
}
@ -131,13 +129,13 @@ Layer *layer_new_copy(const Layer *layer)
Layer *child_copy;
JLink link;
layer_copy = layer_set_new(layer->sprite);
layer_copy = layer_set_new(dst_sprite);
if (!layer_copy)
break;
JI_LIST_FOR_EACH(layer->layers, link) {
JI_LIST_FOR_EACH(src_layer->layers, link) {
/* copy the child */
child_copy = layer_new_copy(link->data);
child_copy = layer_new_copy(dst_sprite, link->data);
/* not enough memory? */
if (!child_copy) {
layer_free(layer_copy);
@ -153,15 +151,68 @@ Layer *layer_new_copy(const Layer *layer)
}
/* copy general properties */
if (layer_copy) {
layer_set_name(layer_copy, layer->name);
layer_copy->readable = layer->readable;
layer_copy->writable = layer->writable;
if (layer_copy != NULL) {
layer_set_name(layer_copy, src_layer->name);
layer_copy->readable = src_layer->readable;
layer_copy->writable = src_layer->writable;
}
return layer_copy;
}
/**
* Returns a new layer (flat_layer) with all "layer" rendered frame by
* frame from "frmin" to "frmax" (inclusive). "layer" can be a set of
* layers, so the routine flattens all children to an unique output
* layer.
*
* @param dst_sprite The sprite where to put the new flattened layer.
* @param src_layer Generally a set of layers to be flattened.
*/
Layer *layer_new_flatten_copy(Sprite *dst_sprite, const Layer *src_layer,
int x, int y, int w, int h, int frmin, int frmax)
{
Layer *flat_layer;
Image *image;
Cel *cel;
int frame;
flat_layer = layer_new(dst_sprite);
if (!flat_layer)
return NULL;
layer_set_name(flat_layer, "Flat Layer");
for (frame=frmin; frame<=frmax; frame++) {
/* does this frame have cels to render? */
if (has_cels(src_layer, frame)) {
/* create a new image */
image = image_new(flat_layer->sprite->imgtype, w, h);
if (!image) {
layer_free(flat_layer);
return NULL;
}
/* create the new cel for the output layer (add the image to
stock too) */
cel = cel_new(frame, stock_add_image(flat_layer->sprite->stock, image));
cel_set_position(cel, x, y);
if (!cel) {
layer_free(flat_layer);
image_free(image);
return NULL;
}
/* clear the image and render this frame */
image_clear(image, 0);
layer_render(src_layer, image, -x, -y, frame);
layer_add_cel(flat_layer, cel);
}
}
return flat_layer;
}
void layer_free(Layer *layer)
{
switch (layer->gfxobj.type) {
@ -192,7 +243,7 @@ void layer_free(Layer *layer)
/**
* Returns TRUE if "layer" is a normal layer type (an image layer)
*/
int layer_is_image(const Layer *layer)
bool layer_is_image(const Layer *layer)
{
return (layer->gfxobj.type == GFXOBJ_LAYER_IMAGE) ? TRUE: FALSE;
}
@ -200,7 +251,7 @@ int layer_is_image(const Layer *layer)
/**
* Returns TRUE if "layer" is a set of layers
*/
int layer_is_set(const Layer *layer)
bool layer_is_set(const Layer *layer)
{
return (layer->gfxobj.type == GFXOBJ_LAYER_SET) ? TRUE: FALSE;
}
@ -226,8 +277,8 @@ bool layer_is_writable(const Layer *layer)
*/
Layer *layer_get_prev(Layer *layer)
{
if (layer->parent && layer->parent->type == GFXOBJ_LAYER_SET) {
JList list = ((Layer *)layer->parent)->layers;
if (layer->parent_layer != NULL) {
JList list = layer->parent_layer->layers;
JLink link = jlist_find(list, layer);
if (link != list->end && link->prev != list->end)
return link->prev->data;
@ -237,8 +288,8 @@ Layer *layer_get_prev(Layer *layer)
Layer *layer_get_next(Layer *layer)
{
if (layer->parent && layer->parent->type == GFXOBJ_LAYER_SET) {
JList list = ((Layer *)layer->parent)->layers;
if (layer->parent_layer != NULL) {
JList list = layer->parent_layer->layers;
JLink link = jlist_find(list, layer);
if (link != list->end && link->next != list->end)
return link->next->data;
@ -248,20 +299,16 @@ Layer *layer_get_next(Layer *layer)
void layer_set_name(Layer *layer, const char *name)
{
/* TODO warning overflow */
strcpy(layer->name, name);
}
void layer_set_blend_mode(Layer *layer, int blend_mode)
{
if (layer->gfxobj.type == GFXOBJ_LAYER_IMAGE)
if (layer_is_image(layer))
layer->blend_mode = blend_mode;
}
void layer_set_parent(Layer *layer, GfxObj *gfxobj)
{
layer->parent = gfxobj;
}
void layer_add_cel(Layer *layer, Cel *cel)
{
if (layer_is_image(layer)) {
@ -299,32 +346,32 @@ Cel *layer_get_cel(Layer *layer, int frame)
void layer_add_layer(Layer *set, Layer *layer)
{
if (set->gfxobj.type == GFXOBJ_LAYER_SET) {
jlist_append(set->layers, layer);
layer_set_parent(layer, (GfxObj *)set);
}
assert(set != NULL && layer_is_set(set));
jlist_append(set->layers, layer);
layer_set_parent(layer, set);
}
void layer_remove_layer(Layer *set, Layer *layer)
{
if (set->gfxobj.type == GFXOBJ_LAYER_SET) {
jlist_remove(set->layers, layer);
layer_set_parent(layer, NULL);
}
assert(set != NULL && layer_is_set(set));
jlist_remove(set->layers, layer);
layer_set_parent(layer, NULL);
}
void layer_move_layer(Layer *set, Layer *layer, Layer *after)
{
if (set->gfxobj.type == GFXOBJ_LAYER_SET) {
jlist_remove(set->layers, layer);
assert(set != NULL && layer_is_set(set));
if (after) {
JLink before = jlist_find(set->layers, after)->next;
jlist_insert_before(set->layers, before, layer);
}
else
jlist_prepend(set->layers, layer);
jlist_remove(set->layers, layer);
if (after) {
JLink before = jlist_find(set->layers, after)->next;
jlist_insert_before(set->layers, before, layer);
}
else
jlist_prepend(set->layers, layer);
}
void layer_render(Layer *layer, Image *image, int x, int y, int frame)
@ -364,60 +411,11 @@ void layer_render(Layer *layer, Image *image, int x, int y, int frame)
}
}
/**
* Returns a new layer (flat_layer) with all "layer" rendered frame
* by frame from "frmin" to "frmax" (inclusive). "layer" can be a set
* of layers, so the routines flatten all childs to the unique output
* layer.
*/
Layer *layer_flatten(Layer *layer, int x, int y, int w, int h, int frmin, int frmax)
{
Layer *flat_layer;
Image *image;
Cel *cel;
int frame;
flat_layer = layer_new(layer->sprite);
if (!flat_layer)
return NULL;
layer_set_name(flat_layer, "Flat Layer");
for (frame=frmin; frame<=frmax; frame++) {
/* does this frame have cels to render? */
if (has_cels(layer, frame)) {
/* create a new image */
image = image_new(flat_layer->sprite->imgtype, w, h);
if (!image) {
layer_free(flat_layer);
return NULL;
}
/* create the new cel for the output layer (add the image to
stock too) */
cel = cel_new(frame, stock_add_image(flat_layer->sprite->stock, image));
cel_set_position(cel, x, y);
if (!cel) {
layer_free(flat_layer);
image_free(image);
return NULL;
}
/* clear the image and render this frame */
image_clear(image, 0);
layer_render(layer, image, -x, -y, frame);
layer_add_cel(flat_layer, cel);
}
}
return flat_layer;
}
/**
* Returns TRUE if the "layer" (or him childs) has cels to render in
* frame.
*/
static bool has_cels(Layer *layer, int frame)
static bool has_cels(const Layer *layer, int frame)
{
if (!layer->readable)
return FALSE;
@ -440,3 +438,10 @@ static bool has_cels(Layer *layer, int frame)
return FALSE;
}
static void layer_set_parent(Layer *layer, Layer *parent_set)
{
assert(parent_set == NULL || layer_is_set(parent_set));
layer->parent_layer = parent_set;
}

View File

@ -33,7 +33,8 @@ struct Layer
GfxObj gfxobj;
char name[256]; /* layer name */
struct Sprite *sprite; /* owner of the layer */
GfxObj *parent; /* parent object */
/* GfxObj *parent; /\* parent object *\/ */
Layer *parent_layer; /* parent layer */
unsigned readable : 1;
unsigned writable : 1;
@ -47,11 +48,13 @@ struct Layer
Layer *layer_new(struct Sprite *sprite);
Layer *layer_set_new(struct Sprite *sprite);
Layer *layer_new_copy(const Layer *layer);
Layer *layer_new_copy(struct Sprite *dst_sprite, const Layer *src_layer);
Layer *layer_new_flatten_copy(struct Sprite *dst_sprite, const Layer *src_layer,
int x, int y, int w, int h, int frmin, int frmax);
void layer_free(Layer *layer);
int layer_is_image(const Layer *layer);
int layer_is_set(const Layer *layer);
bool layer_is_image(const Layer *layer);
bool layer_is_set(const Layer *layer);
bool layer_is_readable(const Layer *layer);
bool layer_is_writable(const Layer *layer);
@ -61,7 +64,6 @@ Layer *layer_get_next(Layer *layer);
void layer_set_name(Layer *layer, const char *name);
void layer_set_blend_mode(Layer *layer, int blend_mode);
void layer_set_parent(Layer *layer, GfxObj *gfxobj);
/* for LAYER_IMAGE */
void layer_add_cel(Layer *layer, struct Cel *cel);
@ -74,6 +76,5 @@ void layer_remove_layer(Layer *set, Layer *layer);
void layer_move_layer(Layer *set, Layer *layer, Layer *after);
void layer_render(Layer *layer, struct Image *image, int x, int y, int frame);
Layer *layer_flatten(Layer *layer, int x, int y, int w, int h, int frmin, int frmax);
#endif /* RASTER_LAYER_H */

View File

@ -65,46 +65,46 @@ void mask_free (Mask *mask)
gfxobj_free((GfxObj *)mask);
}
int mask_is_empty (Mask *mask)
int mask_is_empty(Mask *mask)
{
return (!mask->bitmap)? TRUE: FALSE;
}
void mask_set_name (Mask *mask, const char *name)
void mask_set_name(Mask *mask, const char *name)
{
if (mask->name)
jfree (mask->name);
jfree(mask->name);
mask->name = name ? jstrdup (name): NULL;
mask->name = name ? jstrdup(name): NULL;
}
void mask_copy (Mask *mask_dst, const Mask *mask_src)
void mask_copy(Mask *mask_dst, const Mask *mask_src)
{
mask_none (mask_dst);
mask_none(mask_dst);
if (mask_src->name)
mask_set_name (mask_dst, mask_src->name);
mask_set_name(mask_dst, mask_src->name);
if (mask_src->bitmap) {
/* add all the area of "mask" */
mask_union (mask_dst, mask_src->x, mask_src->y,
mask_src->w, mask_src->h);
mask_union(mask_dst, mask_src->x, mask_src->y,
mask_src->w, mask_src->h);
/* and copy the "mask" bitmap */
image_copy (mask_dst->bitmap, mask_src->bitmap, 0, 0);
image_copy(mask_dst->bitmap, mask_src->bitmap, 0, 0);
}
}
void mask_move (Mask *mask, int x, int y)
void mask_move(Mask *mask, int x, int y)
{
mask->x += x;
mask->y += y;
}
void mask_none (Mask *mask)
void mask_none(Mask *mask)
{
if (mask->bitmap) {
image_free (mask->bitmap);
image_free(mask->bitmap);
mask->bitmap = NULL;
mask->x = 0;
mask->y = 0;
@ -133,7 +133,7 @@ void mask_invert(Mask *mask)
}
}
void mask_replace (Mask *mask, int x, int y, int w, int h)
void mask_replace(Mask *mask, int x, int y, int w, int h)
{
mask->x = x;
mask->y = y;
@ -141,76 +141,76 @@ void mask_replace (Mask *mask, int x, int y, int w, int h)
mask->h = h;
if (mask->bitmap)
image_free (mask->bitmap);
image_free(mask->bitmap);
mask->bitmap = image_new (IMAGE_BITMAP, w, h);
image_clear (mask->bitmap, 1);
mask->bitmap = image_new(IMAGE_BITMAP, w, h);
image_clear(mask->bitmap, 1);
}
void mask_union (Mask *mask, int x, int y, int w, int h)
void mask_union(Mask *mask, int x, int y, int w, int h)
{
if (!mask->bitmap) {
mask->x = x;
mask->y = y;
mask->w = w;
mask->h = h;
mask->bitmap = image_new (IMAGE_BITMAP, w, h);
mask->bitmap = image_new(IMAGE_BITMAP, w, h);
}
else {
Image *image;
int x1 = mask->x;
int y1 = mask->y;
int x2 = MAX (mask->x+mask->w-1, x+w-1);
int y2 = MAX (mask->y+mask->h-1, y+h-1);
int x2 = MAX(mask->x+mask->w-1, x+w-1);
int y2 = MAX(mask->y+mask->h-1, y+h-1);
mask->x = MIN (x, x1);
mask->y = MIN (y, y1);
mask->x = MIN(x, x1);
mask->y = MIN(y, y1);
mask->w = x2 - mask->x + 1;
mask->h = y2 - mask->y + 1;
image = image_crop (mask->bitmap, mask->x-x1, mask->y-y1, mask->w, mask->h);
image_free (mask->bitmap);
image = image_crop(mask->bitmap, mask->x-x1, mask->y-y1, mask->w, mask->h);
image_free(mask->bitmap);
mask->bitmap = image;
}
image_rectfill (mask->bitmap,
x-mask->x, y-mask->y,
x-mask->x+w-1, y-mask->y+h-1, 1);
image_rectfill(mask->bitmap,
x-mask->x, y-mask->y,
x-mask->x+w-1, y-mask->y+h-1, 1);
}
void mask_subtract (Mask *mask, int x, int y, int w, int h)
{
if (mask->bitmap) {
image_rectfill (mask->bitmap,
x-mask->x, y-mask->y,
x-mask->x+w-1, y-mask->y+h-1, 0);
shrink_mask (mask);
image_rectfill(mask->bitmap,
x-mask->x, y-mask->y,
x-mask->x+w-1, y-mask->y+h-1, 0);
shrink_mask(mask);
}
}
void mask_intersect (Mask *mask, int x, int y, int w, int h)
void mask_intersect(Mask *mask, int x, int y, int w, int h)
{
if (mask->bitmap) {
Image *image;
int x1 = mask->x;
int y1 = mask->y;
int x2 = MIN (mask->x+mask->w-1, x+w-1);
int y2 = MIN (mask->y+mask->h-1, y+h-1);
int x2 = MIN(mask->x+mask->w-1, x+w-1);
int y2 = MIN(mask->y+mask->h-1, y+h-1);
mask->x = MAX (x, x1);
mask->y = MAX (y, y1);
mask->x = MAX(x, x1);
mask->y = MAX(y, y1);
mask->w = x2 - mask->x + 1;
mask->h = y2 - mask->y + 1;
image = image_crop (mask->bitmap, mask->x-x1, mask->y-y1, mask->w, mask->h);
image_free (mask->bitmap);
image = image_crop(mask->bitmap, mask->x-x1, mask->y-y1, mask->w, mask->h);
image_free(mask->bitmap);
mask->bitmap = image;
shrink_mask (mask);
shrink_mask(mask);
}
}
void mask_merge (Mask *mask, const Mask *src)
void mask_merge(Mask *mask, const Mask *src)
{
/* TODO!!! */
}
@ -343,7 +343,7 @@ void mask_by_color(Mask *mask, const Image *src, int color, int fuzziness)
/* } */
/* } */
void mask_crop (Mask *mask, const Image *image)
void mask_crop(Mask *mask, const Image *image)
{
#define ADVANCE(beg, end, o_end, cmp, op, getpixel1, getpixel) \
{ \

View File

@ -21,11 +21,12 @@
#include "raster/blend.h"
#include "raster/image.h"
#include "raster/quant.h"
#include "raster/palette.h"
Image *image_set_imgtype(Image *image, int imgtype,
int dithering_method,
RGB_MAP *rgb_map,
RGB *palette)
Palette *palette)
{
ase_uint32 *rgb_address;
ase_uint16 *gray_address;
@ -40,7 +41,7 @@ Image *image_set_imgtype(Image *image, int imgtype,
else if (image->imgtype == IMAGE_RGB &&
imgtype == IMAGE_INDEXED &&
dithering_method == DITHERING_ORDERED)
return image_rgb_to_indexed (image, 0, 0, rgb_map, palette);
return image_rgb_to_indexed(image, 0, 0, rgb_map, palette);
new_image = image_new(imgtype, image->w, image->h);
if (!new_image)
@ -130,9 +131,9 @@ Image *image_set_imgtype(Image *image, int imgtype,
if (c == 0)
*rgb_address = 0;
else
*rgb_address = _rgba (_rgb_scale_6[palette[c].r],
_rgb_scale_6[palette[c].g],
_rgb_scale_6[palette[c].b], 255);
*rgb_address = _rgba(_rgba_getr(palette->color[c]),
_rgba_getg(palette->color[c]),
_rgba_getb(palette->color[c]), 255);
idx_address++;
rgb_address++;
}
@ -145,11 +146,11 @@ Image *image_set_imgtype(Image *image, int imgtype,
if (c == 0)
*gray_address = 0;
else {
r = _rgb_scale_6[palette[c].r];
g = _rgb_scale_6[palette[c].g];
b = _rgb_scale_6[palette[c].b];
rgb_to_hsv_int (&r, &g, &b);
*gray_address = _graya (b, 255);
r = _rgba_getr(palette->color[c]);
g = _rgba_getg(palette->color[c]);
b = _rgba_getb(palette->color[c]);
rgb_to_hsv_int(&r, &g, &b);
*gray_address = _graya(b, 255);
}
idx_address++;
gray_address++;
@ -196,7 +197,7 @@ static int pattern[8][8] = {
Image *image_rgb_to_indexed(Image *src_image,
int offsetx, int offsety,
RGB_MAP *rgb_map,
RGB *palette)
Palette *palette)
{
int oppr, oppg, oppb, oppnrcm;
Image *dst_image;
@ -206,29 +207,29 @@ Image *image_rgb_to_indexed(Image *src_image,
int nearestcm;
int c, x, y;
dst_image = image_new (IMAGE_INDEXED, src_image->w, src_image->h);
dst_image = image_new(IMAGE_INDEXED, src_image->w, src_image->h);
if (!dst_image)
return NULL;
for (y=0; y<src_image->h; y++) {
for (x=0; x<src_image->w; x++) {
c = src_image->method->getpixel (src_image, x, y);
c = src_image->method->getpixel(src_image, x, y);
r = _rgba_getr (c);
g = _rgba_getg (c);
b = _rgba_getb (c);
a = _rgba_geta (c);
r = _rgba_getr(c);
g = _rgba_getg(c);
b = _rgba_getb(c);
a = _rgba_geta(c);
if (a != 0) {
nearestcm = rgb_map->data[r>>3][g>>3][b>>3];
/* rgb values for nearest color */
nr = _rgb_scale_6[palette[nearestcm].r];
ng = _rgb_scale_6[palette[nearestcm].g];
nb = _rgb_scale_6[palette[nearestcm].b];
nr = _rgba_getr(palette->color[nearestcm]);
ng = _rgba_getg(palette->color[nearestcm]);
nb = _rgba_getb(palette->color[nearestcm]);
/* Color as far from rgb as nrngnb but in the other direction */
oppr = MID (0, 2*r - nr, 255);
oppg = MID (0, 2*g - ng, 255);
oppb = MID (0, 2*b - nb, 255);
oppr = MID(0, 2*r - nr, 255);
oppg = MID(0, 2*g - ng, 255);
oppb = MID(0, 2*b - nb, 255);
/* Nearest match for opposite color: */
oppnrcm = rgb_map->data[oppr>>3][oppg>>3][oppb>>3];
/* If they're not the same, dither between them. */
@ -240,14 +241,14 @@ Image *image_rgb_to_indexed(Image *src_image,
case the r-nr distance can actually be less than the nr-oppr
distance. */
if (oppnrcm != nearestcm) {
oppr = _rgb_scale_6[palette[oppnrcm].r];
oppg = _rgb_scale_6[palette[oppnrcm].g];
oppb = _rgb_scale_6[palette[oppnrcm].b];
oppr = _rgba_getr(palette->color[oppnrcm]);
oppg = _rgba_getg(palette->color[oppnrcm]);
oppb = _rgba_getb(palette->color[oppnrcm]);
dither_const = DIST(nr, ng, nb, oppr, oppg, oppb);
if (dither_const != 0) {
dither_const = MIN (63, (64 * DIST(r, g, b, nr, ng, nb))
/ dither_const);
dither_const = 64 * DIST(r, g, b, nr, ng, nb) / dither_const;
dither_const = MIN(63, dither_const);
if (pattern[(x+offsetx) & 7][(y+offsety) & 7] < dither_const)
nearestcm = oppnrcm;
@ -257,7 +258,7 @@ Image *image_rgb_to_indexed(Image *src_image,
else
nearestcm = 0;
dst_image->method->putpixel (dst_image, x, y, nearestcm);
dst_image->method->putpixel(dst_image, x, y, nearestcm);
}
}

View File

@ -28,15 +28,16 @@ enum {
};
struct Image;
struct Palette;
struct Image *image_set_imgtype(struct Image *image, int imgtype,
int dithering_method,
RGB_MAP *rgb_map,
RGB *palette);
struct Palette *palette);
struct Image *image_rgb_to_indexed(struct Image *src_image,
int offsetx, int offsety,
RGB_MAP *rgb_map,
RGB *palette);
struct Palette *palette);
#endif /* RASTER_QUANT_H */

View File

@ -28,6 +28,7 @@
#include "raster/image.h"
#include "raster/layer.h"
#include "raster/mask.h"
#include "raster/palette.h"
#include "raster/path.h"
#include "raster/quant.h"
#include "raster/rotate.h"

Some files were not shown because too many files have changed in this diff Show More