6 Replies Latest reply: May 7, 2013 3:50 AM by bfi616 RSS

    Preview of art objects in real time.

    bfi616

      Hi together,

       

      I'm programming a tool handling with width profile and width markers. I would like to see a preview while I'm editing the width marker values (in real time).

      I'm editing the width of strokes during dragging the mouse in small steps. Each mouse drag event means a small adaption of the widths. The problem is, that I do not see the change during I drag the mouse. I see the change after I release the mouse. Is it possible to update the artwork during dragging the mouse? So that I see the art object changing during I drag the mouse.

       

      Thank you very much

        • 1. Re: Preview of art objects in real time.
          A. Patterson Community Member

          Try AIDocumentSuite::RedrawDocument(), it might do the trick.

          • 2. Re: Preview of art objects in real time.
            bfi616 Community Member

            Thank you for the fast response.

             

            I already tried the AIDocumentSuite::RedrawDocument(), without success. Maybe I use it in a wrong way?

             

            Here are two example code snippets. I reduced the code to show the problem. This code will be executed in the

            ToolMouseDrag function. (For each mouse drag event.) Below are small videos showing how the code acts.

             

            CodeSnippet1)

            //...

            // get selected art object

            // ...

            AIReal fraction = 0.5;

            err = sAIBeautifulStrokes->GetWidthsAtDistance(selectedArt, fraction, 0, &width, &lWidth, &rWidth, &wSource, &mIndex, &mDetails);

            err = sAIBeautifulStrokes->SetCenteredWidthAtDistance(selectedArt, fraction, width+1, kNoWidthMarkerFlags);

            sAIDocument->RedrawDocument();

            //...

             

             

             

            CodeSnippet2)

            //...

            // get selected art object

            // ...

            // Get the partial width at specified length fraction

            AIReal fraction = 0.5;

            err = sAIBeautifulStrokes->GetWidthsAtDistance(selectedArt, fraction, 0, &width, &lWidth, &rWidth, &wSource, &mIndex, &mDetails);

             

            // remove the width profile

            {

                           AIDictionaryRef paramDict = 0;

                           AIStrokeStyle strokeStyle;

                           AIBoolean hasBrush = false;

                           AIReal scaleFactor = 0;

                           AIBoolean canAccept = false;

             

                           err = sAIBeautifulStrokes->GetArtStrokeParams(selectedArt, paramDict, &strokeStyle, &hasBrush, &scaleFactor, &canAccept);

                           sAIBeautifulStrokes->SetCenteredWidthProfile(paramDict, 0, 0);

                           sAIDictionary->Release(paramDict);

            }

             

            // Set changed width at specified length fraction.

            err = sAIBeautifulStrokes->SetCenteredWidthAtDistance(selectedArt, fraction, width+0.5, kNoWidthMarkerFlags);

             

            sAIDocument->RedrawDocument();

            //...

             

             

             

            The second code snippet seems to go in the right direction, but for some reason in this case the width profile seems to be ignored while redrawing. After moving the line it will be drawn correctly. This behavior is very confusing.

            • 3. Re: Preview of art objects in real time.
              bfi616 Community Member

              I have some additional information:

               

              I tried to use the code of CodeSnipped 1 in a filter. (kCallerAIFilter, kSelectorAIGoFilter)

              That works fine!

               

              //...

              // get selected art object

              // ...

              for(int j=0; j<30; j++)

              {

                AIReal fraction = 0.5;

                err = sAIBeautifulStrokes->GetWidthsAtDistance(selectedArt, fraction, 0, &width, &lWidth, &rWidth, &wSource, &mIndex, &mDetails);

                err = sAIBeautifulStrokes->SetCenteredWidthAtDistance(selectedArt, fraction, width+1, kNoWidthMarkerFlags);

               

                sAIDocument->RedrawDocument();

                usleep(20000);

              }

              //...

               

              • 4. Re: Preview of art objects in real time.
                A. Patterson Community Member

                This will sound stupid, but we've found that sometimes we have to call RedrawDocument() twice in a row to get it to properly update. Give that a try and see if it fixes it

                • 5. Re: Preview of art objects in real time.
                  bfi616 Community Member

                  :-( Unfortunately not... I tried to call RedrawDocument() twice in a row, but nothing changed.

                   

                  I tried to run the last posted code in different events. In the events GoFilter, GoTimer, MouseUp, MouseTrack, SelectTool the code works fine and the code acts like shown in the last posted video. But in the events MouseDown and MouseDrag redrawn document appears only after releasing the mouse without intermediate steps.

                  I think there are two possible reasons for that: Either Illustrator blocks redrawing while the mouse is pressed, or the content for redrawing will not be updated while the mouse is pressed, so that redrawing result does not change while the mouse is pressed.

                   

                  I tried also another approach. The idea was to outline the stroke after each step of width change, to be able to draw an annotation representing the changed stroke. But this approach faild also. The outline after each width change was always the same. That why I think that the changed width profile will be applied after releasing the mouse.

                   

                  ...have no idea how to solve that :-(

                  • 6. Re: Preview of art objects in real time.
                    bfi616 Community Member

                    I noticed something new what could be a hint. The following screen record shows the behavior of the first CodeSnippet above.

                    But in this record a progress bar appears for a very short time when I release the mouse (00:22). The message of the progress bar is "Applying Art Brush". Illustrator seems to apply the brush to the stroke after I release the mouse button. I guess this is the step I need to do before RedrawDocument(). But I do not know how? Does someone have an idea how to "Apply Art Brush"?