Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Example: applying transitions to a widget

The example code shown below shows how to add two scroller transitions on a widget and how to interact with a transition manager. For the scroller transitions to work properly, the target widget must support EVT_WDG_SCROLL.

An application needs to do the following to apply transitions:

  1. Include the required files for transitions and transition manager.
  2. Create the widget to which the transitions will be applied.
  3. Create and initialize the desired transition(s).
  4. (optional) Create and initialize transition manager(s) to organize the transitions.
  5. Query the root container for its transition manager.
  6. Insert the transitions within the root container's transition manager.

An application that wishes to keep track of a transition can do so by adding signals using the ITransition2_OnStep(), ITransition2_OnStart(), and ITransition2_OnEnd() helper functions. Refer to the http://developer.brewmp.com/reference/api-all for more details.

Include files

The following include files are needed to create and use the scroller transitions and the transition manager.

#include "AEEITransitionMgr.h"
#include "AEEITransition2.h"
#include "AEETransition2_Scroller.h"
#include "AEETransition2Helpers.h"
#include "AEETransitionMgrHelpers.h" 

Create a widget and insert it into the root container

This example creates a static widget with a red background, and inserts it into the root container:

   int nErr = 0;   
   WidgetPos WidPos = {0};   
   WidgetExtent we = {0};
   IWidget *piwTargetWidget = NULL;

   // Create a red static widget as the target widget   
   ERR_TRY( ISHELL_CreateInstance(pMe->pIShell, AEECLSID_CStaticWidget,   
               (void**) &piwTargetWidget) );   
   (void) IWidget_SetBGColor(piwTargetWidget, MAKE_RGBA(255,0,0,255));   
   we.height = RESIZER_START_H;   
   we.width  = RESIZER_START_W;   
   IWidget_SetExtent(piwTargetWidget, &we);   
     
   // Insert it into RootContainer   
   WidPos.bVisible = TRUE;   
   WidPos.x = MOVER_START_X;   
   WidPos.y = MOVER_START_Y;   
   ERR_TRY( IRootContainer_Insert(pMe->picRoot, piwTargetWidget, WIDGET_ZNORMAL,    
               &WidPos) );     
   

Create the transitions

The following example gets the root container transition manager and creates two scroll transitions, for vertical and horizontal scrolling:

nErr = IWidget_GetTransitionMgr(piwRoot, &(me->piTrMgr));

if(!nErr && me->piTrMgr) {
   nErr = ISHELL_CreateInstance(me->piShell, AEECLSID_CTransition2_Scroller,
            (void **)&me->piHorzTr);
   if (!nErr) {
      nErr = ISHELL_CreateInstance(me->piShell, AEECLSID_CTransition2_Scroller,
               (void **)&me->piVertTr);
   }
}

Initialize the transitions

In this example, the two scroll transitions are initialized and inserted into the root container's transition manager:

   do {
      (void) IWidget_GetOffsetX(MYWIDGET(me), &me->nLastFlickX);
      (void) IWidget_GetOffsetY(MYWIDGET(me), &me->nLastFlickY);
      if (me->piTrMgr) {
         if (me->piVertTr) {
            (void) ITransitionMgr_Remove(me->piTrMgr, CAST(IQI*, me->piVertTr));
            if (TOUCHOBS_DIR_NONE != me->nVertScrollDir) {
               nErr = Transition2Scroller_Init(me->piVertTr, CAST(IWidget*,
                           &me->widget), me->nScrollSpeed, me->nScrollAccel,
                           me->nVertScrollDir);
               BREAKIF(nErr);
               nErr = ITransition2_SetStepTime(me->piVertTr, me->nStepTime);
               BREAKIF(nErr);
               nErr = ITransition2_SetRuntime(me->piVertTr, me->nTotalScrollTime);
               BREAKIF(nErr);
               nErr = ITransitionMgr_Insert(me->piTrMgr,  me->piVertTr);
               BREAKIF(nErr);
            }
         }
         if (me->piHorzTr) {
            (void) ITransitionMgr_Remove(me->piTrMgr, CAST(IQI*, me->piHorzTr));
            if (TOUCHOBS_DIR_NONE != me->nHorzScrollDir) {
               nErr = Transition2Scroller_Init(me->piHorzTr,
                        CAST(IWidget*, &me->widget), me->nScrollSpeed,
                        me->nScrollAccel, me->nHorzScrollDir);
               BREAKIF(nErr);
               nErr = ITransition2_SetStepTime(me->piHorzTr, me->nStepTime);
               BREAKIF(nErr);
               nErr = ITransition2_SetRuntime(me->piHorzTr, me->nTotalScrollTime);
               BREAKIF(nErr);
               nErr = ITransitionMgr_Insert(me->piTrMgr,  me->piHorzTr);
               BREAKIF(nErr);
            }
         }
      }
   } while (0);