⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pointer.c

📁 FreeRTOS is a portable, open source, mini Real Time Kernel - a free to download and royalty free RTO
💻 C
📖 第 1 页 / 共 2 页
字号:
void POINTER_SetCurrentAreaStore( u8* ptr )
   {
   ptrAreaStore = ( ptr == 0 ) ? DefaultAreaStore : ptr;
   }

/*******************************************************************************
*
*                                POINTER_SetMode
*
*******************************************************************************/
/**
*
*  Change the current mode of the pointer management.
*
*  @note Must be called only ONCE!!
*
*  @param[in]  mode New pointer management mode.
*
**/
/******************************************************************************/
void POINTER_SetMode( enum POINTER_mode mode )
   {
   u16*  ptr;
   u16   i;
   u16   color;

   switch( mode )
      {
      case POINTER_APPLICATION:
         ptr   = (u16*)DefaultAreaStore;
         color = DRAW_GetBGndColor();

         for ( i = 0; i < (CurrentPointerWidth*CurrentPointerHeight) ; i++ )
            {
            *ptr++ = color;
            }

         POINTER_Draw( POINTER_Info.xPos, POINTER_Info.yPos, CurrentPointerWidth, CurrentPointerHeight, CurrentPointerBmp );
         break;

      case POINTER_RESTORE_LESS:
         POINTER_Draw( POINTER_Info.xPos, POINTER_Info.yPos, CurrentPointerWidth, CurrentPointerHeight, CurrentPointerBmp );
         break;

      case POINTER_ON:
         POINTER_SetCurrentAreaStore( 0 );
         POINTER_Save( POINTER_Info.xPos, POINTER_Info.yPos, POINTER_WIDTH, POINTER_WIDTH );
         POINTER_Draw( POINTER_Info.xPos, POINTER_Info.yPos, CurrentPointerWidth, CurrentPointerHeight,CurrentPointerBmp );
         break;

      case POINTER_OFF:
         POINTER_Info.xPos = ( SCREEN_WIDTH - POINTER_WIDTH ) / 2;
         POINTER_Info.yPos = ( SCREEN_WIDTH - POINTER_WIDTH ) / 2;

      case POINTER_MENU:
         if( Pointer_Mode == POINTER_ON )
            {
            POINTER_SetCurrentAreaStore( 0 );
            POINTER_Restore( POINTER_Info.xPos, POINTER_Info.yPos, POINTER_WIDTH, POINTER_WIDTH );
            }
         break;
      }

   Pointer_Mode = mode;
   }

/*******************************************************************************
*
*                                POINTER_GetMode
*
*******************************************************************************/
/**
*
*  Return the current mode of the pointer management
*
*  @return  Current pointer management mode.
*
**/
/******************************************************************************/
enum POINTER_mode POINTER_GetMode( void )
   {
   return Pointer_Mode;
   }

/*******************************************************************************
*
*                                POINTER_GetState
*
*******************************************************************************/
/**
*
*  Return current pointer state.
*
*  @return  Current pointer state.
*
**/
/******************************************************************************/
enum POINTER_state POINTER_GetState( void )
   {
   return Pointer_State;
   }

/*******************************************************************************
*
*                                POINTER_SetRect
*
*******************************************************************************/
/**
*
*  Set new limits for the move of the pointer
*
*  @param[in]  x        Horizontal coordinate of the bottom left corner of the new area.
*  @param[in]  y        Vertical coordinate of the bottom left corner of the new are.
*  @param[in]  width    New area width.
*  @param[in]  height   New area height.
*
*  @warning       The (0x0) point in on the low left corner.
*
**/
/******************************************************************************/
void POINTER_SetRect( s16 x, s16 y, s16 width, s16 height )
   {
   POINTER_Info.X_PosMin = x;

   if( POINTER_Info.xPos < POINTER_Info.X_PosMin )
      {
      POINTER_Info.xPos = POINTER_Info.X_PosMin;
      }

   POINTER_Info.X_PosMax = x + width - 1;

   if( POINTER_Info.xPos > POINTER_Info.X_PosMax )
      {
      POINTER_Info.xPos = POINTER_Info.X_PosMax;
      }

   POINTER_Info.Y_PosMin = y;

   if( POINTER_Info.yPos < POINTER_Info.Y_PosMin )
      {
      POINTER_Info.yPos = POINTER_Info.Y_PosMin;
      }

   POINTER_Info.Y_PosMax = y + height - 1;

   if( POINTER_Info.yPos > POINTER_Info.Y_PosMax )
      {
      POINTER_Info.yPos = POINTER_Info.Y_PosMax;
      }
   }

/*******************************************************************************
*
*                                POINTER_SetRectScreen
*
*******************************************************************************/
/**
*
*  Allow the pointer to move on the whole screen.
*
**/
/******************************************************************************/
void POINTER_SetRectScreen( void )
   {
   POINTER_SetRect( 0, 0, POS_MAX, POS_MAX );
   }

/*******************************************************************************
*
*                                POINTER_GetPos
*
*******************************************************************************/
/**
*
*  Return the current position of the pointer (on the screen).
*
*  @return  The current pointer screen position with X in the LSB and Y in the MSB.
*
*  @warning       The (0x0) point in on the low left corner.
**/
/******************************************************************************/
u16 POINTER_GetPos( void )
   {
   return ( POINTER_Info.xPos | ( POINTER_Info.yPos << 8 ) );
   }

/*******************************************************************************
*
*                                POINTER_SetPos
*
*******************************************************************************/
/**
*
*  Force the screen position of the pointer.
*
*  @param[in]  x  New horizontal coordinate.
*  @param[in]  y  New vertical coordinate.
*
*  @warning       The (0x0) point in on the low left corner.
*
**/
/******************************************************************************/
void POINTER_SetPos( u16 x, u16 y )
   {
   POINTER_Info.xPos = x;
   POINTER_Info.yPos = y;
   }

/*******************************************************************************
*
*                                POINTER_Draw
*
*******************************************************************************/
/**
*
*  Draw pointer.
*
*  @param[in]  x        Horizontal coordinate of the bottom left corner of the pointer.
*  @param[in]  y        Vertical coordinate of the bottom left corner of the pointer.
*  @param[in]  width    Pointer bitmap width.
*  @param[in]  height   Pointer bitmap height.
*  @param[in]  bmp      Pointer to width * height bit array. If null used default
*                       pointer bitmap.
*
*  @note          The provided bitmap is a monochrome one.
*  @warning       The (0x0) point in on the low left corner.
*
**/
/******************************************************************************/
void POINTER_Draw( u8 x, u8 y, u8 width, u8 height, u8* bmp )
   {
   int   i     = 0;
   int   l     = 0;
   int   n     = 0;
   char* ptr   = ptrAreaStore;
   char  c;
   u16   val;

   // No bitmap provided, use the default one!
   if( bmp == 0 )
      {
      bmp = BallPointerBmp;
      }

   // Select the screen area were going to take care about!
   LCD_SetRect_For_Cmd( x, y, width, height );

   // Let draw to the LCD screen.
   LCD_SendLCDCmd( ST7637_RAMWR );

   while( n < ( width * height ) )
      {
      if( Pointer_Mode != POINTER_RESTORE_LESS )
         {
         // Draw pixel using current storage area data for background pixels.
         c = *ptr++;
         LCD_SendLCDData( ( bmp[ l + ( i / 8 ) ] & ( 1 << ( 7 - ( i % 8 ) ) ) ) ? ( POINTER_GetColor() & 255 ) : c );

         c = *ptr++;
         LCD_SendLCDData( ( bmp[ l + ( i / 8 ) ] & ( 1 << ( 7 - ( i % 8 ) ) ) ) ? ( POINTER_GetColor() >> 8 )  : c );
         }
      else
         {
         // POINTER_RESTORE_LESS: use current background color for background color.
         c = DRAW_GetBGndColor();
         val = ( bmp[ l + ( i / 8 ) ] & ( 1 << ( 7 - ( i % 8 ) ) ) ) ? POINTER_GetColor() : c;

         LCD_SendLCDData( val & 255 );
         LCD_SendLCDData( val >> 8 );
         }

      n++;

      i++;

      // End of line ?
      if( i == width )
         {
         // Next line!
         l++;
         i=0;
         }
      }
   }

/*******************************************************************************
*
*                                POINTER_Save
*
*******************************************************************************/
/**
*
*  Save the background of the pointer.
*
*  @param[in]  x        Horizontal coordinate of the bottom left corner of the area to save.
*  @param[in]  y        Vertical coordinate of the bottom left corner of the area to save.
*  @param[in]  width    Width of the area to save.
*  @param[in]  height   Height of the area to save.
*
*  @note          The store area must be large enough to store all the pixels (16 bits).
*  @warning       The (0x0) point in on the low left corner.
*  @see  POINTER_Restore
*  @see  POINTER_SetCurrentAreaStore
*
**/
/******************************************************************************/
void POINTER_Save( u8 x, u8 y, u8 width, u8 height )
   {
   int   i;
   char* ptr      = ptrAreaStore;
   int   bytesize = ( width * height ) * 2;                // 2 bytes per pixel.

   // Is this pointer management mode, don't save pointer background!
   if( Pointer_Mode == POINTER_RESTORE_LESS )
      {
      return;
      }

   // Select the LCD screen area to read.
   LCD_SetRect_For_Cmd ( x, y, width, height );

   // Send the memory read command to the LCD controller.
   LCD_SendLCDCmd( ST7637_RAMRD );

   // First returned byte is a dummy!
   LCD_ReadLCDData();

   for( i = 0; i < bytesize; i++ )
      {
      *ptr++ = LCD_ReadLCDData();
      }
   }

/*******************************************************************************
*
*                                POINTER_Restore
*
*******************************************************************************/
/**
*
*  Restore the background of the pointer with data saved in the current store area.
*
*  @param[in]  x        Horizontal coordinate of the bottom left corner of the area to restore.
*  @param[in]  y        Vertical coordinate of the bottom left corner of the area to restore.
*  @param[in]  width    Width of the area to restore.
*  @param[in]  height   Height of the area to restore.
*
*  @warning       The (0x0) point in on the low left corner.
*  @see  POINTER_Save
*  @see  POINTER_SetCurrentAreaStore
*
**/
/******************************************************************************/
void POINTER_Restore( u8 x, u8 y, u8 width, u8 height )
   {
   int   i;
   char* ptr      = ptrAreaStore;
   int   bytesize = ( width * height ) * 2;                // 2 bytes per pixel.

   // Select the screen area to write.
   LCD_SetRect_For_Cmd( x, y, width, height );

   // Send the memory write command to the LCD controller.
   LCD_SendLCDCmd( ST7637_RAMWR );

   for( i = 0; i < bytesize; i++ )
      {
      // In this mode, use background color (no data was previously saved).
      if ( Pointer_Mode == POINTER_RESTORE_LESS )
         {
         LCD_SendLCDData( DRAW_GetBGndColor() );
         }
      else
         {
         LCD_SendLCDData( *ptr++ );
         }
      }
   }

/*******************************************************************************
*
*                                POINTER_SetApplication_Pointer_Mgr
*
*******************************************************************************/
/**
*
*  Provides an user defined pointer manager.
*
*  @param[in]  mgr Pointer to the user defined pointer manager.
*
**/
/******************************************************************************/
void POINTER_SetApplication_Pointer_Mgr( tAppPtrMgr mgr )
   {
   Application_Pointer_Mgr = mgr;
   }

/*******************************************************************************
*
*                                POINTER_SetColor
*
*******************************************************************************/
/**
*
*  Set the pointer color.
*
*  @param[in]  color The new pointer color.
*
**/
/******************************************************************************/
void POINTER_SetColor( u16 color )
   {
   CurrentPointerColor = color;
   }

/*******************************************************************************
*
*                                POINTER_GetColor
*
*******************************************************************************/
/**
*
*  Return the current pointer color.
*
*  @return  Current pointer color.
*
**/
/******************************************************************************/
u16 POINTER_GetColor( void )
   {
   return CurrentPointerColor;
   }

/*******************************************************************************
*
*                                POINTER_GetInfo
*
*******************************************************************************/
/**
*
*  Get pointer informations.
*
*  @return  A pointer to a pointer information structure.
*
**/
/******************************************************************************/
tPointer_Info* POINTER_GetInfo( void )
   {
   return &POINTER_Info;
   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -