About   |   Getting Started   |   Downloads   |   Documentation   |   Forum


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
modal dialog preview
01-17-2018, 11:43 AM
Post: #1
modal dialog preview
How could one add a preview option to a modal dialog to show the result of its settings before the user commits with the OK button? Perhaps a future CORE release could demonstrate that in the Tool sample project.
Find all posts by this user
Quote this message in a reply
01-18-2018, 05:12 PM
Post: #2
RE: modal dialog preview
(01-17-2018 11:43 AM)Rick Johnson Wrote:  How could one add a preview option to a modal dialog to show the result of its settings before the user commits with the OK button? Perhaps a future CORE release could demonstrate that in the Tool sample project.

This isn't possible in Illustrator. A modal dialog, by definition, blocks the main thread of the app, and it is within this thread that all communication with Illustrator must occur. If it works for your use case, a floating dialog can be used instead, since it does not block the main thread (we do this in a plugin or two ourselves).
Find all posts by this user
Quote this message in a reply
01-18-2018, 07:25 PM
Post: #3
RE: modal dialog preview
Hmmm, that confirms my understanding of a modal dialog, but I'm stumped by the preview option in Illustrator's Transform Each, Path > Simplify, and other windows. I wonder how they did that, and if a similar behavior could be accomplished entirely, or at least mostly, within CORE.
Find all posts by this user
Quote this message in a reply
04-02-2018, 04:25 PM
Post: #4
RE: modal dialog preview
Wait, it CAN be done!

In a callback for e.g. a text field called when settings change, add something like this:

Code:
    this->myModalDlg.dismiss();
    goDrawStuff();
    HDI_CORE_ILLUSTRATOR->currentDocument()->redraw();
    this->myModalDlg.show();

Of course, you'll want to add more code so the temporary art is removed after each update or cancel, but kept if the user clicks OK. At least with simple art redraws there's no discernible flickering of the dialog.

Simple, but by golly, it works! :-)
Find all posts by this user
Quote this message in a reply
04-08-2018, 02:00 PM (This post was last modified: 04-09-2018 03:58 PM by Rick Johnson.)
Post: #5
RE: modal dialog preview
I implemented a checkbox to turn previewing on, but its behavior is a bit erratic. The checkbox's callback dismisses and then shows the dialog, then it seems to forget it has a callback until clicked again several times. When it does get called, it works correctly. Reassigning the callback with PreviewChk.setClickCallback(...)) at the end of the callback doesn't help. The stepper widget may provide some clues. If the dialog is dismissed and then shown again, on the first click it gets "stuck" in the pressed position, then the second click calls the callback just fine.

Code:
// some variables declared in the .hpp header
hdi::core::ModalDialog modalDlg
hdi::core::Checkbox PreviewChk
hdi::core::Art previewArt
bool PreviewOn;
hdi::core::Art goDrawSomething();

// the checkbox's callback in the .cpp file
void thePlugin::Plugin::__doPreviewChkCB(){
    this->modalDlg.dismiss();
    this->PreviewOn = (this->PreviewChk.state() == hdi::core::Checkbox::StateOn);
    if (!this->previewArt.isEmpty())
        this->previewArt.dispose();
    if (this->PreviewOn)
        this->previewArt = goDrawSomething();
    HDI_CORE_ILLUSTRATOR->currentDocument()->redraw();
    this->modalDlg.show();
}

Is it possible that some context operations could solve this issue? Hot Door's NitPicker has a preview function; is that done with annotations?

For the benefit of others, the OK and Cancel callbacks work fine. The callback for Cancel deletes this->previewArt if it exists. The callback for OK deletes this->previewArt if it exists, then calls goDrawSomething();
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)