1 /* mainwindow.h 2 Copyright (C) 2004-2021 Mark Tyler and Dmitry Groshev 3 4 This file is part of mtPaint. 5 6 mtPaint is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3 of the License, or 9 (at your option) any later version. 10 11 mtPaint is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with mtPaint in the file COPYING. 18 */ 19 20 21 /* Keyboard action codes */ 22 #define ACTMOD_DUMMY -1 /* Means action is done already */ 23 enum { // To let constants renumber themselves when adding new ones 24 ACT_QUIT = 1, 25 ACT_ZOOM, 26 ACT_VIEW, 27 ACT_PAN, 28 ACT_CROP, 29 ACT_SWAP_AB, 30 ACT_TOOL, 31 ACT_SEL_MOVE, 32 ACT_OPAC, 33 ACT_LR_MOVE, 34 ACT_ESC, 35 ACT_COMMIT, 36 ACT_RCLICK, 37 ACT_ARROW, 38 ACT_A, 39 ACT_B, 40 ACT_CHANNEL, 41 ACT_VWZOOM, 42 ACT_SAVE, 43 ACT_FACTION, 44 ACT_LOAD_RECENT, 45 ACT_DO_UNDO, 46 ACT_COPY, 47 ACT_PASTE, 48 ACT_COPY_PAL, 49 ACT_PASTE_PAL, 50 ACT_LOAD_CLIP, 51 ACT_SAVE_CLIP, 52 ACT_TBAR, 53 ACT_DOCK, 54 ACT_CENTER, 55 ACT_GRID, 56 ACT_SNAP, 57 ACT_VWWIN, 58 ACT_VWSPLIT, 59 ACT_VWFOCUS, 60 ACT_FLIP_V, 61 ACT_FLIP_H, 62 ACT_ROTATE, 63 ACT_SELECT, 64 ACT_LASSO, 65 ACT_OUTLINE, 66 ACT_ELLIPSE, 67 ACT_SEL_FLIP_V, 68 ACT_SEL_FLIP_H, 69 ACT_SEL_ROT, 70 ACT_RAMP, 71 ACT_SEL_ALPHA_AB, 72 ACT_SEL_ALPHAMASK, 73 ACT_SEL_MASK_AB, 74 ACT_SEL_MASK, 75 ACT_PAL_DEF, 76 ACT_PAL_MASK, 77 ACT_DITHER_A, 78 ACT_PAL_MERGE, 79 ACT_PAL_CLEAN, 80 ACT_ISOMETRY, 81 ACT_CHN_DIS, 82 ACT_SET_RGBA, 83 ACT_SET_OVERLAY, 84 ACT_LR_SAVE, 85 ACT_LR_ADD, 86 ACT_LR_DEL, 87 ACT_DOCS, 88 ACT_REBIND_KEYS, 89 ACT_MODE, 90 ACT_LR_SHIFT, 91 ACT_LR_CENTER, 92 ACT_SCRIPT, 93 ACT_RUN_SCRIPT, 94 ACT_SIZE, 95 ACT_PAT, 96 97 DLG_BRCOSA, 98 DLG_CHOOSER, 99 DLG_SCALE, 100 DLG_SIZE, 101 DLG_NEW, 102 DLG_FSEL, 103 DLG_FACTIONS, 104 DLG_TEXT, 105 DLG_TEXT_FT, 106 DLG_LAYERS, 107 DLG_INDEXED, 108 DLG_ROTATE, 109 DLG_INFO, 110 DLG_PREFS, 111 DLG_COLORS, 112 DLG_PAL_SIZE, 113 DLG_PAL_SORT, 114 DLG_PAL_SHIFTER, 115 DLG_FILTER, 116 DLG_CHN_DEL, 117 DLG_ANI, 118 DLG_ANI_VIEW, 119 DLG_ANI_KEY, 120 DLG_ANI_KILLKEY, 121 DLG_ABOUT, 122 DLG_SKEW, 123 DLG_FLOOD, 124 DLG_SMUDGE, 125 DLG_CLONE, 126 DLG_GRAD, 127 DLG_STEP, 128 DLG_FILT, 129 DLG_TRACE, 130 DLG_PICK_GRAD, 131 DLG_SEGMENT, 132 DLG_SCRIPT, 133 DLG_LASSO, 134 DLG_KEYS, 135 DLG_XHOLD, 136 DLG_NOISE, 137 138 FILT_2RGB, 139 FILT_INVERT, 140 FILT_GREY, 141 FILT_EDGE, 142 FILT_DOG, 143 FILT_SHARPEN, 144 FILT_UNSHARP, 145 FILT_SOFTEN, 146 FILT_GAUSS, 147 FILT_FX, 148 FILT_BACT, 149 FILT_THRES, 150 FILT_UALPHA, 151 FILT_KUWAHARA, 152 FILT_NORM, 153 FILT_MAP, 154 155 ACT_TEST /* Reserved for testing things */ 156 }; 157 158 // New layer sources for ACT_LR_ADD 159 #define LR_NEW 0 160 #define LR_DUP 1 161 #define LR_PASTE 2 162 #define LR_COMP 3 163 164 int key_action(key_ext *key, int toggle); 165 #define wtf_pressed(X) key_action((X), FALSE) 166 void action_dispatch(int action, int mode, int state, int kbd); 167 168 /* Widget dependence flags */ 169 #define NEED_UNDO 0x0001 170 #define NEED_REDO 0x0002 171 #define NEED_CROP 0x0004 172 #define NEED_MARQ 0x0008 173 #define NEED_SEL 0x0010 174 #define NEED_CLIP 0x0020 175 #define NEED_24 0x0040 176 #define NEED_NOIDX 0x0080 177 #define NEED_IDX 0x0100 178 #define NEED_LASSO 0x0200 179 #define NEED_ACLIP 0x0400 180 #define NEED_CHAN 0x0800 181 #define NEED_RGBA 0x1000 182 #define NEED_PCLIP 0x2000 183 #define NEED_SKIP 0x4000 /* Never activated at all */ 184 #define NEED_SEL2 (NEED_SEL | NEED_LASSO) 185 #define NEED_PSEL (NEED_MARQ | NEED_PCLIP) 186 #define NEED_LAS2 (NEED_LASSO | NEED_PCLIP) 187 188 /* Notable menu items */ 189 enum { 190 MENU_FACTION1 = 1, 191 MENU_FACTION2, 192 MENU_FACTION3, 193 MENU_FACTION4, 194 MENU_FACTION5, 195 MENU_FACTION6, 196 MENU_FACTION7, 197 MENU_FACTION8, 198 MENU_FACTION9, 199 MENU_FACTION10, 200 MENU_FACTION11, 201 MENU_FACTION12, 202 MENU_FACTION13, 203 MENU_FACTION14, 204 MENU_FACTION15, 205 MENU_FACTION_S, 206 MENU_RECENT_S, 207 MENU_RECENT1, 208 MENU_RECENT2, 209 MENU_RECENT3, 210 MENU_RECENT4, 211 MENU_RECENT5, 212 MENU_RECENT6, 213 MENU_RECENT7, 214 MENU_RECENT8, 215 MENU_RECENT9, 216 MENU_RECENT10, 217 MENU_RECENT11, 218 MENU_RECENT12, 219 MENU_RECENT13, 220 MENU_RECENT14, 221 MENU_RECENT15, 222 MENU_RECENT16, 223 MENU_RECENT17, 224 MENU_RECENT18, 225 MENU_RECENT19, 226 MENU_RECENT20, 227 MENU_SCRIPT, 228 MENU_SCRIPT_M, 229 MENU_SCRIPT1, 230 MENU_SCRIPT2, 231 MENU_SCRIPT3, 232 MENU_SCRIPT4, 233 MENU_SCRIPT5, 234 MENU_SCRIPT6, 235 MENU_SCRIPT7, 236 MENU_SCRIPT8, 237 MENU_SCRIPT9, 238 MENU_SCRIPT10, 239 MENU_SCRIPTC, 240 MENU_TBSET, 241 MENU_VIEW, 242 MENU_LAYER, 243 MENU_PREFS, 244 MENU_CHAN0, 245 MENU_CHAN1, 246 MENU_CHAN2, 247 MENU_CHAN3, 248 MENU_DCHAN0, 249 MENU_DCHAN1, 250 MENU_DCHAN2, 251 MENU_DCHAN3, 252 MENU_OALPHA, 253 MENU_HELP, 254 MENU_DOCK, 255 256 TOTAL_MENU_IDS 257 }; 258 259 /// TRACING IMAGE 260 261 unsigned char *bkg_rgb; 262 int bkg_x, bkg_y, bkg_w, bkg_h, bkg_scale, bkg_flag; 263 264 int config_bkg(int src); // 0 = unchanged, 1 = none, 2 = image, 3 = clipboard 265 266 /// GRID 267 268 /* !!! Indices 0-2 are hardcoded in draw_grid() */ 269 #define GRID_NORMAL 0 /* Normal/image grid */ 270 #define GRID_BORDER 1 271 #define GRID_TRANS 2 /* For transparency */ 272 #define GRID_TILE 3 273 #define GRID_SEGMENT 4 274 275 #define GRID_MAX 5 276 277 int grid_rgb[GRID_MAX]; // Grid colors to use 278 int mem_show_grid; // Boolean show toggle 279 int mem_grid_min; // Minimum zoom to show it at 280 int color_grid; // If to use grid coloring 281 int show_tile_grid; // Tile grid toggle 282 int tgrid_x0, tgrid_y0; // Tile grid origin 283 int tgrid_dx, tgrid_dy; // Tile grid spacing 284 int tgrid_snap; // Coordinates snap toggle 285 286 /* Snap coordinate pair to tile grid (floored) */ 287 void snap_xy(int *xy); 288 289 const unsigned char greyz[2]; // For opacity squares 290 291 292 char *channames[NUM_CHANNELS + 1], *allchannames[NUM_CHANNELS + 1]; 293 char *cspnames[NUM_CSPACES]; 294 295 char *channames_[NUM_CHANNELS + 1]; 296 char *cspnames_[NUM_CSPACES]; 297 298 void **main_window_, **main_keys, **settings_dock, **layers_dock, **main_split, 299 **drawing_canvas, **scrolledwindow_canvas, 300 **menu_slots[TOTAL_MENU_IDS]; 301 302 int view_image_only, viewer_mode, drag_index, q_quit, cursor_tool; 303 int show_menu_icons, paste_commit, scroll_zoom, arrow_scroll; 304 int drag_index_vals[2], cursor_corner, use_gamma, view_vsplit; 305 int files_passed, cmd_mode, tablet_working; 306 char **file_args, **script_cmds; 307 #define FILES_MAX (1024 * 1024) /* A million+ files should be enough */ 308 309 int perim_wx, perim_wy; // Cursor position 310 311 extern char mem_clip_file[]; 312 313 extern void *scriptbar_code[]; // Set up scriptable items for tools toolbar 314 315 int kpix_threads; // Min kpixels per render thread 316 317 /* With 2 cores and uniform layers stack, no noticeable difference between 318 * 1, 4 and 8 strips per thread; time jitter of about 10% is common, and spikes 319 * of about 40% sometimes happen; with 1 strip, even 50% was observed once. 320 * Still, with nonuniform layers, more strips can maybe balance better - WJ */ 321 #define MAX_TH_STRIPS 8 322 323 void var_init(); // Load INI variables 324 void string_init(); // Translate static strings 325 void main_init(); // Initialise and display the main window 326 327 char **wj_parse_argv(char *src); // Parse string into commands 328 int run_script(char **res); // Interpret parsed sequence of commands 329 330 void draw_dash(int c0, int c1, int ofs, int x, int y, int w, int h, rgbcontext *ctx); 331 void draw_poly(int *xy, int cnt, int shift, int x00, int y00, rgbcontext *ctx); 332 333 void canvas_size(int *w, int *h); // Get zoomed canvas size 334 void prepare_line_clip(int *lxy, int *vxy, int scale); // Map clipping rectangle to line-space 335 void main_update_area(int x, int y, int w, int h); // Update x,y,w,h area of current image 336 void repaint_canvas( int px, int py, int pw, int ph ); // Redraw area of canvas 337 void grad_stroke(int x, int y); // Update stroke gradient 338 339 int async_bk; 340 341 typedef struct { 342 int dx; 343 int width; 344 int xwid; 345 int zoom; 346 int scale; 347 int mw; 348 int opac; 349 int xpm; 350 int bpp; 351 int cmask; 352 png_color *pal; 353 } renderstate; 354 355 void setup_row(renderstate *r, int x0, int width, int zoom, int scale, int mw, 356 int xpm, int opac, int bpp, png_color *pal); 357 void render_row(renderstate *r, unsigned char *rgb, chanlist base_img, 358 int x, int y, chanlist xtra_img); 359 360 void stop_line(); 361 void change_to_tool(int icon); 362 363 void spot_undo(int mode); // Take snapshot for undo 364 void set_cursor(void **what); // Set mouse cursor 365 int check_for_changes(); // 1=STOP, 2=IGNORE, 10=ESCAPE, -10=NOT CHECKED 366 367 // Try to save file + warn if error + return < 0 if fail 368 int gui_save(char *filename, ls_settings *settings); 369 370 // Load system clipboard like a file, return TRUE if successful 371 int import_clipboard(int mode); 372 373 void pressed_select(int all); 374 void pressed_opacity(int opacity); 375 376 int check_zoom_keys(int act_m); 377 int check_zoom_keys_real(int act_m); 378 379 void setup_language(); // Change language 380 381 // Image/palette has just changed - update vars as needed 382 void notify_changed(); 383 // Image has just been unchanged: saved to file, or loaded if "filename" is NULL 384 void notify_unchanged(char *filename); 385 void update_titlebar(); // Update filename in titlebar 386 387 void force_main_configure(); // Force reconfigure of main drawing area - for centralizing code 388 389 390 void set_image(int state); // Toggle image access (nestable) 391 392 int dock_focused(); // Check if focus is inside dock window 393