From 19e8083256a49163b9c025b9c0ccc07b1325b4de Mon Sep 17 00:00:00 2001 From: David Capello <davidcapello@gmail.com> Date: Sat, 22 Mar 2008 18:43:56 +0000 Subject: [PATCH] + 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. --- ChangeLog | 69 ++++ NEWS.txt | 9 +- TODO.txt | 26 +- config.h | 2 +- data/gui-en.xml | 4 +- data/jids/confscr.jid | 2 +- data/jids/dupspr.jid | 2 +- data/jids/newspr.jid | 3 +- data/jids/replcol.jid | 18 +- data/tips/anicontrols.pcx | Bin 0 -> 1393 bytes data/tips/eyedropper.pcx | Bin 0 -> 1618 bytes data/tips/tips.en | 56 +-- data/tips/tips.es | 120 ------ docs/files/ase.txt | 4 +- docs/jid_file.txt | 2 + makefile.lst | 5 +- src/commands/cmd_change_image_type.c | 2 +- src/commands/cmd_configure_screen.c | 6 +- src/commands/cmd_configure_tools.c | 75 ++-- src/commands/cmd_duplicate_layer.c | 8 +- src/commands/cmd_grid.c | 22 +- src/commands/cmd_merge_down_layer.c | 2 +- src/commands/cmd_new_file.c | 11 - src/commands/cmd_new_frame.c | 6 + src/commands/cmd_palette_editor.c | 429 +++++++++++++++++++++- src/commands/cmd_play_animation.c | 16 +- src/commands/cmd_redo.c | 6 + src/commands/cmd_save_mask.c | 4 +- src/commands/cmd_sprite_properties.c | 8 +- src/commands/cmd_undo.c | 6 + src/commands/fx/cmd_color_curve.c | 3 + src/commands/fx/cmd_convolution_matrix.c | 26 +- src/commands/fx/cmd_despeckle.c | 20 +- src/commands/fx/cmd_invert_color.c | 8 +- src/commands/fx/cmd_replace_color.c | 60 +-- src/console/console.c | 4 +- src/core/app.c | 111 +++++- src/core/app.h | 10 + src/core/color.c | 172 +++------ src/core/color.h | 4 +- src/core/core.c | 4 +- src/core/modules.c | 2 +- src/dialogs/colsel.c | 344 ----------------- src/dialogs/colsel.h | 27 -- src/dialogs/dpaledit.c | 447 ----------------------- src/dialogs/dpaledit.h | 25 -- src/dialogs/drawtext.c | 6 +- src/dialogs/filmedit.c | 38 +- src/dialogs/maskcol.c | 28 +- src/dialogs/minipal.c | 116 ------ src/dialogs/minipal.h | 27 -- src/dialogs/options.c | 4 +- src/dialogs/quick.c | 2 +- src/dialogs/tips.c | 24 +- src/effect/colcurve.c | 12 +- src/effect/convmatr.c | 21 +- src/effect/invrtcol.c | 10 +- src/effect/median.c | 16 +- src/file/ase_format.c | 120 ++++-- src/file/bmp_format.c | 12 +- src/file/file.c | 37 +- src/file/file.h | 6 +- src/file/fli_format.c | 36 +- src/file/gif_format.c | 90 ++--- src/file/ico_format.c | 30 +- src/file/jpeg_format.c | 2 +- src/file/pcx_format.c | 24 +- src/file/png_format.c | 12 +- src/file/tga_format.c | 14 +- src/jinete/jbutton.c | 3 +- src/jinete/jfile.c | 7 +- src/jinete/jgrid.c | 7 + src/jinete/jintern.c | 12 +- src/jinete/jmanager.c | 245 +++++++------ src/jinete/jmanager.h | 2 + src/jinete/jmem.c | 2 +- src/jinete/jmenu.c | 29 +- src/jinete/jslider.c | 23 +- src/jinete/jsystem.c | 2 +- src/jinete/jtooltips.c | 39 +- src/jinete/jwidget.c | 1 + src/jinete/jwindow.c | 4 +- src/modules/editors.c | 2 +- src/modules/gfx.c | 159 +++++++- src/modules/gfx.h | 8 + src/modules/gui.c | 72 +--- src/modules/gui.h | 13 +- src/modules/palette.c | 443 ---------------------- src/modules/palettes.c | 274 ++++++++++++++ src/modules/{palette.h => palettes.h} | 28 +- src/modules/tools.c | 50 +-- src/raster/blend.c | 8 +- src/raster/image.c | 2 + src/raster/image.h | 12 +- src/raster/layer.c | 209 +++++------ src/raster/layer.h | 13 +- src/raster/mask.c | 84 ++--- src/raster/quant.c | 59 +-- src/raster/quant.h | 5 +- src/raster/raster.h | 1 + src/raster/sprite.c | 276 +++++++------- src/raster/sprite.h | 18 +- src/raster/stock.c | 5 +- src/raster/undo.c | 76 ++-- src/raster/undo.h | 3 + src/raster/x86/blenders.s | 3 +- src/script/bindings.c | 8 +- src/script/functions.c | 9 +- src/util/boundary.c | 25 ++ src/util/boundary.h | 15 +- src/util/clipbrd.c | 4 +- src/util/col_file.c | 65 ++-- src/util/col_file.h | 6 +- src/util/crop.c | 2 +- src/util/misc.c | 34 +- src/util/pic_file.c | 34 +- src/util/quantize.c | 27 +- src/util/quantize.h | 10 +- src/util/render.c | 2 +- src/util/thmbnail.c | 16 +- src/widgets/colbar.c | 291 +++++++-------- src/widgets/colbar.h | 2 + src/widgets/colbut.c | 294 ++++++++++----- src/widgets/colbut.h | 12 +- src/widgets/colsel2.c | 174 +++++---- src/widgets/colsel2.h | 6 +- src/widgets/colview.c | 2 +- src/widgets/editor.h | 6 +- src/widgets/editor/cursor.c | 10 +- src/widgets/editor/editor.c | 145 +++++--- src/widgets/fileview.c | 16 +- src/widgets/groupbut.c | 8 +- src/widgets/paledit.c | 37 +- src/widgets/paledit.h | 6 +- src/widgets/statebar.c | 82 ++++- src/widgets/statebar.h | 14 +- src/widgets/tabs.c | 21 +- src/widgets/target.c | 26 +- src/widgets/toolbar.c | 6 +- third_party/libart_lgpl/art_pixbuf.c | 2 +- 140 files changed, 3151 insertions(+), 3342 deletions(-) create mode 100644 data/tips/anicontrols.pcx create mode 100644 data/tips/eyedropper.pcx delete mode 100644 data/tips/tips.es delete mode 100644 src/dialogs/colsel.c delete mode 100644 src/dialogs/colsel.h delete mode 100644 src/dialogs/dpaledit.c delete mode 100644 src/dialogs/dpaledit.h delete mode 100644 src/dialogs/minipal.c delete mode 100644 src/dialogs/minipal.h delete mode 100644 src/modules/palette.c create mode 100644 src/modules/palettes.c rename src/modules/{palette.h => palettes.h} (63%) diff --git a/ChangeLog b/ChangeLog index 19bca9558..4954cf6e5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/NEWS.txt b/NEWS.txt index 57b4d3f3d..192908006 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -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 diff --git a/TODO.txt b/TODO.txt index 3ca012626..b2976f4a5 100644 --- a/TODO.txt +++ b/TODO.txt @@ -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); diff --git a/config.h b/config.h index 5bcc61cad..3f7641e7c 100644 --- a/config.h +++ b/config.h @@ -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" diff --git a/data/gui-en.xml b/data/gui-en.xml index 980771736..499c94043 100644 --- a/data/gui-en.xml +++ b/data/gui-en.xml @@ -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" /> diff --git a/data/jids/confscr.jid b/data/jids/confscr.jid index 0e2e462c7..d951cfd8f 100644 --- a/data/jids/confscr.jid +++ b/data/jids/confscr.jid @@ -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> diff --git a/data/jids/dupspr.jid b/data/jids/dupspr.jid index 7585edc9f..7e07cd70e 100644 --- a/data/jids/dupspr.jid +++ b/data/jids/dupspr.jid @@ -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" /> diff --git a/data/jids/newspr.jid b/data/jids/newspr.jid index a6803bd07..bbc0af0eb 100644 --- a/data/jids/newspr.jid +++ b/data/jids/newspr.jid @@ -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> diff --git a/data/jids/replcol.jid b/data/jids/replcol.jid index bca1f1423..fe24783c8 100644 --- a/data/jids/replcol.jid +++ b/data/jids/replcol.jid @@ -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" /> diff --git a/data/tips/anicontrols.pcx b/data/tips/anicontrols.pcx new file mode 100644 index 0000000000000000000000000000000000000000..21c42e411a806938750667c62ffc16cdf63a0c6e GIT binary patch literal 1393 zcmeHFT?)c53~tg0BEIN}Jcc`r7x2*o`OrTH!UTQuGBvGh>&Bq$QCL}M+I-)aF3DyE zYr*R%cH#hSa4+Z6>wfj#heLHiBS17_Uj<GBynM@KPYI8o&q*r{D$+;>K{_Np1kWP1 zyoDH&iyq$xAlROxGL$iirRbJuifr%dArUo81#Mk;x=+GVB^om1gf5aannE%;1K%=` zC1W&m25R|@^<0WV>Texbqqy~-n_J0_pFJ{eiG&W-$YS9;P;zK4_crx-%VRKaz^3PB Lxm_yomlgN``Btk# literal 0 HcmV?d00001 diff --git a/data/tips/eyedropper.pcx b/data/tips/eyedropper.pcx new file mode 100644 index 0000000000000000000000000000000000000000..087d9b41f7fb48600411d8f40cdde25874b246c4 GIT binary patch literal 1618 zcmeHGQA@)x7|b0ABK|0UivAe)!`6;gChVa?g>LS_hgm!5pu&U-@sc4z)4=vPSfF>8 z@4hQZ+T2{>+GsqQdvk}}No%d6BL^l1W?~+WY#+8+TIPBj_FSSJ!Hyqj7-GYn>LI@K zTlEktTF4lsQr=8vj0^cs@?*U4e#?KZk@)>AxIs#=(%$CWV#X4kR0FDh(4Sy}DPO%& zyNLpBmMP$7mDh?$FTM5=uKx5CeDhjqy{W=p*;;Dlm0P^4960gZGsYG<^hriARXvpx zV@qbRY6@tN9~KC)!xz^GvBg$L6yiqp4k4~p?-62&oz@#-p?<f+7|(s~88Oa${slw6 T)gOM^4H{mF%lvWzXM6&`{Ix=# literal 0 HcmV?d00001 diff --git a/data/tips/tips.en b/data/tips/tips.en index 0dc000463..04d17522f 100644 --- a/data/tips/tips.en +++ b/data/tips/tips.en @@ -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 diff --git a/data/tips/tips.es b/data/tips/tips.es deleted file mode 100644 index 31d082c17..000000000 --- a/data/tips/tips.es +++ /dev/null @@ -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 diff --git a/docs/files/ase.txt b/docs/files/ase.txt index 41f611fb8..84b8ff3d9 100644 --- a/docs/files/ase.txt +++ b/docs/files/ase.txt @@ -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) diff --git a/docs/jid_file.txt b/docs/jid_file.txt index abc262640..687d3f955 100644 --- a/docs/jid_file.txt +++ b/docs/jid_file.txt @@ -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 diff --git a/makefile.lst b/makefile.lst index 2664e1019..911892b1e 100644 --- a/makefile.lst +++ b/makefile.lst @@ -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 \ diff --git a/src/commands/cmd_change_image_type.c b/src/commands/cmd_change_image_type.c index 7f42f4e7e..d31d48312 100644 --- a/src/commands/cmd_change_image_type.c +++ b/src/commands/cmd_change_image_type.c @@ -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" diff --git a/src/commands/cmd_configure_screen.c b/src/commands/cmd_configure_screen.c index b8ff84b78..95a03e2e2 100644 --- a/src/commands/cmd_configure_screen.c +++ b/src/commands/cmd_configure_screen.c @@ -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(); diff --git a/src/commands/cmd_configure_tools.c b/src/commands/cmd_configure_tools.c index 181f73ec4..8d6602363 100644 --- a/src/commands/cmd_configure_tools.c +++ b/src/commands/cmd_configure_tools.c @@ -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, diff --git a/src/commands/cmd_duplicate_layer.c b/src/commands/cmd_duplicate_layer.c index 26f0d3c03..1eee89080 100644 --- a/src/commands/cmd_duplicate_layer.c +++ b/src/commands/cmd_duplicate_layer.c @@ -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; diff --git a/src/commands/cmd_grid.c b/src/commands/cmd_grid.c index 5b1f5c158..034c0f3ca 100644 --- a/src/commands/cmd_grid.c +++ b/src/commands/cmd_grid.c @@ -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 }; diff --git a/src/commands/cmd_merge_down_layer.c b/src/commands/cmd_merge_down_layer.c index 3e288705d..be64af822 100644 --- a/src/commands/cmd_merge_down_layer.c +++ b/src/commands/cmd_merge_down_layer.c @@ -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); diff --git a/src/commands/cmd_new_file.c b/src/commands/cmd_new_file.c index c6ab0d5f3..161ad28ff 100644 --- a/src/commands/cmd_new_file.c +++ b/src/commands/cmd_new_file.c @@ -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 */ diff --git a/src/commands/cmd_new_frame.c b/src/commands/cmd_new_frame.c index 56d49b5fc..871802b68 100644 --- a/src/commands/cmd_new_frame.c +++ b/src/commands/cmd_new_frame.c @@ -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) diff --git a/src/commands/cmd_palette_editor.c b/src/commands/cmd_palette_editor.c index 0f43fac00..6eeae26a2 100644 --- a/src/commands/cmd_palette_editor.c +++ b/src/commands/cmd_palette_editor.c @@ -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 = { diff --git a/src/commands/cmd_play_animation.c b/src/commands/cmd_play_animation.c index 85cc67726..deb927484 100644 --- a/src/commands/cmd_play_animation.c +++ b/src/commands/cmd_play_animation.c @@ -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(); diff --git a/src/commands/cmd_redo.c b/src/commands/cmd_redo.c index 6ee75ac11..ebeaa576c 100644 --- a/src/commands/cmd_redo.c +++ b/src/commands/cmd_redo.c @@ -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); diff --git a/src/commands/cmd_save_mask.c b/src/commands/cmd_save_mask.c index f4ef979e0..b21d0ed0d 100644 --- a/src/commands/cmd_save_mask.c +++ b/src/commands/cmd_save_mask.c @@ -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 = { diff --git a/src/commands/cmd_sprite_properties.c b/src/commands/cmd_sprite_properties.c index 200f29118..4280d0c0f 100644 --- a/src/commands/cmd_sprite_properties.c +++ b/src/commands/cmd_sprite_properties.c @@ -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) { diff --git a/src/commands/cmd_undo.c b/src/commands/cmd_undo.c index 54106ef38..6c2981865 100644 --- a/src/commands/cmd_undo.c +++ b/src/commands/cmd_undo.c @@ -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); diff --git a/src/commands/fx/cmd_color_curve.c b/src/commands/fx/cmd_color_curve.c index 1e3ea669c..db406c170 100644 --- a/src/commands/fx/cmd_color_curve.c +++ b/src/commands/fx/cmd_color_curve.c @@ -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); diff --git a/src/commands/fx/cmd_convolution_matrix.c b/src/commands/fx/cmd_convolution_matrix.c index 9765949b3..cfa51d25d 100644 --- a/src/commands/fx/cmd_convolution_matrix.c +++ b/src/commands/fx/cmd_convolution_matrix.c @@ -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(); diff --git a/src/commands/fx/cmd_despeckle.c b/src/commands/fx/cmd_despeckle.c index 86f440a30..c9d857bb9 100644 --- a/src/commands/fx/cmd_despeckle.c +++ b/src/commands/fx/cmd_despeckle.c @@ -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(); diff --git a/src/commands/fx/cmd_invert_color.c b/src/commands/fx/cmd_invert_color.c index 27e928fc7..a0a57718a 100644 --- a/src/commands/fx/cmd_invert_color.c +++ b/src/commands/fx/cmd_invert_color.c @@ -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(); diff --git a/src/commands/fx/cmd_replace_color.c b/src/commands/fx/cmd_replace_color.c index 51ac28d20..abcebe45c 100644 --- a/src/commands/fx/cmd_replace_color.c +++ b/src/commands/fx/cmd_replace_color.c @@ -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(); diff --git a/src/console/console.c b/src/console/console.c index 079a19fd4..6a4d7635e 100644 --- a/src/console/console.c +++ b/src/console/console.c @@ -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, ...) diff --git a/src/core/app.c b/src/core/app.c index 2126af10e..e6113d16b 100644 --- a/src/core/app.c +++ b/src/core/app.c @@ -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); +} diff --git a/src/core/app.h b/src/core/app.h index b99565849..a7d1606a2 100644 --- a/src/core/app.h +++ b/src/core/app.h @@ -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); diff --git a/src/core/color.c b/src/core/color.c index 5143fac0c..01d4b87e3 100644 --- a/src/core/color.c +++ b/src/core/color.c @@ -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) diff --git a/src/core/color.h b/src/core/color.h index 7e92461d2..83dc05f56 100644 --- a/src/core/color.h +++ b/src/core/color.h @@ -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 */ diff --git a/src/core/core.c b/src/core/core.c index 2d32c2713..917f1073e 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -39,7 +39,9 @@ # define NO_STDERR #endif -/* ASE mode */ +/** + * Current running mode of ASE. + */ int ase_mode = 0; #ifdef NEED_LOG diff --git a/src/core/modules.c b/src/core/modules.c index d38188519..cfb760c75 100644 --- a/src/core/modules.c +++ b/src/core/modules.c @@ -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" diff --git a/src/dialogs/colsel.c b/src/dialogs/colsel.c deleted file mode 100644 index eb1b5d30c..000000000 --- a/src/dialogs/colsel.c +++ /dev/null @@ -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; -} diff --git a/src/dialogs/colsel.h b/src/dialogs/colsel.h deleted file mode 100644 index 459e3d45f..000000000 --- a/src/dialogs/colsel.h +++ /dev/null @@ -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 */ - diff --git a/src/dialogs/dpaledit.c b/src/dialogs/dpaledit.c deleted file mode 100644 index b7625cd8e..000000000 --- a/src/dialogs/dpaledit.c +++ /dev/null @@ -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(); -} diff --git a/src/dialogs/dpaledit.h b/src/dialogs/dpaledit.h deleted file mode 100644 index c350dd193..000000000 --- a/src/dialogs/dpaledit.h +++ /dev/null @@ -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 */ - diff --git a/src/dialogs/drawtext.c b/src/dialogs/drawtext.c index 350c0bbf5..03af93266 100644 --- a/src/dialogs/drawtext.c +++ b/src/dialogs/drawtext.c @@ -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", diff --git a/src/dialogs/filmedit.c b/src/dialogs/filmedit.c index b55ab7a9f..761c4f125 100644 --- a/src/dialogs/filmedit.c +++ b/src/dialogs/filmedit.c @@ -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) diff --git a/src/dialogs/maskcol.c b/src/dialogs/maskcol.c index ec74c9469..046acbe5a 100644 --- a/src/dialogs/maskcol.c +++ b/src/dialogs/maskcol.c @@ -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(); diff --git a/src/dialogs/minipal.c b/src/dialogs/minipal.c deleted file mode 100644 index dc5cb9d85..000000000 --- a/src/dialogs/minipal.c +++ /dev/null @@ -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; -} diff --git a/src/dialogs/minipal.h b/src/dialogs/minipal.h deleted file mode 100644 index 704ec4084..000000000 --- a/src/dialogs/minipal.h +++ /dev/null @@ -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 */ - diff --git a/src/dialogs/options.c b/src/dialogs/options.c index 83e3564fd..2c6f713a7 100644 --- a/src/dialogs/options.c +++ b/src/dialogs/options.c @@ -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; diff --git a/src/dialogs/quick.c b/src/dialogs/quick.c index a8be9191d..aec8cd74d 100644 --- a/src/dialogs/quick.c +++ b/src/dialogs/quick.c @@ -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); diff --git a/src/dialogs/tips.c b/src/dialogs/tips.c index 0ba402f1c..c9b393230 100644 --- a/src/dialogs/tips.c +++ b/src/dialogs/tips.c @@ -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; diff --git a/src/effect/colcurve.c b/src/effect/colcurve.c index bdfa3346a..928831e1d 100644 --- a/src/effect/colcurve.c +++ b/src/effect/colcurve.c @@ -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]; diff --git a/src/effect/convmatr.c b/src/effect/convmatr.c index 966c81b3e..e282437e4 100644 --- a/src/effect/convmatr.c +++ b/src/effect/convmatr.c @@ -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]; } diff --git a/src/effect/invrtcol.c b/src/effect/invrtcol.c index 13c7a7c7a..643b6d061 100644 --- a/src/effect/invrtcol.c +++ b/src/effect/invrtcol.c @@ -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; diff --git a/src/effect/median.c b/src/effect/median.c index e06774c64..a39235503 100644 --- a/src/effect/median.c +++ b/src/effect/median.c @@ -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]; } diff --git a/src/file/ase_format.c b/src/file/ase_format.c index e51e95d1a..18302d7ec 100644 --- a/src/file/ase_format.c +++ b/src/file/ase_format.c @@ -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); diff --git a/src/file/bmp_format.c b/src/file/bmp_format.c index c7000ef9b..48c919345 100644 --- a/src/file/bmp_format.c +++ b/src/file/bmp_format.c @@ -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); } } diff --git a/src/file/file.c b/src/file/file.c index ba6dc71f3..c3a7b8aa6 100644 --- a/src/file/file.c +++ b/src/file/file.c @@ -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) diff --git a/src/file/file.h b/src/file/file.h index e3f800f8c..15cd5d205 100644 --- a/src/file/file.h +++ b/src/file/file.h @@ -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 */ diff --git a/src/file/fli_format.c b/src/file/fli_format.c index fcfca351f..9aa83c480 100644 --- a/src/file/fli_format.c +++ b/src/file/fli_format.c @@ -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 */ diff --git a/src/file/gif_format.c b/src/file/gif_format.c index de8f33906..60980f89c 100644 --- a/src/file/gif_format.c +++ b/src/file/gif_format.c @@ -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); diff --git a/src/file/ico_format.c b/src/file/ico_format.c index 12da79186..fcc9d9e98 100644 --- a/src/file/ico_format.c +++ b/src/file/ico_format.c @@ -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++; } diff --git a/src/file/jpeg_format.c b/src/file/jpeg_format.c index 7805f9cc4..bd6f30cec 100644 --- a/src/file/jpeg_format.c +++ b/src/file/jpeg_format.c @@ -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) { diff --git a/src/file/pcx_format.c b/src/file/pcx_format.c index 821cb21d7..dff228b48 100644 --- a/src/file/pcx_format.c +++ b/src/file/pcx_format.c @@ -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); } } diff --git a/src/file/png_format.c b/src/file/png_format.c index 209ef13b9..dc8def3c5 100644 --- a/src/file/png_format.c +++ b/src/file/png_format.c @@ -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); diff --git a/src/file/tga_format.c b/src/file/tga_format.c index f031cd700..094152c48 100644 --- a/src/file/tga_format.c +++ b/src/file/tga_format.c @@ -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); } diff --git a/src/jinete/jbutton.c b/src/jinete/jbutton.c index 331bb9cb8..0fe4b8a2e 100644 --- a/src/jinete/jbutton.c +++ b/src/jinete/jbutton.c @@ -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; diff --git a/src/jinete/jfile.c b/src/jinete/jfile.c index c2a137036..810706941 100644 --- a/src/jinete/jfile.c +++ b/src/jinete/jfile.c @@ -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]); } } diff --git a/src/jinete/jgrid.c b/src/jinete/jgrid.c index 259c44528..5f80f4e37 100644 --- a/src/jinete/jgrid.c +++ b/src/jinete/jgrid.c @@ -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; diff --git a/src/jinete/jintern.c b/src/jinete/jintern.c index 7d0c0ba94..56677f7ab 100644 --- a/src/jinete/jintern.c +++ b/src/jinete/jintern.c @@ -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(); } diff --git a/src/jinete/jmanager.c b/src/jinete/jmanager.c index 20ca11107..fcf13ecb2 100644 --- a/src/jinete/jmanager.c +++ b/src/jinete/jmanager.c @@ -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; } diff --git a/src/jinete/jmanager.h b/src/jinete/jmanager.h index 1c5fbe154..7a89e8998 100644 --- a/src/jinete/jmanager.h +++ b/src/jinete/jmanager.h @@ -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 diff --git a/src/jinete/jmem.c b/src/jinete/jmem.c index 834904474..4298b0105 100644 --- a/src/jinete/jmem.c +++ b/src/jinete/jmem.c @@ -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; } diff --git a/src/jinete/jmenu.c b/src/jinete/jmenu.c index c1aefa140..118c0993c 100644 --- a/src/jinete/jmenu.c +++ b/src/jinete/jmenu.c @@ -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; diff --git a/src/jinete/jslider.c b/src/jinete/jslider.c index c2d06b0f0..498ef6d2d 100644 --- a/src/jinete/jslider.c +++ b/src/jinete/jslider.c @@ -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; diff --git a/src/jinete/jsystem.c b/src/jinete/jsystem.c index 2a766f933..57593790b 100644 --- a/src/jinete/jsystem.c +++ b/src/jinete/jsystem.c @@ -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 diff --git a/src/jinete/jtooltips.c b/src/jinete/jtooltips.c index ac460385e..1c77a5d25 100644 --- a/src/jinete/jtooltips.c +++ b/src/jinete/jtooltips.c @@ -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; } diff --git a/src/jinete/jwidget.c b/src/jinete/jwidget.c index 67bb33d60..b28e3fd41 100644 --- a/src/jinete/jwidget.c +++ b/src/jinete/jwidget.c @@ -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) diff --git a/src/jinete/jwindow.c b/src/jinete/jwindow.c index 1014b9f01..76e1ac091 100644 --- a/src/jinete/jwindow.c +++ b/src/jinete/jwindow.c @@ -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; } diff --git a/src/modules/editors.c b/src/modules/editors.c index 78b94567b..86a369745 100644 --- a/src/modules/editors.c +++ b/src/modules/editors.c @@ -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" diff --git a/src/modules/gfx.c b/src/modules/gfx.c index 20c3e5ac3..6a02ed325 100644 --- a/src/modules/gfx.c +++ b/src/modules/gfx.c @@ -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 */ diff --git a/src/modules/gfx.h b/src/modules/gfx.h index 77462cf2f..f110963be 100644 --- a/src/modules/gfx.h +++ b/src/modules/gfx.h @@ -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); diff --git a/src/modules/gui.c b/src/modules/gui.c index 10d02736c..00b2635f6 100644 --- a/src/modules/gui.c +++ b/src/modules/gui.c @@ -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; diff --git a/src/modules/gui.h b/src/modules/gui.h index 3886cf6bf..647a07a28 100644 --- a/src/modules/gui.h +++ b/src/modules/gui.h @@ -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 */ diff --git a/src/modules/palette.c b/src/modules/palette.c deleted file mode 100644 index 7433673ff..000000000 --- a/src/modules/palette.c +++ /dev/null @@ -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; -} diff --git a/src/modules/palettes.c b/src/modules/palettes.c new file mode 100644 index 000000000..75ea0c205 --- /dev/null +++ b/src/modules/palettes.c @@ -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); + } +} diff --git a/src/modules/palette.h b/src/modules/palettes.h similarity index 63% rename from src/modules/palette.h rename to src/modules/palettes.h index 86ae37b04..135a9a1a5 100644 --- a/src/modules/palette.h +++ b/src/modules/palettes.h @@ -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 */ diff --git a/src/modules/tools.c b/src/modules/tools.c index ab802fc4a..eb1df1e80 100644 --- a/src/modules/tools.c +++ b/src/modules/tools.c @@ -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] */ diff --git a/src/raster/blend.c b/src/raster/blend.c index 100e18271..219c1762f 100644 --- a/src/raster/blend.c +++ b/src/raster/blend.c @@ -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, diff --git a/src/raster/image.c b/src/raster/image.c index d37de4fe1..33882012a 100644 --- a/src/raster/image.c +++ b/src/raster/image.c @@ -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); } diff --git a/src/raster/image.h b/src/raster/image.h index 3175f56d9..c5cad5d29 100644 --- a/src/raster/image.h +++ b/src/raster/image.h @@ -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) \ diff --git a/src/raster/layer.c b/src/raster/layer.c index 28caae426..4482bd9e4 100644 --- a/src/raster/layer.c +++ b/src/raster/layer.c @@ -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; +} diff --git a/src/raster/layer.h b/src/raster/layer.h index 2444b949e..619a6901f 100644 --- a/src/raster/layer.h +++ b/src/raster/layer.h @@ -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 */ diff --git a/src/raster/mask.c b/src/raster/mask.c index afc4f6f79..cc9d9e582 100644 --- a/src/raster/mask.c +++ b/src/raster/mask.c @@ -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) \ { \ diff --git a/src/raster/quant.c b/src/raster/quant.c index 5a39756b6..2eb46820a 100644 --- a/src/raster/quant.c +++ b/src/raster/quant.c @@ -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); } } diff --git a/src/raster/quant.h b/src/raster/quant.h index fb0c3d85b..e847ba57a 100644 --- a/src/raster/quant.h +++ b/src/raster/quant.h @@ -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 */ diff --git a/src/raster/raster.h b/src/raster/raster.h index 66070c005..d12e35631 100644 --- a/src/raster/raster.h +++ b/src/raster/raster.h @@ -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" diff --git a/src/raster/sprite.c b/src/raster/sprite.c index 735b97f88..e9ecb3e61 100644 --- a/src/raster/sprite.c +++ b/src/raster/sprite.c @@ -24,27 +24,24 @@ #include "jinete/jlist.h" #include "jinete/jmutex.h" -#include "modules/palette.h" +#include "modules/palettes.h" #include "raster/raster.h" #include "util/boundary.h" -typedef struct PAL -{ - int frame; - PALETTE pal; -} PAL; - static Layer *index2layer(Layer *layer, int index, int *index_count); static int layer2index(const Layer *layer, const Layer *find_layer, int *index_count); -static Sprite *general_copy(const Sprite *sprite); +static Sprite *general_copy(const Sprite *src_sprite); Sprite *sprite_new(int imgtype, int w, int h) { - Sprite *sprite = (Sprite *)gfxobj_new(GFXOBJ_SPRITE, sizeof(Sprite)); - PALETTE pal; + Sprite *sprite; + Palette *pal; int c; + assert(w > 0 && h > 0); + + sprite = (Sprite *)gfxobj_new(GFXOBJ_SPRITE, sizeof(Sprite)); if (!sprite) return NULL; @@ -58,7 +55,6 @@ Sprite *sprite_new(int imgtype, int w, int h) sprite->frames = 1; sprite->frlens = jmalloc(sizeof(int)*sprite->frames); sprite->frame = 0; -/* sprite->palette = jmalloc(sizeof(PALETTE)); */ sprite->palettes = jlist_new(); sprite->stock = stock_new(imgtype); sprite->set = layer_set_new(sprite); @@ -78,104 +74,103 @@ Sprite *sprite_new(int imgtype, int w, int h) sprite->preferred.scroll_y = 0; sprite->preferred.zoom = 0; - /* setup the layer set */ - layer_set_parent (sprite->set, (GfxObj *)sprite); - /* generate palette */ + pal = palette_new(0, MAX_PALETTE_COLORS); switch (imgtype) { /* for colored images */ case IMAGE_RGB: case IMAGE_INDEXED: - for (c=0; c<256; c++) { - pal[c].r = default_palette[c].r; - pal[c].g = default_palette[c].g; - pal[c].b = default_palette[c].b; - } + palette_copy_colors(pal, get_default_palette()); break; /* for black and white images */ case IMAGE_GRAYSCALE: case IMAGE_BITMAP: - for (c=0; c<256; c++) { - pal[c].r = c >> 2; - pal[c].g = c >> 2; - pal[c].b = c >> 2; - } + for (c=0; c<256; c++) + palette_set_entry(pal, c, _rgba(c, c, c, 255)); break; } - - sprite_set_palette(sprite, pal, sprite->frame); + sprite_set_palette(sprite, pal, TRUE); sprite_set_speed(sprite, 100); /* multiple access */ sprite->locked = FALSE; sprite->mutex = jmutex_new(); + + /* free the temporary palette */ + palette_free(pal); return sprite; } -Sprite *sprite_new_copy(const Sprite *sprite) +Sprite *sprite_new_copy(const Sprite *src_sprite) { - Sprite *sprite_copy; + Sprite *dst_sprite; int selected_layer; - sprite_copy = general_copy(sprite); - if (!sprite_copy) + assert(src_sprite != NULL); + + dst_sprite = general_copy(src_sprite); + if (!dst_sprite) return NULL; /* copy layers */ - if (sprite_copy->set) { - layer_free(sprite_copy->set); - sprite_copy->set = NULL; + if (dst_sprite->set) { + layer_free(dst_sprite->set); + dst_sprite->set = NULL; } - if (sprite->set) { - sprite_copy->set = layer_new_copy(sprite->set); - if (!sprite_copy->set) { - sprite_free(sprite_copy); - return NULL; - } + assert(src_sprite->set != NULL); - /* setup the layer set */ - layer_set_parent(sprite_copy->set, (GfxObj *)sprite_copy); + undo_disable(dst_sprite->undo); + dst_sprite->set = layer_new_copy(dst_sprite, src_sprite->set); + undo_enable(dst_sprite->undo); + + if (dst_sprite->set == NULL) { + sprite_free(dst_sprite); + return NULL; } /* selected layer */ - if (sprite->layer) { - selected_layer = sprite_layer2index(sprite, sprite->layer); - sprite_copy->layer = sprite_index2layer(sprite_copy, selected_layer); + if (src_sprite->layer != NULL) { + selected_layer = sprite_layer2index(src_sprite, src_sprite->layer); + dst_sprite->layer = sprite_index2layer(dst_sprite, selected_layer); } - sprite_generate_mask_boundaries(sprite_copy); + sprite_generate_mask_boundaries(dst_sprite); - return sprite_copy; + return dst_sprite; } -Sprite *sprite_new_flatten_copy(const Sprite *sprite) +Sprite *sprite_new_flatten_copy(const Sprite *src_sprite) { - Sprite *sprite_copy; + Sprite *dst_sprite; + Layer *flat_layer; - sprite_copy = general_copy(sprite); - if (!sprite_copy) + assert(src_sprite != NULL); + + dst_sprite = general_copy(src_sprite); + if (dst_sprite == NULL) return NULL; /* flatten layers */ - if (sprite->set) { - Layer *flat_layer = layer_flatten(sprite->set, - 0, 0, sprite->w, sprite->h, - 0, sprite->frames-1); - if (!flat_layer) { - sprite_free(sprite_copy); - return NULL; - } + assert(src_sprite->set != NULL); - /* add and select the new flat layer */ - layer_add_layer(sprite_copy->set, flat_layer); - sprite_copy->layer = flat_layer; + flat_layer = layer_new_flatten_copy(dst_sprite, + src_sprite->set, + 0, 0, src_sprite->w, src_sprite->h, + 0, src_sprite->frames-1); + if (flat_layer == NULL) { + sprite_free(dst_sprite); + return NULL; } - return sprite_copy; + /* add and select the new flat layer */ + layer_add_layer(dst_sprite->set, flat_layer); + dst_sprite->layer = flat_layer; + + return dst_sprite; } Sprite *sprite_new_with_layer(int imgtype, int w, int h) @@ -239,6 +234,7 @@ void sprite_free(Sprite *sprite) { JLink link; + assert(sprite != NULL); assert(!sprite->locked); /* destroy images' stock */ @@ -284,12 +280,16 @@ void sprite_free(Sprite *sprite) bool sprite_is_modified(Sprite *sprite) { + assert(sprite != NULL); + return (sprite->undo->diff_count == sprite->undo->diff_saved) ? FALSE: TRUE; } bool sprite_is_associated_to_file(Sprite *sprite) { + assert(sprite != NULL); + return sprite->associated_to_file; } @@ -297,6 +297,8 @@ bool sprite_is_locked(Sprite *sprite) { bool locked; + assert(sprite != NULL); + jmutex_lock(sprite->mutex); locked = sprite->locked; jmutex_unlock(sprite->mutex); @@ -306,12 +308,16 @@ bool sprite_is_locked(Sprite *sprite) void sprite_mark_as_saved(Sprite *sprite) { + assert(sprite != NULL); + sprite->undo->diff_saved = sprite->undo->diff_count; sprite->associated_to_file = TRUE; } bool sprite_need_alpha(Sprite *sprite) { + assert(sprite != NULL); + switch (sprite->imgtype) { case IMAGE_RGB: @@ -328,6 +334,8 @@ bool sprite_lock(Sprite *sprite) { bool res = FALSE; + assert(sprite != NULL); + jmutex_lock(sprite->mutex); if (!sprite->locked) { sprite->locked = TRUE; @@ -340,55 +348,63 @@ bool sprite_lock(Sprite *sprite) void sprite_unlock(Sprite *sprite) { + assert(sprite != NULL); + jmutex_lock(sprite->mutex); assert(sprite->locked); sprite->locked = FALSE; jmutex_unlock(sprite->mutex); } -RGB *sprite_get_palette(Sprite *sprite, int frame) +Palette *sprite_get_palette(Sprite *sprite, int frame) { - RGB *rgb = NULL; + Palette *found = NULL; + Palette *pal; JLink link; - PAL *pal; - frame = MAX(0, frame); + assert(sprite != NULL); + assert(frame >= 0); JI_LIST_FOR_EACH(sprite->palettes, link) { pal = link->data; if (frame < pal->frame) break; - rgb = pal->pal; + + found = pal; if (frame == pal->frame) break; } - return rgb; + assert(found != NULL); + return found; } -void sprite_set_palette(Sprite *sprite, RGB *rgb, int frame) +void sprite_set_palette(Sprite *sprite, Palette *pal, bool truncate) { - JLink link; - PAL *pal; + assert(sprite != NULL); - frame = MAX(0, frame); - - JI_LIST_FOR_EACH(sprite->palettes, link) { - pal = link->data; - - if (frame == pal->frame) { - palette_copy(pal->pal, rgb); - return; - } - else if (frame < pal->frame) - break; + if (!truncate) { + Palette *sprite_pal = sprite_get_palette(sprite, sprite->frame); + palette_copy_colors(sprite_pal, pal); } + else { + JLink link; + Palette *other; - pal = jmalloc(sizeof(PAL)); - pal->frame = frame; - palette_copy(pal->pal, rgb); + JI_LIST_FOR_EACH(sprite->palettes, link) { + other = link->data; - jlist_insert_before(sprite->palettes, link, pal); + if (pal->frame == other->frame) { + palette_copy_colors(other, pal); + return; + } + else if (pal->frame < other->frame) + break; + } + + jlist_insert_before(sprite->palettes, link, + palette_new_copy(pal)); + } } /** @@ -400,7 +416,7 @@ void sprite_reset_palettes(Sprite *sprite) JI_LIST_FOR_EACH_SAFE(sprite->palettes, link, next) { if (jlist_first(sprite->palettes) != link) { - jfree(link->data); + palette_free(link->data); jlist_delete_link(sprite->palettes, link); } } @@ -502,7 +518,7 @@ void sprite_set_frame(Sprite *sprite, int frame) */ void sprite_set_imgtype(Sprite *sprite, int imgtype, int dithering_method) { - RGB *palette = sprite_get_palette(sprite, 0); + Palette *palette = sprite_get_palette(sprite, 0); Image *old_image; Image *new_image; int c, r, g, b; @@ -570,18 +586,16 @@ void sprite_set_imgtype(Sprite *sprite, int imgtype, int dithering_method) if (c == 0) c = 0; else - c = _rgba(_rgb_scale_6[palette[c].r], - _rgb_scale_6[palette[c].g], - _rgb_scale_6[palette[c].b], 255); + c = palette->color[c]; break; /* Indexed -> Grayscale */ case IMAGE_GRAYSCALE: if (c == 0) c = 0; else { - r = _rgb_scale_6[palette[c].r]; - g = _rgb_scale_6[palette[c].g]; - b = _rgb_scale_6[palette[c].b]; + 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); c = _graya(b, 255); } @@ -825,80 +839,80 @@ static int layer2index(const Layer *layer, const Layer *find_layer, int *index_c /** * Makes a copy "sprite" without the layers (only with the empty layer set) */ -static Sprite *general_copy(const Sprite *sprite) +static Sprite *general_copy(const Sprite *src_sprite) { - Sprite *sprite_copy; + Sprite *dst_sprite; JLink link; - sprite_copy = sprite_new(sprite->imgtype, sprite->w, sprite->h); - if (!sprite_copy) + dst_sprite = sprite_new(src_sprite->imgtype, src_sprite->w, src_sprite->h); + if (!dst_sprite) return NULL; /* copy stock */ - stock_free(sprite_copy->stock); - sprite_copy->stock = stock_new_copy(sprite->stock); - if (!sprite_copy->stock) { - sprite_free(sprite_copy); + stock_free(dst_sprite->stock); + dst_sprite->stock = stock_new_copy(src_sprite->stock); + if (!dst_sprite->stock) { + sprite_free(dst_sprite); return NULL; } /* copy general properties */ - strcpy(sprite_copy->filename, sprite->filename); - sprite_set_bgcolor(sprite_copy, sprite->bgcolor); - sprite_set_frames(sprite_copy, sprite->frame); - memcpy(sprite_copy->frlens, sprite->frlens, sizeof(int)*sprite->frames); + strcpy(dst_sprite->filename, src_sprite->filename); + sprite_set_bgcolor(dst_sprite, src_sprite->bgcolor); + sprite_set_frames(dst_sprite, src_sprite->frames); + memcpy(dst_sprite->frlens, src_sprite->frlens, sizeof(int)*src_sprite->frames); /* copy color palettes */ - JI_LIST_FOR_EACH(sprite->palettes, link) { - PAL *pal = link->data; - sprite_set_palette(sprite_copy, pal->pal, pal->frame); + JI_LIST_FOR_EACH(src_sprite->palettes, link) { + Palette *pal = link->data; + sprite_set_palette(dst_sprite, pal, TRUE); } /* copy path */ - if (sprite_copy->path) { - path_free(sprite_copy->path); - sprite_copy->path = NULL; + if (dst_sprite->path) { + path_free(dst_sprite->path); + dst_sprite->path = NULL; } - if (sprite->path) { - sprite_copy->path = path_new_copy(sprite->path); - if (!sprite_copy->path) { - sprite_free(sprite_copy); + if (src_sprite->path) { + dst_sprite->path = path_new_copy(src_sprite->path); + if (!dst_sprite->path) { + sprite_free(dst_sprite); return NULL; } } /* copy mask */ - if (sprite_copy->mask) { - mask_free(sprite_copy->mask); - sprite_copy->mask = NULL; + if (dst_sprite->mask) { + mask_free(dst_sprite->mask); + dst_sprite->mask = NULL; } - if (sprite->mask) { - sprite_copy->mask = mask_new_copy(sprite->mask); - if (!sprite_copy->mask) { - sprite_free(sprite_copy); + if (src_sprite->mask) { + dst_sprite->mask = mask_new_copy(src_sprite->mask); + if (!dst_sprite->mask) { + sprite_free(dst_sprite); return NULL; } } /* copy repositories */ - JI_LIST_FOR_EACH(sprite->repository.paths, link) { + JI_LIST_FOR_EACH(src_sprite->repository.paths, link) { Path *path_copy = path_new_copy(link->data); if (path_copy) - sprite_add_path(sprite_copy, path_copy); + sprite_add_path(dst_sprite, path_copy); } - JI_LIST_FOR_EACH(sprite->repository.masks, link) { + JI_LIST_FOR_EACH(src_sprite->repository.masks, link) { Mask *mask_copy = mask_new_copy(link->data); if (mask_copy) - sprite_add_mask(sprite_copy, mask_copy); + sprite_add_mask(dst_sprite, mask_copy); } /* copy preferred edition options */ - sprite_copy->preferred.scroll_x = sprite->preferred.scroll_x; - sprite_copy->preferred.scroll_y = sprite->preferred.scroll_y; - sprite_copy->preferred.zoom = sprite->preferred.zoom; + dst_sprite->preferred.scroll_x = src_sprite->preferred.scroll_x; + dst_sprite->preferred.scroll_y = src_sprite->preferred.scroll_y; + dst_sprite->preferred.zoom = src_sprite->preferred.zoom; - return sprite_copy; + return dst_sprite; } diff --git a/src/raster/sprite.h b/src/raster/sprite.h index 247027bb1..5afda7340 100644 --- a/src/raster/sprite.h +++ b/src/raster/sprite.h @@ -21,14 +21,14 @@ #include "jinete/jbase.h" #include "raster/gfxobj.h" -#include <allegro/color.h> -struct Layer; -struct Path; -struct Mask; -struct Undo; struct Image; +struct Layer; +struct Mask; +struct Palette; +struct Path; struct Stock; +struct Undo; typedef struct Sprite Sprite; @@ -70,8 +70,8 @@ struct Sprite }; Sprite *sprite_new(int imgtype, int w, int h); -Sprite *sprite_new_copy(const Sprite *sprite); -Sprite *sprite_new_flatten_copy(const Sprite *sprite); +Sprite *sprite_new_copy(const Sprite *src_sprite); +Sprite *sprite_new_flatten_copy(const Sprite *src_sprite); Sprite *sprite_new_with_layer(int imgtype, int w, int h); void sprite_free(Sprite *sprite); @@ -85,8 +85,8 @@ bool sprite_need_alpha(Sprite *sprite); bool sprite_lock(Sprite *sprite); void sprite_unlock(Sprite *sprite); -RGB *sprite_get_palette(Sprite *sprite, int frame); -void sprite_set_palette(Sprite *sprite, RGB *rgb, int frame); +struct Palette *sprite_get_palette(Sprite *sprite, int frame); +void sprite_set_palette(Sprite *sprite, struct Palette *pal, bool truncate); void sprite_reset_palettes(Sprite *sprite); void sprite_set_filename(Sprite *sprite, const char *filename); diff --git a/src/raster/stock.c b/src/raster/stock.c index 103b2bd51..9d0fddf2e 100644 --- a/src/raster/stock.c +++ b/src/raster/stock.c @@ -19,6 +19,7 @@ #include "config.h" #include <string.h> +#include <assert.h> #include "raster/image.h" #include "raster/stock.h" @@ -81,6 +82,8 @@ Stock *stock_new_copy(const Stock *stock) } } + assert(stock_copy->nimage == stock->nimage); + return stock_copy; } @@ -109,7 +112,7 @@ int stock_add_image(Stock *stock, Image *image) { int i = stock->nimage++; - stock->image = jrealloc (stock->image, sizeof (Image *) * stock->nimage); + stock->image = jrealloc(stock->image, sizeof(Image *) * stock->nimage); if (!stock->image) return -1; diff --git a/src/raster/undo.c b/src/raster/undo.c index 7964324c9..b9fd7e011 100644 --- a/src/raster/undo.c +++ b/src/raster/undo.c @@ -18,6 +18,7 @@ #include "config.h" +#include <assert.h> #include <errno.h> #include <limits.h> #include <stdio.h> @@ -287,6 +288,26 @@ void undo_redo(Undo *undo) run_undo(undo, DO_REDO, FALSE); } +const char *undo_get_next_undo_label(Undo *undo) +{ + UndoChunk *chunk; + + assert(undo_can_undo(undo)); + + chunk = jlist_first_data(undo->undo_stream->chunks); + return undo_actions[chunk->type].name; +} + +const char *undo_get_next_redo_label(Undo *undo) +{ + UndoChunk *chunk; + + assert(undo_can_redo(undo)); + + chunk = jlist_first_data(undo->redo_stream->chunks); + return undo_actions[chunk->type].name; +} + static void run_undo(Undo *undo, int state, int discard_tail) { UndoStream *undo_stream = ((state == DO_UNDO)? undo->undo_stream: @@ -302,12 +323,12 @@ static void run_undo(Undo *undo, int state, int discard_tail) if (!chunk) break; - /* { int c; */ - /* for (c=0; c<ABS (level); c++) */ - /* fprintf (stderr, " "); */ - /* fprintf (stderr, "%s: %s\n", */ - /* (state == DO_UNDO) ? "Undo": "Redo", */ - /* undo_actions[chunk->type].name); } */ +/* { int c; */ +/* for (c=0; c<ABS(level); c++) */ +/* PRINTF(" "); */ +/* PRINTF("%s: %s\n", */ +/* (state == DO_UNDO) ? "Undo": "Redo", */ +/* undo_actions[chunk->type].name); } */ (undo_actions[chunk->type].invert)(redo_stream, chunk, state); @@ -694,7 +715,7 @@ static void chunk_dirty(UndoStream *stream, Dirty *dirty) static void chunk_dirty_invert(UndoStream *stream, UndoChunk *chunk, int state) { unsigned long id = undo_chunk_get32(chunk); - int imgtype = undo_chunk_get8 (chunk); + int imgtype = undo_chunk_get8(chunk); Image *image = (Image *)gfxobj_find(id); if ((image) && (image->gfxobj.type == GFXOBJ_IMAGE) && @@ -710,24 +731,25 @@ static void chunk_dirty_invert(UndoStream *stream, UndoChunk *chunk, int state) dirty = dirty_new(image, x1, y1, x2, y2, FALSE); dirty->rows = undo_chunk_get16(chunk); - dirty->row = jmalloc(sizeof(struct DirtyRow) * dirty->rows); + if (dirty->rows > 0) { + dirty->row = jmalloc(sizeof(struct DirtyRow) * dirty->rows); + for (v=0; v<dirty->rows; v++) { + dirty->row[v].y = y = undo_chunk_get16(chunk); + dirty->row[v].cols = undo_chunk_get16(chunk); + dirty->row[v].col = jmalloc(sizeof(struct DirtyCol) * dirty->row[v].cols); - for (v=0; v<dirty->rows; v++) { - dirty->row[v].y = y = undo_chunk_get16(chunk); - dirty->row[v].cols = undo_chunk_get16(chunk); - dirty->row[v].col = jmalloc(sizeof(struct DirtyCol) * dirty->row[v].cols); + for (u=0; u<dirty->row[v].cols; u++) { + dirty->row[v].col[u].x = x = undo_chunk_get16(chunk); + dirty->row[v].col[u].w = undo_chunk_get16(chunk); - for (u=0; u<dirty->row[v].cols; u++) { - dirty->row[v].col[u].x = x = undo_chunk_get16(chunk); - dirty->row[v].col[u].w = undo_chunk_get16(chunk); + size = dirty->row[v].col[u].w << IMAGE_SHIFT(dirty->image); - size = dirty->row[v].col[u].w << IMAGE_SHIFT(dirty->image); + dirty->row[v].col[u].flags = DIRTY_VALID_COLUMN; + dirty->row[v].col[u].data = jmalloc (size); + dirty->row[v].col[u].ptr = IMAGE_ADDRESS(dirty->image, x, y); - dirty->row[v].col[u].flags = DIRTY_VALID_COLUMN; - dirty->row[v].col[u].data = jmalloc (size); - dirty->row[v].col[u].ptr = IMAGE_ADDRESS(dirty->image, x, y); - - undo_chunk_read(chunk, dirty->row[v].col[u].data, size); + undo_chunk_read(chunk, dirty->row[v].col[u].data, size); + } } } @@ -824,7 +846,7 @@ static void chunk_remove_image_invert(UndoStream *stream, UndoChunk *chunk, int if (stock) { Image *image = undo_chunk_read_image(chunk); - /* ji_assert(image); */ + /* assert(image != NULL); */ stock_replace_image(stock, index, image); chunk_add_image(stream, stock, image); @@ -867,8 +889,6 @@ static void chunk_replace_image_invert(UndoStream *stream, UndoChunk *chunk, int if (stock) { Image *image = undo_chunk_read_image(chunk); - /* ji_assert(image); */ - chunk_replace_image(stream, stock, index); if (stock->image[index]) @@ -950,7 +970,7 @@ static void chunk_remove_cel_invert(UndoStream *stream, UndoChunk *chunk, int st if (layer) { Cel *cel = undo_chunk_read_cel(chunk); - /* ji_assert (cel); */ + /* assert(cel != NULL); */ chunk_add_cel(stream, layer, cel); layer_add_cel(layer, cel); @@ -1015,7 +1035,7 @@ void undo_remove_layer(Undo *undo, Layer *layer) static void chunk_remove_layer(UndoStream *stream, Layer *layer) { UndoChunk *chunk = undo_chunk_new(UNDO_TYPE_REMOVE_LAYER); - Layer *set = (Layer *)layer->parent; + Layer *set = layer->parent_layer; Layer *after = layer_get_prev(layer); undo_chunk_put32(chunk, set->gfxobj.id); @@ -1035,7 +1055,7 @@ static void chunk_remove_layer_invert(UndoStream *stream, UndoChunk *chunk, int if (set) { Layer *layer = undo_chunk_read_layer(chunk); - /* ji_assert(layer); */ + /* assert(layer != NULL); */ chunk_add_layer(stream, set, layer); layer_add_layer(set, layer); @@ -1062,7 +1082,7 @@ void undo_move_layer(Undo *undo, Layer *layer) static void chunk_move_layer(UndoStream *stream, Layer *layer) { UndoChunk *chunk = undo_chunk_new(UNDO_TYPE_MOVE_LAYER); - Layer *set = (Layer *)layer->parent; + Layer *set = layer->parent_layer; Layer *after = layer_get_prev(layer); undo_chunk_put32(chunk, set->gfxobj.id); diff --git a/src/raster/undo.h b/src/raster/undo.h index c230316cf..1b978999e 100644 --- a/src/raster/undo.h +++ b/src/raster/undo.h @@ -61,6 +61,9 @@ bool undo_can_redo(Undo *undo); void undo_undo(Undo *undo); void undo_redo(Undo *undo); +const char *undo_get_next_undo_label(Undo *undo); +const char *undo_get_next_redo_label(Undo *undo); + void undo_open(Undo *undo); void undo_close(Undo *undo); void undo_data(Undo *undo, GfxObj *gfxobj, void *data, int size); diff --git a/src/raster/x86/blenders.s b/src/raster/x86/blenders.s index ee959d185..ac0bc3090 100644 --- a/src/raster/x86/blenders.s +++ b/src/raster/x86/blenders.s @@ -173,7 +173,8 @@ L3: #endif -#if 1 /* TODO add SSE support */ +#if 1 /* TODO add SSE support (the routine is called "_sse" but + doesn't use any SSE at the moment :) */ #define LOCAL_OLD_EBX -12(%ebp) #define LOCAL_OLD_ESI -8(%ebp) diff --git a/src/script/bindings.c b/src/script/bindings.c index 5bfe56cb2..293da436a 100644 --- a/src/script/bindings.c +++ b/src/script/bindings.c @@ -27,8 +27,6 @@ #include "core/cfg.h" #include "core/color.h" #include "core/core.h" -#include "dialogs/colsel.h" -#include "dialogs/dpaledit.h" #include "dialogs/filesel.h" #include "effect/colcurve.h" #include "effect/convmatr.h" @@ -37,7 +35,7 @@ #include "effect/replcol.h" #include "modules/editors.h" #include "modules/gui.h" -#include "modules/palette.h" +#include "modules/palettes.h" #include "modules/recent.h" #include "modules/sprites.h" #include "modules/tools.h" @@ -253,9 +251,7 @@ static int metatable_index(lua_State *L) if (strcmp(index, "name") == 0) lua_pushstring(L, layer->name); else if (strcmp(index, "parent") == 0) - push_userdata(L, - layer->parent->type == GFXOBJ_LAYER_SET ? - Type_Layer: Type_Sprite, layer->parent); + push_userdata(L, Type_Layer, layer->parent_layer); else if (strcmp(index, "readable") == 0) lua_pushboolean(L, layer->readable); else if (strcmp(index, "writable") == 0) diff --git a/src/script/functions.c b/src/script/functions.c index 4b9cd81fe..3bbad5916 100644 --- a/src/script/functions.c +++ b/src/script/functions.c @@ -273,7 +273,7 @@ void RemoveLayer(void) Sprite *sprite = current_sprite; if (sprite && sprite->layer) { Layer *layer = sprite->layer; - Layer *parent = (Layer *)layer->parent; + Layer *parent = layer->parent_layer; Layer *layer_select; /* select: previous layer, or next layer, or parent(if it is not @@ -337,8 +337,9 @@ Layer *FlattenLayers(void) return NULL; /* generate the flat_layer */ - flat_layer = layer_flatten(sprite->set, 0, 0, sprite->w, sprite->h, - 0, sprite->frames-1); + flat_layer = layer_new_flatten_copy(sprite, sprite->set, + 0, 0, sprite->w, sprite->h, + 0, sprite->frames-1); if (!flat_layer) { console_printf("Not enough memory"); return NULL; @@ -388,7 +389,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; diff --git a/src/util/boundary.c b/src/util/boundary.c index b7c167ed2..13b64f383 100644 --- a/src/util/boundary.c +++ b/src/util/boundary.c @@ -542,3 +542,28 @@ sort_boundary (BoundSeg *segs, /* Return the new boundary */ return new_segs; } + +/* dacap: for ASE to avoid informed memory leaks */ +void boundary_exit(void) +{ + if (vert_segs != NULL) { + jfree(vert_segs); + vert_segs = NULL; + } + if (tmp_segs != NULL) { + jfree(tmp_segs); + tmp_segs = NULL; + } + if (empty_segs_n != NULL) { + jfree(empty_segs_n); + empty_segs_n = NULL; + } + if (empty_segs_c != NULL) { + jfree(empty_segs_c); + empty_segs_c = NULL; + } + if (empty_segs_l != NULL) { + jfree(empty_segs_l); + empty_segs_l = NULL; + } +} diff --git a/src/util/boundary.h b/src/util/boundary.h index d68fe6bdb..ddc7427fa 100644 --- a/src/util/boundary.h +++ b/src/util/boundary.h @@ -43,16 +43,11 @@ typedef struct _BoundSeg unsigned visited : 1; } BoundSeg; -BoundSeg * find_mask_boundary (const struct Image *maskPR, - int *num_elems, - BoundaryType type, - int x1, - int y1, - int x2, - int y2); -BoundSeg * sort_boundary (BoundSeg *segs, - int num_segs, - int *num_groups); +BoundSeg *find_mask_boundary(const struct Image *maskPR, int *num_elems, + BoundaryType type, int x1, int y1, int x2, int y2); +BoundSeg *sort_boundary(BoundSeg *segs, int num_segs, int *num_groups); + +void boundary_exit(void); #ifdef __cplusplus } diff --git a/src/util/clipbrd.c b/src/util/clipbrd.c index 7d55bbc86..e2a8a1983 100644 --- a/src/util/clipbrd.c +++ b/src/util/clipbrd.c @@ -29,7 +29,7 @@ #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 "modules/tools2.h" @@ -124,7 +124,7 @@ void copy_image_to_clipboard(Image *image) dest = GetImage2(sprite, NULL, NULL, NULL); image_copy(dest, image, 0, 0); - sprite_set_palette(sprite, current_palette, 0); + sprite_set_palette(sprite, get_current_palette(), FALSE); set_clipboard_sprite(sprite); } diff --git a/src/util/col_file.c b/src/util/col_file.c index f291880c5..d4b7948ea 100644 --- a/src/util/col_file.c +++ b/src/util/col_file.c @@ -23,9 +23,12 @@ #include "file/file.h" #include "raster/image.h" +#include "raster/palette.h" + +#define PROCOL_MAGIC_NUMBER 0xB123 /* loads a COL file (Animator and Animator Pro format) */ -RGB *load_col_file(const char *filename) +Palette *load_col_file(const char *filename) { #if (MAKE_VERSION(4, 2, 1) >= MAKE_VERSION(ALLEGRO_VERSION, \ ALLEGRO_SUB_VERSION, \ @@ -36,7 +39,7 @@ RGB *load_col_file(const char *filename) #endif int pro = (size == 768)? FALSE: TRUE; /* is Animator Pro format? */ div_t d = div(size-8, 3); - RGB *palette = NULL; + Palette *pal = NULL; int c, r, g, b; FILE *f; @@ -49,15 +52,19 @@ RGB *load_col_file(const char *filename) /* Animator format */ if (!pro) { - palette = jmalloc(sizeof (PALETTE)); + pal = palette_new(0, MAX_PALETTE_COLORS); for (c=0; c<256; c++) { r = fgetc(f); g = fgetc(f); b = fgetc(f); - palette[c].r = MID(0, r, 63); - palette[c].g = MID(0, g, 63); - palette[c].b = MID(0, b, 63); + if (ferror(f)) + break; + + palette_set_entry(pal, c, + _rgba(_rgb_scale_6[MID(0, r, 63)], + _rgb_scale_6[MID(0, g, 63)], + _rgb_scale_6[MID(0, b, 63)], 255)); } } /* Animator Pro format */ @@ -69,48 +76,54 @@ RGB *load_col_file(const char *filename) version = fgetw(f); /* version file */ /* unknown format */ - if (magic != 0xB123 || version != 0) { - fclose (f); + if (magic != PROCOL_MAGIC_NUMBER || version != 0) { + fclose(f); return NULL; } - palette = jmalloc(sizeof (PALETTE)); + pal = palette_new(0, MIN(d.quot, MAX_PALETTE_COLORS)); - for (c=0; c<d.quot && c<256; c++) { + for (c=0; c<pal->ncolors; c++) { r = fgetc(f); g = fgetc(f); b = fgetc(f); - palette[c].r = MID(0, r, 255)>>2; - palette[c].g = MID(0, g, 255)>>2; - palette[c].b = MID(0, b, 255)>>2; - } + if (ferror(f)) + break; - for (; c<256; c++) - palette[c].r = palette[c].g = palette[c].b = 0; + palette_set_entry(pal, c, + _rgba(MID(0, r, 255), + MID(0, g, 255), + MID(0, b, 255), 255)); + } } fclose(f); - return palette; + return pal; } /* saves an Animator Pro COL file */ -int save_col_file(RGB *palette, const char *filename) +bool save_col_file(Palette *pal, const char *filename) { + ase_uint32 c; FILE *f; - int c; + int i; f = fopen(filename, "wb"); if (!f) return -1; - fputl(8+768, f); /* file size */ - fputw(0xB123, f); /* file format identifier */ - fputw(0, f); /* version file */ + fputl(8+768, f); /* file size */ + fputw(PROCOL_MAGIC_NUMBER, f); /* file format identifier */ + fputw(0, f); /* version file */ - for (c=0; c<256; c++) { - fputc(_rgb_scale_6[palette[c].r], f); - fputc(_rgb_scale_6[palette[c].g], f); - fputc(_rgb_scale_6[palette[c].b], f); + for (i=0; i<MAX_PALETTE_COLORS; i++) { + c = palette_get_entry(pal, i); + + fputc(_rgba_getr(c), f); + fputc(_rgba_getg(c), f); + fputc(_rgba_getb(c), f); + if (ferror(f)) + break; } fclose(f); diff --git a/src/util/col_file.h b/src/util/col_file.h index 16006abe8..029bb6763 100644 --- a/src/util/col_file.h +++ b/src/util/col_file.h @@ -19,10 +19,10 @@ #ifndef UTIL_COL_FILE_H #define UTIL_COL_FILE_H -#include <allegro/color.h> +struct Palette; -struct RGB *load_col_file (const char *filename); -int save_col_file (struct RGB *palette, const char *filename); +struct Palette *load_col_file(const char *filename); +bool save_col_file(struct Palette *pal, const char *filename); #endif /* UTIL_COL_FILE_H */ diff --git a/src/util/crop.c b/src/util/crop.c index 22df260b9..b1e195278 100644 --- a/src/util/crop.c +++ b/src/util/crop.c @@ -78,7 +78,7 @@ void crop_layer(void) Layer *new_layer; Cel *new_cel; Image *new_image; - Layer *set = (Layer *)layer->parent; + Layer *set = layer->parent_layer; JLink link; new_layer = layer_new(sprite); diff --git a/src/util/misc.c b/src/util/misc.c index 684eeffab..4e6795476 100644 --- a/src/util/misc.c +++ b/src/util/misc.c @@ -32,17 +32,10 @@ #include "core/dirs.h" #include "modules/editors.h" #include "modules/gui.h" -#include "modules/palette.h" +#include "modules/palettes.h" #include "modules/sprites.h" #include "modules/tools2.h" -#include "raster/blend.h" -#include "raster/cel.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" @@ -91,28 +84,25 @@ void LoadPalette(const char *filename) DIRS *dir, *dirs; char buf[512]; - dirs = dirs_new (); - dirs_add_path (dirs, filename); + dirs = dirs_new(); + dirs_add_path(dirs, filename); - usprintf (buf, "palettes/%s", filename); - dirs_cat_dirs (dirs, filename_in_datadir (buf)); + usprintf(buf, "palettes/%s", filename); + dirs_cat_dirs(dirs, filename_in_datadir (buf)); for (dir=dirs; dir; dir=dir->next) { - if (exists (dir->path)) { - RGB *pal = palette_load (dir->path); - if (pal) { + if (exists(dir->path)) { + Palette *pal = palette_load(dir->path); + if (pal != NULL) { + /* set the palette calling the hooks */ + set_current_palette(pal, FALSE); + /* just one palette */ sprite_reset_palettes(current_sprite); sprite_set_palette(current_sprite, pal, 0); - /* set the palette calling the hooks */ - set_current_palette(pal, FALSE); - /* redraw the entire screen */ jmanager_refresh_screen(); - - /* free the memory */ - jfree(pal); } break; } diff --git a/src/util/pic_file.c b/src/util/pic_file.c index 8181f605d..6ead7ffba 100644 --- a/src/util/pic_file.c +++ b/src/util/pic_file.c @@ -24,7 +24,7 @@ #include "raster/image.h" /* loads a PIC file (Animator and Animator Pro format) */ -Image *load_pic_file (const char *filename, int *x, int *y, RGB *palette) +Image *load_pic_file(const char *filename, int *x, int *y, RGB *palette) { int size, compression; int image_size; @@ -173,7 +173,7 @@ Image *load_pic_file (const char *filename, int *x, int *y, RGB *palette) } /* saves an Animator Pro PIC file */ -int save_pic_file (const char *filename, int x, int y, RGB *palette, Image *image) +int save_pic_file(const char *filename, int x, int y, RGB *palette, Image *image) { int c, u, v, bpp, size, byte; PACKFILE *f; @@ -200,18 +200,18 @@ int save_pic_file (const char *filename, int x, int y, RGB *palette, Image *imag else size += (4+2+2+256*3) + (4+2+image->w*image->h); - pack_iputl (size, f); /* file size */ - pack_iputw (0x9500, f); /* magic number 9500h */ - pack_iputw (image->w, f); /* width */ - pack_iputw (image->h, f); /* height */ - pack_iputw (x, f); /* X offset */ - pack_iputw (y, f); /* Y offset */ - pack_iputl (0, f); /* user ID, is 0 */ - pack_putc (bpp, f); /* bits per pixel */ + pack_iputl(size, f); /* file size */ + pack_iputw(0x9500, f); /* magic number 9500h */ + pack_iputw(image->w, f); /* width */ + pack_iputw(image->h, f); /* height */ + pack_iputw(x, f); /* X offset */ + pack_iputw(y, f); /* Y offset */ + pack_iputl(0, f); /* user ID, is 0 */ + pack_putc(bpp, f); /* bits per pixel */ /* reserved data */ for (c=0; c<45; c++) - pack_putc (0, f); + pack_putc(0, f); /* 1 bpp */ if (bpp == 1) { @@ -230,13 +230,13 @@ int save_pic_file (const char *filename, int x, int y, RGB *palette, Image *imag /* 8 bpp */ else { /* color palette info */ - pack_iputl ((4+2+2+256*3), f); /* block size */ - pack_iputw (0, f); /* block type */ - pack_iputw (0, f); /* version */ + pack_iputl((4+2+2+256*3), f); /* block size */ + pack_iputw(0, f); /* block type */ + pack_iputw(0, f); /* version */ for (c=0; c<256; c++) { /* 256 palette entries */ - pack_putc (_rgb_scale_6[palette[c].r], f); - pack_putc (_rgb_scale_6[palette[c].g], f); - pack_putc (_rgb_scale_6[palette[c].b], f); + pack_putc(_rgb_scale_6[palette[c].r], f); + pack_putc(_rgb_scale_6[palette[c].g], f); + pack_putc(_rgb_scale_6[palette[c].b], f); } /* pixel-per-data image data block */ diff --git a/src/util/quantize.c b/src/util/quantize.c index 809c391e7..b951a1708 100644 --- a/src/util/quantize.c +++ b/src/util/quantize.c @@ -23,22 +23,26 @@ #include "console/console.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" +static int quantize_bitmaps1(struct Stock *stock, struct RGB *pal, int *bmp_i, int fill_other); +/* static int quantize_bitmaps2(struct Stock *stock, struct Palette *pal); */ + void sprite_quantize(struct Sprite *sprite) { - PALETTE palette; + Palette *palette = palette_new(0, MAX_PALETTE_COLORS); sprite_quantize_ex(sprite, palette); /* just one palette */ sprite_reset_palettes(sprite); - sprite_set_palette(sprite, palette, 0); + sprite_set_palette(sprite, palette, FALSE); } -void sprite_quantize_ex(Sprite *sprite, RGB *palette) +void sprite_quantize_ex(Sprite *sprite, Palette *palette) { Stock *stock; Image *flat_image; @@ -54,22 +58,25 @@ void sprite_quantize_ex(Sprite *sprite, RGB *palette) /* generate the optimized palette */ { + PALETTE rgbpal; int *ibmp; for (c=0; c<256; c++) - palette[c].r = palette[c].g = palette[c].b = 255; + rgbpal[c].r = rgbpal[c].g = rgbpal[c].b = 255; - ibmp = jmalloc (sizeof (int) * stock->nimage); + ibmp = jmalloc(sizeof (int) * stock->nimage); for (c=0; c<stock->nimage; c++) ibmp[c] = 128; - quantize_bitmaps1 (stock, palette, ibmp, TRUE); + quantize_bitmaps1(stock, rgbpal, ibmp, TRUE); - jfree (ibmp); + palette_from_allegro(palette, rgbpal); + + jfree(ibmp); } - stock_free (stock); - image_free (flat_image); + stock_free(stock); + image_free(flat_image); } } @@ -288,7 +295,7 @@ static void destroy_tree(PALETTE_NODE *tree) { jfree(tree); } -int quantize_bitmaps1 (Stock *stock, RGB *pal, int *bmp_i, int fill_other) +static int quantize_bitmaps1(Stock *stock, RGB *pal, int *bmp_i, int fill_other) { int c_bmp,x,y,c,r,g,b,n_colours=0,n_entries=0,Ep; PALETTE_NODE *tree,*node; diff --git a/src/util/quantize.h b/src/util/quantize.h index aad14321e..197cc91cf 100644 --- a/src/util/quantize.h +++ b/src/util/quantize.h @@ -19,16 +19,12 @@ #ifndef UTIL_QUANTIZE_H #define UTIL_QUANTIZE_H -#include <allegro/color.h> - +struct Palette; struct Sprite; struct Stock; -void sprite_quantize (struct Sprite *sprite); -void sprite_quantize_ex (struct Sprite *sprite, struct RGB *palette); - -int quantize_bitmaps1 (struct Stock *stock, struct RGB *pal, int *bmp_i, int fill_other); -/* int quantize_bitmaps2 (struct Stock *stock, struct RGB *pal); */ +void sprite_quantize(struct Sprite *sprite); +void sprite_quantize_ex(struct Sprite *sprite, struct Palette *palette); #endif /* UTIL_QUANTIZE_H */ diff --git a/src/util/render.c b/src/util/render.c index 245dc8f77..00d5c8422 100644 --- a/src/util/render.c +++ b/src/util/render.c @@ -23,7 +23,7 @@ #include "jinete/jlist.h" -#include "modules/palette.h" +#include "modules/palettes.h" #include "modules/tools.h" #include "raster/raster.h" diff --git a/src/util/thmbnail.c b/src/util/thmbnail.c index d3efe262c..2e7334018 100644 --- a/src/util/thmbnail.c +++ b/src/util/thmbnail.c @@ -24,9 +24,10 @@ #include "jinete/jlist.h" -#include "modules/palette.h" +#include "modules/palettes.h" #include "raster/cel.h" #include "raster/image.h" +#include "raster/palette.h" #include "raster/sprite.h" #include "raster/stock.h" #include "util/thmbnail.h" @@ -119,7 +120,8 @@ static void thumbnail_create_bitmap(BITMAP *bmp, Image *image) line(bmp, 0, bmp->h-1, bmp->w-1, 0, makecol(0, 0, 0)); } else { - int c, x, y, w, h, x1, y1; + register int c, x, y; + int w, h, x1, y1; double sx, sy, scale; sx = (double)image->w / (double)bmp->w; @@ -158,13 +160,15 @@ static void thumbnail_create_bitmap(BITMAP *bmp, Image *image) } break; case IMAGE_INDEXED: { + Palette *pal = get_current_palette(); + for (y=0; y<h; y++) for (x=0; x<w; x++) { c = image_getpixel(image, x*scale, y*scale); - putpixel(bmp, x1+x, y1+y, - makecol(_rgb_scale_6[current_palette[c].r], - _rgb_scale_6[current_palette[c].g], - _rgb_scale_6[current_palette[c].b])); + c = pal->color[MID(0, c, MAX_PALETTE_COLORS-1)]; + putpixel(bmp, x1+x, y1+y, makecol(_rgba_getr(c), + _rgba_getg(c), + _rgba_getb(c))); } break; } diff --git a/src/widgets/colbar.c b/src/widgets/colbar.c index a5fa51f70..623d3a979 100644 --- a/src/widgets/colbar.c +++ b/src/widgets/colbar.c @@ -28,14 +28,13 @@ #include "core/app.h" #include "core/cfg.h" #include "core/color.h" -#include "dialogs/colsel.h" -#include "dialogs/minipal.h" #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 "raster/image.h" +#include "raster/palette.h" #include "raster/sprite.h" #include "widgets/colbar.h" #include "widgets/colsel2.h" @@ -69,18 +68,13 @@ static ColorBar *colorbar_data(JWidget colorbar); static bool colorbar_msg_proc(JWidget widget, JMessage msg); static color_t colorbar_get_hot_color(JWidget widget); static void colorbar_open_tooltip(JWidget widget, int x, int y1, int y2, - JRect bounds, color_t color, hotcolor_t hot); + color_t color, hotcolor_t hot); static void colorbar_close_tooltip(JWidget widget); static bool tooltip_window_msg_proc(JWidget widget, JMessage msg); static void update_status_bar(color_t color, int msecs); static void get_info(JWidget widget, int *beg, int *end); -static void draw_colorbox(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); JWidget colorbar_new(int align) { @@ -171,6 +165,59 @@ void colorbar_set_color(JWidget widget, int index, color_t color) jwidget_dirty(widget); } +color_t colorbar_get_color_by_position(JWidget widget, int x, int y) +{ + ColorBar *colorbar = colorbar_data(widget); + int x1, y1, x2, y2, v1, v2; + int c, h, beg, end; + + get_info(widget, &beg, &end); + + x1 = widget->rc->x1; + y1 = widget->rc->y1; + x2 = widget->rc->x2-1; + y2 = widget->rc->y2-1; + + ++x1, ++y1, --x2, --y2; + + h = (y2-y1+1-(4+16+4+16+16+4)); + + for (c=beg; c<=end; c++) { + v1 = y1 + h*(c-beg )/(end-beg+1); + v2 = y1 + h*(c-beg+1)/(end-beg+1) - 1; + + if ((y >= v1) && (y <= v2)) + return colorbar->color[c]; + } + + /* in tool foreground color */ + v1 = y2-4-16-4-16-16; + v2 = y2-4-16-4-16; + if ((y >= v1) && (y <= v2)) { + return colorbar->fgcolor; + } + + /* in tool background color */ + v1 = y2-4-16-4-16+1; + v2 = y2-4-16-4; + if ((y >= v1) && (y <= v2)) { + return colorbar->bgcolor; + } + + /* in sprite background color */ + v1 = y2-4-16; + v2 = y2-4; + if ((y >= v1) && (y <= v2)) { + color_t c = + current_sprite != NULL ? color_from_image(current_sprite->imgtype, + current_sprite->bgcolor): + color_mask(); + return c; + } + + return color_mask(); +} + static ColorBar *colorbar_data(JWidget widget) { return jwidget_get_data(widget, colorbar_type()); @@ -254,51 +301,28 @@ static bool colorbar_msg_proc(JWidget widget, JMessage msg) v1 = y1 + h*(c-beg )/(end-beg+1); v2 = y1 + h*(c-beg+1)/(end-beg+1) - 1; - draw_colorbox(doublebuffer, x1, v1, x2, v2, - c == beg, c == beg, - c == end, c == end, imgtype, colorbar->color[c], - (c == colorbar->hot)); - - /* a selected color */ -#if 0 - if ((c == colorbar->select[0]) || (c == colorbar->select[1])) { - color_t new_color; - int color; - - new_color = color_from_image(imgtype, - get_color_for_image(imgtype, - colorbar->color[c])); - - r = color_get_red(imgtype, new_color); - g = color_get_green(imgtype, new_color); - b = color_get_blue(imgtype, new_color); - - jfree(new_color); - - color = blackandwhite_neg(r, g, b); - - if (c == colorbar->select[0]) - rectfill(ji_screen, x1, v1, x1+1, v2, color); - - if (c == colorbar->select[1]) - rectfill(ji_screen, x2-1, v1, x2, v2, color); - } -#endif + draw_color_button(doublebuffer, x1, v1, x2, v2, + c == beg, c == beg, + c == end, c == end, imgtype, colorbar->color[c], + (c == colorbar->hot || + c == colorbar->hot_editing)); } /* draw tool foreground color */ v1 = y2-4-16-4-16-16; v2 = y2-4-16-4-16; - draw_colorbox(doublebuffer, x1, v1, x2, v2, 1, 1, 0, 0, - imgtype, colorbar->fgcolor, - (colorbar->hot == HOTCOLOR_FGCOLOR)); + draw_color_button(doublebuffer, x1, v1, x2, v2, 1, 1, 0, 0, + imgtype, colorbar->fgcolor, + (colorbar->hot == HOTCOLOR_FGCOLOR || + colorbar->hot_editing == HOTCOLOR_FGCOLOR)); /* draw tool background color */ v1 = y2-4-16-4-16+1; v2 = y2-4-16-4; - draw_colorbox(doublebuffer, x1, v1, x2, v2, 0, 0, 1, 1, - imgtype, colorbar->bgcolor, - (colorbar->hot == HOTCOLOR_BGCOLOR)); + draw_color_button(doublebuffer, x1, v1, x2, v2, 0, 0, 1, 1, + imgtype, colorbar->bgcolor, + (colorbar->hot == HOTCOLOR_BGCOLOR || + colorbar->hot_editing == HOTCOLOR_BGCOLOR)); /* draw sprite background color */ v1 = y2-4-16; @@ -308,9 +332,10 @@ static bool colorbar_msg_proc(JWidget widget, JMessage msg) current_sprite != NULL ? color_from_image(imgtype, current_sprite->bgcolor): color_mask(); - draw_colorbox(doublebuffer, x1, v1, x2, v2, 1, 1, 1, 1, - imgtype, c, - (colorbar->hot == HOTCOLOR_BGSPRITE)); + draw_color_button(doublebuffer, x1, v1, x2, v2, 1, 1, 1, 1, + imgtype, c, + (colorbar->hot == HOTCOLOR_BGSPRITE || + colorbar->hot_editing == HOTCOLOR_BGSPRITE)); } blit(doublebuffer, ji_screen, 0, 0, @@ -391,24 +416,17 @@ static bool colorbar_msg_proc(JWidget widget, JMessage msg) if (colorbar->hot != old_hot) { jwidget_dirty(widget); + /* close the old tooltip window to edit the 'old_hot' color slot */ + colorbar_close_tooltip(widget); + if (colorbar->hot != HOTCOLOR_NONE) { color_t color = colorbar_get_hot_color(widget); - JRect bounds = jwidget_get_rect(widget); update_status_bar(color, 0); /* open the tooltip window to edit the hot color */ - bounds->y1 = hot_v1; - bounds->y2 = hot_v2; - - colorbar_open_tooltip(widget, bounds->x2+1, hot_v1, hot_v2, - bounds, color, colorbar->hot); - - jrect_free(bounds); - } - else { - /* close the old tooltip window to edit the 'old_hot' color slot */ - colorbar_close_tooltip(widget); + colorbar_open_tooltip(widget, widget->rc->x2+1, + hot_v1, hot_v2, color, colorbar->hot); } } @@ -424,8 +442,6 @@ static bool colorbar_msg_proc(JWidget widget, JMessage msg) if (msg->mouse.right) { colorbar_set_bg_color(widget, color); } - - return TRUE; } return TRUE; @@ -443,37 +459,6 @@ static bool colorbar_msg_proc(JWidget widget, JMessage msg) jwidget_release_mouse(widget); break; - case JM_DOUBLECLICK: - if (colorbar->hot != HOTCOLOR_NONE) { - int hot = colorbar->hot; - color_t color = colorbar_get_hot_color(widget); - - while (jmouse_b(0)) - jmouse_poll(); - - /* change this color with the color-select dialog */ - if (ji_color_select(app_get_current_image_type(), &color)) { - switch (hot) { - case HOTCOLOR_FGCOLOR: - colorbar->fgcolor = color; - break; - case HOTCOLOR_BGCOLOR: - colorbar->bgcolor = color; - break; - case HOTCOLOR_BGSPRITE: - /* TODO setup sprite background color */ - break; - default: - assert(hot >= 0 && hot < colorbar->ncolor); - colorbar->color[hot] = color; - break; - } - jwidget_dirty(widget); - } - return TRUE; - } - break; - case JM_SETCURSOR: if (colorbar->hot != HOTCOLOR_FGCOLOR && colorbar->hot != HOTCOLOR_NONE) { @@ -524,7 +509,6 @@ static color_t colorbar_get_hot_color(JWidget widget) } static void colorbar_open_tooltip(JWidget widget, int x, int y1, int y2, - JRect bounds, color_t color, hotcolor_t hot) { ColorBar *colorbar = colorbar_data(widget); @@ -533,14 +517,15 @@ static void colorbar_open_tooltip(JWidget widget, int x, int y1, int y2, int y; if (colorbar->tooltip_window == NULL) { - window = colorselector_new(); + window = colorselector_new(TRUE); window->user_data[0] = widget; jwidget_add_hook(window, -1, tooltip_window_msg_proc, NULL); colorbar->tooltip_window = window; } - else + else { window = colorbar->tooltip_window; + } switch (colorbar->hot) { case HOTCOLOR_NONE: @@ -549,7 +534,7 @@ static void colorbar_open_tooltip(JWidget widget, int x, int y1, int y2, case HOTCOLOR_FGCOLOR: { Command *cmd; - ustrcpy(buf, _("Foreground Tool Color")); + ustrcpy(buf, _("Tool Foreground Color")); cmd = command_get_by_name(CMD_SWITCH_COLORS); assert(cmd != NULL); @@ -562,7 +547,7 @@ static void colorbar_open_tooltip(JWidget widget, int x, int y1, int y2, break; } case HOTCOLOR_BGCOLOR: - ustrcpy(buf, _("Background Tool Color")); + ustrcpy(buf, _("Tool Background Color")); break; case HOTCOLOR_BGSPRITE: ustrcpy(buf, _("Sprite Background Color")); @@ -580,12 +565,13 @@ static void colorbar_open_tooltip(JWidget widget, int x, int y1, int y2, x = MID(0, x, JI_SCREEN_W-jrect_w(window->rc)); y = (y1+y2)/2-jrect_h(window->rc)/2; - y = MID(0, y, JI_SCREEN_H-jrect_h(window->rc)); + y = MID(widget->rc->y1, y, widget->rc->y2-jrect_h(window->rc)); jwindow_position(window, x, y); jmanager_dispatch_messages(jwidget_get_manager(window)); jwidget_relayout(window); + /* setup the hot-region */ { JRect rc = jrect_new(window->rc->x1, window->rc->y1-8, @@ -609,8 +595,13 @@ static void colorbar_close_tooltip(JWidget widget) { ColorBar *colorbar = colorbar_data(widget); - if (colorbar->tooltip_window != NULL) + if (colorbar->tooltip_window != NULL) { + /* close the widget */ jwindow_close(colorbar->tooltip_window, NULL); + + /* dispatch the JM_CLOSE event to 'tooltip_window_msg_proc' */ + jmanager_dispatch_messages(jwidget_get_manager(widget)); + } } static bool tooltip_window_msg_proc(JWidget widget, JMessage msg) @@ -620,23 +611,39 @@ static bool tooltip_window_msg_proc(JWidget widget, JMessage msg) case JM_CLOSE: { /* change the sprite palette */ Sprite *sprite = current_sprite; + if (sprite != NULL) { - RGB *rgb = sprite_get_palette(sprite, sprite->frame); + Palette *pal = sprite_get_palette(sprite, sprite->frame); int from, to; - if (palette_diff(rgb, current_palette, &from, &to) > 0) { + if (palette_count_diff(pal, get_current_palette(), &from, &to) > 0) { /* TODO add undo support */ /* if (undo_is_enabled(sprite->undo)) */ -/* undo_data(sprite->undo, (GfxObj *)sprite, rgb, ); */ - - sprite_set_palette(sprite, current_palette, sprite->frame); +/* undo_data(sprite->undo, (GfxObj *)sprite, pal, ); */ + + pal = get_current_palette(); + pal->frame = sprite->frame; /* TODO warning, modifing + the current palette in + this point... */ + + sprite_set_palette(sprite, pal, FALSE); + set_current_palette(pal, TRUE); } update_editors_with_sprite(sprite); } /* change the system palette */ else - set_default_palette(current_palette); + set_default_palette(get_current_palette()); + + /* set the 'hot_editing' to NONE */ + { + JWidget colorbar_widget = (JWidget)widget->user_data[0]; + ColorBar *colorbar = colorbar_data(colorbar_widget); + + colorbar->hot_editing = HOTCOLOR_NONE; + jwidget_dirty(colorbar_widget); + } break; } @@ -648,7 +655,7 @@ static bool tooltip_window_msg_proc(JWidget widget, JMessage msg) switch (colorbar->hot_editing) { case HOTCOLOR_NONE: - assert(FALSE); + /* assert(FALSE); */ break; case HOTCOLOR_FGCOLOR: colorbar->fgcolor = color; @@ -701,10 +708,16 @@ static bool tooltip_window_msg_proc(JWidget widget, JMessage msg) with that sprite */ if (current_sprite != NULL && bitmap_color_depth(screen) != 8) { Sprite *sprite = current_sprite; - RGB *rgb = sprite_get_palette(sprite, sprite->frame); + Palette *pal = sprite_get_palette(sprite, sprite->frame); - if (palette_diff(rgb, current_palette, NULL, NULL) > 0) { - sprite_set_palette(sprite, current_palette, sprite->frame); + if (palette_count_diff(pal, get_current_palette(), NULL, NULL) > 0) { + pal = get_current_palette(); + pal->frame = sprite->frame; /* TODO warning, modifing + the current palette in + this point... */ + + sprite_set_palette(sprite, pal, FALSE); + set_current_palette(pal, TRUE); jmanager_start_timer(colorbar->refresh_timer_id); } @@ -738,61 +751,3 @@ static void get_info(JWidget widget, int *_beg, int *_end) if (_beg) *_beg = beg; if (_end) *_end = end; } - -static void draw_colorbox(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); - } -} diff --git a/src/widgets/colbar.h b/src/widgets/colbar.h index 4b4568d1e..6a602ae84 100644 --- a/src/widgets/colbar.h +++ b/src/widgets/colbar.h @@ -36,4 +36,6 @@ void colorbar_set_bg_color(JWidget widget, color_t color); void colorbar_set_color(JWidget widget, int index, color_t color); +color_t colorbar_get_color_by_position(JWidget widget, int x, int y); + #endif /* WIDGETS_COLBAR_H */ diff --git a/src/widgets/colbut.c b/src/widgets/colbut.c index 336620979..cf491e1ff 100644 --- a/src/widgets/colbut.c +++ b/src/widgets/colbut.c @@ -20,46 +20,48 @@ #include <allegro.h> -#include "jinete/jbutton.h" -#include "jinete/jdraw.h" -#include "jinete/jhook.h" -#include "jinete/jmessage.h" -#include "jinete/jrect.h" -#include "jinete/jsystem.h" -#include "jinete/jtheme.h" -#include "jinete/jwidget.h" +#include "jinete/jinete.h" #include "core/color.h" -#include "dialogs/colsel.h" #include "modules/gfx.h" +#include "raster/sprite.h" +#include "widgets/colbar.h" #include "widgets/colbut.h" +#include "widgets/colsel2.h" +#include "widgets/editor.h" typedef struct ColorButton { color_t color; int imgtype; + JWidget tooltip_window; } ColorButton; -static ColorButton *color_button_data(JWidget widget); -static bool color_button_msg_proc(JWidget widget, JMessage msg); -static void color_button_draw(JWidget widget); +static ColorButton *colorbutton_data(JWidget widget); +static bool colorbutton_msg_proc(JWidget widget, JMessage msg); +static void colorbutton_draw(JWidget widget); +static void colorbutton_open_tooltip(JWidget widget); +static void colorbutton_close_tooltip(JWidget widget); -JWidget color_button_new(color_t color, int imgtype) +static bool tooltip_window_msg_proc(JWidget widget, JMessage msg); + +JWidget colorbutton_new(color_t color, int imgtype) { JWidget widget = jbutton_new(""); - ColorButton *color_button = jnew(ColorButton, 1); + ColorButton *colorbutton = jnew(ColorButton, 1); - color_button->color = color; - color_button->imgtype = imgtype; + colorbutton->color = color; + colorbutton->imgtype = imgtype; + colorbutton->tooltip_window = NULL; - jwidget_add_hook(widget, color_button_type(), - color_button_msg_proc, color_button); + jwidget_add_hook(widget, colorbutton_type(), + colorbutton_msg_proc, colorbutton); jwidget_focusrest(widget, TRUE); return widget; } -int color_button_type(void) +int colorbutton_type(void) { static int type = 0; if (!type) @@ -67,41 +69,44 @@ int color_button_type(void) return type; } -int color_button_get_imgtype(JWidget widget) +int colorbutton_get_imgtype(JWidget widget) { - ColorButton *color_button = color_button_data(widget); + ColorButton *colorbutton = colorbutton_data(widget); - return color_button->imgtype; + return colorbutton->imgtype; } -color_t color_button_get_color(JWidget widget) +color_t colorbutton_get_color(JWidget widget) { - ColorButton *color_button = color_button_data(widget); + ColorButton *colorbutton = colorbutton_data(widget); - return color_button->color; + return colorbutton->color; } -void color_button_set_color(JWidget widget, color_t color) +void colorbutton_set_color(JWidget widget, color_t color) { - ColorButton *color_button = color_button_data(widget); + ColorButton *colorbutton = colorbutton_data(widget); - color_button->color = color; + colorbutton->color = color; jwidget_dirty(widget); } -static ColorButton *color_button_data(JWidget widget) +static ColorButton *colorbutton_data(JWidget widget) { - return jwidget_get_data(widget, color_button_type()); + return jwidget_get_data(widget, colorbutton_type()); } -static bool color_button_msg_proc(JWidget widget, JMessage msg) +static bool colorbutton_msg_proc(JWidget widget, JMessage msg) { - ColorButton *color_button = color_button_data(widget); + ColorButton *colorbutton = colorbutton_data(widget); switch (msg->type) { case JM_DESTROY: - jfree(color_button); + if (colorbutton->tooltip_window != NULL) + jwidget_free(colorbutton->tooltip_window); + + jfree(colorbutton); break; case JM_REQSIZE: { @@ -114,88 +119,114 @@ static bool color_button_msg_proc(JWidget widget, JMessage msg) msg->reqsize.w = jrect_w(&box) + widget->border_width.l + widget->border_width.r; msg->reqsize.h = jrect_h(&box) + widget->border_width.t + widget->border_width.b; return TRUE; - } + } + + case JM_MOUSEENTER: + colorbutton_open_tooltip(widget); + break; case JM_DRAW: - color_button_draw(widget); + colorbutton_draw(widget); return TRUE; case JM_SIGNAL: if (msg->signal.num == JI_SIGNAL_BUTTON_SELECT) { - color_t color = color_button->color; - - if (ji_color_select(color_button->imgtype, &color)) { - color_button_set_color(widget, color); - jwidget_emit_signal(widget, SIGNAL_COLOR_BUTTON_CHANGE); - } + colorbutton_close_tooltip(widget); + jwidget_hard_capture_mouse(widget); return TRUE; } break; + + case JM_BUTTONPRESSED: + if (jwidget_has_capture(widget) && + widget->flags & JI_HARDCAPTURE) { + return TRUE; + } + break; + + case JM_MOTION: + if (jwidget_has_capture(widget) && + widget->flags & JI_HARDCAPTURE) { + JWidget picked = jwidget_pick(ji_get_default_manager(), + msg->mouse.x, + msg->mouse.y); + color_t color = colorbutton->color; + + if (picked) { + /* pick a color from another color-button */ + if (picked->type == colorbutton_type()) { + color = colorbutton_data(picked)->color; + } + /* pick a color from the color-bar */ + else if (picked->type == colorbar_type()) { + color = colorbar_get_color_by_position(picked, + msg->mouse.x, + msg->mouse.y); + } + /* pick a color from a editor */ + else if (picked->type == editor_type()) { + Sprite *sprite = editor_get_sprite(picked); + int x, y, imgcolor; + + if (sprite) { + x = msg->mouse.x; + y = msg->mouse.y; + screen_to_editor(picked, x, y, &x, &y); + imgcolor = sprite_getpixel(sprite, x, y); + color = color_from_image(sprite->imgtype, imgcolor); + } + } + } + + /* does the color change? */ + if (!color_equals(color, colorbutton->color)) { + colorbutton_set_color(widget, color); + jwidget_emit_signal(widget, SIGNAL_COLORBUTTON_CHANGE); + } + + return TRUE; + } + break; + + case JM_BUTTONRELEASED: + if (jwidget_has_capture(widget) && + widget->flags & JI_HARDCAPTURE) { + jwidget_release_mouse(widget); + } + break; + + case JM_SETCURSOR: + if (jwidget_has_capture(widget) && + widget->flags & JI_HARDCAPTURE) { + jmouse_set_cursor(JI_CURSOR_EYEDROPPER); + return TRUE; + } + break; + } return FALSE; } -static void color_button_draw(JWidget widget) +static void colorbutton_draw(JWidget widget) { - ColorButton *color_button = color_button_data(widget); + ColorButton *colorbutton = colorbutton_data(widget); struct jrect box, text, icon; - int x1, y1, x2, y2; - int bg, c1, c2; + jwidget_get_texticon_info(widget, &box, &text, &icon, 0, 0, 0); char buf[256]; - jwidget_get_texticon_info(widget, &box, &text, &icon, 0, 0, 0); - - /* with mouse */ - if (jwidget_has_mouse(widget)) - bg = makecol(224, 224, 224); - /* without mouse */ - else - bg = makecol(192, 192, 192); - - /* selected */ - if (jwidget_is_selected(widget)) { - c1 = makecol(128, 128, 128); - c2 = makecol(255, 255, 255); - } - /* non-selected */ - else { - c1 = makecol(255, 255, 255); - c2 = makecol(128, 128, 128); - } - - /* widget position */ - x1 = widget->rc->x1; - y1 = widget->rc->y1; - x2 = widget->rc->x2-1; - y2 = widget->rc->y2-1; - - /* extern background */ - rectfill(ji_screen, x1, y1, x2, y2, makecol (192, 192, 192)); - - /* 1st border */ - if (jwidget_has_focus(widget)) - bevel_box(ji_screen, x1, y1, x2, y2, - makecol(0, 0, 0), makecol(0, 0, 0), 2); - else - bevel_box(ji_screen, x1, y1, x2, y2, c1, c2, 1); - - /* 2nd border */ - x1++, y1++, x2--, y2--; - if (jwidget_has_focus(widget)) - bevel_box(ji_screen, x1, y1, x2, y2, c1, c2, 1); - else - bevel_box(ji_screen, x1, y1, x2, y2, bg, bg, 0); - - /* background */ - x1++, y1++, x2--, y2--; - draw_color(ji_screen, x1, y1, x2, y2, - color_button->imgtype, - color_button->color); + draw_color_button + (ji_screen, + widget->rc->x1, widget->rc->y1, + widget->rc->x2-1, widget->rc->y2-1, + 1, 1, 1, 1, + colorbutton->imgtype, + colorbutton->color, + jwidget_has_mouse(widget)); /* draw text */ - color_to_formalstring(color_button->imgtype, - color_button->color, buf, sizeof(buf), FALSE); + color_to_formalstring(colorbutton->imgtype, + colorbutton->color, buf, sizeof(buf), FALSE); jwidget_set_text_soft(widget, buf); jwidget_get_texticon_info(widget, &box, &text, &icon, 0, 0, 0); @@ -205,3 +236,76 @@ static void color_button_draw(JWidget widget) makecol(255, 255, 255), makecol(0, 0, 0), FALSE); } + +static void colorbutton_open_tooltip(JWidget widget) +{ + ColorButton *colorbutton = colorbutton_data(widget); + JWidget window; + int x, y; + + if (colorbutton->tooltip_window == NULL) { + window = colorselector_new(FALSE); + window->user_data[0] = widget; + jwidget_add_hook(window, -1, tooltip_window_msg_proc, NULL); + jwidget_set_text(window, "Select color"); + + colorbutton->tooltip_window = window; + } + else { + window = colorbutton->tooltip_window; + } + + colorselector_set_color(window, colorbutton->color); + + jwindow_open(window); + + x = MID(0, widget->rc->x1, JI_SCREEN_W-jrect_w(window->rc)); + if (widget->rc->y2 <= JI_SCREEN_H-jrect_h(window->rc)) + y = MAX(0, widget->rc->y2); + else + y = MAX(0, widget->rc->y1-jrect_h(window->rc)); + + jwindow_position(window, x, y); + + jmanager_dispatch_messages(jwidget_get_manager(window)); + jwidget_relayout(window); + + /* setup the hot-region */ + { + JRect rc = jrect_new(MIN(widget->rc->x1, window->rc->x1)-8, + MIN(widget->rc->y1, window->rc->y1)-8, + MAX(widget->rc->x2, window->rc->x2)+8, + MAX(widget->rc->y2, window->rc->y2)+8); + JRegion rgn = jregion_new(rc, 1); + jrect_free(rc); + + jtooltip_window_set_hotregion(window, rgn); + } +} + +static void colorbutton_close_tooltip(JWidget widget) +{ + ColorButton *colorbutton = colorbutton_data(widget); + + if (colorbutton->tooltip_window != NULL) + jwindow_close(colorbutton->tooltip_window, NULL); +} + +static bool tooltip_window_msg_proc(JWidget widget, JMessage msg) +{ + switch (msg->type) { + + case JM_SIGNAL: + if (msg->signal.num == SIGNAL_COLORSELECTOR_COLOR_CHANGED) { + JWidget colorbutton_widget = (JWidget)widget->user_data[0]; + color_t color = colorselector_get_color(widget); + + colorbutton_set_color(colorbutton_widget, color); + jwidget_emit_signal(colorbutton_widget, SIGNAL_COLORBUTTON_CHANGE); + } + break; + + } + + return FALSE; +} diff --git a/src/widgets/colbut.h b/src/widgets/colbut.h index b07a746a7..f038d81bd 100644 --- a/src/widgets/colbut.h +++ b/src/widgets/colbut.h @@ -22,14 +22,14 @@ #include "core/color.h" /* TODO use some JI_SIGNAL_USER */ -#define SIGNAL_COLOR_BUTTON_CHANGE 0x10001 +#define SIGNAL_COLORBUTTON_CHANGE 0x10001 -JWidget color_button_new(color_t color, int imgtype); -int color_button_type(void); +JWidget colorbutton_new(color_t color, int imgtype); +int colorbutton_type(void); -int color_button_get_imgtype(JWidget color_button); +int colorbutton_get_imgtype(JWidget widget); -color_t color_button_get_color(JWidget color_button); -void color_button_set_color(JWidget color_button, color_t color); +color_t colorbutton_get_color(JWidget widget); +void colorbutton_set_color(JWidget widget, color_t color); #endif /* WIDGETS_COLBUT_H */ diff --git a/src/widgets/colsel2.c b/src/widgets/colsel2.c index 841705be5..ca81749bc 100644 --- a/src/widgets/colsel2.c +++ b/src/widgets/colsel2.c @@ -27,8 +27,9 @@ #include "core/color.h" #include "modules/gui.h" #include "modules/gfx.h" -#include "modules/palette.h" +#include "modules/palettes.h" #include "raster/image.h" +#include "raster/palette.h" #include "widgets/colsel2.h" #include "widgets/paledit.h" #include "widgets/tabs.h" @@ -52,6 +53,7 @@ typedef struct ColorSelector { color_t color; bool palette_locked; + bool editable_palette; } ColorSelector; static JWidget create_rgb_container(void); @@ -63,13 +65,14 @@ static int colorselector_type(void); static ColorSelector *colorselector_data(JWidget widget); static bool colorselector_msg_proc(JWidget widget, JMessage msg); static void colorselector_update_lock_button(JWidget widget); -static void colorselector_set_color2(JWidget widget, color_t color, bool select_index_entry); -static void colorselector_set_paledit_index(JWidget widget, int index); +static void colorselector_set_color2(JWidget widget, color_t color, bool select_index_entry, Model *exclude_this_model); +static void colorselector_set_paledit_index(JWidget widget, int index, bool select_index_entry); static void select_tab_callback(JWidget tabs, void *data); -static int slider_change_signal(JWidget widget, int user_data); -static int paledit_change_signal(JWidget widget, int user_data); -static int lock_button_select_hook(JWidget widget, int user_data); +static bool slider_change_hook(JWidget widget, void *data); +static bool button_mask_select_hook(JWidget widget, void *data); +static bool paledit_change_hook(JWidget widget, void *data); +static bool lock_button_select_hook(JWidget widget, void *data); static Model models[] = { { "RGB", MODEL_RGB, COLOR_TYPE_RGB, create_rgb_container }, @@ -79,43 +82,42 @@ static Model models[] = { { NULL, 0, 0, NULL } }; -JWidget colorselector_new(void) +JWidget colorselector_new(bool editable_palette) { - int guiscale = GUISCALE; JWidget window = jtooltip_window_new(""); JWidget grid1 = jgrid_new(3, FALSE); JWidget grid2 = jgrid_new(5, FALSE); JWidget tabs = tabs_new(select_tab_callback); - JWidget pal = paledit_new(current_palette, FALSE, 4); - JWidget idx = jlabel_new("Index=888"); + JWidget pal = paledit_new(get_current_palette(), FALSE, 1); + JWidget idx = jlabel_new("None"); JWidget lock = jbutton_new(""); JWidget child; ColorSelector *colorselector = jnew(ColorSelector, 1); Model *m; + jwidget_set_name(pal, "pal"); + jwidget_set_name(idx, "idx"); + jwidget_set_name(lock, "lock"); + jwidget_set_name(tabs, "tabs"); + jwidget_set_name(grid2, "grid2"); + + /* color selector */ colorselector->color = color_mask(); colorselector->palette_locked = TRUE; + colorselector->editable_palette = editable_palette; /* palette */ - jwidget_set_name(pal, "pal"); jwidget_add_tooltip_text(pal, _("Use SHIFT or CTRL to select ranges")); - /* idx label */ - jwidget_set_name(idx, "idx"); - jwidget_set_min_size(idx, jwidget_get_text_length(idx), 0); - /* lock button */ - jwidget_set_name(lock, "lock"); add_gfxicon_to_button(lock, GFX_BOX_LOCK, JI_CENTER | JI_MIDDLE); /* tabs */ - jwidget_set_name(tabs, "tabs"); jwidget_set_bg_color(tabs, window->bg_color); /* data for a better layout */ grid1->child_spacing = 0; grid2->border_width.t = 3; - jwidget_set_min_size(grid2, 200*guiscale, 0); jwidget_expansive(grid2, TRUE); /* append a tab for each color-model */ @@ -140,17 +142,19 @@ JWidget colorselector_new(void) colorselector_type(), colorselector_msg_proc, colorselector); - HOOK(pal, SIGNAL_PALETTE_EDITOR_CHANGE, paledit_change_signal, 0); + HOOK(pal, SIGNAL_PALETTE_EDITOR_CHANGE, paledit_change_hook, 0); HOOK(lock, JI_SIGNAL_BUTTON_SELECT, lock_button_select_hook, 0); /* update the lock button */ colorselector_update_lock_button(window); + + jwidget_init_theme(window); return window; } void colorselector_set_color(JWidget widget, color_t color) { - colorselector_set_color2(widget, color, TRUE); + colorselector_set_color2(widget, color, TRUE, NULL); } color_t colorselector_get_color(JWidget widget) @@ -185,10 +189,10 @@ static JWidget create_rgb_container(void) jwidget_set_name(bslider, "rgb_b"); jwidget_set_name(aslider, "rgb_a"); - HOOK(rslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_signal, 0); - HOOK(gslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_signal, 0); - HOOK(bslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_signal, 0); - HOOK(aslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_signal, 0); + HOOK(rslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0); + HOOK(gslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0); + HOOK(bslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0); + HOOK(aslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0); return grid; } @@ -218,10 +222,10 @@ static JWidget create_hsv_container(void) jwidget_set_name(vslider, "hsv_v"); jwidget_set_name(aslider, "hsv_a"); - HOOK(hslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_signal, 0); - HOOK(sslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_signal, 0); - HOOK(vslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_signal, 0); - HOOK(aslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_signal, 0); + HOOK(hslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0); + HOOK(sslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0); + HOOK(vslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0); + HOOK(aslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0); return grid; } @@ -241,15 +245,17 @@ static JWidget create_gray_container(void) jwidget_set_name(vslider, "gray_v"); jwidget_set_name(aslider, "gray_a"); - HOOK(vslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_signal, 0); - HOOK(aslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_signal, 0); + HOOK(vslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0); + HOOK(aslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0); return grid; } static JWidget create_mask_container(void) { - return jlabel_new("M"); + JWidget button = jbutton_new("Mask Color"); + HOOK(button, JI_SIGNAL_BUTTON_SELECT, button_mask_select_hook, 0); + return button; } static int colorselector_type(void) @@ -276,6 +282,19 @@ static bool colorselector_msg_proc(JWidget widget, JMessage msg) jfree(colorselector); break; + case JM_SIGNAL: + if (msg->signal.num == JI_SIGNAL_INIT_THEME) { + JWidget idx = jwidget_find_name(widget, "idx"); + JWidget pal = jwidget_find_name(widget, "pal"); + JWidget grid2 = jwidget_find_name(widget, "grid2"); + int idxlen = ji_font_text_len(jwidget_get_font(idx), "Index=888"); + + jwidget_set_min_size(idx, idxlen, 0); + paledit_set_boxsize(pal, 4*GUISCALE); + jwidget_set_min_size(grid2, 200*GUISCALE, 0); + } + break; + } return FALSE; @@ -296,7 +315,8 @@ static void colorselector_update_lock_button(JWidget widget) } } -static void colorselector_set_color2(JWidget widget, color_t color, bool select_index_entry) +static void colorselector_set_color2(JWidget widget, color_t color, + bool select_index_entry, Model *exclude_this_model) { ColorSelector *colorselector = colorselector_data(widget); JWidget tabs = jwidget_find_name(widget, "tabs"); @@ -315,16 +335,22 @@ static void colorselector_set_color2(JWidget widget, color_t color, bool select_ colorselector->color = color; - jslider_set_value(rgb_rslider, color_get_red(imgtype, color)); - jslider_set_value(rgb_gslider, color_get_green(imgtype, color)); - jslider_set_value(rgb_bslider, color_get_blue(imgtype, color)); - jslider_set_value(rgb_aslider, color_get_alpha(imgtype, color)); - jslider_set_value(hsv_hslider, color_get_hue(imgtype, color)); - jslider_set_value(hsv_sslider, color_get_saturation(imgtype, color)); - jslider_set_value(hsv_vslider, color_get_value(imgtype, color)); - jslider_set_value(hsv_aslider, color_get_alpha(imgtype, color)); - jslider_set_value(gray_vslider, color_get_value(imgtype, color)); - jslider_set_value(gray_aslider, color_get_alpha(imgtype, color)); + if (exclude_this_model != models+MODEL_RGB) { + jslider_set_value(rgb_rslider, color_get_red(imgtype, color)); + jslider_set_value(rgb_gslider, color_get_green(imgtype, color)); + jslider_set_value(rgb_bslider, color_get_blue(imgtype, color)); + jslider_set_value(rgb_aslider, color_get_alpha(imgtype, color)); + } + if (exclude_this_model != models+MODEL_HSV) { + jslider_set_value(hsv_hslider, color_get_hue(imgtype, color)); + jslider_set_value(hsv_sslider, color_get_saturation(imgtype, color)); + jslider_set_value(hsv_vslider, color_get_value(imgtype, color)); + jslider_set_value(hsv_aslider, color_get_alpha(imgtype, color)); + } + if (exclude_this_model != models+MODEL_GRAY) { + jslider_set_value(gray_vslider, color_get_value(imgtype, color)); + jslider_set_value(gray_aslider, color_get_alpha(imgtype, color)); + } switch (color_type(color)) { case COLOR_TYPE_MASK: @@ -355,41 +381,49 @@ static void colorselector_set_color2(JWidget widget, color_t color, bool select_ if (select_index_entry) { switch (color_type(color)) { case COLOR_TYPE_INDEX: - colorselector_set_paledit_index(widget, color_get_index(IMAGE_INDEXED, color)); + colorselector_set_paledit_index(widget, color_get_index(IMAGE_INDEXED, color), FALSE); break; case COLOR_TYPE_MASK: - colorselector_set_paledit_index(widget, 0); + colorselector_set_paledit_index(widget, 0, TRUE); break; default: { - int palr = color_get_red (IMAGE_RGB, color)/4; - int palg = color_get_green(IMAGE_RGB, color)/4; - int palb = color_get_blue (IMAGE_RGB, color)/4; - int i = bestfit_color(current_palette, palr, palg, palb); + int r = color_get_red (IMAGE_RGB, color); + int g = color_get_green(IMAGE_RGB, color); + int b = color_get_blue (IMAGE_RGB, color); + int i = palette_find_bestfit(get_current_palette(), r, g, b); if (i >= 0 && i < 256) - colorselector_set_paledit_index(widget, i); + colorselector_set_paledit_index(widget, i, TRUE); else - colorselector_set_paledit_index(widget, -1); + colorselector_set_paledit_index(widget, -1, TRUE); break; } } } } -static void colorselector_set_paledit_index(JWidget widget, int index) +static void colorselector_set_paledit_index(JWidget widget, int index, bool select_index_entry) { + ColorSelector *colorselector = colorselector_data(widget); JWidget pal = jwidget_find_name(widget, "pal"); JWidget idx = jwidget_find_name(widget, "idx"); JWidget lock = jwidget_find_name(widget, "lock"); char buf[256]; if (index >= 0) { - paledit_select_color(pal, index); + if (select_index_entry) + paledit_select_color(pal, index); + sprintf(buf, "Index=%d", index); - jwidget_enable(lock); + if (colorselector->editable_palette) + jwidget_enable(lock); + else + jwidget_disable(lock); } else { - paledit_select_range(pal, -1, -1, PALETTE_EDITOR_RANGE_NONE); + if (select_index_entry) + paledit_select_range(pal, -1, -1, PALETTE_EDITOR_RANGE_NONE); + sprintf(buf, "None"); jwidget_disable(lock); @@ -427,7 +461,7 @@ static void select_tab_callback(JWidget tabs, void *data) jwidget_relayout(window); } -static int slider_change_signal(JWidget widget, int user_data) +static bool slider_change_hook(JWidget widget, void *data) { JWidget window = jwidget_get_window(widget); ColorSelector *colorselector = colorselector_data(window); @@ -435,7 +469,7 @@ static int slider_change_signal(JWidget widget, int user_data) JWidget pal = jwidget_find_name(window, "pal"); Model *m = tabs_get_selected_tab(tabs); color_t color = colorselector->color; - int i, palr, palg, palb; + int i, r, g, b; switch (m->model) { case MODEL_RGB: { @@ -472,16 +506,16 @@ static int slider_change_signal(JWidget widget, int user_data) } } - palr = color_get_red (IMAGE_RGB, color)/4; - palg = color_get_green(IMAGE_RGB, color)/4; - palb = color_get_blue (IMAGE_RGB, color)/4; + r = color_get_red (IMAGE_RGB, color); + g = color_get_green(IMAGE_RGB, color); + b = color_get_blue (IMAGE_RGB, color); /* if the palette is locked then we have to search for the closest color to the RGB values */ if (colorselector->palette_locked) { - i = bestfit_color(current_palette, palr, palg, palb); + i = palette_find_bestfit(get_current_palette(), r, g, b); if (i >= 0 && i < 256) - colorselector_set_paledit_index(window, i); + colorselector_set_paledit_index(window, i, TRUE); } /* the palette is unlocked, we have to modify the select entries */ else { @@ -490,7 +524,7 @@ static int slider_change_signal(JWidget widget, int user_data) paledit_get_selected_entries(pal, array); for (i=0; i<256; ++i) if (array[i]) - set_current_color(i, palr, palg, palb); + set_current_color(i, r, g, b); jwidget_dirty(pal); @@ -499,12 +533,20 @@ static int slider_change_signal(JWidget widget, int user_data) color = color_index(i); } - colorselector_set_color2(window, color, FALSE); + colorselector_set_color2(window, color, FALSE, m); jwidget_emit_signal(window, SIGNAL_COLORSELECTOR_COLOR_CHANGED); return 0; } -static int paledit_change_signal(JWidget widget, int user_data) +static bool button_mask_select_hook(JWidget widget, void *data) +{ + JWidget window = jwidget_get_window(widget); + colorselector_set_color(window, color_mask()); + jwidget_emit_signal(window, SIGNAL_COLORSELECTOR_COLOR_CHANGED); + return TRUE; +} + +static bool paledit_change_hook(JWidget widget, void *data) { JWidget window = jwidget_get_window(widget); bool array[256]; @@ -518,12 +560,12 @@ static int paledit_change_signal(JWidget widget, int user_data) break; } - colorselector_set_color2(window, color, TRUE); + colorselector_set_color2(window, color, TRUE, NULL); jwidget_emit_signal(window, SIGNAL_COLORSELECTOR_COLOR_CHANGED); return 0; } -static int lock_button_select_hook(JWidget widget, int user_data) +static bool lock_button_select_hook(JWidget widget, void *data) { JWidget window = jwidget_get_window(widget); ColorSelector *colorselector = colorselector_data(window); diff --git a/src/widgets/colsel2.h b/src/widgets/colsel2.h index 98dbf21be..357c95ab5 100644 --- a/src/widgets/colsel2.h +++ b/src/widgets/colsel2.h @@ -26,9 +26,9 @@ /* TODO use some JI_SIGNAL_USER */ #define SIGNAL_COLORSELECTOR_COLOR_CHANGED 0x10009 -JWidget colorselector_new(void); +JWidget colorselector_new(bool editable_palette); -void colorselector_set_color(JWidget colsel, color_t color); -color_t colorselector_get_color(JWidget colsel); +void colorselector_set_color(JWidget widget, color_t color); +color_t colorselector_get_color(JWidget widget); #endif /* WIDGETS_COLSEL2_H */ diff --git a/src/widgets/colview.c b/src/widgets/colview.c index c1d737c95..cda94a19e 100644 --- a/src/widgets/colview.c +++ b/src/widgets/colview.c @@ -29,7 +29,7 @@ #include "jinete/jtheme.h" #include "jinete/jwidget.h" -#include "core/color.h" +#include "modules/gfx.h" #include "widgets/colview.h" typedef struct ColorViewer diff --git a/src/widgets/editor.h b/src/widgets/editor.h index 5b6e26312..463fc14b6 100644 --- a/src/widgets/editor.h +++ b/src/widgets/editor.h @@ -43,7 +43,9 @@ typedef struct Editor int cursor_editor_y; int old_cursor_thick; bool cursor_candraw : 1; - bool cursor_eyedropper : 1; + + bool alt_pressed : 1; + bool space_pressed : 1; /* offset for the sprite */ int offset_x; @@ -104,6 +106,8 @@ void editor_refresh_region(JWidget editor); /**********************************************************************/ /* src/gui/editor/cursor.c */ +void editor_cursor_exit(void); + void editor_draw_cursor(JWidget editor, int x, int y); void editor_clean_cursor(JWidget editor); bool editor_cursor_is_subpixel(JWidget editor); diff --git a/src/widgets/editor/cursor.c b/src/widgets/editor/cursor.c index 5e5b0f19d..d153491dd 100644 --- a/src/widgets/editor/cursor.c +++ b/src/widgets/editor/cursor.c @@ -80,6 +80,12 @@ static void cleanpixel(BITMAP *bmp, int x, int y, int color); static int point_inside_region(int x, int y, JRegion region); +void editor_cursor_exit(void) +{ + if (cursor_bound.seg != NULL) + jfree(cursor_bound.seg); +} + /** * Draws the brush cursor inside the specified editor. * @@ -208,7 +214,7 @@ bool editor_cursor_is_subpixel(JWidget widget) static void generate_cursor_boundaries(void) { - if (!cursor_bound.seg || + if (cursor_bound.seg == NULL || cursor_bound.brush_type != get_brush_type() || cursor_bound.brush_size != get_brush_size() || cursor_bound.brush_angle != get_brush_angle()) { @@ -216,7 +222,7 @@ static void generate_cursor_boundaries(void) cursor_bound.brush_size = get_brush_size(); cursor_bound.brush_angle = get_brush_angle(); - if (cursor_bound.seg) + if (cursor_bound.seg != NULL) jfree(cursor_bound.seg); cursor_bound.seg = find_mask_boundary(get_brush()->image, diff --git a/src/widgets/editor/editor.c b/src/widgets/editor/editor.c index dbac3e45a..854db91fa 100644 --- a/src/widgets/editor/editor.c +++ b/src/widgets/editor/editor.c @@ -33,13 +33,14 @@ #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/brush.h" #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/sprite.h" @@ -97,7 +98,8 @@ JWidget editor_new(void) editor->cursor_thick = 0; editor->old_cursor_thick = 0; editor->cursor_candraw = FALSE; - editor->cursor_eyedropper = FALSE; + editor->alt_pressed = FALSE; + editor->space_pressed = FALSE; jwidget_add_hook(widget, editor_type(), editor_msg_proc, editor); jwidget_focusrest(widget, TRUE); @@ -379,10 +381,7 @@ void editor_draw_sprite(JWidget widget, int x1, int y1, int x2, int y2) Image *rgb_rendered = rendered; rendered = image_rgb_to_indexed(rgb_rendered, source_x, source_y, orig_rgb_map, - /* TODO */ -/* sprite_get_palette(editor->sprite, */ -/* editor->sprite->frpos)); */ - current_palette); + get_current_palette()); image_free(rgb_rendered); } @@ -406,8 +405,12 @@ void editor_draw_sprite(JWidget widget, int x1, int y1, int x2, int y2) image_to_allegro(rendered, ji_screen, dest_x, dest_y); } else { - select_palette(sprite_get_palette(editor->sprite, - editor->sprite->frame)); + PALETTE rgbpal; + Palette *pal = sprite_get_palette(editor->sprite, + editor->sprite->frame); + palette_to_allegro(pal, rgbpal); + + select_palette(rgbpal); image_to_allegro(rendered, ji_screen, dest_x, dest_y); unselect_palette(); } @@ -834,7 +837,8 @@ void editor_update_statusbar_for_standby(JWidget widget) screen_to_editor(widget, jmouse_x(0), jmouse_y(0), &x, &y); - if (editor->cursor_eyedropper) { + /* for eye-dropper */ + if (editor->alt_pressed) { color_t color = color_from_image(editor->sprite->imgtype, sprite_getpixel(editor->sprite, x, y)); @@ -1086,13 +1090,20 @@ static bool editor_msg_proc(JWidget widget, JMessage msg) editor->sprite->frame) != NULL); if (msg->any.shifts & KB_ALT_FLAG) - editor->cursor_eyedropper = TRUE; + editor->alt_pressed = TRUE; + + if (key[KEY_SPACE]) /* TODO another way to get the KEY_SPACE state? */ + editor->space_pressed = TRUE; break; case JM_MOUSELEAVE: hide_drawing_cursor(widget); - if (editor->cursor_eyedropper) - editor->cursor_eyedropper = FALSE; + + if (editor->alt_pressed) + editor->alt_pressed = FALSE; + + if (editor->space_pressed) + editor->space_pressed = FALSE; break; case JM_BUTTONPRESSED: { @@ -1104,7 +1115,8 @@ static bool editor_msg_proc(JWidget widget, JMessage msg) /* move the scroll */ if ((msg->mouse.left && has_only_shifts(msg, KB_SHIFT_FLAG)) || - (msg->mouse.middle && has_only_shifts(msg, 0))) { + (msg->mouse.middle && has_only_shifts(msg, 0)) || + (msg->mouse.left && editor->space_pressed)) { editor->state = EDIT_MOVING_SCROLL; editor_setcursor(widget, msg->mouse.x, msg->mouse.y); @@ -1123,7 +1135,7 @@ static bool editor_msg_proc(JWidget widget, JMessage msg) } } /* call the eyedropper command */ - else if (editor->cursor_eyedropper) { + else if (editor->alt_pressed) { Command *command = command_get_by_name(CMD_EYEDROPPER_TOOL); if (command_is_enabled(command, NULL)) command_execute(command, msg->mouse.right ? "background": NULL); @@ -1171,37 +1183,38 @@ static bool editor_msg_proc(JWidget widget, JMessage msg) editor->state = EDIT_STANDBY; jwidget_release_mouse(widget); } + else { + /* Draw cursor */ + if (editor->cursor_thick) { + int x, y; - /* Draw cursor */ - if (editor->cursor_thick) { - int x, y; + /* jmouse_set_cursor(JI_CURSOR_NULL); */ - /* jmouse_set_cursor(JI_CURSOR_NULL); */ + x = msg->mouse.x; + y = msg->mouse.y; - x = msg->mouse.x; - y = msg->mouse.y; - - /* Redraw it only when the mouse change to other pixel (not - when the mouse moves only). */ - if ((editor->cursor_screen_x != x) || (editor->cursor_screen_y != y)) { - jmouse_hide(); - editor_clean_cursor(widget); - editor_draw_cursor(widget, x, y); - jmouse_show(); + /* Redraw it only when the mouse change to other pixel (not + when the mouse moves only). */ + if ((editor->cursor_screen_x != x) || (editor->cursor_screen_y != y)) { + jmouse_hide(); + editor_clean_cursor(widget); + editor_draw_cursor(widget, x, y); + jmouse_show(); + } } - } - /* status bar text */ - if (editor->state == EDIT_STANDBY) { - editor_update_statusbar_for_standby(widget); - } - else if (editor->state == EDIT_MOVING_SCROLL) { - int x, y; - screen_to_editor(widget, jmouse_x(0), jmouse_y(0), &x, &y); - statusbar_set_text - (app_get_statusbar(), 0, - "Pos %3d %3d (Size %3d %3d)", x, y, - editor->sprite->w, editor->sprite->h); + /* status bar text */ + if (editor->state == EDIT_STANDBY) { + editor_update_statusbar_for_standby(widget); + } + else if (editor->state == EDIT_MOVING_SCROLL) { + int x, y; + screen_to_editor(widget, jmouse_x(0), jmouse_y(0), &x, &y); + statusbar_set_text + (app_get_statusbar(), 0, + "Pos %3d %3d (Size %3d %3d)", x, y, + editor->sprite->w, editor->sprite->h); + } } return TRUE; } @@ -1221,23 +1234,45 @@ static bool editor_msg_proc(JWidget widget, JMessage msg) editor_keys_toset_brushsize(widget, msg->key.scancode)) return TRUE; - /* eye-dropper is activated with ALT key */ - if (msg->key.scancode == KEY_ALT && - jwidget_has_mouse(widget)) { - editor->cursor_eyedropper = TRUE; - editor_setcursor(widget, jmouse_x(0), jmouse_y(0)); - return TRUE; + if (jwidget_has_mouse(widget)) { + switch (msg->key.scancode) { + + /* eye-dropper is activated with ALT key */ + case KEY_ALT: + editor->alt_pressed = TRUE; + editor_setcursor(widget, jmouse_x(0), jmouse_y(0)); + return TRUE; + + case KEY_SPACE: + editor->space_pressed = TRUE; + editor_setcursor(widget, jmouse_x(0), jmouse_y(0)); + return TRUE; + } } break; case JM_KEYRELEASED: - if (editor->cursor_eyedropper) { + switch (msg->key.scancode) { + /* eye-dropper is deactivated with ALT key */ - if (msg->key.scancode == KEY_ALT) { - editor->cursor_eyedropper = FALSE; - editor_setcursor(widget, jmouse_x(0), jmouse_y(0)); - return TRUE; - } + case KEY_ALT: + if (editor->alt_pressed) { + editor->alt_pressed = FALSE; + editor_setcursor(widget, jmouse_x(0), jmouse_y(0)); + return TRUE; + } + break; + + case KEY_SPACE: + if (editor->space_pressed) { + /* we have to clear all the KEY_SPACE in buffer */ + clear_keybuf(); + + editor->space_pressed = FALSE; + editor_setcursor(widget, jmouse_x(0), jmouse_y(0)); + return TRUE; + } + break; } break; @@ -1375,10 +1410,14 @@ static void editor_setcursor(JWidget widget, int x, int y) case EDIT_STANDBY: if (editor->sprite) { if (editor->cursor_candraw) { - if (editor->cursor_eyedropper) { + if (editor->alt_pressed) { hide_drawing_cursor(widget); jmouse_set_cursor(JI_CURSOR_EYEDROPPER); } + else if (editor->space_pressed) { + hide_drawing_cursor(widget); + jmouse_set_cursor(JI_CURSOR_MOVE); + } else { jmouse_set_cursor(JI_CURSOR_NULL); show_drawing_cursor(widget); diff --git a/src/widgets/fileview.c b/src/widgets/fileview.c index a0be9246b..7e98ea23f 100644 --- a/src/widgets/fileview.c +++ b/src/widgets/fileview.c @@ -31,10 +31,11 @@ #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/sprites.h" #include "raster/image.h" +#include "raster/palette.h" #include "raster/rotate.h" #include "raster/sprite.h" #include "widgets/fileview.h" @@ -70,7 +71,7 @@ typedef struct ThumbnailData JWidget fileview; Image *thumbnail; JThread thread; - PALETTE pal; + PALETTE rgbpal; } ThumbnailData; static FileView *fileview_data(JWidget widget); @@ -255,7 +256,7 @@ static bool fileview_msg_proc(JWidget widget, JMessage msg) int bgcolor; int fgcolor; BITMAP *thumbnail = NULL; - int thumbnail_y; + int thumbnail_y = 0; /* rows */ JI_LIST_FOR_EACH(fileview->list, link) { @@ -751,7 +752,7 @@ static void openfile_bg(void *_data) sprite_free(fop->sprite); else { /* the palette to convert the Image to a BITMAP */ - palette_copy(data->pal, sprite_get_palette(sprite, 0)); + palette_to_allegro(sprite_get_palette(sprite, 0), data->rgbpal); /* render the 'sprite' in one plain 'image' */ image = image_new(sprite->imgtype, sprite->w, sprite->h); @@ -795,10 +796,11 @@ static void monitor_thumbnail_generation(void *_data) if (fop_is_done(fop)) { /* set the thumbnail of the file-item */ if (data->thumbnail) { - BITMAP *bmp = create_bitmap(data->thumbnail->w, - data->thumbnail->h); + BITMAP *bmp = create_bitmap_ex(16, + data->thumbnail->w, + data->thumbnail->h); - select_palette(data->pal); + select_palette(data->rgbpal); image_to_allegro(data->thumbnail, bmp, 0, 0); unselect_palette(); diff --git a/src/widgets/groupbut.c b/src/widgets/groupbut.c index 80c1261a9..8c6f0f9ff 100644 --- a/src/widgets/groupbut.c +++ b/src/widgets/groupbut.c @@ -34,7 +34,7 @@ static JWidget find_selected(JWidget widget); static int select_button(JWidget widget, int index); -static int radio_change_signal(JWidget widget, int user_data); +static bool radio_change_hook(JWidget widget, void *data); JWidget group_button_new(int w, int h, int first_selected, ...) { @@ -69,7 +69,7 @@ JWidget group_button_new(int w, int h, int first_selected, ...) if (icon >= 0) add_gfxicon_to_button(radio, icon, JI_CENTER | JI_MIDDLE); - HOOK(radio, JI_SIGNAL_RADIO_CHANGE, radio_change_signal, vbox); + HOOK(radio, JI_SIGNAL_RADIO_CHANGE, radio_change_hook, vbox); if (c == first_selected) jwidget_select(radio); @@ -146,8 +146,8 @@ static int select_button(JWidget widget, int index) return FALSE; } -static int radio_change_signal(JWidget widget, int user_data) +static bool radio_change_hook(JWidget widget, void *data) { - jwidget_emit_signal((JWidget)user_data, SIGNAL_GROUP_BUTTON_CHANGE); + jwidget_emit_signal((JWidget)data, SIGNAL_GROUP_BUTTON_CHANGE); return TRUE; } diff --git a/src/widgets/paledit.c b/src/widgets/paledit.c index 70ab1de48..ea608fb39 100644 --- a/src/widgets/paledit.c +++ b/src/widgets/paledit.c @@ -32,8 +32,10 @@ #include "core/color.h" #include "modules/gui.h" -#include "modules/palette.h" +#include "modules/palettes.h" #include "raster/blend.h" +#include "raster/image.h" +#include "raster/palette.h" #include "widgets/paledit.h" /* #define COLOR_SIZE 6 */ @@ -42,7 +44,7 @@ typedef struct PalEdit { JWidget widget; - RGB *palette; + Palette *palette; bool editable; unsigned range_type; unsigned columns; @@ -55,7 +57,7 @@ static bool paledit_msg_proc(JWidget widget, JMessage msg); static void paledit_request_size(JWidget widget, int *w, int *h); static void paledit_update_scroll(JWidget widget, int color); -JWidget paledit_new(RGB *palette, bool editable, int boxsize) +JWidget paledit_new(Palette *palette, bool editable, int boxsize) { JWidget widget = jwidget_new(paledit_type()); PalEdit *paledit = jnew(PalEdit, 1); @@ -87,7 +89,7 @@ int paledit_type(void) return type; } -RGB *paledit_get_palette(JWidget widget) +Palette *paledit_get_palette(JWidget widget) { PalEdit *paledit = paledit_data(widget); @@ -167,21 +169,13 @@ void paledit_select_range(JWidget widget, int begin, int end, int range_type) jwidget_dirty(widget); } -static void swap_color(RGB *palette, int c1, int c2) +static void swap_color(Palette *palette, int i1, int i2) { - int r, g, b; + ase_uint32 c1 = palette_get_entry(palette, i1); + ase_uint32 c2 = palette_get_entry(palette, i2); - r = palette[c1].r; - g = palette[c1].g; - b = palette[c1].b; - - palette[c1].r = palette[c2].r; - palette[c1].g = palette[c2].g; - palette[c1].b = palette[c2].b; - - palette[c2].r = r; - palette[c2].g = g; - palette[c2].b = b; + palette_set_entry(palette, i2, c1); + palette_set_entry(palette, i1, c2); } void paledit_move_selection(JWidget widget, int x, int y) @@ -397,8 +391,7 @@ static bool paledit_msg_proc(JWidget widget, JMessage msg) break; case JM_REQSIZE: - paledit_request_size(widget, - &msg->reqsize.w, &msg->reqsize.h); + paledit_request_size(widget, &msg->reqsize.w, &msg->reqsize.h); return TRUE; case JM_KEYPRESSED: @@ -447,9 +440,9 @@ static bool paledit_msg_proc(JWidget widget, JMessage msg) else color = makecol_depth (bitmap_color_depth(ji_screen), - _rgb_scale_6[paledit->palette[c].r], - _rgb_scale_6[paledit->palette[c].g], - _rgb_scale_6[paledit->palette[c].b]); + _rgba_getr(paledit->palette->color[c]), + _rgba_getg(paledit->palette->color[c]), + _rgba_getb(paledit->palette->color[c])); rectfill(bmp, x, y, x+COLOR_SIZE-1, y+COLOR_SIZE-1, color); diff --git a/src/widgets/paledit.h b/src/widgets/paledit.h index f8d275bd4..a58d80972 100644 --- a/src/widgets/paledit.h +++ b/src/widgets/paledit.h @@ -23,7 +23,7 @@ #include "jinete/jbase.h" -struct RGB; +struct Palette; /* TODO use some JI_SIGNAL_USER */ #define SIGNAL_PALETTE_EDITOR_CHANGE 0x10005 @@ -34,10 +34,10 @@ enum { PALETTE_EDITOR_RANGE_RECTANGULAR, }; -JWidget paledit_new(RGB *palette, bool editable, int boxsize); +JWidget paledit_new(struct Palette *palette, bool editable, int boxsize); int paledit_type(void); -struct RGB *paledit_get_palette(JWidget widget); +struct Palette *paledit_get_palette(JWidget widget); int paledit_get_range_type(JWidget widget); int paledit_get_columns(JWidget widget); diff --git a/src/widgets/statebar.c b/src/widgets/statebar.c index 8beee171a..4d328cc9c 100644 --- a/src/widgets/statebar.c +++ b/src/widgets/statebar.c @@ -29,7 +29,7 @@ #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 "raster/cel.h" #include "raster/layer.h" @@ -49,8 +49,9 @@ enum { }; static bool statusbar_msg_proc(JWidget widget, JMessage msg); +static bool tipwindow_msg_proc(JWidget widget, JMessage msg); -static int slider_change_signal(JWidget widget, int user_data); +static bool slider_change_hook(JWidget widget, void *data); static void button_command(JWidget widget, void *data); static void update_from_layer(StatusBar *statusbar); @@ -79,6 +80,7 @@ JWidget statusbar_new(void) statusbar->widget = widget; statusbar->timeout = 0; statusbar->progress = jlist_new(); + statusbar->tipwindow = NULL; /* construct the commands box */ box1 = jbox_new(JI_HORIZONTAL); @@ -91,7 +93,7 @@ JWidget statusbar_new(void) ICON_NEW(statusbar->b_next, GFX_ANI_NEXT, ACTION_NEXT); ICON_NEW(statusbar->b_last, GFX_ANI_LAST, ACTION_LAST); - HOOK(statusbar->slider, JI_SIGNAL_SLIDER_CHANGE, slider_change_signal, 0); + HOOK(statusbar->slider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0); jwidget_set_min_size(statusbar->slider, JI_SCREEN_W/5, 0); jwidget_noborders(box1); @@ -131,7 +133,7 @@ void statusbar_set_text(JWidget widget, int msecs, const char *format, ...) StatusBar *statusbar = statusbar_data(widget); if ((ji_clock > statusbar->timeout) || (msecs > 0)) { - char buf[256]; + char buf[256]; /* TODO warning buffer overflow */ va_list ap; va_start(ap, format); @@ -147,11 +149,50 @@ void statusbar_set_text(JWidget widget, int msecs, const char *format, ...) } } -void statusbar_show_color(JWidget statusbar, int msecs, int imgtype, color_t color) +void statusbar_show_tip(JWidget widget, int msecs, const char *format, ...) { - char buf[128]; + StatusBar *statusbar = statusbar_data(widget); + JWidget tipwindow = statusbar->tipwindow; + char buf[256]; /* TODO warning buffer overflow */ + va_list ap; + int x, y; + + va_start(ap, format); + vsprintf(buf, format, ap); + va_end(ap); + + if (tipwindow == NULL) { + tipwindow = jtooltip_window_new(buf); + tipwindow->user_data[0] = (void *)jmanager_add_timer(tipwindow, msecs); + tipwindow->user_data[1] = statusbar; + jwidget_add_hook(tipwindow, -1, tipwindow_msg_proc, NULL); + + statusbar->tipwindow = tipwindow; + } + else { + jwidget_set_text(tipwindow, buf); + + jmanager_set_timer_interval((int)tipwindow->user_data[0], msecs); + } + + if (jwidget_is_visible(tipwindow)) + jwindow_close(tipwindow, NULL); + + jwindow_open(tipwindow); + jwindow_remap(tipwindow); + + x = widget->rc->x2 - jrect_w(tipwindow->rc); + y = widget->rc->y1 - jrect_h(tipwindow->rc); + jwindow_position(tipwindow, x, y); + + jmanager_start_timer((int)tipwindow->user_data[0]); +} + +void statusbar_show_color(JWidget widget, int msecs, int imgtype, color_t color) +{ + char buf[128]; /* TODO warning buffer overflow */ color_to_formalstring(imgtype, color, buf, sizeof(buf), TRUE); - statusbar_set_text(statusbar, msecs, "%s %s", _("Color"), buf); + statusbar_set_text(widget, msecs, "%s %s", _("Color"), buf); } void statusbar_update(JWidget widget) @@ -161,18 +202,17 @@ void statusbar_update(JWidget widget) update_from_layer(statusbar); } -Progress *progress_new(JWidget statusbar) +Progress *progress_new(JWidget widget) { Progress *progress = jnew(Progress, 1); if (!progress) return NULL; - progress->statusbar = statusbar; + progress->statusbar = widget; progress->pos = 0.0f; - jlist_append(statusbar_data(statusbar)->progress, - progress); - jwidget_dirty(statusbar); + jlist_append(statusbar_data(widget)->progress, progress); + jwidget_dirty(widget); return progress; } @@ -324,7 +364,23 @@ static bool statusbar_msg_proc(JWidget widget, JMessage msg) return FALSE; } -static int slider_change_signal(JWidget widget, int user_data) +static bool tipwindow_msg_proc(JWidget widget, JMessage msg) +{ + switch (msg->type) { + + case JM_DESTROY: + jmanager_remove_timer((int)widget->user_data[0]); + break; + + case JM_TIMER: + jwindow_close(widget, NULL); + break; + } + + return FALSE; +} + +static bool slider_change_hook(JWidget widget, void *data) { Sprite *sprite = current_sprite; diff --git a/src/widgets/statebar.h b/src/widgets/statebar.h index 432b5c5e8..7891a3daf 100644 --- a/src/widgets/statebar.h +++ b/src/widgets/statebar.h @@ -46,6 +46,9 @@ typedef struct StatusBar JWidget b_play; /* play animation */ JWidget b_next; /* go to next frame */ JWidget b_last; /* go to last frame */ + + /* tip window */ + JWidget tipwindow; } StatusBar; /* statusbar */ @@ -53,15 +56,16 @@ typedef struct StatusBar JWidget statusbar_new(void); int statusbar_type(void); -StatusBar *statusbar_data(JWidget statusbar); +StatusBar *statusbar_data(JWidget widget); -void statusbar_set_text(JWidget statusbar, int msecs, const char *format, ...); -void statusbar_show_color(JWidget statusbar, int msecs, int imgtype, color_t color); -void statusbar_update(JWidget statusbar); +void statusbar_set_text(JWidget widget, int msecs, const char *format, ...); +void statusbar_show_tip(JWidget widget, int msecs, const char *format, ...); +void statusbar_show_color(JWidget widget, int msecs, int imgtype, color_t color); +void statusbar_update(JWidget widget); /* progress */ -Progress *progress_new(JWidget statusbar); +Progress *progress_new(JWidget widget); void progress_free(Progress *progress); void progress_update(Progress *progress, float progress_pos); diff --git a/src/widgets/tabs.c b/src/widgets/tabs.c index 06f64ee62..57b592802 100644 --- a/src/widgets/tabs.c +++ b/src/widgets/tabs.c @@ -19,6 +19,7 @@ #include "config.h" #include <allegro.h> +#include <assert.h> #include "jinete/jinete.h" #include "jinete/jintern.h" @@ -101,7 +102,7 @@ JWidget tabs_new(void (*select_callback)(JWidget tabs, void *data)) jwidget_add_hook(tabs->button_left, tabs_type(), tabs_button_msg_proc, (void *)-1); jwidget_add_hook(tabs->button_right, tabs_type(), tabs_button_msg_proc, (void *)+1); - jwidget_set_bg_color(widget, ji_color_face()); + jwidget_init_theme(widget); return widget; } @@ -215,11 +216,6 @@ static bool tabs_msg_proc(JWidget widget, JMessage msg) msg->reqsize.h = 4 + jwidget_get_text_height(widget) + 5; return TRUE; -/* case JM_SIGNAL: */ -/* if (msg->signal.num == JI_SIGNAL_SHOW) */ -/* set_scroll_x(widget, tabs->scroll_x); */ -/* break; */ - case JM_SETPOS: jrect_copy(widget->rc, &msg->setpos.rect); set_scroll_x(widget, tabs->scroll_x); @@ -319,9 +315,6 @@ static bool tabs_msg_proc(JWidget widget, JMessage msg) } case JM_TIMER: { -/* JWidget parent = jwidget_get_parent(widget); */ -/* Tabs *tabs = jwidget_get_data(parent, tabs_type()); */ -/* int dir = (int)jwidget_get_data(widget, tabs_type()); */ int dir = jmanager_get_capture() == tabs->button_left ? -1: 1; set_scroll_x(widget, tabs->scroll_x + dir*8*msg->timer.count); break; @@ -336,6 +329,10 @@ static bool tabs_msg_proc(JWidget widget, JMessage msg) tab->width = CALC_TAB_WIDTH(widget, tab); } } + else if (msg->signal.num == JI_SIGNAL_INIT_THEME) { + /* setup the background color */ + jwidget_set_bg_color(widget, ji_color_face()); + } break; } @@ -346,7 +343,7 @@ static bool tabs_msg_proc(JWidget widget, JMessage msg) static bool tabs_button_msg_proc(JWidget widget, JMessage msg) { JWidget parent; - Tabs *tabs; + Tabs *tabs = NULL; parent = jwidget_get_parent(widget); if (parent) @@ -359,6 +356,8 @@ static bool tabs_button_msg_proc(JWidget widget, JMessage msg) return TRUE; } else if (msg->signal.num == JI_SIGNAL_DISABLE) { + assert(tabs != NULL); + if (jwidget_is_selected(widget)) { jmanager_stop_timer(tabs->timer_id); jwidget_deselect(widget); @@ -368,10 +367,12 @@ static bool tabs_button_msg_proc(JWidget widget, JMessage msg) break; case JM_BUTTONPRESSED: + assert(tabs != NULL); jmanager_start_timer(tabs->timer_id); break; case JM_BUTTONRELEASED: + assert(tabs != NULL); jmanager_stop_timer(tabs->timer_id); break; diff --git a/src/widgets/target.c b/src/widgets/target.c index 73638fdcb..7424b7f67 100644 --- a/src/widgets/target.c +++ b/src/widgets/target.c @@ -32,8 +32,8 @@ #include "raster/image.h" #include "widgets/target.h" -static int channel_change(JWidget widget, int user_data); -static int images_change(JWidget widget, int user_data); +static bool channel_change_hook(JWidget widget, void *data); +static bool images_change_hook(JWidget widget, void *data); static int get_target_image_gfx(void); /* creates a new button to handle "targets" to apply some effect in @@ -102,24 +102,24 @@ JWidget target_button_new(int imgtype, bool with_channels) JI_CENTER | JI_MIDDLE); /* make hierarchy */ - ADD(hbox, r, channel_change); - ADD(hbox, g, channel_change); - ADD(hbox, b, channel_change); - ADD(hbox, k, channel_change); - ADD(hbox, a, channel_change); + ADD(hbox, r, channel_change_hook); + ADD(hbox, g, channel_change_hook); + ADD(hbox, b, channel_change_hook); + ADD(hbox, k, channel_change_hook); + ADD(hbox, a, channel_change_hook); if (with_channels) jwidget_add_child(vbox, hbox); else jwidget_free(hbox); - ADD(vbox, index, channel_change); - ADD(vbox, images, images_change); + ADD(vbox, index, channel_change_hook); + ADD(vbox, images, images_change_hook); return vbox; } -static int channel_change(JWidget widget, int user_data) +static bool channel_change_hook(JWidget widget, void *data) { const char *name; @@ -136,17 +136,17 @@ static int channel_change(JWidget widget, int user_data) set_config_bool("Target", name, jwidget_is_selected(widget)); - jwidget_emit_signal((JWidget)user_data, SIGNAL_TARGET_BUTTON_CHANGE); + jwidget_emit_signal((JWidget)data, SIGNAL_TARGET_BUTTON_CHANGE); return TRUE; } -static int images_change(JWidget widget, int user_data) +static bool images_change_hook(JWidget widget, void *data) { int images = get_config_int("Target", "Images", 0); set_config_int("Target", "Images", (images+1)%4); set_gfxicon_in_button(widget, get_target_image_gfx()); - jwidget_emit_signal((JWidget)user_data, SIGNAL_TARGET_BUTTON_CHANGE); + jwidget_emit_signal((JWidget)data, SIGNAL_TARGET_BUTTON_CHANGE); return TRUE; } diff --git a/src/widgets/toolbar.c b/src/widgets/toolbar.c index 700277c71..58e953c2d 100644 --- a/src/widgets/toolbar.c +++ b/src/widgets/toolbar.c @@ -31,7 +31,7 @@ #include "widgets/groupbut.h" #include "widgets/toolbar.h" -static int group_change_signal(JWidget widget, int user_data); +static bool group_change_hook(JWidget widget, void *data); static void conf_command(JWidget widget); JWidget toolbar_new(int align) @@ -79,7 +79,7 @@ JWidget toolbar_new(int align) jwidget_add_child(box, fillbox); jwidget_add_child(box, confbutton); - HOOK(group, SIGNAL_GROUP_BUTTON_CHANGE, group_change_signal, 0); + HOOK(group, SIGNAL_GROUP_BUTTON_CHANGE, group_change_hook, 0); jbutton_add_command(confbutton, conf_command); box->user_data[0] = group; @@ -99,7 +99,7 @@ void toolbar_update(JWidget widget) group_button_select(group, c); } -static int group_change_signal(JWidget widget, int user_data) +static bool group_change_hook(JWidget widget, void *data) { int c = group_button_get_selected(widget); diff --git a/third_party/libart_lgpl/art_pixbuf.c b/third_party/libart_lgpl/art_pixbuf.c index 267bd5bcb..e18a40cd4 100644 --- a/third_party/libart_lgpl/art_pixbuf.c +++ b/third_party/libart_lgpl/art_pixbuf.c @@ -271,7 +271,7 @@ art_pixbuf_duplicate (const ArtPixBuf *pixbuf) size = (pixbuf->height - 1) * pixbuf->rowstride + pixbuf->width * ((pixbuf->n_channels * pixbuf->bits_per_sample + 7) >> 3); result->pixels = art_alloc (size); - memcpy (result->pixels, pixbuf->pixels, size); + memcpy(result->pixels, pixbuf->pixels, size); result->width = pixbuf->width; result->height = pixbuf->height;