1 /* vim:expandtab:ts=2 sw=2: 2 */ 3 /* Grafx2 - The Ultimate 256-color bitmap paint program 4 5 Copyright owned by various GrafX2 authors, see COPYRIGHT.txt for details. 6 7 Grafx2 is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License 9 as published by the Free Software Foundation; version 2 10 of the License. 11 12 Grafx2 is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Grafx2; if not, see <http://www.gnu.org/licenses/> 19 */ 20 21 ////////////////////////////////////////////////////////////////////////////// 22 ///@file global.h 23 /// This file contains all global variables. 24 /// They are prefixed by ::GFX2_GLOBAL so they are extern when needed. 25 ////////////////////////////////////////////////////////////////////////////// 26 #ifndef _GLOBAL_H_ 27 #define _GLOBAL_H_ 28 29 #include "struct.h" 30 31 // MAIN declares the variables, 32 // other files only have an extern definition. 33 #ifdef GLOBAL_VARIABLES 34 /// Magic prefix to make all declarations extern, except when included by main.c. 35 #define GFX2_GLOBAL 36 #else 37 #define GFX2_GLOBAL extern 38 #endif 39 40 // -- CONFIGURATION variables 41 42 /// Current configuration. 43 GFX2_GLOBAL T_Config Config; 44 45 /// Array of special keys. 46 GFX2_GLOBAL word Config_Key[NB_SPECIAL_SHORTCUTS][2]; 47 48 /// A video mode (resolution) usable by Grafx2. 49 typedef struct 50 { 51 short Width; ///< Screen width 52 short Height; ///< Screen height 53 byte Mode; ///< Unused (used to be Mode-X, SVGA, etc) 54 word Fullscreen; ///< 0 for window, 1 for fullscreen 55 byte State; ///< How good is the mode supported. 0:Good (white) 1:OK (light) 2:So-so (dark) 4:User-disabled (black); +128 => System doesn't support it at all. 56 } T_Video_mode; 57 58 /// Array of all video modes supported by your platform. Actually filled up to ::Nb_video_modes, excluded. 59 GFX2_GLOBAL T_Video_mode Video_mode[MAX_VIDEO_MODES]; 60 61 /// Actual number of video modes in ::Video_mode. 62 GFX2_GLOBAL int Nb_video_modes; 63 64 // -- Menu colors 65 66 GFX2_GLOBAL byte MC_Black; ///< Index of color to use as "black" in the GUI menus. 67 GFX2_GLOBAL byte MC_Dark; ///< Index of color to use as "dark grey" in the GUI menus. 68 GFX2_GLOBAL byte MC_Light; ///< Index of color to use as "light grey" in the GUI menus. 69 GFX2_GLOBAL byte MC_White; ///< Index of color to use as "white" in the GUI menus. 70 GFX2_GLOBAL byte MC_Trans; ///< Index of color to use as "transparent" while loading the GUI file. 71 72 GFX2_GLOBAL byte MC_OnBlack; ///< Index of color immediately lighter than "black" in the GUI menus. 73 GFX2_GLOBAL byte MC_Window; ///< Index of color to use as window background in the GUI menus. 74 GFX2_GLOBAL byte MC_Lighter; ///< Index of color lighter than window in the GUI menus. 75 GFX2_GLOBAL byte MC_Darker; ///< Index of color darker than window in the GUI menus. 76 77 78 // Input state 79 GFX2_GLOBAL word Mouse_X; ///< Current mouse cursor position. 80 GFX2_GLOBAL word Mouse_Y; ///< Current mouse cursor position. 81 GFX2_GLOBAL byte Mouse_K; ///< Current mouse buttons state. Bitfield: 1 for RMB, 2 for LMB. 82 GFX2_GLOBAL byte Keyboard_click_allowed; ///< Set to 0 when you edit a textfield so you can use space without exiting it 83 84 /// Helper macro to take only one button when both are pressed (LMB has priority) 85 #define Mouse_K_unique (Mouse_K==0?0:(Mouse_K&1?1:(Mouse_K&2?2:0))) 86 87 /// Last key pressed, 0 if none. Set by the latest call to ::Get_input() 88 GFX2_GLOBAL dword Key; 89 90 /// 91 /// Last character typed, converted to ANSI character set (Windows-1252). 92 /// This is mostly used when the user enters text (filename, etc). 93 GFX2_GLOBAL dword Key_ANSI; 94 95 GFX2_GLOBAL dword Key_UNICODE; 96 97 /// from SDL_TextInputEvent 98 #if defined(USE_SDL2) 99 GFX2_GLOBAL char Key_Text[32]; 100 #endif 101 102 // Keyboard modifiers 103 104 /// Key modifier for SHIFT key. Used as mask in ::Key, for example. 105 #define GFX2_MOD_SHIFT 0x1000 106 /// Key modifier for CONTROL key. Used as mask in ::Key, for example. 107 #define GFX2_MOD_CTRL 0x2000 108 /// Key modifier for ALT key. Used as mask in ::Key, for example. 109 #define GFX2_MOD_ALT 0x4000 110 /// Key modifier for META key. Used as mask in ::Key, for example. 111 #define GFX2_MOD_META 0x8000 112 113 /// Boolean set to true when the OS/window manager requests the application to close. ie: [X] button 114 GFX2_GLOBAL byte Quit_is_required; 115 116 /// 117 /// This boolean is true when the current operation allows changing the 118 /// foreground or background color. 119 GFX2_GLOBAL byte Allow_color_change_during_operation; 120 121 // -- Mouse cursor data 122 123 /// Current mouse cursor. Value is in enum ::CURSOR_SHAPES 124 GFX2_GLOBAL byte Cursor_shape; 125 /// Backup of ::Cursor_shape, used while a window is open (and needs a different cursor) 126 GFX2_GLOBAL byte Cursor_shape_before_window; 127 /// Boolean, means the cursor should not be drawn. It's togglable by the user. 128 GFX2_GLOBAL byte Cursor_hidden; 129 /// Boolean, means the cursor is currently hovering over a menu GUI element. 130 GFX2_GLOBAL byte Cursor_in_menu; 131 /// Boolean, means the cursor was hovering over a menu GUI element. 132 GFX2_GLOBAL byte Cursor_in_menu_previous; 133 /// Storage for the graphics under the mouse cursor. Used by ::Hide_cursor and ::Display_cursor 134 GFX2_GLOBAL byte Cursor_background[CURSOR_SPRITE_HEIGHT][CURSOR_SPRITE_WIDTH]; 135 136 // -- Paintbrush data 137 138 /// Active paintbrush. It's an index in enum ::PAINTBRUSH_SHAPES 139 GFX2_GLOBAL byte Paintbrush_shape; 140 /// Backup of ::Paintbrush_shape, before fill operation 141 GFX2_GLOBAL byte Paintbrush_shape_before_fill; 142 /// Backup of ::Paintbrush_shape, before color picker operation 143 GFX2_GLOBAL byte Paintbrush_shape_before_colorpicker; 144 /// Backup of ::Paintbrush_shape, before lasso operation 145 GFX2_GLOBAL byte Paintbrush_shape_before_lasso; 146 /// Boolean, true when the preview paintbrush shouldn't be drawn. 147 GFX2_GLOBAL byte Paintbrush_hidden; 148 /// Cordinate of the preview paintbrush in image space. 149 GFX2_GLOBAL short Paintbrush_X; 150 /// Cordinate of the preview paintbrush in image space. 151 GFX2_GLOBAL short Paintbrush_Y; 152 /// Pixel data of the current brush 153 GFX2_GLOBAL byte * Paintbrush_sprite; 154 /// Current paintbrush's width 155 GFX2_GLOBAL short Paintbrush_width; 156 /// Current paintbrush's height 157 GFX2_GLOBAL short Paintbrush_height; 158 /// Position of current paintbrush's handle 159 GFX2_GLOBAL short Paintbrush_offset_X; 160 /// Position of current paintbrush's handle 161 GFX2_GLOBAL short Paintbrush_offset_Y; 162 163 // -- Graphic commands 164 165 /// On the screen, draw a point. 166 GFX2_GLOBAL Func_pixel Pixel; 167 /// Test a pixel color from screen. 168 GFX2_GLOBAL Func_read Read_pixel; 169 /// Redraw all screen, without overwriting the menu. 170 GFX2_GLOBAL Func_display Display_screen; 171 /// Draw a rectangle on screen. 172 GFX2_GLOBAL Func_block Block; 173 /// Draw a point from the image to screen (no zoom). 174 GFX2_GLOBAL Func_pixel Pixel_preview_normal; 175 /// Draw a point from the image to screen (magnified part). 176 GFX2_GLOBAL Func_pixel Pixel_preview_magnifier; 177 /// Draw a point from the image to screen (zoomed if needed). 178 GFX2_GLOBAL Func_pixel Pixel_preview; 179 /// Draw a horizontal XOR line on screen. 180 GFX2_GLOBAL Func_line_XOR Horizontal_XOR_line; 181 /// Draw a vertical XOR line on screen. 182 GFX2_GLOBAL Func_line_XOR Vertical_XOR_line; 183 /// Display part of the brush on screen, color mode. 184 GFX2_GLOBAL Func_display_brush_color Display_brush_color; 185 /// Display part of the brush on screen, monochrome mode. 186 GFX2_GLOBAL Func_display_brush_mono Display_brush_mono; 187 /// Clear the brush currently displayed on screen, redrawing the image instead. 188 GFX2_GLOBAL Func_display_brush_color Clear_brush; 189 /// Remap part of the screen after the menu colors have changed. 190 GFX2_GLOBAL Func_remap Remap_screen; 191 /// Draw a line on screen. 192 GFX2_GLOBAL Func_procsline Display_line; 193 /// Draw a line on screen, without doubling it if using wide pixels. (to be used when the line is already doubled in the input buffer) 194 GFX2_GLOBAL Func_procsline Display_line_fast; 195 /// Read a line of pixels from screen. 196 GFX2_GLOBAL Func_procsline Read_line; 197 /// Redraw all magnified part on screen, without overwriting the menu. 198 GFX2_GLOBAL Func_display_zoom Display_zoomed_screen; 199 /// Display part of the brush on the magnified part of screen, color mode. 200 GFX2_GLOBAL Func_display_brush_color_zoom Display_brush_color_zoom; 201 /// Display part of the brush on the magnified part of screen, monochrome mode. 202 GFX2_GLOBAL Func_display_brush_mono_zoom Display_brush_mono_zoom; 203 /// Clear the brush currently displayed on the magnified part of screen, redrawing the image instead. 204 GFX2_GLOBAL Func_display_brush_color_zoom Clear_brush_scaled; 205 /// Draw an arbitrary brush on screen (not the current brush) 206 GFX2_GLOBAL Func_draw_brush Display_brush; 207 208 // -- Screen data 209 210 /// Requested window width. This is set when the user resizes the window. 211 GFX2_GLOBAL int Resize_width; 212 /// Requested window height. This is set when the user resizes the window. 213 GFX2_GLOBAL int Resize_height; 214 /// Current window state (standard, minimized, maximized) 215 GFX2_GLOBAL enum GFX2_WINDOW_STATES Window_state; 216 /// Default window width (not maximized) 217 GFX2_GLOBAL int Default_window_width; 218 /// Default window height (not maximized) 219 GFX2_GLOBAL int Default_window_height; 220 /// Current video mode. Index in ::Video_mode 221 GFX2_GLOBAL int Current_resolution; 222 /// After loading an image, this holds the "original screen width", if the file format supported it. 223 GFX2_GLOBAL short Original_screen_X; 224 /// After loading an image, this holds the "original screen height", if the file format supported it. 225 GFX2_GLOBAL short Original_screen_Y; 226 /// 227 /// Current screen (or window) width, in pixels. 228 /// Note that this takes ::Pixel_ratio into account. 229 GFX2_GLOBAL short Screen_width; 230 /// 231 /// Current screen (or window) height, in pixels. 232 /// Note that this takes ::Pixel_ratio into account. 233 GFX2_GLOBAL short Screen_height; 234 /// Coordinate (in image space) of the topmost visible pixel. 235 GFX2_GLOBAL short Limit_top; 236 /// 237 /// Coordinate (in image space) of the lowest visible pixel. 238 /// This can be larger than the image height, if the screen is bigger than image. 239 GFX2_GLOBAL short Limit_bottom; 240 /// Coordinate (in image space) of the leftmost visible pixel. 241 GFX2_GLOBAL short Limit_left; 242 /// 243 /// Coordinate (in image space) of the rightmost visible pixel. 244 /// This can be larger than the image width, if the screen is bigger than image. 245 GFX2_GLOBAL short Limit_right; 246 /// 247 /// Coordinate (in image space) of the lowest visible pixel, limited by the 248 /// image height. Compare with ::Limit_bottom, which is not clipped. 249 GFX2_GLOBAL short Limit_visible_bottom; 250 /// 251 /// Coordinate (in image space) of the rightmost visible pixel, limited by the 252 /// image width. Compare with ::Limit_right, which is not clipped. 253 GFX2_GLOBAL short Limit_visible_right; 254 255 /// Coordinate (in image space) of the pixel at the top of the magnified view. 256 GFX2_GLOBAL short Limit_top_zoom; 257 /// 258 /// Coordinate (in image space) of the pixel at the bottom of the magnified view. 259 /// This can be larger than the image height, if the screen is bigger than image. 260 GFX2_GLOBAL short Limit_bottom_zoom; 261 /// Coordinate (in image space) of the pixel at the left of the magnified view. 262 GFX2_GLOBAL short Limit_left_zoom; 263 /// 264 /// Coordinate (in image space) of the pixel at the right of the magnified view. 265 /// This can be larger than the image width, if the screen is bigger than image. 266 GFX2_GLOBAL short Limit_right_zoom; 267 /// 268 /// Coordinate (in image space) of the lowest visible pixel, limited by the 269 /// image height. Compare with ::Limit_bottom, which is not clipped. 270 GFX2_GLOBAL short Limit_visible_bottom_zoom; 271 /// Coordinate (in image space) of the rightmost visible pixel. 272 /// This can be larger than the image width, if the screen is bigger than image. 273 GFX2_GLOBAL short Limit_visible_right_zoom; 274 275 /// Buffer of pixels, used when drawing something to screen. 276 GFX2_GLOBAL byte * Horizontal_line_buffer; 277 278 /// Current pixel ratio. Index in enum ::PIXEL_RATIO 279 GFX2_GLOBAL int Pixel_ratio; 280 /// Current width of pixels, according to ::Pixel_ratio 281 GFX2_GLOBAL int Pixel_width; 282 /// Current height of pixels, according to ::Pixel_ratio 283 GFX2_GLOBAL int Pixel_height; 284 285 286 /// Current image data 287 GFX2_GLOBAL T_Document Main; 288 289 /// Pointer to the pixel data of the main image 290 GFX2_GLOBAL byte * Main_screen; 291 /// Lookup table for XOR effects, pointing each color to the most different one 292 GFX2_GLOBAL byte xor_lut[256]; 293 294 /// Spare page data 295 GFX2_GLOBAL T_Document Spare; 296 297 // -- Image backups 298 299 /// Backup of the current screen, used during drawing when FX feedback is OFF. 300 GFX2_GLOBAL byte * Screen_backup; 301 302 // -- Palette load/Save selector 303 304 /// Fileselector settings 305 GFX2_GLOBAL T_Selector_settings Palette_selector; 306 307 // -- Brush data 308 309 /// Pixel data of the current brush (remapped). 310 GFX2_GLOBAL byte * Brush; 311 /// Pixel data of the current brush (before remap). 312 GFX2_GLOBAL byte * Brush_original_pixels; 313 /// Palette of the brush, from when it was grabbed. 314 GFX2_GLOBAL T_Palette Brush_original_palette; 315 /// Back_color used when the brush was grabbed 316 GFX2_GLOBAL byte Brush_original_back_color; 317 /// Color mapping from ::Brush_original_pixels to ::Brush 318 GFX2_GLOBAL byte Brush_colormap[256]; 319 /// X coordinate of the brush's "hot spot". It is < ::Brush_width 320 GFX2_GLOBAL word Brush_offset_X; 321 /// Y coordinate of the brush's "hot spot". It is < ::Brush_height 322 GFX2_GLOBAL word Brush_offset_Y; 323 /// Width of the current brush. 324 GFX2_GLOBAL word Brush_width; 325 /// Height of the current brush. 326 GFX2_GLOBAL word Brush_height; 327 /// Name of the directory that holds the brush fil (after loading or saving it). 328 GFX2_GLOBAL char * Brush_file_directory; 329 /// Filename (without directory) of the brush (after loading or saving it). 330 GFX2_GLOBAL char * Brush_filename; 331 /// Filename (without directory) of the brush (after loading or saving it) unicode. 332 GFX2_GLOBAL word * Brush_filename_unicode; 333 /// File format of the brush. It's a value of enum ::FILE_FORMATS 334 GFX2_GLOBAL byte Brush_fileformat; 335 /// Fileselector settings 336 GFX2_GLOBAL T_Selector_settings Brush_selector; 337 /// Indicator used for the "Rotate brush" operation. 338 GFX2_GLOBAL byte Brush_rotation_center_is_defined; 339 /// Position of the brush's rotation center, in screen coordinates. 340 GFX2_GLOBAL short Brush_rotation_center_X; 341 /// Position of the brush's rotation center, in screen coordinates. 342 GFX2_GLOBAL short Brush_rotation_center_Y; 343 344 // -- Menu data (toolbox) 345 346 /// Boolean, true if the menu has to be displayed. 347 GFX2_GLOBAL byte Menu_is_visible; 348 /// Height of the menu, when it's displayed 349 GFX2_GLOBAL word Menu_height; 350 /// 351 /// Y position (in screen coordinates) where the menu begins. 352 /// This is always either ::Screen_height (when menu is hidden) or (::Screen_height - ::Menu_height) 353 /// As a result, the drawing algoritm always draws the image from 0 to ::Menu_Y-1 354 GFX2_GLOBAL word Menu_Y; 355 /// Y position of the status bar (in screen coordinates) 356 GFX2_GLOBAL word Menu_status_Y; 357 /// Scaling factor for the menu and all GUI elements 358 GFX2_GLOBAL byte Menu_factor_X; 359 /// Scaling factor for the menu and all GUI elements 360 GFX2_GLOBAL byte Menu_factor_Y; 361 /// Size of a color cell in the menu's palette. 362 GFX2_GLOBAL word Menu_palette_cell_width; 363 364 // -- Window data 365 366 /// Number of stacked windows currently displayed. 0 when no window is present. 367 GFX2_GLOBAL byte Windows_open; 368 /// Backup of ::Menu_is_visible, used to store it while a window is open. 369 GFX2_GLOBAL byte Menu_is_visible_before_window; 370 /// Backup of ::Menu_Y, used to store it while a window is open. 371 GFX2_GLOBAL word Menu_Y_before_window; 372 /// Backup of ::Paintbrush_hidden, used to store it while a window is open. 373 GFX2_GLOBAL byte Paintbrush_hidden_before_window; 374 375 /// The global stack of editor screens. 376 GFX2_GLOBAL T_Window Window_stack[8]; 377 378 /// Position of the left border of the topmost window (in screen coordinates) 379 #define Window_pos_X Window_stack[Windows_open-1].Pos_X 380 381 /// Position of the top border of the topmost window (in screen coordinates) 382 #define Window_pos_Y Window_stack[Windows_open-1].Pos_Y 383 384 /// 385 /// Width of the topmost window, in "window pixels" 386 /// (multiply by ::Menu_factor_X to get screen pixels) 387 #define Window_width Window_stack[Windows_open-1].Width 388 389 /// 390 /// Height of the topmost window, in "window pixels" 391 /// (multiply by ::Menu_factor_Y to get screen pixels) 392 #define Window_height Window_stack[Windows_open-1].Height 393 394 /// Total number of buttons/controls in the topmost window. 395 #define Window_nb_buttons Window_stack[Windows_open-1].Nb_buttons 396 397 /// List of normal buttons in the topmost window. 398 #define Window_normal_button_list Window_stack[Windows_open-1].Normal_button_list 399 400 /// List of "palette" buttons in the topmost window. 401 #define Window_palette_button_list Window_stack[Windows_open-1].Palette_button_list 402 403 /// List of sliders (scrollers) in the topmost window. 404 #define Window_scroller_button_list Window_stack[Windows_open-1].Scroller_button_list 405 406 /// List of special buttons in the topmost window. 407 #define Window_special_button_list Window_stack[Windows_open-1].Special_button_list 408 409 /// List of dropdown buttons in the topmost window. 410 #define Window_dropdown_button_list Window_stack[Windows_open-1].Dropdown_button_list 411 412 /// List of list buttons in the topmost window. 413 #define Window_list_button_list Window_stack[Windows_open-1].List_button_list 414 415 /// 416 /// The function ::Window_clicked_button() set this to ::LEFT_SIDE or ::RIGHT_SIDE 417 /// after a button is activated through left or right mouse click. 418 #define Window_attribute1 Window_stack[Windows_open-1].Attribute1 419 420 /// 421 /// The function ::Window_clicked_button() set this to return extra information: 422 /// - When a scroller was clicked: the scroller position (0-n) 423 /// - When a palette was clicked: the color index (0-255) 424 /// - When a dropdown was used: the selected item's number T_Dropdown_choice::Number 425 #define Window_attribute2 Window_stack[Windows_open-1].Attribute2 426 427 #define Window_draggable Window_stack[Windows_open-1].Draggable 428 429 // -- Information about the different drawing modes (effects) 430 431 /// Current effecting function. When no effect is selected this is ::No_effect() 432 GFX2_GLOBAL Func_effect Effect_function; 433 434 /// 435 /// Array of booleans, indicates which colors should never be picked by 436 /// ::Best_color() 437 GFX2_GLOBAL byte Exclude_color[256]; 438 439 // -- Smear mode 440 441 /// Smear mode is activated 442 GFX2_GLOBAL byte Smear_mode; 443 /// Boolean, indicates that a smear is in progress. 444 GFX2_GLOBAL byte Smear_start; 445 /// Pointer to the sprite to use for smear; it contains pixels from the image. 446 GFX2_GLOBAL byte * Smear_brush; 447 /// Width of the ::Smear_brush 448 GFX2_GLOBAL word Smear_brush_width; 449 /// Height of the ::Smear_brush 450 GFX2_GLOBAL word Smear_brush_height; 451 /// Limits of the smear. 452 GFX2_GLOBAL short Smear_min_X; 453 /// Limits of the smear. 454 GFX2_GLOBAL short Smear_max_X; 455 /// Limits of the smear. 456 GFX2_GLOBAL short Smear_min_Y; 457 /// Limits of the smear. 458 GFX2_GLOBAL short Smear_max_Y; 459 460 // -- Shade mode 461 /// List of the shade tables 462 GFX2_GLOBAL T_Shade Shade_list[8]; 463 /// Shade currently selected (index in ::Shade_list) 464 GFX2_GLOBAL byte Shade_current; 465 /// Conversion table in use 466 GFX2_GLOBAL byte * Shade_table; 467 /// Conversion table for a left click 468 GFX2_GLOBAL byte Shade_table_left[256]; 469 /// Conversion table for a right click 470 GFX2_GLOBAL byte Shade_table_right[256]; 471 /// Boolean, true when the shade mode is active. 472 GFX2_GLOBAL byte Shade_mode; 473 474 /// Boolean, true when the quick-shade mode is active. 475 GFX2_GLOBAL byte Quick_shade_mode; 476 /// Size of the step, in Quick-shade mode. It's the number of colors to "jump". 477 GFX2_GLOBAL byte Quick_shade_step; 478 /// Determines how colors should loop in Quick-shade more. Value in enum ::SHADE_MODES 479 GFX2_GLOBAL byte Quick_shade_loop; 480 481 // -- Stencil mode 482 483 /// Boolean, true when stencil mode is active. 484 GFX2_GLOBAL byte Stencil_mode; 485 /// Array of the protected colors by Stencil mode. 486 GFX2_GLOBAL byte Stencil[256]; 487 488 // -- Grid mode 489 490 /// Boolean, true when the Grid mode is active. 491 GFX2_GLOBAL byte Snap_mode; 492 /// Boolean, true when the Grid is displayed in zoomed view. 493 GFX2_GLOBAL byte Show_grid; 494 /// Width of the grid in Grid mode. 495 GFX2_GLOBAL word Snap_width; 496 /// Height of the grid in Grid mode. 497 GFX2_GLOBAL word Snap_height; 498 /// Position of the starting pixel, in Grid mode. 499 GFX2_GLOBAL word Snap_offset_X; 500 /// Position of the starting pixel, in Grid mode. 501 GFX2_GLOBAL word Snap_offset_Y; 502 503 // -- Sieve mode 504 505 /// Boolean, true when the Sieve mode is active 506 GFX2_GLOBAL byte Sieve_mode; 507 /// Sprite of the sieve pattern. It's actually an array of booleans. 508 GFX2_GLOBAL byte Sieve[16][16]; 509 /// Width of the sieve pattern, in Sieve mode. 510 GFX2_GLOBAL short Sieve_width; 511 /// Height of the sieve pattern, in Sieve mode. 512 GFX2_GLOBAL short Sieve_height; 513 514 // -- Colorize mode 515 516 /// Boolean, true when the Colorize mode is active. 517 GFX2_GLOBAL byte Colorize_mode; 518 /// % of opacity of Colorize mode (for translucency) 519 GFX2_GLOBAL byte Colorize_opacity; 520 /// Sets the colorization mode: 0 transparency, 1 additive, 2 substractive 521 GFX2_GLOBAL byte Colorize_current_mode; 522 /// 523 /// Table of precomputed factors used by Colorize mode. It hold 0 to 255 when 524 /// opacity is 100%, 0 to 128 when opacity is 50%, etc. 525 // FIXME: This only caches a multiplication and a division. Maybe we should scrap it 526 GFX2_GLOBAL word Factors_table[256]; 527 /// 528 /// Table of precomputed factors used by Colorize mode. It hold 255 to 0 when 529 /// opacity is 100%, 128 to 0 when opacity is 50%, etc. 530 // FIXME: This only caches a multiplication, a division, a substraction. Maybe we should scrap it 531 GFX2_GLOBAL word Factors_inv_table[256]; 532 533 // -- Smooth mode 534 535 /// Boolean, true when the Smooth mode is active 536 GFX2_GLOBAL byte Smooth_mode; 537 /// Matrix of "weights" used by the Smooth mode. 538 GFX2_GLOBAL byte Smooth_matrix[3][3]; 539 540 // -- Tiling mode 541 542 /// Boolean, true when the Tiling mode is active 543 GFX2_GLOBAL byte Tiling_mode; 544 /// Position of the starting pixel in Tiling mode. 545 GFX2_GLOBAL short Tiling_offset_X; 546 /// Position of the starting pixel in Tiling mode. 547 GFX2_GLOBAL short Tiling_offset_Y; 548 549 // -- Mask mode 550 551 /// Boolean, true when the Tiling mode is active 552 GFX2_GLOBAL byte Mask_mode; 553 /// Array of booleans. True if the indexed color is protected by the mask. 554 GFX2_GLOBAL byte Mask_table[256]; 555 556 // -- 8 bit constraints mode 557 558 /// Selected constraint mode 559 GFX2_GLOBAL enum IMAGE_MODES Selected_Constraint_Mode; 560 561 562 // -- Magnifier data 563 564 #ifdef GLOBAL_VARIABLES 565 const byte ZOOM_FACTOR[NB_ZOOM_FACTORS]={2,3,4,5,6,8,10,12,14,16,18,20, 24, 28, 32}; 566 #else 567 /// Successive zoom factors, used by the Magnifier. 568 extern const byte ZOOM_FACTOR[NB_ZOOM_FACTORS]; 569 #endif 570 571 // -- Data for gradients 572 573 /// First color of the gradient. 574 GFX2_GLOBAL short Gradient_lower_bound; 575 /// Last color of the gradient 576 GFX2_GLOBAL short Gradient_upper_bound; 577 /// Boolean, true if the gradient should use colors in descending order 578 GFX2_GLOBAL int Gradient_is_inverted; 579 /// Number of colors in the range ::Gradient_lower_bound to ::Gradient_upper_bound (included) 580 GFX2_GLOBAL long Gradient_bounds_range; 581 /// Maximum value passed to the gradient function. The pixels assigned this value should use last gradient color. 582 GFX2_GLOBAL long Gradient_total_range; 583 /// Amount of randomness to use in gradient (1-256+) 584 GFX2_GLOBAL long Gradient_random_factor; 585 /// Gradient speed of cycling (0-64) 586 GFX2_GLOBAL byte Gradient_speed; 587 /// Pointer to a gradient function, depending on the selected method. 588 GFX2_GLOBAL Func_gradient Gradient_function; 589 /// 590 /// Pointer to the pixel-drawing function that gradients should use: 591 /// either ::Pixel (if the gradient must be drawn on menus only) 592 /// or ::Display_pixel (if the gradient must be drawn on the image) 593 GFX2_GLOBAL Func_pixel Gradient_pixel; 594 /// Index in ::T_Page::Gradients of the currently selected gradient. 595 GFX2_GLOBAL byte Current_gradient; 596 /// Boolean, true when the color cycling is active. 597 GFX2_GLOBAL byte Cycling_mode; 598 599 // -- Airbrush data 600 601 /// Mode to use in airbrush: 0 for multicolor, 1 for mono. 602 GFX2_GLOBAL byte Airbrush_mode; 603 /// Diameter of the airbrush, in pixels. 604 GFX2_GLOBAL short Airbrush_size; 605 /// Delay between two airbrush "shots", in 1/100s 606 GFX2_GLOBAL byte Airbrush_delay; 607 /// Number of pixels that are emitted by the airbrush, in mono mode. 608 GFX2_GLOBAL byte Airbrush_mono_flow; 609 /// Number of pixels that are emitted by the airbrush for each color (multi mode) 610 GFX2_GLOBAL byte Airbrush_multi_flow[256]; 611 612 /// -- Misc data about the program 613 614 /// Boolean, set to true to exit the program. 615 GFX2_GLOBAL byte Quitting; 616 /// Name of the directory that was current when the program was run. 617 GFX2_GLOBAL char * Initial_directory; 618 /// Name of the directory that holds the program's (read-only) data: skins, icon, etc. 619 GFX2_GLOBAL char * Data_directory; 620 /// Name of the directory where grafx2 reads and writes configuration (gfx2.ini, gfx2.cfg) 621 GFX2_GLOBAL char * Config_directory; 622 /// Current foreground color for drawing. 623 GFX2_GLOBAL byte Fore_color; 624 /// Current background color for drawing. 625 GFX2_GLOBAL byte Back_color; 626 /// For the "Freehand draw" tool, this determines which variant is selected, from ::OPERATION_CONTINUOUS_DRAW to ::OPERATION_FILLED_CONTOUR 627 GFX2_GLOBAL byte Selected_freehand_mode; 628 /// For the Curve tool, this determines which variant is selected, either ::OPERATION_3_POINTS_CURVE or ::OPERATION_4_POINTS_CURVE 629 GFX2_GLOBAL byte Selected_curve_mode; 630 /// For the Line tool, this determines which variant is selected, either ::OPERATION_LINE, ::OPERATION_K_LINE or ::OPERATION_CENTERED_LINES 631 GFX2_GLOBAL byte Selected_line_mode; 632 /// Select which kind of Circle/ellipse mode is selected from 0 to 3 : CIRCLE_CTR/CIRCLE_CRN/ELLIPSE_CTR/ELLIPSE_CRN 633 GFX2_GLOBAL byte Selected_circle_ellipse_mode; 634 /// Determines which color appears in the first cell of the menu palette. Change this value to "scroll" the palette. 635 GFX2_GLOBAL byte First_color_in_palette; 636 /// Boolean, true if Grafx2 was run with a command-line argument to set a resolution on startup (overrides config) 637 GFX2_GLOBAL byte Resolution_in_command_line; 638 639 // - Graphic 640 641 /// Pointer to the font selected for menus. 642 GFX2_GLOBAL byte * Menu_font; 643 644 /// additional fonts for unicode characters 645 GFX2_GLOBAL T_Unicode_Font * Unicode_fonts; 646 647 /// Pointer to the current active skin. 648 GFX2_GLOBAL T_Gui_skin * Gfx; 649 650 /// Pointer to the current active skin. 651 GFX2_GLOBAL T_Paintbrush Paintbrush[NB_PAINTBRUSH_SPRITES]; 652 653 // -- Help data 654 655 /// Index of the ::Help_section shown by the Help screen. 656 GFX2_GLOBAL byte Current_help_section; 657 /// Line number of the help viewer, in current ::Help_section. 0 for top, increase value to scroll down. 658 GFX2_GLOBAL word Help_position; 659 660 // -- Operation data 661 662 /// Index of the operation which was selected (ex: drawing rectangle) before the current interruption (ex: colorpicking). 663 GFX2_GLOBAL word Operation_before_interrupt; 664 /// Index of the current operation. This is the active "tool". 665 GFX2_GLOBAL word Current_operation; 666 /// 667 /// This stack is used to memorize all parameters needed during the course of 668 /// an operation. For example when drawing a rectangle: color, starting 669 /// coordinates, ending coordinates. 670 GFX2_GLOBAL word Operation_stack[OPERATION_STACK_SIZE]; 671 /// Number of parameters stored in ::Operation_stack (0=empty) 672 GFX2_GLOBAL byte Operation_stack_size; 673 /// Boolean, true if the operation (drawing) started in the magnified area. 674 GFX2_GLOBAL byte Operation_in_magnifier; 675 /// Last color hovered by the colorpicker. -1 if it wasn't over the image. 676 GFX2_GLOBAL short Colorpicker_color; 677 /// Position of the colorpicker tool, in image coordinates. 678 GFX2_GLOBAL short Colorpicker_X; 679 /// Position of the colorpicker tool, in image coordinates. 680 GFX2_GLOBAL short Colorpicker_Y; 681 682 GFX2_GLOBAL short * Polyfill_table_of_points; 683 GFX2_GLOBAL int Polyfill_number_of_points; 684 685 /// Brush container 686 GFX2_GLOBAL T_Brush_template Brush_container[BRUSH_CONTAINER_COLUMNS*BRUSH_CONTAINER_ROWS]; 687 688 #ifdef GLOBAL_VARIABLES 689 const byte CURSOR_FOR_OPERATION[NB_OPERATIONS]= 690 { 691 CURSOR_SHAPE_TARGET , // Freehand continuous draw 692 CURSOR_SHAPE_TARGET , // Freehand discontinuous draw 693 CURSOR_SHAPE_TARGET , // Freehand point-by-point draw 694 CURSOR_SHAPE_TARGET , // Filled contour 695 CURSOR_SHAPE_TARGET , // Lines 696 CURSOR_SHAPE_TARGET , // Linked lines 697 CURSOR_SHAPE_TARGET , // Centered lines 698 CURSOR_SHAPE_XOR_TARGET , // Empty rectangle 699 CURSOR_SHAPE_XOR_TARGET , // Filled rectangle 700 CURSOR_SHAPE_XOR_TARGET , // Empty circle (center radius) 701 CURSOR_SHAPE_XOR_TARGET , // Empty circle (corners) 702 CURSOR_SHAPE_XOR_TARGET , // Empty ellipse (center radius) 703 CURSOR_SHAPE_XOR_TARGET , // Empty ellipse (corners) 704 CURSOR_SHAPE_XOR_TARGET , // Filled circle (center radius) 705 CURSOR_SHAPE_XOR_TARGET , // Filled circle (corners) 706 CURSOR_SHAPE_XOR_TARGET , // Filled ellipse (center radius) 707 CURSOR_SHAPE_XOR_TARGET , // Filled ellipse (corners) 708 CURSOR_SHAPE_BUCKET , // Fill 709 CURSOR_SHAPE_BUCKET , // Color replacer 710 CURSOR_SHAPE_XOR_TARGET , // Rectangular brush grabbing 711 CURSOR_SHAPE_TARGET , // Polygonal brush grabbing 712 CURSOR_SHAPE_COLORPICKER , // Colorpicker 713 CURSOR_SHAPE_XOR_RECTANGLE , // Position the magnify window 714 CURSOR_SHAPE_TARGET , // Curve with 3 control points 715 CURSOR_SHAPE_TARGET , // Curve with 4 control points 716 CURSOR_SHAPE_TARGET , // Airbrush 717 CURSOR_SHAPE_TARGET , // Polygon 718 CURSOR_SHAPE_TARGET , // Polyform 719 CURSOR_SHAPE_TARGET , // Filled polygon 720 CURSOR_SHAPE_TARGET , // Filled polyform 721 CURSOR_SHAPE_MULTIDIRECTIONAL , // Scroll image 722 CURSOR_SHAPE_XOR_TARGET , // Gradient-filled circle (center radius) 723 CURSOR_SHAPE_XOR_TARGET , // Gradient-filled circle (corners) 724 CURSOR_SHAPE_XOR_TARGET , // Gradient-filled ellipse (center radius) 725 CURSOR_SHAPE_XOR_TARGET , // Gradient-filled ellipse (corners) 726 CURSOR_SHAPE_XOR_ROTATION , // Rotate brush 727 CURSOR_SHAPE_XOR_TARGET , // Stretch brush 728 CURSOR_SHAPE_TARGET , // Distort brush 729 CURSOR_SHAPE_XOR_TARGET , // Gradient-filled rectangle 730 CURSOR_SHAPE_COLORPICKER , // Colorpick on right mouse button 731 CURSOR_SHAPE_MULTIDIRECTIONAL , // Pan view 732 }; 733 #else 734 /// ::Cursor_shape to use for each operation. 735 extern const byte CURSOR_FOR_OPERATION[NB_OPERATIONS]; 736 #endif 737 738 /// 739 /// Procedures to call for each state (determined by ::Operation_stack_size) of 740 /// each operation, and for each mouse state (no button,left button,right button) 741 GFX2_GLOBAL struct 742 { 743 Func_action Action; ///< Function to call 744 byte Hide_cursor; ///< Boolean: Need to hide/unhide cursor during this step 745 byte Fast_mouse; ///< Operation should take shortcuts with mouse movements 746 } Operation[NB_OPERATIONS][3][OPERATION_STACK_SIZE]; 747 748 // -- misc 749 750 /// 751 /// Indicator of error in previous file operations. 752 /// - 0: OK 753 /// - 1: Error when beginning operation. Existing data should be ok. 754 /// - 2: Error while operation was in progress. Data is modified. 755 /// - -1: Interruption of a preview. 756 GFX2_GLOBAL signed char File_error; 757 /// Current line number when reading/writing gfx2.ini 758 GFX2_GLOBAL int Line_number_in_INI_file; 759 760 /// Set to true when the .cfg and .ini files are along the executable 761 GFX2_GLOBAL byte Portable_Installation_Detected; 762 763 // -- For iconv 764 765 #ifdef ENABLE_FILENAMES_ICONV 766 767 #include <iconv.h> 768 769 #define TOCODE "CP1252" 770 #ifdef __macosx__ 771 #define FROMCODE "UTF-8-MAC" 772 #else 773 #define FROMCODE "UTF-8" 774 #endif 775 GFX2_GLOBAL iconv_t cd; // FROMCODE => TOCODE 776 GFX2_GLOBAL iconv_t cd_inv; // TOCODE => FROMCODE 777 GFX2_GLOBAL iconv_t cd_utf16; // FROMCODE => UTF16 778 GFX2_GLOBAL iconv_t cd_utf16_inv; // UTF16 => FROMCODE 779 #endif /* ENABLE_FILENAMES_ICONV */ 780 781 #endif 782