├── README.md └── Round Corner Customization.jsx /README.md: -------------------------------------------------------------------------------- 1 | # Round Corners Customization Script for Adobe Illustrator 2 | 3 | The script changes rude default rounding of corners — by simply inserting fragments of circles — to a smooth one without sharp jumps in curvature. What's wrong with the standard rounding and much more about the script is explained in detail [in the article](https://medium.com/@kefiijrw/smooth-corner-rounding-in-adobe-illustrator-94003145a7bf). 4 | 5 | ![slide_1-copy-------](https://user-images.githubusercontent.com/8041203/194974425-19fcffdd-2125-452f-9ce7-a5fa4c431016.gif) 6 | 7 | 8 | 9 | ## Script features 10 | 11 | — Displaying the corner curvature profile (can be disabled) for a better understanding of its shape: 12 | 13 | ![2000 copy](https://user-images.githubusercontent.com/8041203/194973297-a08809bd-ad28-43dd-889d-b8a290c8583c.gif) 14 | 15 | — Saving preferred parameters to presets: 16 | 17 | ![2021-09-19 06 31 36](https://user-images.githubusercontent.com/8041203/194973001-5afc521f-4249-46e7-8549-996e7be089de.gif) 18 | 19 | — Silent startup without a settings window to speed up work. **To bring back the options panel display, run the script with the *Shift key* pressed.** 20 | 21 | 22 | ## How to use 23 | 24 | The script does not round corners by itself, but modifies already rounded corners. It modifies all corners that are selected when you run the script. 25 | 26 | The script can process all corners of an object at once: 27 | 28 | ![2021-09-19 04 08 43](https://user-images.githubusercontent.com/8041203/194973053-616efb4a-6d46-48e6-aafc-6c01bba0b25b.gif) 29 | 30 | 31 | Or just the selected corners: 32 | 33 | ![2021-09-19 04 14 25](https://user-images.githubusercontent.com/8041203/194973026-e81900e9-0bf6-4edd-aca7-3310929afa7f.gif) 34 | 35 | 36 | Or even many objects at once: 37 | 38 | ![2021-09-19 03 49 35](https://user-images.githubusercontent.com/8041203/194972959-0f1f1fa2-bd03-479b-84a9-173d6179a123.gif) 39 | 40 | 41 | A cheat sheet on how coefficients affect the rounding nature: 42 | 43 | ![Artboard 2 copy](https://user-images.githubusercontent.com/8041203/194977549-5376af60-ca9c-43b3-87ea-1f95559773a8.png) 44 | -------------------------------------------------------------------------------- /Round Corner Customization.jsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Round Corners Customization v.0.1.4 3 | * https://github.com/kefiijrw/Round-Corners-Customization-for-Illustrator 4 | * 5 | * Author: Sergey Nikolaev 6 | * kefiijrw.com 7 | * 8 | * Date: 2024-06-12 9 | * 10 | * 11 | * CHANGELOG: 12 | * 13 | * v.0.0.1 14 | * Initial release 15 | * 16 | * v.0.0.2 17 | * Added a warning when trying to run the script on points without rounding. 18 | * 19 | * Now if a point has handles in both directions, and only one of them is 20 | * directed to the other selected point, then only this handle will move. 21 | * 22 | * v.0.0.3 23 | * Fixed a bug that removed the opposite to the corner handle. 24 | * 25 | * v.0.0.4 26 | * Option to hide the curvature profile is now avaible in the interface. 27 | * The language of the settings panel adjusts to the Illustrator locale. 28 | * 29 | * v.0.1.0 30 | * Public release 31 | * The script file and the settings window title now have a more specific name. 32 | * 33 | * v.0.1.1 34 | * Isolation mode support 35 | * 36 | * v.0.1.2 37 | * Symbol editing mode support 38 | * 39 | * v.0.1.3 40 | * Fixed Illustrator crashing when script runned with the "Show curvature profile" option disabled 41 | * 42 | * v.0.1.4 43 | * Fixed script encoding problem 44 | * 45 | */ 46 | 47 | //show the settings panel on startup 48 | var ui = true; 49 | 50 | //show the curvature profile 51 | var show_profile = true; 52 | 53 | //curvature profile color 54 | var curviture_color = newCMYKColor(0, 35, 60, 0); 55 | 56 | //do we write in the log file 57 | var debug_mode = false; 58 | 59 | //max value of the first coefficient on the slider 60 | var max_coef1 = 3; 61 | 62 | //max value of the second coefficient on the slider 63 | var max_coef2 = 1; 64 | 65 | //script was run with the shift key pressed 66 | var shifted = false; 67 | 68 | 69 | 70 | //Working with current documents 71 | var doc = app.activeDocument; 72 | 73 | var i, p, dxl, dxr, dyl, dyr; 74 | 75 | var coefs = []; 76 | 77 | var coef1; //point offset 78 | var coef2; //handle offset 79 | var tmp_layer; 80 | 81 | var selectedPointsSaved = []; 82 | 83 | //a global flag that remembers if there is something suitable for the script among the selected points 84 | var points_to_move = false; 85 | 86 | 87 | 88 | /* 89 | 90 | 91 | 92 | SOME HELPING FUNTIONS 93 | 94 | 95 | 96 | */ 97 | 98 | 99 | // color creation 100 | function newCMYKColor(c, m, y, k) { 101 | var col = new CMYKColor(); 102 | col.cyan = c; 103 | col.magenta = m; 104 | col.yellow = y; 105 | col.black = k; 106 | return col; 107 | } 108 | 109 | 110 | //write a line in the log file (sorry, bad habit) 111 | function echo(what) { 112 | if (debug_mode) 113 | log_file.write(what + '\n'); 114 | } 115 | 116 | 117 | // rounding values of coefficients to .000 to show in inputs 118 | function roundOff(x) { 119 | 120 | var place = 1000; 121 | x = Math.round(x * place); 122 | x /= place; 123 | 124 | return x; 125 | } 126 | 127 | 128 | // return the line in the right language, depending on the illustrator's locale 129 | function loc(vars) { 130 | if (app.locale.indexOf('ru_') == 0) 131 | return vars.ru; 132 | else 133 | return vars.en; 134 | } 135 | 136 | 137 | 138 | 139 | 140 | 141 | /* 142 | 143 | CONFIG OPERATION FUNCTIONS 144 | 145 | */ 146 | 147 | 148 | 149 | // Read presets from illustrator settings 150 | function init_configs() { 151 | echo('init_configs'); 152 | 153 | //flag in the illustrator settings saying that the script has already been run before 154 | var was = app.preferences.getIntegerPreference('corner_smoothing_script_first_launch_already_was'); 155 | 156 | if (was != 6) { //very dumb, sorry. it didn't work to save boolean so 6 is true and 2 is false 157 | 158 | //first launch 159 | echo('first_launch!'); 160 | 161 | //default presets 162 | coefs = [ 163 | { 164 | "name": "Default", 165 | "coef1": 0.702, 166 | "coef2": 0.111 167 | }, 168 | { 169 | "name": "big", 170 | "coef1": 0.494, 171 | "coef2": 0.171 172 | }, 173 | { 174 | "name": "ellipsoid", 175 | "coef1": 0.682, 176 | "coef2": 0.365 177 | } 178 | ]; 179 | 180 | coef1 = coefs[0].coef1; //point 181 | coef2 = coefs[0].coef2; //handle 182 | 183 | //save these values in illustrator settings 184 | from_vars_to_prefs(); 185 | 186 | //remember that first launch was 187 | app.preferences.setIntegerPreference('corner_smoothing_script_first_launch_already_was', 6); 188 | 189 | 190 | } else { 191 | 192 | echo('not first launch'); 193 | 194 | //not first launch 195 | //read script settings from illustrator settings 196 | from_prefs_to_vars(); 197 | 198 | } 199 | 200 | } 201 | 202 | // saving current state (coefficients, presets, checkboxes) to the illustrator settings, so they can be recovered again after restarting the illustrator 203 | 204 | function from_vars_to_prefs() { 205 | 206 | echo('from_vars_to_prefs '); 207 | 208 | for (var i = 0; i < coefs.length; i++) { 209 | echo('set config ' + i + ': ' + coefs[i].name + ', ' + coefs[i].coef1 + ', ' + coefs[i].coef2); 210 | app.preferences.setStringPreference('corner_smoothing_script_config_' + i + '_name', coefs[i].name); 211 | app.preferences.setRealPreference('corner_smoothing_script_config_' + i + '_coef1', coefs[i].coef1); 212 | app.preferences.setRealPreference('corner_smoothing_script_config_' + i + '_coef2', coefs[i].coef2); 213 | } 214 | 215 | echo('set congifs_count to ' + coefs.length); 216 | app.preferences.setIntegerPreference("corner_smoothing_script_saved_congifs_count", coefs.length); 217 | 218 | echo('set current coefs to ' + coef1 + ', ' + coef2); 219 | 220 | app.preferences.setRealPreference('corner_smoothing_script_current_coef1', coef1); 221 | app.preferences.setRealPreference('corner_smoothing_script_current_coef2', coef2); 222 | 223 | 224 | var uii = ui ? 6 : 2; 225 | echo('set ui to ' + uii); 226 | app.preferences.setIntegerPreference('corner_smoothing_script_show_ui', uii); 227 | 228 | var prof = show_profile ? 6 : 2; 229 | echo('set show_profile to ' + prof); 230 | app.preferences.setIntegerPreference('corner_smoothing_script_show_profile', prof); 231 | 232 | 233 | 234 | } 235 | 236 | 237 | //opposite, restoring the state of the script from the saved illustrator settings 238 | 239 | function from_prefs_to_vars() { 240 | echo('from_prefs_to_vars'); 241 | 242 | //how many presets are saved 243 | var saved_congifs_count = app.preferences.getIntegerPreference('corner_smoothing_script_saved_congifs_count'); 244 | echo(saved_congifs_count); 245 | 246 | //If it is unknown (although this is strange), then let it be 0 247 | if (saved_congifs_count == undefined || saved_congifs_count < 0 || saved_congifs_count > 10) { 248 | echo('no corner_smoothing_script_saved_congifs_count or invalid values, set 0'); 249 | saved_congifs_count = 0; 250 | app.preferences.setIntegerPreference("corner_smoothing_script_saved_congifs_count", 0); 251 | } 252 | 253 | //if such a variable is not saved in the Illustrator settings, it can give an absurdly large number instead of null or undefined, so cut it out 254 | if (saved_congifs_count > 40) { 255 | echo('nooo, terminate'); 256 | saved_congifs_count = 0; 257 | } 258 | 259 | /* if(saved_congifs_count == 0 ){ 260 | echo('all presets are gone, strange'); 261 | }*/ 262 | 263 | echo(saved_congifs_count + ' configs'); 264 | 265 | for (var i = 0; i < saved_congifs_count; i++) { 266 | var conf = {}; 267 | conf.name = app.preferences.getStringPreference('corner_smoothing_script_config_' + i + '_name'); 268 | conf.coef1 = app.preferences.getRealPreference('corner_smoothing_script_config_' + i + '_coef1'); 269 | conf.coef2 = app.preferences.getRealPreference('corner_smoothing_script_config_' + i + '_coef2'); 270 | echo('coef' + i + ': ' + conf.name + ', ' + conf.coef1 + ', ' + conf.coef2); 271 | coefs.push(conf); 272 | } 273 | 274 | 275 | coef1 = app.preferences.getRealPreference('corner_smoothing_script_current_coef1'); 276 | coef2 = app.preferences.getRealPreference('corner_smoothing_script_current_coef2'); 277 | var s = app.preferences.getIntegerPreference('corner_smoothing_script_show_ui'); 278 | var p = app.preferences.getIntegerPreference('corner_smoothing_script_show_profile'); 279 | 280 | echo(s); 281 | if (s == 6) { 282 | echo('ui: true'); 283 | ui = true; 284 | } else { 285 | echo('ui: false'); 286 | ui = false; 287 | } 288 | 289 | echo(p); 290 | if (p == 6) { 291 | echo('profile: true'); 292 | show_profile = true; 293 | } else { 294 | echo('profile: false'); 295 | show_profile = false; 296 | } 297 | 298 | 299 | 300 | } 301 | 302 | //erase all about script from illustrator settings and write from the variables instead 303 | function update_prefs_from_vars() { 304 | clear_all_prefs(); 305 | from_vars_to_prefs(); 306 | } 307 | 308 | 309 | //erase all saved settings 310 | function clear_all_prefs() { 311 | echo('clear_all_prefs:'); 312 | 313 | var saved_congifs_count = app.preferences.getIntegerPreference('corner_smoothing_script_saved_congifs_count'); 314 | echo(saved_congifs_count); 315 | echo(typeof saved_congifs_count); 316 | 317 | //If it is unknown (although this is strange), then let it be 0 318 | if (saved_congifs_count == undefined || saved_congifs_count < 0 || saved_congifs_count > 10) { 319 | echo('no corner_smoothing_script_saved_congifs_count, set 0'); 320 | saved_congifs_count = 0; 321 | } 322 | 323 | for (var i = 0; i < saved_congifs_count; i++) { 324 | echo('removePreference ' + i); 325 | app.preferences.removePreference('corner_smoothing_script_config_' + i + '_name'); 326 | app.preferences.removePreference('corner_smoothing_script_config_' + i + '_coef1'); 327 | app.preferences.removePreference('corner_smoothing_script_config_' + i + '_coef2'); 328 | } 329 | echo('set corner_smoothing_script_saved_congifs_count to 0'); 330 | app.preferences.setIntegerPreference("corner_smoothing_script_saved_congifs_count", 0); 331 | 332 | } 333 | 334 | 335 | //full reset, as if the script had never been run before 336 | function factory_reset() { 337 | echo('factory_reset'); 338 | 339 | clear_all_prefs(); 340 | 341 | echo('removePreference corner_smoothing_script_saved_congifs_count'); 342 | app.preferences.removePreference('corner_smoothing_script_saved_congifs_count'); 343 | 344 | echo('removePreference corner_smoothing_script_first_launch_already_was'); 345 | app.preferences.removePreference('corner_smoothing_script_first_launch_already_was'); 346 | 347 | echo('removePreference corner_smoothing_script_current_coef1'); 348 | echo('removePreference corner_smoothing_script_current_coef2'); 349 | echo('removePreference corner_smoothing_script_show_ui'); 350 | echo('removePreference corner_smoothing_script_show_profile'); 351 | app.preferences.removePreference('corner_smoothing_script_current_coef1'); 352 | app.preferences.removePreference('corner_smoothing_script_current_coef2'); 353 | app.preferences.removePreference('corner_smoothing_script_show_ui'); 354 | app.preferences.removePreference('corner_smoothing_script_show_profile'); 355 | } 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | /* 371 | 372 | CORE FUNCTIONS 373 | 374 | */ 375 | 376 | 377 | 378 | 379 | 380 | 381 | //Let's go. We need to process all the corners from what 382 | function go(what) { 383 | echo('go!'); 384 | 385 | //see `what` it is. if it didn't pass, then work with the selection 386 | if (what == undefined) { 387 | what = doc.selection; 388 | } 389 | 390 | 391 | if (what.length == 0) { 392 | alert(loc({'en':'Nothing selected\nSelect paths or individual points and run the script again', 'ru':'Ничего не выделено\nВыделите объекты или отдельные точки и запустите скрипт снова'})); 393 | return false; 394 | } 395 | 396 | 397 | //go through everything that needs to be processed and sorted out 398 | for (var i = 0; i < what.length; i++) { 399 | 400 | echo('path' + (i + 1)); 401 | 402 | //create a subarray to save the points that will be processed (will be needed later) 403 | if (selectedPointsSaved[i] === undefined) { 404 | selectedPointsSaved[i] = []; 405 | } 406 | 407 | if (what[i].typename == 'PathItem') { 408 | 409 | if (selectedPointsSaved[i].length == 0) { 410 | 411 | echo('NATURAL SELECTED'); 412 | for (var j = 0; j < what[i].pathPoints.length; j++) { 413 | if (what[i].pathPoints[j].selected == PathPointSelection.ANCHORPOINT) { 414 | 415 | p = what[i].pathPoints[j]; 416 | 417 | var prev_point_i = (j == 0 ? what[i].pathPoints.length - 1 : j - 1); 418 | var next_point_i = (j == what[i].pathPoints.length - 1 ? 0 : j + 1); 419 | 420 | var is_prev_point_selected = (what[i].pathPoints[prev_point_i].selected == PathPointSelection.ANCHORPOINT); 421 | 422 | var is_next_point_selected = (what[i].pathPoints[next_point_i].selected == PathPointSelection.ANCHORPOINT); 423 | 424 | 425 | selectedPointsSaved[i].push({ 'n': j, 'prev_selected': is_prev_point_selected, 'next_selected': is_next_point_selected }); 426 | 427 | poiint(p, is_prev_point_selected, is_next_point_selected); 428 | } 429 | } 430 | 431 | 432 | } else { 433 | 434 | echo('RESTORE SELECTED POINTS'); 435 | for (var j = 0; j < selectedPointsSaved[i].length; j++) { 436 | 437 | p = what[i].pathPoints[selectedPointsSaved[i][j].n]; 438 | poiint(p, selectedPointsSaved[i][j].prev_selected, selectedPointsSaved[i][j].next_selected); 439 | } 440 | 441 | 442 | } 443 | 444 | } 445 | } 446 | 447 | if (points_to_move == false) { 448 | 449 | alert(loc({'en':'Nothing to tune\nSelect rounded corners and run the script again.', 'ru':'Нечего обрабатывать\nВыделите скругленные углы и запустите скрипт снова.'})); 450 | 451 | return false; 452 | 453 | } 454 | 455 | //draw a curvature profile 456 | if (show_profile) { 457 | draw_evolute(what); 458 | } 459 | 460 | return true; 461 | } 462 | 463 | 464 | //point processing 465 | function poiint(p, is_prev_point_selected, is_next_point_selected) { 466 | echo('POINT ' + is_prev_point_selected + ' ' + is_next_point_selected); 467 | 468 | if (p.selected == PathPointSelection.ANCHORPOINT) { 469 | 470 | //measuring the length of the point handles 471 | dxl = p.leftDirection[0] - p.anchor[0]; 472 | dyl = p.leftDirection[1] - p.anchor[1]; 473 | dxr = p.rightDirection[0] - p.anchor[0]; 474 | dyr = p.rightDirection[1] - p.anchor[1]; 475 | 476 | if (dxl == 0 && dyl == 0 && dxr == 0 && dyr == 0) { 477 | echo('point without handles'); 478 | 479 | } else if (!(dxl == 0 && dyl == 0) && dxr == 0 && dyr == 0) { 480 | //only the handle to the left 481 | echo('handle to the left'); 482 | points_to_move = true; 483 | 484 | move_point(p, 'al'); 485 | 486 | } else if (dxl == 0 && dyl == 0 && !(dxr == 0 && dyr == 0)) { 487 | //only the handle to the right 488 | 489 | echo('handle to the right'); 490 | 491 | points_to_move = true; 492 | 493 | move_point(p, 'ar'); 494 | 495 | } else { //both handles 496 | 497 | echo('both handles'); 498 | points_to_move = true; 499 | 500 | 501 | if (is_prev_point_selected && is_next_point_selected) { 502 | //if both before and after points are selected, then move both handles 503 | 504 | move_point(p, 'rl'); 505 | 506 | 507 | } else if (is_prev_point_selected) { 508 | //otherwise move only handle to the other selected point 509 | move_point(p, 'l'); 510 | 511 | } else if (is_next_point_selected) { 512 | move_point(p, 'r'); 513 | 514 | } else { 515 | //if a point has two handles and the neighbor points are not selected, then move both handles 516 | move_point(p, 'rl'); 517 | 518 | } 519 | 520 | } 521 | 522 | } 523 | } 524 | 525 | 526 | 527 | 528 | //moving anchor and handle 529 | function move_point(p, l_or_r) { 530 | 531 | echo('moving point ' + l_or_r); 532 | 533 | //anchor and left handle 534 | if (l_or_r == 'al') { 535 | 536 | p.anchor = [p.anchor[0] - dxl * coef1, p.anchor[1] - dyl * coef1]; 537 | p.leftDirection = [p.leftDirection[0] + dxl * coef2, p.leftDirection[1] + dyl * coef2]; 538 | p.rightDirection = [p.anchor[0], p.anchor[1]]; 539 | 540 | //anchor and right handle 541 | } else if (l_or_r == 'ar') { 542 | 543 | p.anchor = [p.anchor[0] - dxr * coef1, p.anchor[1] - dyr * coef1]; 544 | p.rightDirection = [p.rightDirection[0] + dxr * coef2, p.rightDirection[1] + dyr * coef2]; 545 | p.leftDirection = [p.anchor[0], p.anchor[1]]; 546 | 547 | //only left handle 548 | } else if (l_or_r == 'l') { 549 | 550 | p.leftDirection = [p.leftDirection[0] + dxl * coef2, p.leftDirection[1] + dyl * coef2]; 551 | 552 | //only right handle 553 | } else if (l_or_r == 'r') { 554 | 555 | p.rightDirection = [p.rightDirection[0] + dxr * coef2, p.rightDirection[1] + dyr * coef2]; 556 | 557 | //both handles 558 | } else if (l_or_r == 'rl') { 559 | 560 | p.rightDirection = [p.rightDirection[0] + dxr * coef2, p.rightDirection[1] + dyr * coef2]; 561 | p.leftDirection = [p.leftDirection[0] + dxl * coef2, p.leftDirection[1] + dyl * coef2]; 562 | 563 | } 564 | 565 | 566 | } 567 | 568 | //restore point selection (it is reset for some reason) 569 | function restore_points_selection() { 570 | echo('RESTORE SELECTED POINTS'); 571 | 572 | var what = doc.selection; 573 | 574 | for (i = 0; i < what.length; i++) { 575 | 576 | if (what[i].typename == 'PathItem') { 577 | 578 | for (var j = 0; j < what[i].pathPoints.length; j++) { 579 | what[i].pathPoints[j].selected = PathPointSelection.NOSELECTION; 580 | } 581 | 582 | for (var j = 0; j < selectedPointsSaved[i].length; j++) { 583 | 584 | what[i].pathPoints[selectedPointsSaved[i][j].n].selected = PathPointSelection.ANCHORPOINT; 585 | 586 | } 587 | 588 | } 589 | 590 | } 591 | 592 | 593 | } 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | /* 621 | 622 | 623 | 624 | CURVATURE VISUALIZATION FUNCTIONS 625 | 626 | 627 | 628 | */ 629 | 630 | 631 | 632 | //drawing curvature profile for `what` 633 | function draw_evolute(what) { 634 | 635 | 636 | //recursively look around all that was given and for Path start drawing curvature 637 | 638 | for (var i = 0; i < what.length; i++) { 639 | 640 | // draw_evolute_for_path(what[i]); 641 | 642 | switch (what[i].typename) { 643 | 644 | case "PathItem": 645 | if (what[i].pathPoints.length > 1) 646 | draw_evolute_for_path(what[i]); 647 | break; 648 | 649 | case "GroupItem": 650 | draw_evolute(what[i].pageItems); 651 | break; 652 | 653 | case "CompoundPathItem": 654 | draw_evolute(what[i].pathItems); 655 | break; 656 | 657 | case "TextFrame": 658 | // maybe sometime 659 | break; 660 | 661 | } 662 | 663 | } 664 | 665 | } 666 | 667 | 668 | 669 | 670 | 671 | 672 | //drawing curvature profile for the opath path 673 | function draw_evolute_for_path(opath) { 674 | echo('DRAW_EVOLUTE_FOR_PATH'); 675 | 676 | 677 | var t; 678 | var bx, by; 679 | var dots = []; 680 | var evo_dots = []; 681 | var curv_dots = []; 682 | var curv_graph_dots = [[0, 0]]; 683 | 684 | 685 | var total_path_length = 0; 686 | var current_sector_length = 0; 687 | // var curv_graph_dots = []; 688 | 689 | 690 | 691 | // var ss = doc.layers.getByName('Symbol Editing Mode'); 692 | 693 | 694 | //create a test layer, where the profile will be drawn, if it does not already exist 695 | try { 696 | tmp_layer = doc.layers.getByName('corner_smoothing_script_tmp_layer'); 697 | } catch (e) { 698 | 699 | //if we can`t find tmp layer, trying to create it 700 | try { 701 | tmp_layer = doc.layers.add(); 702 | 703 | } catch (e) { 704 | //if we can`t create tmp layer, we are most likely in isolation mode or symbol editing mode 705 | 706 | try { 707 | //isolation mode in layer 708 | tmp_layer = doc.layers.getByName('Isolation Mode').layers[0].groupItems.add(); 709 | } catch (e) { 710 | 711 | //isolation mode in group 712 | try { 713 | 714 | tmp_layer = doc.layers.getByName('Isolation Mode').groupItems[0].groupItems.add(); 715 | 716 | } catch (e) { 717 | //symbol editing mode 718 | tmp_layer = doc.layers.getByName('Symbol Editing Mode').layers[0].groupItems.add(); 719 | 720 | } 721 | 722 | } 723 | 724 | 725 | } 726 | 727 | tmp_layer.name = 'corner_smoothing_script_tmp_layer'; 728 | } 729 | 730 | 731 | 732 | var test_group = tmp_layer.groupItems.add(); 733 | 734 | test_group.opacity = 40; 735 | 736 | var curv_path = create_empty_curv_path(test_group, true); 737 | curv_path.name = 'start_path'; 738 | 739 | var path_for_length_measuring = create_empty_curv_path(test_group, false); 740 | path_for_length_measuring.name = 'path_for_length_measuring'; 741 | 742 | 743 | var stroke_offset = 0; 744 | if (opath.stroked) { 745 | stroke_offset = opath.strokeWidth / 2; 746 | } 747 | 748 | //TODO: understand 749 | stroke_offset = 0;//doesn't work yet 750 | echo('stroke: ' + stroke_offset); 751 | 752 | echo(opath.pathPoints.length + ' points'); 753 | 754 | var curv_path_start_point_index = 0; 755 | 756 | 757 | var to_l = opath.pathPoints.length - 1; 758 | 759 | /* if path is closed, return to the zero point at the end of loop */ 760 | if (opath.closed) { 761 | to_l++; 762 | } 763 | 764 | /* loop for points of path */ 765 | for (var j = 0; j < to_l; j++) { 766 | 767 | echo(' '); 768 | echo(' '); 769 | 770 | //current point index 771 | var from_index = j; 772 | 773 | //next point index (assuming that after last will zero again) 774 | var to_index = (j + 1) % opath.pathPoints.length; 775 | 776 | echo('from point ' + from_index + ' to ' + to_index + ' (' + (j + 1) + ')'); 777 | 778 | var p_cur = opath.pathPoints[from_index]; 779 | 780 | var P0 = p_cur.anchor; 781 | var P1 = p_cur.rightDirection; 782 | 783 | var p_next = opath.pathPoints[to_index]; 784 | 785 | var P2 = p_next.leftDirection; 786 | var P3 = p_next.anchor; 787 | 788 | if (j == 0) { 789 | copy_point_to_path(p_cur, path_for_length_measuring); 790 | } 791 | 792 | copy_point_to_path(p_next, path_for_length_measuring); 793 | 794 | echo('total_length: ' + total_path_length + ' -> ' + path_for_length_measuring.length); 795 | 796 | //how much longer 797 | current_sector_length = path_for_length_measuring.length - total_path_length; 798 | 799 | //redefining 800 | total_path_length = path_for_length_measuring.length; 801 | 802 | echo('sector_length = ' + current_sector_length); 803 | echo('true total_length = ' + opath.length); 804 | 805 | echo('P0 ' + P0); 806 | echo('P1 ' + P1); 807 | echo('P2 ' + P2); 808 | echo('P3 ' + P3); 809 | 810 | if (P0[0] == P1[0] && 811 | P0[1] == P1[1] && 812 | P2[0] == P3[0] && 813 | P2[1] == P3[1]) { 814 | 815 | echo('straight part'); 816 | 817 | //add points of original path to profile 818 | reverse_points_adding(opath, curv_path_start_point_index, from_index, curv_path, stroke_offset); 819 | 820 | //put it back 821 | if (curv_path.pathPoints.length > 0) { 822 | 823 | echo('creating new curv_path'); 824 | curv_path = create_empty_curv_path(test_group, true); 825 | curv_path.name = 'from ' + j + ' path'; 826 | 827 | } 828 | 829 | curv_path_start_point_index = j + 1; 830 | 831 | curv_dots.push([P0[0], P0[1]], [P3[0], P3[1]]); 832 | 833 | continue; 834 | } 835 | 836 | 837 | 838 | /* 839 | there are four points: 840 | P0 [x,y] — start point 841 | P1 [x,y] - handle extending from it 842 | P2 [x,y] – handle extending from second point 843 | P3 [x,y] - second point 844 | 845 | B = (1-t)***3 * P0 + 3*t*(1-t)**2 * P1 + 3*t*t*(1-t) * P2 + t***3 * P3; 846 | 847 | t - in length from 0 to 1 848 | */ 849 | 850 | var steps = 50; 851 | 852 | 853 | for (var i = 0; i <= steps; i++) { 854 | // echo(' '); 855 | 856 | t = i / steps; //from 0 to 1 857 | 858 | bx = coord_from_t(P0[0], P1[0], P2[0], P3[0], t); 859 | by = coord_from_t(P0[1], P1[1], P2[1], P3[1], t); 860 | dots.push([bx, by]); 861 | 862 | var evolute_d = evolute(P0[0], P1[0], P2[0], P3[0], P0[1], P1[1], P2[1], P3[1], t, current_sector_length, opath.length, stroke_offset, opath); 863 | 864 | if (evolute_d != undefined) { 865 | 866 | evo_dots.push(evolute_d[0]); 867 | curv_dots.push(evolute_d[1]); 868 | curv_graph_dots.push(evolute_d[2]); 869 | 870 | var pp = curv_path.pathPoints.add(); 871 | pp.anchor = evolute_d[1]; 872 | pp.leftDirection = pp.anchor; 873 | pp.rightDirection = pp.anchor; 874 | // echo('adding point to curv_path '+evolute_d[1][0]+' '+evolute_d[1][1]); 875 | 876 | } 877 | 878 | 879 | 880 | } 881 | 882 | 883 | } 884 | 885 | echo('draw paths'); 886 | path_for_length_measuring.remove(); 887 | 888 | reverse_points_adding(opath, curv_path_start_point_index, j, curv_path, stroke_offset); 889 | 890 | // echo('so length of curv_path is '+); 891 | 892 | if (curv_path.pathPoints.length == 0) { 893 | echo('path is empty, delete'); 894 | curv_path.remove(); 895 | } 896 | 897 | 898 | if (curv_dots.length > 0) { 899 | 900 | 901 | } else { 902 | echo('SORRY, NO POINTS – NO CURV PATH'); 903 | } 904 | 905 | 906 | 907 | } 908 | 909 | 910 | 911 | 912 | 913 | function create_empty_curv_path(where, clsed) { 914 | 915 | var newPath; 916 | if (where) { 917 | newPath = where.pathItems.add(); 918 | } else { 919 | newPath = tmp_layer.pathItems.add(); 920 | } 921 | 922 | 923 | newPath.name = 'curiate'; 924 | newPath.filled = true; 925 | newPath.stroked = false; 926 | newPath.fillColor = curviture_color; 927 | newPath.closed = clsed; 928 | 929 | return newPath; 930 | } 931 | 932 | 933 | 934 | function copy_point_to_path(p1, to) { 935 | 936 | var pp1 = to.pathPoints.add(); 937 | pp1.anchor = p1.anchor; 938 | pp1.leftDirection = p1.leftDirection; 939 | pp1.rightDirection = p1.rightDirection; 940 | 941 | } 942 | 943 | function reverse_points_adding(path_from, point_from_i, point_to_i, path_to, stroke_offset) { 944 | echo('[reverse_points_adding] from ' + point_from_i + ' to ' + point_to_i + ' in path with length ' + path_from.pathPoints.length); 945 | 946 | 947 | var donor; 948 | var pp; 949 | 950 | 951 | if (point_from_i == point_to_i) { 952 | 953 | echo('same point. ignore'); 954 | 955 | 956 | // return ; 957 | } else if (point_to_i == path_from.pathPoints.length) { //ending at the first point (end of the cycle) 958 | 959 | 960 | echo('case 1 (closed to the end)'); 961 | 962 | donor = path_from.pathPoints[0]; 963 | 964 | echo('>adding point ' + 0); 965 | 966 | pp = path_to.pathPoints.add(); 967 | pp.anchor = donor.anchor; 968 | pp.leftDirection = donor.anchor; 969 | pp.rightDirection = donor.leftDirection; 970 | 971 | 972 | for (var i = path_from.pathPoints.length - 1; i >= point_from_i; i--) { 973 | echo('>adding point ' + i); 974 | 975 | donor = path_from.pathPoints[i]; 976 | 977 | pp = path_to.pathPoints.add(); 978 | pp.anchor = donor.anchor; 979 | pp.leftDirection = donor.rightDirection; 980 | pp.rightDirection = donor.leftDirection; 981 | // echo('adding point to curv_path '+evolute_d[1][0]+' '+evolute_d[1][1]); 982 | 983 | if (i == point_from_i) { 984 | pp.rightDirection = donor.anchor; 985 | } 986 | 987 | } 988 | 989 | 990 | /* 991 | echo('case 3'); 992 | 993 | var donor = path_from.pathPoints[point_to_i]; 994 | echo('>adding point '+point_to_i); 995 | 996 | var pp = path_to.pathPoints.add(); 997 | pp.anchor = donor.anchor; 998 | pp.leftDirection = donor.anchor; 999 | pp.rightDirection = donor.leftDirection; 1000 | 1001 | var donor = path_from.pathPoints[point_from_i]; 1002 | echo('>adding point '+point_from_i); 1003 | 1004 | var pp = path_to.pathPoints.add(); 1005 | pp.anchor = donor.anchor; 1006 | pp.leftDirection = donor.rightDirection; 1007 | pp.rightDirection = donor.anchor; 1008 | */ 1009 | 1010 | 1011 | 1012 | } else if (point_from_i < point_to_i) {//normal case 1013 | echo('case 2 (normal)'); 1014 | 1015 | for (var i = point_to_i; i >= point_from_i; i--) { 1016 | echo('>adding point ' + i); 1017 | 1018 | donor = path_from.pathPoints[i]; 1019 | 1020 | pp = path_to.pathPoints.add(); 1021 | pp.anchor = donor.anchor; 1022 | pp.leftDirection = donor.rightDirection; 1023 | pp.rightDirection = donor.leftDirection; 1024 | // echo('adding point to curv_path '+evolute_d[1][0]+' '+evolute_d[1][1]); 1025 | 1026 | if (i == point_from_i) { 1027 | pp.rightDirection = donor.anchor; 1028 | } else if (i == point_to_i) { 1029 | pp.leftDirection = donor.anchor; 1030 | } 1031 | 1032 | 1033 | } 1034 | 1035 | } else { //The thing here is that we join to the starting point - from 12 to 0, for example 1036 | echo('WTF'); 1037 | 1038 | } 1039 | 1040 | } 1041 | 1042 | // https://en.wikipedia.org/wiki/Bezier_curve#Cubic_Bezier_curves 1043 | // cubic Bezier curve 1044 | function coord_from_t(p0, p1, p2, p3, t) { 1045 | var by = (1 - t) * (1 - t) * (1 - t) * p0 + 3 * t * (1 - t) * (1 - t) * p1 + 3 * t * t * (1 - t) * p2 + t * t * t * p3; 1046 | return by; 1047 | } 1048 | 1049 | 1050 | // derivative of the cubic Bezier curve with respect to t 1051 | function d_coord_from_t(p0, p1, p2, p3, t) { 1052 | 1053 | var d = 3 * (1 - t) * (1 - t) * (p1 - p0) + 6 * (1 - t) * t * (p2 - p1) + 3 * t * t * (p3 - p2); 1054 | 1055 | echo("d't with t = " + t + ', p0 = ' + p0 + ', p1 = ' + p1 + ' is ' + d); 1056 | 1057 | return d; 1058 | } 1059 | 1060 | //second derivative of the Bezier curve with respect to t 1061 | function dd_coord_from_t(p0, p1, p2, p3, t) { 1062 | 1063 | var dd = 6 * (1 - t) * (p2 - 2 * p1 + p0) + 6 * t * (p3 - 2 * p2 + p1); 1064 | 1065 | return dd; 1066 | } 1067 | 1068 | 1069 | 1070 | function evolute(p0x, p1x, p2x, p3x, p0y, p1y, p2y, p3y, t, current_sector_length, total_length, stroke_offset, ppath) { 1071 | // echo('evolute '); 1072 | 1073 | var evo_x = 0; 1074 | var evo_y = 0; 1075 | var curv_x = 0; 1076 | var curv_y = 0; 1077 | 1078 | var x = coord_from_t(p0x, p1x, p2x, p3x, t); //x 1079 | var y = coord_from_t(p0y, p1y, p2y, p3y, t); //y 1080 | 1081 | var dx_t = d_coord_from_t(p0x, p1x, p2x, p3x, t); //x' 1082 | var dy_t = d_coord_from_t(p0y, p1y, p2y, p3y, t); //y' 1083 | 1084 | var ddx_t = dd_coord_from_t(p0x, p1x, p2x, p3x, t); //x'' 1085 | var ddy_t = dd_coord_from_t(p0y, p1y, p2y, p3y, t); //y'' 1086 | 1087 | var limit = 0.000001; 1088 | 1089 | 1090 | if (Math.abs(dx_t * dx_t + dy_t * dy_t) < limit) { 1091 | 1092 | echo('dividing by zero2'); 1093 | return undefined; 1094 | } 1095 | 1096 | var top_part = dx_t * ddy_t - ddx_t * dy_t; 1097 | var normal_sq_len = dx_t * dx_t + dy_t * dy_t; 1098 | var normal_len = Math.sqrt(normal_sq_len); 1099 | 1100 | 1101 | echo(top_part); 1102 | 1103 | 1104 | //curvature at the point https://en.wikipedia.org/wiki/Curvature 1105 | //https://pomax.github.io/bezierinfo/ (Curve inflections) here they say that the curvature is only the numerator of the design below 1106 | var curv = top_part / (Math.pow(normal_len, 3)); 1107 | //canonical curvature. when reduced by a factor of two, the curvature increases by a factor of four 1108 | 1109 | // how to show it? 1110 | var version = 3; 1111 | 1112 | switch (version) { 1113 | 1114 | //option 3: the opposite - increase the curvature in proportion to the normal. scalability is ok, otherwise it's a dilemma 1115 | case 3: 1116 | curv_x = x + 0.1 * curv * dy_t * normal_len; 1117 | curv_y = y - 0.1 * curv * dx_t * normal_len; 1118 | break; 1119 | // the rate of change of curvature with respect to the scale is exactly equal to the curvature 1120 | 1121 | 1122 | // option 5: without normalization, but with multiplication by segment length 1123 | // if(dy_t > 0) var dy_sign; 1124 | case 5: 1125 | curv_x = x /*- stroke_offset*Math.sign(dy_t)*/ + curv * dy_t * current_sector_length / 25; 1126 | curv_y = y /*+ stroke_offset*Math.sign(dx_t)*/ - curv * dx_t * current_sector_length / 25; 1127 | break; 1128 | 1129 | } 1130 | 1131 | 1132 | 1133 | return [[evo_x, evo_y], [curv_x, curv_y], [t, Math.abs(curv)]]; 1134 | 1135 | // var X 1136 | } 1137 | 1138 | 1139 | 1140 | 1141 | 1142 | 1143 | 1144 | 1145 | 1146 | 1147 | 1148 | 1149 | 1150 | 1151 | 1152 | 1153 | 1154 | 1155 | 1156 | 1157 | 1158 | 1159 | 1160 | 1161 | 1162 | 1163 | 1164 | 1165 | 1166 | 1167 | 1168 | 1169 | 1170 | 1171 | 1172 | 1173 | // UI FUNCTIONS 1174 | 1175 | 1176 | 1177 | //OK button processing 1178 | function actionOK() { 1179 | 1180 | echo('actionOK'); 1181 | 1182 | if (show_profile) { 1183 | tmp_layer.remove(); 1184 | } 1185 | 1186 | settings.close(); 1187 | 1188 | } 1189 | 1190 | //Cancel button processing 1191 | function actionCanceled() { 1192 | 1193 | 1194 | // Undo the changes and close the panel 1195 | echo('onClose'); 1196 | app.undo(); 1197 | app.redraw(); 1198 | settings.close(); 1199 | 1200 | 1201 | } 1202 | 1203 | 1204 | 1205 | 1206 | // Update parameters in the panel 1207 | function settings_updated() { 1208 | 1209 | echo('settings_updated'); 1210 | app.undo(); 1211 | 1212 | restore_points_selection(); 1213 | go(); 1214 | 1215 | app.redraw(); 1216 | 1217 | } 1218 | 1219 | 1220 | 1221 | 1222 | 1223 | // Creating a panel with settings 1224 | function build_ui() { 1225 | 1226 | 1227 | var dark_theme = false; 1228 | 1229 | 1230 | // DIALOG 1231 | // ====== 1232 | var win = new Window("dialog", undefined, undefined, { minimizeButton: true }); 1233 | win.text = loc({'en':"Round Corner Customization", 'ru':"Настройка скругления углов"}); 1234 | win.orientation = "row"; 1235 | win.alignChildren = ["left", "top"]; 1236 | win.spacing = 0; 1237 | win.margins = 0; 1238 | 1239 | 1240 | 1241 | var graphics = win.graphics; 1242 | var col = graphics.newBrush(graphics.BrushType.THEME_COLOR, "background").color[0]; 1243 | 1244 | if (col < 0.5) dark_theme = true; 1245 | 1246 | 1247 | 1248 | 1249 | // LEFT SIZE 1250 | // ====== 1251 | var left_part = win.add("group", undefined, { name: "left_part" }); 1252 | left_part.preferredSize.width = 239; 1253 | left_part.orientation = "column"; 1254 | left_part.alignChildren = ["fill", "top"]; 1255 | left_part.spacing = 0; 1256 | left_part.margins = 16; 1257 | 1258 | 1259 | 1260 | 1261 | 1262 | 1263 | 1264 | // FIRST COEF 1265 | // ====== 1266 | var coef1_ui = left_part.add("group", undefined, { name: "coef1_ui" }); 1267 | coef1_ui.orientation = "column"; 1268 | coef1_ui.alignChildren = ["left", "center"]; 1269 | coef1_ui.spacing = 0; 1270 | coef1_ui.margins = [1, 10, 0, 1]; 1271 | 1272 | // NAME AND INPUT 1273 | // ====== 1274 | var coef1_name_and_input = coef1_ui.add("group", undefined, { name: "coef1_name_and_input" }); 1275 | coef1_name_and_input.orientation = "row"; 1276 | coef1_name_and_input.alignChildren = ["left", "center"]; 1277 | coef1_name_and_input.spacing = 10; 1278 | coef1_name_and_input.margins = 0; 1279 | coef1_name_and_input.alignment = ["fill", "center"]; 1280 | 1281 | //NAME 1282 | var coef1_n = coef1_name_and_input.add("statictext", undefined, undefined, { name: "coef1_n" }); 1283 | coef1_n.text = loc({'en':"Anchors coef", 'ru':"Смещение якорей"}); 1284 | coef1_n.preferredSize.width = 171; 1285 | 1286 | //INPUT 1287 | var coef1_e = coef1_name_and_input.add('edittext {properties: {name: "coef1_e", borderless: true}}'); 1288 | coef1_e.text = coef1; 1289 | coef1_e.preferredSize.width = 50; 1290 | coef1_e.preferredSize.height = 22; 1291 | 1292 | // SLIDER 1293 | // ====== 1294 | var coef1_slider = coef1_ui.add("slider", undefined, coef1, 0, max_coef1, { name: "coef1_slider" }); 1295 | coef1_slider.minvalue = 0; 1296 | coef1_slider.maxvalue = max_coef1; 1297 | coef1_slider.value = coef1; 1298 | coef1_slider.alignment = ["fill", "center"]; 1299 | 1300 | 1301 | coef1_slider.onChanging = function () { 1302 | coef1_e.text = roundOff(coef1_slider.value); 1303 | if (!dropdown_reseted) reset_dropdown(); 1304 | }; 1305 | coef1_slider.onChange = function () { 1306 | coef1 = coef1_e.text; 1307 | // alert('3'); 1308 | update_prefs_from_vars(); 1309 | settings_updated(); 1310 | }; 1311 | coef1_e.onChanging = function () { 1312 | coef1_slider.value = coef1_e.text; 1313 | coef1 = coef1_e.text; 1314 | // alert('4'); 1315 | update_prefs_from_vars(); 1316 | settings_updated(); 1317 | }; 1318 | 1319 | 1320 | 1321 | 1322 | 1323 | 1324 | // SECOND COEF 1325 | // ====== 1326 | var coef2_ui = left_part.add("group", undefined, { name: "coef2_ui" }); 1327 | coef2_ui.orientation = "column"; 1328 | coef2_ui.alignChildren = ["left", "center"]; 1329 | coef2_ui.spacing = 0; 1330 | coef2_ui.margins = [1, 10, 0, 1]; 1331 | 1332 | 1333 | // NAME AND INPUT 1334 | // ====== 1335 | var coef2_name_and_input = coef2_ui.add("group", undefined, { name: "coef2_name_and_input" }); 1336 | coef2_name_and_input.orientation = "row"; 1337 | coef2_name_and_input.alignChildren = ["left", "center"]; 1338 | coef2_name_and_input.spacing = 10; 1339 | coef2_name_and_input.margins = 0; 1340 | coef2_name_and_input.alignment = ["fill", "center"]; 1341 | 1342 | //NAME 1343 | var coef2_n = coef2_name_and_input.add("statictext", undefined, undefined, { name: "coef1_n" }); 1344 | coef2_n.text = loc({'en':"Handles coef", 'ru':"Смещение усиков"}); 1345 | coef2_n.preferredSize.width = 171; 1346 | 1347 | //INPUT 1348 | var coef2_e = coef2_name_and_input.add('edittext {properties: {name: "coef1_e", borderless: true}}'); 1349 | coef2_e.text = coef2; 1350 | coef2_e.preferredSize.width = 50; 1351 | coef2_e.preferredSize.height = 22; 1352 | 1353 | 1354 | function reset_dropdown() { 1355 | 1356 | dropdown_reseted = true; 1357 | 1358 | del_preset_button.enabled = false; 1359 | 1360 | rebuild_dropdown(); 1361 | } 1362 | 1363 | function rebuild_dropdown() { 1364 | echo('rebuild_dropdown'); 1365 | presets_vars_dropdown.removeAll(); 1366 | 1367 | for (var i = 0; i < coefs.length; i++) { 1368 | echo(coefs[i].name); 1369 | presets_vars_dropdown.add("item", coefs[i].name); 1370 | } 1371 | 1372 | 1373 | } 1374 | 1375 | 1376 | var dropdown_reseted = false; 1377 | 1378 | // SLIDER 1379 | // ====== 1380 | var coef2_slider = coef2_ui.add("slider", undefined, coef2, 0, max_coef2, { name: "coef2_slider" }); 1381 | // coef2_slider.helpTip = "Handles coef"; 1382 | coef2_slider.minvalue = 0; 1383 | coef2_slider.maxvalue = max_coef2; 1384 | coef2_slider.value = coef2; 1385 | coef2_slider.alignment = ["fill", "center"]; 1386 | 1387 | coef2_slider.onChanging = function () { 1388 | 1389 | if (!dropdown_reseted) reset_dropdown(); 1390 | 1391 | coef2_e.text = roundOff(coef2_slider.value); 1392 | }; 1393 | 1394 | coef2_slider.onChange = function () { /*set_param*/ 1395 | coef2 = coef2_e.text; 1396 | // alert('5'); 1397 | update_prefs_from_vars(); 1398 | settings_updated(); 1399 | }; 1400 | coef2_e.onChanging = function () { 1401 | coef2_slider.value = coef2_e.text; /*set_param*/ 1402 | coef2 = coef2_e.text; 1403 | // alert('6'); 1404 | update_prefs_from_vars(); 1405 | settings_updated(); 1406 | }; 1407 | 1408 | 1409 | 1410 | 1411 | 1412 | 1413 | 1414 | 1415 | 1416 | // PRESETS 1417 | // ====== 1418 | 1419 | var presets = left_part.add("group", undefined, { name: "presets" }); 1420 | presets.orientation = "row"; 1421 | presets.alignChildren = ["left", "bottom"]; 1422 | // presets.spacing = 10; 1423 | presets.spacing = 0; 1424 | presets.margins = [0, 20, 0, 0]; 1425 | 1426 | var presets_container = presets.add("group", undefined, { name: "presets_container" }); 1427 | presets_container.margins = [0, 0, 5, 0]; 1428 | 1429 | //DROPDOWN LIST 1430 | // var presets_vars = ["Default preset","small","pasha","verylongname"]; 1431 | var kys = []; 1432 | 1433 | var selection = null; 1434 | for (var i = 0; i < coefs.length; i++) { 1435 | // alert(coefs[i].name); 1436 | kys.push(coefs[i].name); 1437 | if (coefs[i].coef1 == coef1 && coefs[i].coef2 == coef2) { 1438 | selection = i; 1439 | } 1440 | } 1441 | 1442 | // alert('3-2: '+kys.length); 1443 | // alert(kys); 1444 | 1445 | var presets_vars_dropdown = presets_container.add("dropdownlist", undefined, undefined, { name: "presets_vars_dropdown", items: kys }); 1446 | 1447 | 1448 | //set not to zero, but to the one that matches the current values of coef1 and coef2 (if none, then the choice is empty) 1449 | presets_vars_dropdown.selection = selection; 1450 | presets_vars_dropdown.preferredSize.width = 185; 1451 | 1452 | presets_vars_dropdown.onChange = function () { 1453 | 1454 | if (presets_vars_dropdown.selection != null) { 1455 | 1456 | dropdown_reseted = false; 1457 | 1458 | coef1 = coefs[presets_vars_dropdown.selection.index].coef1; //anchor 1459 | coef2 = coefs[presets_vars_dropdown.selection.index].coef2; //handle 1460 | 1461 | coef1_e.text = coef1; 1462 | coef1_slider.value = coef1; 1463 | 1464 | coef2_e.text = coef2; 1465 | coef2_slider.value = coef2; 1466 | 1467 | del_preset_button.enabled = true; 1468 | 1469 | update_prefs_from_vars(); 1470 | settings_updated(); 1471 | } 1472 | 1473 | /*set_param*/ 1474 | }; 1475 | 1476 | 1477 | 1478 | //ADD BUTTON 1479 | var icon_add_normal_str = "%C2%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%18%00%00%00%18%08%04%00%00%00J~%C3%B5s%00%00%00%C2%9EIDATx%C3%9A%C2%BD%C2%93%C2%BB%0A%C3%82%40%10E%2F%C3%98D2%C2%83%C2%85%C3%A0%C3%BFW%C2%96%C3%A27%C2%9C%C3%8A%C2%BF%C2%89%10%C2%AD%C3%87%22Q%12%C2%B3%C2%98%1DAg%C2%9Aeg%0Fw%5E%2BI%C2%A2%C3%851%1C%C3%87%5E%C3%AE%C2%93%C3%93%10i5%18g%C2%A2%C3%92O%C2%92%C2%B0%C3%AA%C3%A7AH%C3%82%09%C2%82%C3%83%5B%02%3EI%C3%A5%C3%A9%230(%C2%B8Vm%C2%AE%60%C3%B5%40Z%C2%A1%08%C3%90%C3%91%C2%B1%C3%BD%04%C3%982X%C2%BA%C3%BB%0A%C2%98%15M364%08%C3%B6%15%0A%C3%B4%C2%8Ba%5D%C2%B3%C3%80%C2%BD%C2%9C%C2%92%17j%C3%98a%18%C3%8D%C3%BF%C2%BBT%06n%C3%B4%C2%A9%C3%81%C2%AD%C2%AF%C2%86e%C2%B7%C3%95%7F%C2%A8%C2%90%C3%BE%C2%A2%1B.%C3%95%C3%80Qy%7B%00X%C3%9E%C2%9F%C2%8B%C2%94%C3%8D%14_%00%00%00%00IEND%C2%AEB%60%C2%82"; 1480 | 1481 | var icon_add_hover_str = "%C2%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%18%00%00%00%18%08%04%00%00%00J~%C3%B5s%00%00%00%C2%98IDATx%C3%9A%C2%BDTI%0A%C2%800%0C%0CxQL%C3%B0%20%C3%B8%C3%BF%C2%93G%C3%B1%19%C3%BEFA%3D%C2%8F%C2%B4Up%09%C3%9A%C2%80%C2%9A%C2%81%12H%C2%86%C3%89%C3%92%C2%96%40%20%C3%A4%100%C3%84%C2%9F%1Bd%C3%A7%C2%85H%C3%AEr%5Dz%C2%8BXk%1C%C2%81a1%22%C2%88w%C2%AAS%01%C2%B2%2Be%C3%83J%08%C2%8E%C3%B8%5E%C3%AEqP%C3%A0x%C2%82YA'%C3%B4%C3%A8%C2%91%C3%9D%11X%09%C3%B2K%C2%84c%C3%93%C3%A9%3APge%C2%8C%C3%82xY%C3%95%60%25%C3%8CzI%C2%A2%C3%88%17~%C2%BF%C3%A9%C3%BFS%C3%92%09%13F%C3%9B%C3%A2%1E%C2%AF%06%5Bo%C2%AB%7C%C2%A8%60~%C2%A2%09%C2%BA%C3%A8%C3%B4%3A%C3%BC%1A%26%2CB2%03%C3%AB%1CO%15%C2%9E%00%00%00%00IEND%C2%AEB%60%C2%82"; 1482 | 1483 | 1484 | 1485 | var icon_add_hover_light_theme_str = "%C2%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%18%00%00%00%18%08%04%00%00%00J~%C3%B5s%00%00%00%C2%94IDATx%C3%9A%C2%BDS%C2%BB%0A%C2%800%0C%3CpQLp%10%C3%BC%C3%BF%C3%89Q%C3%BC%0C%C3%BFF%C2%A1%3A%2B%C2%AD%15%7C%04M%40%C2%BD%40%09M%C2%8EK%C2%93%14%C3%B0%C3%88%C3%81%20p87%C3%A3%C2%9D%C2%B7FrD%C2%B4%C2%98%C2%95%C3%96%C3%B8tR%C2%A7%7B%03%C3%80%C3%81%C2%A9N%05%C3%B0%C2%AE%C2%94%C3%8D%22au%18%C3%8F8(%C2%90%C2%9E%60V%C2%90%09%3Dzdw%04%12%C2%82%C3%B4%12%C3%A1%C3%B8%C3%A846%C3%94%C3%9F%C2%95%1A%05w%19%C3%95%60%25LrI%2C%C3%88%17a%C2%BE%C3%A9%C3%BF%5D%C2%92%09%23%C2%9Cmp%C2%8F%C2%ABA%C3%96m%C3%A5%0F%15%C3%8C_4A%C2%A7N%C2%AFa%C3%87%02%01%09%C3%85%C3%BE%C3%9C%C3%AE%C3%93%C3%8D%00%00%00%00IEND%C2%AEB%60%C2%82"; 1486 | 1487 | var icon_add_normal_light_theme_str = "%C2%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%18%00%00%00%18%08%04%00%00%00J~%C3%B5s%00%00%00%C2%9DIDATx%C3%9A%C2%BD%C2%93M%0A%C3%82%40%0CF%3FpSi%C2%82%0B%C3%81%C2%BB%C2%BC%0B%C2%BB%14%C2%8F%C3%A1m*T%C3%97q%C3%91*%C2%AD%1D%C3%ACD%C3%90d3L%C3%A6%C3%B1%C3%A5o%24I%C2%B48%C2%86%C3%A3%C3%98%C3%8B%7Dr%1A%22%C2%AD%06%C3%A3LT%C3%BAI%12V%C3%BD%3C%08I8ApxK%C3%80'%C2%A9%3C%7D%04%06%05%C3%97%C2%AA%C3%8D%15%C2%AC%1EH%2B%14%01%3A%3A%C2%B6%C2%9F%00%5B%06Kw_%01%C2%B3%C2%A2i%C3%86%C2%86%06%C3%81%C2%BEB%C2%81~1%C2%ACk%16%C2%B8%C2%97S%C3%B2B%0D%3B%0C%C2%A3%C3%B9%7F%C2%97%C3%8A%C3%80%C2%8D%3E5%C2%B8%C3%B5%C3%95%C2%B0%C3%AC%C2%B6%C3%BA%0F%15%C3%92_t%C3%83%C2%A5%1A8*o%0F%2B%C3%BE%05%C3%B4%C2%923%C3%A2%C2%8D%00%00%00%00IEND%C2%AEB%60%C2%82"; 1488 | 1489 | 1490 | 1491 | 1492 | var icon_add_normal = ScriptUI.newImage(File.decode(icon_add_normal_str)); 1493 | var icon_add_hover = ScriptUI.newImage(File.decode(icon_add_hover_str)); 1494 | 1495 | var icon_add_normal_light_theme = ScriptUI.newImage(File.decode(icon_add_normal_light_theme_str)); 1496 | var icon_add_hover_light_theme = ScriptUI.newImage(File.decode(icon_add_hover_light_theme_str)); 1497 | 1498 | var new_preset_button = presets.add("iconbutton", undefined, icon_add_normal, { name: "new_preset_button", style: "toolbutton" }); 1499 | new_preset_button.helpTip = loc({'en':"Save current values as new preset", 'ru':"Сохранить значения в пресет"}); 1500 | 1501 | new_preset_button.onClick = function () { 1502 | draw_save_preset_dialog(); 1503 | }; 1504 | 1505 | new_preset_button.size = [22, 22]; 1506 | new_preset_button.fillBrush = new_preset_button.graphics.newBrush(new_preset_button.graphics.BrushType.SOLID_COLOR, [1, 1, 1, 0.1]); 1507 | 1508 | 1509 | 1510 | new_preset_button.onDraw = function (drState) { 1511 | 1512 | 1513 | if (!this.image) return; 1514 | 1515 | var WH = this.size, 1516 | wh = this.image.size, 1517 | k = Math.min(WH[0] / wh[0], WH[1] / wh[1]), 1518 | xy; 1519 | 1520 | var wh2 = [k * wh[0], k * wh[1]]; 1521 | xy = [(WH[0] - wh2[0]) / 2, (WH[1] - wh2[1]) / 2]; 1522 | 1523 | 1524 | 1525 | if (drState.mouseOver) { 1526 | this.graphics.drawOSControl(); 1527 | this.graphics.rectPath(0, 0, this.size[0], this.size[1]); 1528 | this.graphics.fillPath(this.fillBrush); 1529 | 1530 | // this.graphics.drawImage(already, 0, xy[1], 12, 12); 1531 | if (dark_theme) { 1532 | this.graphics.drawImage(icon_add_hover, (WH[0] - wh[0] / 2) / 2, (WH[1] - wh[1] / 2) / 2, 12, 12); 1533 | } else { 1534 | this.graphics.drawImage(icon_add_hover_light_theme, (WH[0] - wh[0] / 2) / 2, (WH[1] - wh[1] / 2) / 2, 12, 12); 1535 | } 1536 | 1537 | 1538 | } 1539 | else { 1540 | // this.graphics.drawImage(this.image, 0, xy[1], 12, 12); 1541 | if (dark_theme) { 1542 | this.graphics.drawImage(this.image, (WH[0] - wh[0] / 2) / 2, (WH[1] - wh[1] / 2) / 2, 12, 12); 1543 | } else { 1544 | this.graphics.drawImage(icon_add_normal_light_theme, (WH[0] - wh[0] / 2) / 2, (WH[1] - wh[1] / 2) / 2, 12, 12); 1545 | } 1546 | } 1547 | 1548 | 1549 | WH = wh = xy = null; 1550 | 1551 | 1552 | }; 1553 | 1554 | function draw_save_preset_dialog() { 1555 | echo('draw_save_preset_dialog'); 1556 | // alert('so2') 1557 | // DIALOG 1558 | // ====== 1559 | var save_preset_dialog = new Window("dialog"); 1560 | save_preset_dialog.text = loc({'en':"New preset", 'ru':"Новый пресет"}); 1561 | save_preset_dialog.orientation = "column"; 1562 | save_preset_dialog.alignChildren = ["center", "top"]; 1563 | save_preset_dialog.spacing = 10; 1564 | save_preset_dialog.margins = 16; 1565 | 1566 | var new_preset_label = save_preset_dialog.add("statictext", undefined, undefined, { name: "new_preset_label" }); 1567 | new_preset_label.text = loc({'en':"Name of new preset", 'ru':"Имя нового пресета"}); 1568 | new_preset_label.alignment = ["left", "top"]; 1569 | 1570 | var new_preset_input = save_preset_dialog.add('edittext {properties: {name: "new_preset_input", borderless: true}}'); 1571 | new_preset_input.text = coef1 + " - " + coef2; 1572 | new_preset_input.preferredSize.width = 200; 1573 | new_preset_input.alignment = ["left", "top"]; 1574 | 1575 | new_preset_input.active = true; 1576 | 1577 | // 1578 | // ====== 1579 | var dial2_ok_and_cancel = save_preset_dialog.add("group", undefined, { name: "dial2_ok_and_cancel" }); 1580 | dial2_ok_and_cancel.orientation = "row"; 1581 | dial2_ok_and_cancel.alignChildren = ["left", "center"]; 1582 | dial2_ok_and_cancel.spacing = 10; 1583 | dial2_ok_and_cancel.margins = 0; 1584 | dial2_ok_and_cancel.alignment = ["right", "top"]; 1585 | 1586 | var dial2_cancel = dial2_ok_and_cancel.add("button", undefined, undefined, { name: "cancel" }); 1587 | dial2_cancel.text = loc({'en':"Cancel", 'ru':"Отмена"}); 1588 | 1589 | var dial2_ok = dial2_ok_and_cancel.add("button", undefined, undefined, { name: "ok" }); 1590 | dial2_ok.text = loc({'en':"Save", 'ru':"Сохранить"}); 1591 | 1592 | 1593 | 1594 | dial2_ok.onClick = function () { 1595 | 1596 | echo('save ' + new_preset_input.text + ' with values ' + coef1 + ' and ' + coef2); 1597 | 1598 | coefs.push({ 1599 | "name": new_preset_input.text, 1600 | "coef1": coef1, 1601 | "coef2": coef2 1602 | }); 1603 | 1604 | 1605 | save_preset_dialog.hide(); 1606 | 1607 | echo('now rebuild_dropdown'); 1608 | rebuild_dropdown(); 1609 | echo('select new'); 1610 | presets_vars_dropdown.selection = coefs.length - 1; 1611 | presets_vars_dropdown.enabled = true; 1612 | del_preset_button.enabled = true; 1613 | 1614 | update_prefs_from_vars(); 1615 | // settings_updated(); 1616 | 1617 | 1618 | 1619 | 1620 | 1621 | }; 1622 | 1623 | save_preset_dialog.show(); 1624 | 1625 | } 1626 | 1627 | 1628 | 1629 | 1630 | 1631 | 1632 | //DELETE BUTTON 1633 | 1634 | var icon_del_normal_str = "%C2%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%18%00%00%00%18%08%04%00%00%00J~%C3%B5s%00%00%00jIDATx%C3%9A%C3%AD%C2%94%C3%91%09%C2%800%0CD%C2%BBn%C3%9D%20%C2%8Ew%C3%A3%24CD%C2%A4%C2%B5j%C3%81%C2%8B%15%C2%BF%C3%84%C3%9CG%08%C3%A4%C3%A5%C3%BAq4%C2%A5%C2%AE%200x%C2%95B%12%2FH%5B%C3%9E4s%40%C3%A1%C2%98%C3%9A%C2%94W%17%0E8%C2%9C%C3%8D%C3%BB%C3%95%7B%C2%B2Q%40%C2%B95%7B%C3%9Ac%00Vl%C2%A1%5D%C2%BF%04%C2%82%C3%BE%03%C2%9F%01%C2%B4D%C3%B8%10%11%7B7%7CC%40%C2%A43%C2%90C%C2%A0~%0D%0B%5B%C3%B1%C2%A5%C3%B9%C2%83%C2%AE%C2%A2q%00%00%00%00IEND%C2%AEB%60%C2%82"; 1635 | 1636 | var icon_del_hover_str = "%C2%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%18%00%00%00%18%08%06%00%00%00%C3%A0w%3D%C3%B8%00%00%00qIDATx%01%C3%AD%C2%96%01%0A%C2%800%08E%C2%BD%C3%AE%C2%BAA%1DY%0Fa%06%0B%40%C2%A2%C3%9F%C3%B8E%11%02%0F%10%C3%A1%C2%BF9%C2%86L%5C%041%07%16xB%7BON%C2%B8%14%C3%AE%C2%80%C2%85%11h%0F%C2%99%0Ezm%C2%9F%C2%84%11%C3%B8%06%C3%91%C3%8F'%C2%BD%15%7BZ%C2%A0%C3%81%C3%A8%C3%88%C3%A3W%C3%BA%C2%BA%C3%80%C3%92%2BQP%0F%0A%C3%B8%C2%BA%04%25(%C3%81%17%04%1A%18X%1D%06%04%7F%C3%9B%C2%A64%40%C3%90%C3%98%C3%B0%C3%BCAX%01%C3%8FO*%C3%AFm%C3%B7I6%00%00%00%00IEND%C2%AEB%60%C2%82"; 1637 | 1638 | var icon_del_disabled_str = "%C2%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%18%00%00%00%18%08%04%00%00%00J~%C3%B5s%00%00%00hIDATx%C3%9A%C3%AD%C2%94%C2%B1%0E%C2%800%08D%C3%BB%C2%BBu%C2%BB%11%3F%19%3E%02%C2%87%C3%96Z%C2%9BxX%C3%A3d%C3%A4%06B%C3%82%03%C2%86%0B)%0D%01%C2%81%C3%81%C2%AB%14%C2%92x%40Z%C3%B3%C2%AE%C2%95%03%0A%C3%87%C3%92%C2%AA%0C%C2%87r%C3%80%C3%A1%C2%AC%3E%C2%A6%C3%9E%C2%93%C3%8D%02%C3%8AW%C2%B3%C3%93%1E%03%C2%B0%C2%B2%16%3A%C3%A4K%20%C3%88%3F%C3%B0%19%40%C2%8B%C2%85%3B%C2%8B%C3%98%C2%BB%C3%A6%C2%9B%02%22%C2%9D%C2%81%1C%02%C3%B55l4%0CX%C3%85%3B%C2%89%3C%24%00%00%00%00IEND%C2%AEB%60%C2%82"; 1639 | 1640 | var icon_del_disabled_light_theme_str = "%C2%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%18%00%00%00%18%08%04%00%00%00J~%C3%B5s%00%00%00jIDATx%C3%9A%C3%AD%C2%94%C3%91%09%C2%800%0CD%C2%BBn%C3%9D%20.r%3B%26CD%C2%A4%C2%B5j%C3%81%C2%8B%15%C2%BF%C3%84%C3%9CG%08%C3%A4%C3%A5%C3%BAq4%C2%A5%C2%AE%200x%C2%95B%12%2FH%5B%C3%9E4s%40%C3%A1%C2%98%C3%9A%C2%94W%17%0E8%C2%9C%C3%8D%C3%BB%C3%95%7B%C2%B2Q%40%C2%B95%7B%C3%9Ac%00Vl%C2%A1%5D%C2%BF%04%C2%82%C3%BE%03%C2%9F%01%C2%B4D%C3%B8%10%11%7B7%7CC%40%C2%A43%C2%90C%C2%A0~%0D%0Bo%C3%97%7C%C3%BD%C2%93%C3%BALv%00%00%00%00IEND%C2%AEB%60%C2%82"; 1641 | 1642 | var icon_del_normal_light_theme_str = "%C2%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%18%00%00%00%18%08%04%00%00%00J~%C3%B5s%00%00%00jIDATx%C3%9A%C3%AD%C2%94%C3%91%09%C2%800%0CD%3B%C3%96%C2%ADT7%C2%88%23'CD%C2%A4%C2%B5j%C3%81%C2%8B%15%C2%BF%C3%84%C3%9CG%08%C3%A4%C3%A5%C3%BAq4%C2%A5%C2%AE%200x%C2%95B%12%2FH%5B%C3%9E4s%40%C3%A1%C2%98%C3%9A%C2%94W%17%0E8%C2%9C%C3%8D%C3%BB%C3%95%7B%C2%B2Q%40%C2%B95%7B%C3%9Ac%00Vl%C2%A1%5D%C2%BF%04%C2%82%C3%BE%03%C2%9F%01%C2%B4D%C3%B8%10%11%7B7%7CC%40%C2%A43%C2%90C%C2%A0~%0D%0BZT%22q%5B%1F%C3%86%0A%00%00%00%00IEND%C2%AEB%60%C2%82"; 1643 | 1644 | var icon_del_hover = ScriptUI.newImage(File.decode(icon_del_hover_str)); 1645 | var icon_del_normal = ScriptUI.newImage(File.decode(icon_del_normal_str)); 1646 | var icon_del_disabled = ScriptUI.newImage(File.decode(icon_del_disabled_str)); 1647 | var icon_del_normal_light_theme = ScriptUI.newImage(File.decode(icon_del_normal_light_theme_str)); 1648 | var icon_del_disabled_light_theme = ScriptUI.newImage(File.decode(icon_del_disabled_light_theme_str)); 1649 | 1650 | 1651 | 1652 | 1653 | var del_preset_button = presets.add("iconbutton", undefined, icon_del_normal, { name: "del_preset_button", style: "toolbutton" }); 1654 | 1655 | del_preset_button.helpTip = loc({'en':"Delete current preset", 'ru':"Удалить текущий пресет"}); 1656 | 1657 | del_preset_button.size = [22, 22]; 1658 | // del_preset_button.enabled = false; 1659 | 1660 | del_preset_button.onClick = function () { 1661 | 1662 | // alert('4: '+coefs.length); 1663 | coefs.splice(presets_vars_dropdown.selection.index, 1); 1664 | 1665 | 1666 | 1667 | rebuild_dropdown(); 1668 | 1669 | if (coefs.length > 0) { 1670 | 1671 | presets_vars_dropdown.selection = 0; 1672 | presets_vars_dropdown.active = true; 1673 | 1674 | } else { 1675 | presets_vars_dropdown.enabled = false; 1676 | del_preset_button.enabled = false; 1677 | } 1678 | 1679 | }; 1680 | 1681 | del_preset_button.fillBrush = del_preset_button.graphics.newBrush(del_preset_button.graphics.BrushType.SOLID_COLOR, [1, 1, 1, 0.1]); 1682 | 1683 | del_preset_button.onDraw = function (drState) { 1684 | 1685 | if (!this.image) return; 1686 | 1687 | var WH = this.size, 1688 | wh = this.image.size, 1689 | // k = Math.min(WH[0]/wh[0], WH[1]/wh[1]), 1690 | xy; 1691 | 1692 | // var wh2 = [k*wh[0],k*wh[1]]; 1693 | // var xy2 = [ (WH[0]-wh2[0])/2, (WH[1]-wh2[1])/2 ]; 1694 | xy = [(WH[0] - wh[0] / 2) / 2, (WH[1] - wh[1] / 2 - 1) / 2]; 1695 | 1696 | 1697 | if (!del_preset_button.enabled) { 1698 | if (dark_theme) { 1699 | this.graphics.drawImage(icon_del_disabled, xy[0], xy[1], 12, 12); 1700 | } else { 1701 | this.graphics.drawImage(icon_del_disabled_light_theme, xy[0], xy[1], 12, 12); 1702 | } 1703 | } else if (drState.mouseOver) { 1704 | this.graphics.drawOSControl(); 1705 | this.graphics.rectPath(0, 0, this.size[0], this.size[1]); 1706 | this.graphics.fillPath(this.fillBrush); 1707 | this.graphics.drawImage(icon_del_hover, xy[0], xy[1], 12, 12); 1708 | } 1709 | else { 1710 | if (dark_theme) { 1711 | this.graphics.drawImage(this.image, xy[0], xy[1], 12, 12); 1712 | } else { 1713 | this.graphics.drawImage(icon_del_normal_light_theme, xy[0], xy[1], 12, 12); 1714 | } 1715 | } 1716 | 1717 | 1718 | 1719 | WH = wh = xy = null; 1720 | }; 1721 | 1722 | 1723 | 1724 | 1725 | 1726 | 1727 | //OPENING OPTIONS 1728 | var group9 = left_part.add("group", undefined, { name: "group9" }); 1729 | group9.orientation = "column"; 1730 | group9.alignChildren = ["left", "center"]; 1731 | group9.spacing = 0; 1732 | group9.margins = [0, 20, 10, 0]; 1733 | 1734 | 1735 | var profile = group9.add("checkbox", undefined, undefined, { name: "profile" }); 1736 | profile.text = loc({'en':"Show curvature profile", 'ru':"Показывать профиль кривизны"}); 1737 | // silent.text = "Silent running please"; 1738 | // silent.preferredSize.width = 221; 1739 | // profile.helpTip = "Silent running with last selected parameters.\nTo view this dialog again run the script with the Shift key pressed."; 1740 | 1741 | profile.value = show_profile; 1742 | 1743 | profile.onClick = function () { 1744 | echo('SET show_profile TO ' + profile.value); 1745 | show_profile = profile.value; 1746 | 1747 | // update_prefs_from_vars(); 1748 | settings_updated(); 1749 | 1750 | var prof = show_profile ? 6 : 2; 1751 | echo('set show_profile to ' + prof); 1752 | app.preferences.setIntegerPreference('corner_smoothing_script_show_profile', prof); 1753 | 1754 | 1755 | }; 1756 | 1757 | 1758 | 1759 | 1760 | 1761 | 1762 | var silent = group9.add("checkbox", undefined, undefined, { name: "silent" }); 1763 | // silent.text = "Show this dialog only when running the script with the Shift key pressed"; 1764 | silent.text = loc({'en':"Don't show this dialog again", 'ru':"Не показывать больше это окно"}); 1765 | // silent.text = "Silent running please"; 1766 | // silent.preferredSize.width = 221; 1767 | // silent.helpTip = "Show this dialog only when running \nthe script with the Shift key pressed"; 1768 | silent.helpTip = loc({'en':"Silent running with last selected parameters.\nTo view this dialog again run the script with the Shift key pressed.", 'ru':"Тихий запуск с использованием последних установленных параметров.\nДля показа окна настроек вновь надо будет запустить скрипт с зажатым шифтом"}); 1769 | 1770 | silent.value = !ui; 1771 | 1772 | silent.onClick = function () { 1773 | echo('SET UI TO ' + !silent.value); 1774 | ui = !silent.value; 1775 | 1776 | var uii = ui ? 6 : 2; 1777 | echo('set ui to ' + uii); 1778 | app.preferences.setIntegerPreference('corner_smoothing_script_show_ui', uii); 1779 | 1780 | }; 1781 | 1782 | 1783 | 1784 | 1785 | 1786 | 1787 | 1788 | 1789 | 1790 | 1791 | 1792 | 1793 | 1794 | // RIGHT SIDE 1795 | // ======= 1796 | var ok_and_cancel = win.add("group", undefined, { name: "ok_and_cancel" }); 1797 | ok_and_cancel.orientation = "column"; 1798 | ok_and_cancel.alignChildren = ["fill", "top"]; 1799 | ok_and_cancel.spacing = 6; 1800 | ok_and_cancel.margins = [0, 22, 16, 16]; 1801 | 1802 | var ok = ok_and_cancel.add("button", undefined, undefined, { name: "ok" }); 1803 | ok.text = "OK"; 1804 | 1805 | var cancel = ok_and_cancel.add("button", undefined, undefined, { name: "cancel" }); 1806 | cancel.text = loc({'en':"Cancel", 'ru':"Отмена"}); 1807 | 1808 | cancel.onClick = actionCanceled; 1809 | ok.onClick = actionOK; 1810 | 1811 | 1812 | return win; 1813 | } 1814 | 1815 | 1816 | 1817 | 1818 | 1819 | 1820 | 1821 | 1822 | 1823 | 1824 | 1825 | 1826 | 1827 | 1828 | 1829 | 1830 | 1831 | 1832 | 1833 | 1834 | 1835 | 1836 | 1837 | 1838 | 1839 | 1840 | 1841 | 1842 | 1843 | 1844 | 1845 | 1846 | 1847 | // LET`S GO 1848 | 1849 | // Create a log file 1850 | if (debug_mode) { 1851 | //TODO: Windows support 1852 | var logFile = "~/Desktop/corner_smoothig_log.txt"; 1853 | var log_file = new File(logFile); 1854 | log_file.open("w"); 1855 | log_file.encoding = 'UTF-8'; 1856 | } 1857 | 1858 | 1859 | 1860 | 1861 | 1862 | echo('start!'); 1863 | echo(app.locale); 1864 | 1865 | 1866 | // factory_reset(); 1867 | init_configs(); 1868 | 1869 | // the script was run with the shift key pressed? 1870 | if (ScriptUI.environment.keyboardState.shiftKey) { 1871 | // ui = !ui; 1872 | shifted = true; 1873 | } 1874 | 1875 | 1876 | 1877 | var settings = build_ui(); 1878 | 1879 | //Start with the standard parameters 1880 | var so = go(); 1881 | if (so) { 1882 | 1883 | app.redraw(); 1884 | 1885 | // show the settings panel 1886 | if ((ui && !shifted) || (!ui && shifted)) 1887 | settings.show(); 1888 | 1889 | } 1890 | 1891 | 1892 | 1893 | if (debug_mode) { 1894 | log_file.close(); 1895 | } 1896 | --------------------------------------------------------------------------------