ILOG
Welcome, Guest | Sign In


Blogs | Forums | Worldwide sites | Contact us

title element1
Product Info
Features
Tutorial
Datasheet
Supported platforms
Technical Forum
Solutions
Customers
News & Events
Press releases
Trial & Purchase
Demos
Evals
Contact info
Tutorial  

2D Graphics

This step demonstrates interaction with graphic objects. We will use a new class: an interactor. The interactors are used to manage the interactions with graphic objects. One of them will be shown here (the selection interactor), but more than 50 other interactors are available with the product, and developers can define their own.

If you run the sample and click on the rectangle, you should now see this:
 

Download Step 2 executable (ZIP, 336 KB).

The only changes from the previous step are the following:
 
 IlvSelectInteractor* selector = new IlvSelectInteractor(manager, view);
This line of code creates a selection interactor, by providing the manager and the view where we want to have the selection behavior. An interactor is dedicated to a specific manager in a specific view.
 
 manager->setInteractor(selector, view);
You can now set the interactor on the view. It will be applied to every object displayed in this view. With the selection interactor, every object will be selectable, moveable, resizable and destroyable. You can select any object by clicking on it (you see eight handles around it), resize it using the handles, and destroy it by pressing the "Del" key.
 
 manager->addAccelerator(QuitAccel, IlvKeyDown, 'q');
This new accelerator allows the user to trigger an action by pressing the 'q' key. This is done with the addAccelerator method, by providing the following information:

  • The function to be called when the action is triggered: the QuitAccel function is described below.
  • The event type: here you use a keyboard key (event type is IlvKeyDown). Other types are available for other kinds of events.
  • The event data: for an IlvKeyDown event, the data is the keyboard key that will trigger the action.
  • Now let's examine the QuitAccel function:
     
    static void QuitAccel(IlvManager* mgr, IlvView* view, IlvEvent& event, IlvAny userArg) 
     { 
      IlvDisplay* display = mgr->getDisplay(); 
      delete display; 
      IlvExit(0); 
     } 
    This function receives the manager and the view where the event took place, the event itself, and a user argument that can be provided when the accelerator is defined. The body of this function simply gets the display from the manager, deletes it and exits the application. Pressing the 'q' key now exits the application at any time.

    Conclusion
    At this point, you can see how easy it is to develop interactive applications. This example is still very simple (less than 30 lines of code), but it shows how ILOG Views manages graphic objects and user interactions.

    Download source code.

    Learn More
        Features  
        Charts  
        Maps  
        Graph Layout  
        Controls  
        Data Access  
        Gantt Chart  
         
    ILOG JViews Diagrammer
    (includes Graph Layout)
    ILOG JViews Maps
    ILOG JViews Gantt
    ILOG JViews Charts
    ILOG JViews Telecom Graphic Objects
    ILOG JViews Maps for Defense
    Customer Spotlight
       
         
     
     
    element3