• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

pointer.c

Go to the documentation of this file.
00001 /****************** COPYRIGHT (C) 2007-2010 RAISONANCE S.A.S. *****************/
00018 /******************************************************************************/
00019 
00020 /* Includes ------------------------------------------------------------------*/
00021 #include "circle.h"
00022 
00024 
00025 /* Private define ------------------------------------------------------------*/
00026 #define POS_MIN                     0
00027 #define POS_MAX                     (Screen_Width - POINTER_WIDTH - 1)
00028 #define POINTER_DIVIDER             50
00029 #define POINTER_DEFAULT_COLOR       RGB_BLUE
00030 
00031 // defines for pointer move
00032 #define ANGLEPAUSE                  500
00033 #define DEFAULT_ANGLESTART          25
00034 #define MIN_ANGLE_FOR_SHIFT_UP      (ANGLEPAUSE+CurrentAngleStart)
00035 #define MIN_ANGLE_FOR_SHIFT_DOWN    (ANGLEPAUSE-CurrentAngleStart)
00036 #define MIN_ANGLE_FOR_SHIFT_RIGHT   (signed)(0+CurrentAngleStart)
00037 #define MIN_ANGLE_FOR_SHIFT_LEFT    (signed)(0-CurrentAngleStart)
00038 #define DEFAULT_SPEED_ON_ANGLE      60
00039 
00040 // define for joystick management
00041 #define JOY_MAXBTIME    20
00042 #define JOY_HIGH_SPEED  5
00043 #define JOY_LOW_SPEED   1
00044 
00045 /* Private variables ---------------------------------------------------------*/
00046 CONST_DATA          u8 BallPointerBmp[POINTER_WIDTH] = { 0x38, 0x7C, 0xFF, 0xFF, 0xFF, 0x7C, 0x38 } ;
00047 
00048 tAppPtrMgr Application_Pointer_Mgr = 0;
00049 
00050 //u8                  locbuf[POINTER_WIDTH];
00051 u8                  DefaultAreaStore[2 * POINTER_WIDTH* POINTER_WIDTH];
00052 
00053 // Variables for pointer.
00054 const u8*           CurrentPointerBmp                = 0;
00055 coord_t             CurrentPointerWidth              = 0;
00056 coord_t             CurrentPointerHeight             = 3;
00057 s16                 CurrentSpeedOnAngle              = DEFAULT_SPEED_ON_ANGLE;
00058 s32                 CurrentAngleStart                = DEFAULT_ANGLESTART;
00059 u8*                 ptrAreaStore                     = DefaultAreaStore;
00060 color_t             CurrentPointerColor              = POINTER_DEFAULT_COLOR;
00061 enum POINTER_mode   Pointer_Mode                     = POINTER_UNDEF;
00062 enum POINTER_state  Pointer_State                    = POINTER_S_UNDEF;
00063 
00064 coord_t             OUT_X;
00065 coord_t             OUT_Y;
00066 
00067 // Variables for joystick
00068 enum JOYSTICK_state JoyPos;
00069 u16                 JoyDelay                         = 0;
00070 u16                 JoyInc                           = 1;
00071 
00072 // Init pointer Info Structure (structure definition in circle.h)
00073 tPointer_Info       POINTER_Info;
00074 
00075 /* Private function prototypes -----------------------------------------------*/
00076 
00077 /* Private functions ---------------------------------------------------------*/
00078 
00079 /*******************************************************************************
00080 *
00081 *                                POINTER_JoyTch
00082 *
00083 *******************************************************************************/
00091 /******************************************************************************/
00092 NODEBUG2 s32 POINTER_JoyTch( void )
00093 {
00094 #if JOYSTICK_AVAIL
00095     //-- Option management of the pointer by the joystick
00096     if ( JoystickAsInput )
00097     {
00098         JoyPos = JOYSTICK_GetState();
00099         switch ( JoyPos )
00100         {
00101         case JOYSTICK_DOWN:
00102             POINTER_Info.shift_PosX = 0;
00103             POINTER_Info.shift_PosY = -JoyInc ;
00104             break;
00105         case JOYSTICK_UP:
00106             POINTER_Info.shift_PosX = 0;
00107             POINTER_Info.shift_PosY =  JoyInc;
00108             break;
00109         case JOYSTICK_LEFT:
00110             POINTER_Info.shift_PosX = -JoyInc;
00111             POINTER_Info.shift_PosY = 0;
00112             break;
00113         case JOYSTICK_RIGHT_UP:
00114             POINTER_Info.shift_PosX =  JoyInc;
00115             POINTER_Info.shift_PosY =  JoyInc;
00116             break;
00117         case JOYSTICK_RIGHT:
00118             POINTER_Info.shift_PosX =  JoyInc;
00119             POINTER_Info.shift_PosY = 0;
00120             break;
00121         case JOYSTICK_RIGHT_DOWN:
00122             POINTER_Info.shift_PosX =  JoyInc;
00123             POINTER_Info.shift_PosY = -JoyInc;
00124             break;
00125         case JOYSTICK_LEFT_UP:
00126             POINTER_Info.shift_PosX = -JoyInc;
00127             POINTER_Info.shift_PosY =  JoyInc;
00128             break;
00129         case JOYSTICK_LEFT_DOWN:
00130             POINTER_Info.shift_PosX = -JoyInc;
00131             POINTER_Info.shift_PosY = -JoyInc;
00132             break;
00133         default:
00134             break;
00135         }
00136 
00137         if ( JoyPos != JOYSTICK_RELEASED )
00138             JoyDelay++;
00139         else
00140             JoyDelay = 0;
00141 
00142         if ( JoyDelay >= WEIGHTED_TIME( JOY_MAXBTIME ) )
00143             JoyInc = JOY_HIGH_SPEED;
00144         else
00145             JoyInc = JOY_LOW_SPEED;
00146     }
00147 #endif //JOYSTICK_AVAIL
00148 
00149 #if TOUCHSCREEN_AVAIL
00150 
00151     //-- Option management of the pointer by the Touchscreen
00152     if ( TchscrAsInput )
00153     {
00154         if ( ( TOUCHSCR_Info.xPos > 2 ) || ( TOUCHSCR_Info.yPos > 2 ) )
00155         {
00156             switch ( LCD_GetScreenOrientation() )
00157             {
00158             case V3 :
00159                 if ( TOUCHSCR_Info.xPos < PHYS_SCREEN_WIDTH + CurrentPointerWidth )
00160                 {
00161                     TOUCHSCR_SetMode( TS_POINTER );
00162                     POINTER_Info.xPos = TOUCHSCR_Info.xPos - 2 * POINTER_WIDTH / 3 ; // To have the bottom left hand corner point of the pointer
00163                     POINTER_Info.yPos = TOUCHSCR_Info.yPos - 2 * POINTER_WIDTH / 3 ; // To have the bottom left hand corner point of the pointer
00164                 }
00165                 break;
00166             case V6 :
00167                 if ( TOUCHSCR_Info.yPos > 0 )
00168                 {
00169                     TOUCHSCR_SetMode( TS_POINTER );
00170                     POINTER_Info.xPos = TOUCHSCR_Info.xPos - 2 * POINTER_WIDTH / 3 ; // To have the bottom left hand corner point of the pointer
00171                     POINTER_Info.yPos = TOUCHSCR_Info.yPos - 2 * POINTER_WIDTH / 3 ; // To have the bottom left hand corner point of the pointer
00172                 }
00173                 break;
00174             case V9 :
00175                 if ( TOUCHSCR_Info.xPos > 0 )
00176                 {
00177                     TOUCHSCR_SetMode( TS_POINTER );
00178                     POINTER_Info.xPos = TOUCHSCR_Info.xPos - 2 * POINTER_WIDTH / 3 ; // To have the bottom left hand corner point of the pointer
00179                     POINTER_Info.yPos = TOUCHSCR_Info.yPos - 2 * POINTER_WIDTH / 3 ; // To have the bottom left hand corner point of the pointer
00180                 }
00181                 break;
00182 
00183             case V12 :
00184                 if ( TOUCHSCR_Info.yPos < PHYS_SCREEN_HEIGHT + CurrentPointerHeight )
00185                 {
00186                     TOUCHSCR_SetMode( TS_POINTER );
00187                     POINTER_Info.xPos = TOUCHSCR_Info.xPos - 2 * POINTER_WIDTH / 3 ; // To have the bottom left hand corner point of the pointer
00188                     POINTER_Info.yPos = TOUCHSCR_Info.yPos - 2 * POINTER_WIDTH / 3 ; // To have the bottom left hand corner point of the pointer
00189                 }
00190                 break;
00191             }
00192         }
00193     }
00194 
00195 #endif //TOUCHSCREEN_AVAIL
00196 
00197     //-- Option management of the pointer also by the mems
00198     if ( ( ( MemsAsInput && ( JoyPos == JOYSTICK_RELEASED ) ) || !JoystickAsInput ) && !( TchscrAsInput ) )
00199     {
00200         return TRUE;
00201     }
00202 
00203 #if JOYSTICK_AVAIL
00204     return FALSE;
00205 #else
00206     return TRUE;
00207 #endif
00208 }
00209 
00210 
00211 /*******************************************************************************
00212 *
00213 *                                Pointer_Move
00214 *
00215 *******************************************************************************/
00223 /******************************************************************************/
00224 static bool POINTER_Move( void )
00225 {
00226     s16 oldPointer_xPos        = POINTER_Info.xPos;
00227     s16 oldPointer_yPos        = POINTER_Info.yPos;
00228     signed outx                = MEMS_Info.OutX;
00229     signed outy                = MEMS_Info.OutY;
00230 
00231     POINTER_Info.shift_PosX  =  POINTER_Info.shift_PosY  = 0;
00232 
00233     if ( POINTER_JoyTch() != 0 )  // If Joystick used as input
00234     {
00235         // The move depends on the screen orientation
00236         switch ( LCD_GetScreenOrientation() )
00237         {
00238             // north
00239         case V12 :
00240             MEMS_Info.RELATIVE_X = outx;
00241             MEMS_Info.RELATIVE_Y = outy;
00242 
00243             if ( outx > MIN_ANGLE_FOR_SHIFT_RIGHT )
00244             {
00245                 POINTER_Info.shift_PosX = ( outx - MIN_ANGLE_FOR_SHIFT_RIGHT );
00246             }
00247             else if ( outx < MIN_ANGLE_FOR_SHIFT_LEFT )
00248             {
00249                 POINTER_Info.shift_PosX  = ( outx - MIN_ANGLE_FOR_SHIFT_LEFT );
00250             }
00251 
00252             if ( outy < -MIN_ANGLE_FOR_SHIFT_UP )
00253             {
00254                 POINTER_Info.shift_PosY = ( outy + MIN_ANGLE_FOR_SHIFT_UP );
00255             }
00256             else if ( outy > -MIN_ANGLE_FOR_SHIFT_DOWN )
00257             {
00258                 POINTER_Info.shift_PosY = ( outy + MIN_ANGLE_FOR_SHIFT_DOWN );
00259             }
00260             break;
00261 
00262             // West
00263         case V9 :
00264             MEMS_Info.RELATIVE_X = -( outy );
00265             MEMS_Info.RELATIVE_Y = outx;
00266 
00267             if ( outy > MIN_ANGLE_FOR_SHIFT_RIGHT )
00268             {
00269                 POINTER_Info.shift_PosX = -( outy - MIN_ANGLE_FOR_SHIFT_RIGHT );
00270             }
00271             else if ( outy < MIN_ANGLE_FOR_SHIFT_LEFT )
00272             {
00273                 POINTER_Info.shift_PosX = -( outy - MIN_ANGLE_FOR_SHIFT_LEFT );
00274             }
00275 
00276             if ( outx < -MIN_ANGLE_FOR_SHIFT_UP )
00277             {
00278                 POINTER_Info.shift_PosY = ( outx + MIN_ANGLE_FOR_SHIFT_UP );
00279             }
00280             else if ( outx > -MIN_ANGLE_FOR_SHIFT_DOWN )
00281             {
00282                 POINTER_Info.shift_PosY = ( outx + MIN_ANGLE_FOR_SHIFT_DOWN );
00283             }
00284             break;
00285 
00286             // South
00287         case V6 :
00288             MEMS_Info.RELATIVE_X = -( outx );
00289             MEMS_Info.RELATIVE_Y = -( outy );
00290 
00291             if ( outx > MIN_ANGLE_FOR_SHIFT_RIGHT )
00292             {
00293                 POINTER_Info.shift_PosX = ( MIN_ANGLE_FOR_SHIFT_RIGHT - outx );
00294             }
00295             else if ( outx < MIN_ANGLE_FOR_SHIFT_LEFT )
00296             {
00297                 POINTER_Info.shift_PosX = ( MIN_ANGLE_FOR_SHIFT_LEFT - outx );
00298             }
00299 
00300             if ( outy > MIN_ANGLE_FOR_SHIFT_UP )
00301             {
00302                 POINTER_Info.shift_PosY = -( outy - MIN_ANGLE_FOR_SHIFT_UP );
00303             }
00304             else if ( outy < MIN_ANGLE_FOR_SHIFT_DOWN )
00305             {
00306                 POINTER_Info.shift_PosY = +( MIN_ANGLE_FOR_SHIFT_DOWN - outy );
00307             }
00308             break;
00309 
00310             // East
00311         case V3 :
00312             MEMS_Info.RELATIVE_X = outy;
00313             MEMS_Info.RELATIVE_Y = -( outx );
00314 
00315             if ( outy > MIN_ANGLE_FOR_SHIFT_RIGHT )
00316             {
00317                 POINTER_Info.shift_PosX = ( outy - MIN_ANGLE_FOR_SHIFT_RIGHT );
00318             }
00319             else if ( outy < MIN_ANGLE_FOR_SHIFT_LEFT )
00320             {
00321                 POINTER_Info.shift_PosX = ( outy - MIN_ANGLE_FOR_SHIFT_LEFT );
00322             }
00323 
00324             if ( outx > MIN_ANGLE_FOR_SHIFT_UP )
00325             {
00326                 POINTER_Info.shift_PosY = ( MIN_ANGLE_FOR_SHIFT_UP - outx );
00327             }
00328             else if ( outx < MIN_ANGLE_FOR_SHIFT_DOWN )
00329             {
00330                 POINTER_Info.shift_PosY = ( MIN_ANGLE_FOR_SHIFT_DOWN - outx );
00331             }
00332 
00333         default :
00334             break;
00335         }
00336 
00337         POINTER_Info.shift_PosX /= CurrentSpeedOnAngle;
00338         POINTER_Info.shift_PosY /= CurrentSpeedOnAngle;
00339     }
00340 
00341     if ( Pointer_Mode == POINTER_APPLICATION )
00342     {
00343         if ( Application_Pointer_Mgr )
00344         {
00345             Application_Pointer_Mgr( POINTER_Info.shift_PosX, POINTER_Info.shift_PosY );
00346         }
00347 
00348         return 0;
00349     }
00350 
00351     POINTER_Info.xPos += POINTER_Info.shift_PosX;
00352     POINTER_Info.yPos += POINTER_Info.shift_PosY;
00353 
00354     if ( POINTER_Info.xPos < POINTER_Info.X_PosMin )
00355     {
00356         POINTER_Info.xPos = POINTER_Info.X_PosMin;
00357     }
00358 
00359     if ( POINTER_Info.xPos > POINTER_Info.X_PosMax )
00360     {
00361         POINTER_Info.xPos = POINTER_Info.X_PosMax;
00362     }
00363 
00364     if ( POINTER_Info.yPos < POINTER_Info.Y_PosMin )
00365     {
00366         POINTER_Info.yPos = POINTER_Info.Y_PosMin;
00367     }
00368 
00369     if ( POINTER_Info.yPos > POINTER_Info.Y_PosMax )
00370     {
00371         POINTER_Info.yPos = POINTER_Info.Y_PosMax;
00372     }
00373 
00374     if ( ( Pointer_Mode != POINTER_MENU ) && ( Pointer_Mode != POINTER_RESTORE_LESS ) &&
00375             ( ( oldPointer_xPos != POINTER_Info.xPos ) || ( oldPointer_yPos != POINTER_Info.yPos ) ) )
00376     {
00377         // Use default area.
00378         POINTER_SetCurrentAreaStore( 0 );
00379 
00380         // Restore previously drawn area.
00381         POINTER_Restore( oldPointer_xPos, oldPointer_yPos, POINTER_WIDTH, POINTER_WIDTH );
00382 
00383         // Save new area and draw pointer
00384         POINTER_Save( POINTER_Info.xPos, POINTER_Info.yPos, POINTER_WIDTH, POINTER_WIDTH );
00385         POINTER_Draw( POINTER_Info.xPos, POINTER_Info.yPos, POINTER_WIDTH, POINTER_WIDTH, CurrentPointerBmp );
00386     }
00387 
00388     if ( ( Pointer_Mode == POINTER_RESTORE_LESS ) &&
00389             ( ( oldPointer_xPos != POINTER_Info.xPos ) || ( oldPointer_yPos != POINTER_Info.yPos ) ) )
00390     {
00391         // Use default area.
00392         POINTER_SetCurrentAreaStore( 0 );
00393 
00394         // Restore previously drawn area.
00395         POINTER_Restore( oldPointer_xPos, oldPointer_yPos, CurrentPointerWidth, CurrentPointerHeight );
00396 
00397         // Save new area and draw pointer
00398         POINTER_Save( POINTER_Info.xPos, POINTER_Info.yPos, CurrentPointerWidth, CurrentPointerHeight );
00399         POINTER_Draw( POINTER_Info.xPos, POINTER_Info.yPos, CurrentPointerWidth, CurrentPointerHeight, CurrentPointerBmp );
00400     }
00401 
00402     // Is the pointer touching one edge of the screen ?
00403     if ( ( POINTER_Info.xPos == POS_MIN ) || ( POINTER_Info.yPos == POS_MIN ) ||
00404             ( POINTER_Info.xPos == POS_MAX ) || ( POINTER_Info.yPos == POS_MAX ) )
00405     {
00406         return -1;
00407     }
00408 
00409     return 0;
00410 }
00411 
00412 /* Public functions for CircleOS ---------------------------------------------*/
00413 
00414 /*******************************************************************************
00415 *
00416 *                                POINTER_Init
00417 *
00418 *******************************************************************************/
00426 /******************************************************************************/
00427 NODEBUG2 void POINTER_Init( void )
00428 {
00429     POINTER_Info.xPos = ( Screen_Width / 2 ) - ( POINTER_WIDTH / 2 ) - 1;
00430     POINTER_Info.yPos = ( Screen_Width / 2 ) - ( POINTER_WIDTH / 2 ) - 1;
00431     POINTER_Info.shift_PosX = 0;
00432     POINTER_Info.shift_PosY = 0;
00433 
00434     // Increase pointer sensibility.
00435     POINTER_SetCurrentSpeedOnAngle( DEFAULT_SPEED_ON_ANGLE );
00436     POINTER_SetCurrentAngleStart( DEFAULT_ANGLESTART );
00437     POINTER_SetRectScreen();
00438     POINTER_SetCurrentPointer( POINTER_WIDTH, POINTER_WIDTH, BallPointerBmp );
00439     POINTER_SetMode( POINTER_ON );
00440 //    POINTER_SetPos( 0x3c, 0x3c );   //FL081103 very first drawing was dirty!
00441     // YRT091120 : second pointer appears
00442 
00443     CurrentPointerColor = POINTER_DEFAULT_COLOR;
00444 }
00445 
00446 /*******************************************************************************
00447 *
00448 *                                POINTER_Handler
00449 *
00450 *******************************************************************************/
00458 /******************************************************************************/
00459 void POINTER_Handler( void )
00460 {
00461     static divider_t dividr = 0;
00462 
00463     // Goes into handler only every POINTER_DIVIDER calls.
00464     if ( ++dividr % WEIGHTED_TIME( POINTER_DIVIDER ) )
00465     {
00466         return;
00467     }
00468 
00469     switch ( Pointer_Mode )
00470     {
00471         // Nothing to do!
00472     case POINTER_OFF  :
00473     case POINTER_UNDEF:
00474         return;
00475     }
00476 
00477 #if MEMS_POINTER     // Not necessary if no MEMS menu handling
00478     // Where is the MEMS ?
00479     MEMS_GetPosition( &OUT_X, &OUT_Y );
00480 #endif
00481 
00482     /*
00483     DRAW_DisplayString  ( 20, 200, "X=" , 3);
00484     UTIL_int2str  ( buffer,  OUT_X, 4, 0);
00485     DRAW_DisplayString  ( 40, 200, buffer , 4);
00486 
00487     DRAW_DisplayString  ( 20, 180, "Y=" , 3);
00488     UTIL_int2str  ( buffer,  OUT_Y, 4, 0);
00489     DRAW_DisplayString  ( 40, 180, buffer , 4);
00490     */
00491 
00492     POINTER_Move();
00493 }
00494 
00496 
00497 /* Public functions ----------------------------------------------------------*/
00498 
00499 /*******************************************************************************
00500 *
00501 *                                POINTER_SetCurrentPointer
00502 *
00503 *******************************************************************************/
00514 /********************************************************************************/
00515 void POINTER_SetCurrentPointer( coord_t width, coord_t height, const u8* bmp )
00516 {
00517     if ( !bmp )
00518     {
00519         bmp = BallPointerBmp;
00520     }
00521 
00522     // Update the area limits for the new pointer depending on its size
00523     POINTER_SetRect( POINTER_Info.X_PosMin, POINTER_Info.Y_PosMin,
00524                      POINTER_Info.X_PosMax - POINTER_Info.X_PosMin + CurrentPointerWidth - width,
00525                      POINTER_Info.Y_PosMax - POINTER_Info.Y_PosMin + CurrentPointerHeight - height );
00526 
00527     CurrentPointerWidth  = width;
00528     CurrentPointerHeight = height;
00529     CurrentPointerBmp    = bmp;
00530 }
00531 
00532 /*******************************************************************************
00533 *
00534 *                                POINTER_GetCurrentAngleStart
00535 *
00536 *******************************************************************************/
00544 /******************************************************************************/
00545 s16 POINTER_GetCurrentAngleStart( void )
00546 {
00547     return CurrentAngleStart;
00548 }
00549 
00550 /*******************************************************************************
00551 *
00552 *                                POINTER_SetCurrentAngleStart
00553 *
00554 *******************************************************************************/
00562 /******************************************************************************/
00563 void POINTER_SetCurrentAngleStart( u16 newangle )
00564 {
00565     CurrentAngleStart = newangle;
00566 }
00567 
00568 /*******************************************************************************
00569 *
00570 *                                POINTER_GetCurrentSpeedOnAngle
00571 *
00572 *******************************************************************************/
00580 /******************************************************************************/
00581 u16 POINTER_GetCurrentSpeedOnAngle( void )
00582 {
00583     return CurrentSpeedOnAngle;
00584 }
00585 
00586 /*******************************************************************************
00587 *
00588 *                                POINTER_SetCurrentSpeedOnAngle
00589 *
00590 *******************************************************************************/
00598 /******************************************************************************/
00599 void POINTER_SetCurrentSpeedOnAngle( u16 newspeed )
00600 {
00601     CurrentSpeedOnAngle = newspeed;
00602 }
00603 
00604 /*******************************************************************************
00605 *
00606 *                                POINTER_SetCurrentAreaStore
00607 *
00608 *******************************************************************************/
00621 /******************************************************************************/
00622 void POINTER_SetCurrentAreaStore( u8* ptr )
00623 {
00624     ptrAreaStore = ( ptr == 0 ) ? DefaultAreaStore : ptr;
00625 }
00626 
00627 /*******************************************************************************
00628 *
00629 *                                POINTER_SetMode
00630 *
00631 *******************************************************************************/
00641 /******************************************************************************/
00642 void POINTER_SetMode( enum POINTER_mode mode )
00643 {
00644     u16* ptr;
00645     u16  i;
00646     u16  color;
00647 
00648     if ( Pointer_Mode == mode )
00649         return;
00650 
00651     switch ( mode )
00652     {
00653     case POINTER_APPLICATION:
00654         ptr   = ( u16* )DefaultAreaStore;
00655         color = DRAW_GetBGndColor();
00656 
00657         for ( i = 0; i < ( CurrentPointerWidth * CurrentPointerHeight ) ; i++ )
00658         {
00659             *ptr++ = color;
00660         }
00661 
00662         POINTER_Draw( POINTER_Info.xPos, POINTER_Info.yPos, CurrentPointerWidth, CurrentPointerHeight, CurrentPointerBmp );
00663         break;
00664 
00665     case POINTER_RESTORE_LESS:
00666         POINTER_Draw( POINTER_Info.xPos, POINTER_Info.yPos, CurrentPointerWidth, CurrentPointerHeight, CurrentPointerBmp );
00667         break;
00668 
00669     case POINTER_ON:
00670         POINTER_SetCurrentAreaStore( 0 );
00671         POINTER_Save( POINTER_Info.xPos, POINTER_Info.yPos, POINTER_WIDTH, POINTER_WIDTH );
00672         POINTER_Draw( POINTER_Info.xPos, POINTER_Info.yPos, CurrentPointerWidth, CurrentPointerHeight, CurrentPointerBmp );
00673         POINTER_Draw( POINTER_Info.xPos, POINTER_Info.yPos, CurrentPointerWidth, CurrentPointerHeight, CurrentPointerBmp );
00674         break;
00675 
00676     case POINTER_OFF:
00677         POINTER_Info.xPos = ( Screen_Width - POINTER_WIDTH ) / 2;
00678         POINTER_Info.yPos = ( Screen_Width - POINTER_WIDTH ) / 2;
00679 
00680     case POINTER_MENU:
00681         if ( Pointer_Mode == POINTER_ON )
00682         {
00683             POINTER_SetCurrentAreaStore( 0 );
00684             POINTER_Restore( POINTER_Info.xPos, POINTER_Info.yPos, POINTER_WIDTH, POINTER_WIDTH );
00685         }
00686         break;
00687     }
00688 
00689     Pointer_Mode = mode;
00690 }
00691 
00692 /*******************************************************************************
00693 *
00694 *                                POINTER_GetMode
00695 *
00696 *******************************************************************************/
00704 /******************************************************************************/
00705 enum POINTER_mode POINTER_GetMode( void )
00706 {
00707     return Pointer_Mode;
00708 }
00709 
00710 /*******************************************************************************
00711 *
00712 *                                POINTER_GetState
00713 *
00714 *******************************************************************************/
00722 /******************************************************************************/
00723 enum POINTER_state POINTER_GetState( void )
00724 {
00725     return Pointer_State;
00726 }
00727 
00728 /*******************************************************************************
00729 *
00730 *                                POINTER_SetRect
00731 *
00732 *******************************************************************************/
00745 /******************************************************************************/
00746 void POINTER_SetRect( coord_t x, coord_t y, coord_t width, coord_t height )
00747 {
00748     POINTER_Info.X_PosMin = x;
00749 
00750     if ( POINTER_Info.xPos < POINTER_Info.X_PosMin )
00751     {
00752         POINTER_Info.xPos = POINTER_Info.X_PosMin;
00753     }
00754 
00755     POINTER_Info.X_PosMax = x + width;
00756 
00757     if ( POINTER_Info.xPos > POINTER_Info.X_PosMax )
00758     {
00759         POINTER_Info.xPos = POINTER_Info.X_PosMax;
00760     }
00761 
00762     POINTER_Info.Y_PosMin = y;
00763 
00764     if ( POINTER_Info.yPos < POINTER_Info.Y_PosMin )
00765     {
00766         POINTER_Info.yPos = POINTER_Info.Y_PosMin;
00767     }
00768 
00769     POINTER_Info.Y_PosMax = y + height;
00770 
00771     if ( POINTER_Info.yPos > POINTER_Info.Y_PosMax )
00772     {
00773         POINTER_Info.yPos = POINTER_Info.Y_PosMax;
00774     }
00775 }
00776 
00777 /*******************************************************************************
00778 *
00779 *                                POINTER_SetRectScreen
00780 *
00781 *******************************************************************************/
00787 /******************************************************************************/
00788 void POINTER_SetRectScreen( void )
00789 {
00790     POINTER_SetRect( 0, 0, Screen_Width - CurrentPointerWidth, Screen_Height - CurrentPointerHeight );
00791 }
00792 
00793 /*******************************************************************************
00794 *
00795 *                                POINTER_GetPos
00796 *
00797 *******************************************************************************/
00806 /******************************************************************************/
00807 u16 POINTER_GetPos( void )
00808 {
00809     return ( POINTER_Info.xPos | ( POINTER_Info.yPos << 8 ) );
00810 }
00811 
00812 /*******************************************************************************
00813 *
00814 *                                POINTER_SetPos
00815 *
00816 *******************************************************************************/
00827 /******************************************************************************/
00828 void POINTER_SetPos( coord_t x, coord_t y ) //TODO GetPos uses a single u16 (u8+u8), why does SetPos use 2 u16?
00829 {
00830     POINTER_Info.xPos = x;
00831     POINTER_Info.yPos = y;
00832 }
00833 
00834 /*******************************************************************************
00835 *
00836 *                                POINTER_Draw
00837 *
00838 *******************************************************************************/
00854 /******************************************************************************/
00855 void POINTER_Draw( coord_t x, coord_t y, coord_t width, coord_t height, const u8* bmp )
00856 {
00857     s32 i   = 0;
00858     s32 l   = 0;
00859     s32 n   = 0;
00860     u8* ptr = ptrAreaStore;
00861     u8  c;
00862     u16 val;
00863 
00864     // No bitmap provided, use the default one!
00865     if ( !bmp )
00866     {
00867         bmp = BallPointerBmp;
00868     }
00869 
00870     // Select the screen area were going to take care about!
00871     LCD_SetRect_For_Cmd( x, y, width, height );
00872 
00873     /* Send LCD RAM write command. */
00874     LCD_SendLCDCmd_RAM_Access();
00875 
00876     while ( n < ( width * height ) )
00877     {
00878         if ( Pointer_Mode != POINTER_RESTORE_LESS )
00879         {
00880             // Draw pixel using current storage area data for background pixels.
00881             c = *ptr++;
00882 
00883             LCD_SendLCDData( ( bmp[l + ( i / 8 )] & ( 1 << ( 7 - ( i % 8 ) ) ) ) ? ( POINTER_GetColor() & 255 ) : c );
00884 
00885             c = *ptr++;
00886             LCD_SendLCDData( ( bmp[l + ( i / 8 )] & ( 1 << ( 7 - ( i % 8 ) ) ) ) ? ( POINTER_GetColor() >> 8 )  : c );
00887         }
00888         else
00889         {
00890             // POINTER_RESTORE_LESS: use current background color for background color.
00891             c = DRAW_GetBGndColor();
00892             val = ( bmp[l + ( i / 8 )] & ( 1 << ( 7 - ( i % 8 ) ) ) ) ? POINTER_GetColor() : c;
00893 
00894             LCD_SendLCDData( val & 255 );
00895             LCD_SendLCDData( val >> 8 );
00896         }
00897 
00898         n++;
00899 
00900         i++;
00901 
00902         // End of line ?
00903         if ( i == width )
00904         {
00905             // Next line!
00906             l++;
00907             i = 0;
00908         }
00909     }
00910 
00911     /* End of select screen area to access.*/
00912     LCD_SendLCDCmd_RAM_Access_End();
00913 
00914 }
00915 
00916 /*******************************************************************************
00917 *
00918 *                                POINTER_Save
00919 *
00920 *******************************************************************************/
00936 /******************************************************************************/
00937 void POINTER_Save( coord_t x, coord_t y, coord_t width, coord_t height )
00938 {
00939     // Is this pointer management mode, don't save pointer background!
00940     if ( Pointer_Mode == POINTER_RESTORE_LESS )
00941     {
00942         return;
00943     }
00944 
00945     //Use standard graphic function
00946     LCD_RectRead( x, y, width, height, ptrAreaStore );
00947 }
00948 
00949 /*******************************************************************************
00950 *
00951 *                                POINTER_Restore
00952 *
00953 *******************************************************************************/
00968 /******************************************************************************/
00969 void POINTER_Restore( coord_t x, coord_t y, coord_t width, coord_t height )
00970 {
00971     u16 i;
00972     u8* ptr      = ptrAreaStore;
00973     u16 bytesize = ( width * height ) * 2;  // 2 bytes per pixel
00974 
00975     // Select the screen area to write.
00976     LCD_SetRect_For_Cmd( x, y, width, height );
00977 
00978     // Send the memory write command to the LCD controller.
00979     LCD_SendLCDCmd_RAM_Access();
00980 
00981     for ( i = 0; i < bytesize; i++ )
00982     {
00983         // In this mode, use background color (no data was previously saved).
00984         if ( Pointer_Mode == POINTER_RESTORE_LESS )
00985         {
00986             LCD_SendLCDData( DRAW_GetBGndColor() );
00987         }
00988         else
00989         {
00990             LCD_SendLCDData( *ptr++ );
00991         }
00992     }
00993 
00994     /* End of select screen area to access.*/
00995     LCD_SendLCDCmd_RAM_Access_End();
00996 
00997 }
00998 
00999 /*******************************************************************************
01000 *
01001 *                                POINTER_SetApplication_Pointer_Mgr
01002 *
01003 *******************************************************************************/
01011 /******************************************************************************/
01012 void POINTER_SetApplication_Pointer_Mgr( tAppPtrMgr mgr )
01013 {
01014     Application_Pointer_Mgr = mgr;
01015 }
01016 
01017 /*******************************************************************************
01018 *
01019 *                                POINTER_SetColor
01020 *
01021 *******************************************************************************/
01029 /******************************************************************************/
01030 void POINTER_SetColor( color_t color )
01031 {
01032     CurrentPointerColor = color;
01033 }
01034 
01035 /*******************************************************************************
01036 *
01037 *                                POINTER_GetColor
01038 *
01039 *******************************************************************************/
01047 /******************************************************************************/
01048 color_t POINTER_GetColor( void )
01049 {
01050     return CurrentPointerColor;
01051 }
01052 
01053 /*******************************************************************************
01054 *
01055 *                                POINTER_GetInfo
01056 *
01057 *******************************************************************************/
01065 /******************************************************************************/
01066 tPointer_Info* POINTER_GetInfo( void )
01067 {
01068     return &POINTER_Info;
01069 }