Skip to main content
Another_Andrew
Inspiring
November 5, 2010
Answered

CS4 drawing frameless lines on a document

  • November 5, 2010
  • 2 replies
  • 793 views

I'm looking for a way of drawing lines (or splines) onto a document (pages and pasteboard) that are purely informational and cannot be interacted with by the user.

In the programming guide in the graphics fundamentals section they show how to work with paths. But these paths need to be drawn within a frame. This makes the paths an object on the document that is selectable by the user. I'm not after this.

I'd like a way of drawing a coloured rectangle on a document in a way that brings attention to an area on a document but doesn't accept selection events nor interfers with the interactions of framed objects (images, text,...) within the area.

It would be great if it "floated" above the document, so that people could work in the area and not cover it up, using it as a guide to their tasks.

Has anyone seen any examples on how to do this? or have some thoughts on how it could be done?

This topic has been closed for replies.
Correct answer D¡rk Becker

Seach the SDK for draweventhandler or IDrwEvtHandler ...

Dirk

2 replies

Inspiring
November 5, 2010

Maybe page item adorners would work, this depends on where would you want draw splines and whether they would be connected with items that already are on page.

Inspiring
November 5, 2010

Some kinds of adornments are unexpectedly "model" in the sense that their class IDs is stored within a persistent list, thereby introducing a dependency from documents to that plugin. A very sneaky, IMO bug. I don't know whether it has been fixed since I last ran into it.

Dirk

D¡rk BeckerCorrect answer
Inspiring
November 5, 2010

Seach the SDK for draweventhandler or IDrwEvtHandler ...

Dirk

Another_Andrew
Inspiring
November 8, 2010

I don't know how much I've looked through the SDK samples but I just never parsed "Drw" as "Draw".

Sometimes you just don't see what's right in front of you.

Thanks for the pointer to IDrwEvtHandler.

A quick search brought up the BasicDrwEvtHandler sample project.

With a little work I should get this going nicely for what I want.

In case people are curious, after implementing the draw event handler/service in the BasicDrwEvtHandler I made some changes to the draw event handler.

In the HandleEvent() method, I made two changes. The first was:

// What event occurred?  Look it up by event ID in our registration list.
bool isDrawEvent = false;  // added
int32 index = ::FindLocation(fSupportedEventIDs, eventID);
if (index >= 0)
{
    // Received one of the events for which BscDEH is registered.
    // Output the corresponding string to trace
    whatWeGot.Append(fSupportedEventIDs[index].Value());
    if (fSupportedEventIDs[index] == ClassID(kEndPageMessage)) // added
    {                                   // added

        isDrawEvent = true; // added

    }                                  // added

    ....

with the second being:

// If it's not PDF or print, it must be screen drawing
if (contextFound == kFalse)
{
    whatWeGot.Append(" Screen Drawing");
    contextFound = kTrue;

    //added vvvvvvv  
    if ((isDrawEvent) && (gdp != nil))
    {
        InterfacePtr<IGraphicsPort> gPort(gdp->GetGraphicsPort(), UseDefaultIID());
        if (gPort != nil)
        {
             IDocument* document = Utils<ILayoutUIUtils>()->GetFrontDocument();
             if (document != nil)
             {
                 IDataBase *database = GetUIDRef(document).GetDataBase();
                 InterfacePtr<ISpreadList> spreadList(document, UseDefaultIID());
                 if ((database != nil) && (spreadList != nil))
                 {
                     int32 spreadCount = spreadList->GetSpreadCount();
                     for (int spreadIndex = 0; spreadIndex < spreadCount; ++spreadIndex)
                     {
                         UIDRef spreadUIDRef(database, spreadList->GetNthSpreadUID(spreadIndex));
                         InterfacePtr<ISpread> spread(spreadUIDRef, UseDefaultIID());
                         for (int32 pageIndex = 0; pageIndex < spread->GetNumPages(); ++pageIndex)
                         {
                             InterfacePtr<IGeometry> pageGeo(spread->QueryNthPage(pageIndex));

                             if (pageGeo != nil)
                             {
                                 PMRect boundBox = pageGeo->GetStrokeBoundingBox();
                                 PMPoint origin = boundBox.LeftBottom();
                                 TransformInnerPointToPasteboard(pageGeo, &origin);

                                 gPort->gsave();
                                 gPort->setlinewidth(PMReal(3));
                                 gPort->setrgbcolor(PMReal(0.0), PMReal(1.0), PMReal(0.0));
                
                                 gPort->moveto(origin.X(), origin.Y() - boundBox.Height() / 2.0);
                                 gPort->lineto(origin.X() + boundBox.Width(), origin.Y() + boundBox.Height() / 2.0);
                                 gPort->stroke();


                                 gPort->moveto(origin.X() + boundBox.Width(), origin.Y() - boundBox.Height() / 2.0);
                                 gPort->lineto(origin.X(), origin.Y() + boundBox.Height() / 2.0);
                                 gPort->stroke();

                                 gPort->grestore();
                             }
                          }
                      }

                 }
             }

         }

    }

    // added ^^^^^^^^^
}

The above is a bit rough (Its function is to place a big green X on all the pages in a document.) but as a proof of concept it's something that I can make good use of.