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

📄 lcdsim.c

📁 最新IAR6.4软集成开发环境及破解文件
💻 C
📖 第 1 页 / 共 2 页
字号:
		  pBitmapInfo = _apBitmapInfo[i];
		  memset(&pBitmapInfo->bmiHeader, 0, sizeof(pBitmapInfo->bmiHeader));
		  pBitmapInfo->bmiHeader.biSize  = sizeof (BITMAPINFOHEADER);
		  pBitmapInfo->bmiHeader.biWidth =   _aXSize[i];
		  pBitmapInfo->bmiHeader.biHeight=  -_aYSize[i];    // Neg. for top up bitmap
		  pBitmapInfo->bmiHeader.biPlanes = 1;  // must be set to 1
		  pBitmapInfo->bmiHeader.biCompression = BI_RGB;
		  if (_aBPP[i] <= 8) {
  		  pBitmapInfo->bmiHeader.biBitCount = 8;
		  } else {
	  	  pBitmapInfo->bmiHeader.biBitCount = 32;
		  }
    }
  }
  return NULL;
}

/*********************************************************************
*
*         LCDSIM_Paint()
*         LCDSIM_PaintAt()
*         LCDSIM_PaintEx()
*
**********************************************************************
*/
void LCDSIM_PaintEx(HWND hWnd, LPRECT lpDCRect, LPRECT lpDIBRect) {
  int LayerIndex;
  HDC hDC;
  PAINTSTRUCT ps;
  RETURN_IF_NOT_INITIALIZED(;);
  LayerIndex = GetWindowLong(hWnd, GWL_USERDATA);
  hDC = BeginPaint(hWnd, &ps);
  //
  // Draw background if necessary
  //
  if (ps.fErase) {
    RECT r = {0, 0, 4095, 4095 };
    FillRect(hDC, &r, (HBRUSH)GetStockObject(BLACK_BRUSH));
    ps.fErase = 0;
  }
  // Make sure to use the stretching mode best for color pictures
  SetStretchBltMode(hDC, COLORONCOLOR);
// Determine whether to call StretchDIBits() or SetDIBitsToDevice()
  if ((RECTWIDTH(lpDCRect)  == RECTWIDTH(lpDIBRect)) &&
      (RECTHEIGHT(lpDCRect) == RECTHEIGHT(lpDIBRect))) {
    SetDIBitsToDevice(hDC,        // hDC
    lpDCRect->left,             // DestX
                lpDCRect->top,              // DestY
                RECTWIDTH(lpDCRect),        // nDestWidth
                RECTHEIGHT(lpDCRect),       // nDestHeight
                lpDIBRect->left,            // SrcX
                _aYSize[LayerIndex] -  lpDIBRect->top - RECTHEIGHT(lpDIBRect),     // SrcY
                0,                          // nStartScan
                _aYSize[LayerIndex],                 // nNumScans
                XY2PTR(0,0, LayerIndex),              // lpBits
                _apBitmapInfo[LayerIndex],  // lpBitsInfo
                DIB_RGB_COLORS);            // wUsage
  } else {
    StretchDIBits(hDC,            // hDC
                   lpDCRect->left,               // DestX
                   lpDCRect->top,                // DestY
                   RECTWIDTH(lpDCRect),          // nDestWidth
                   RECTHEIGHT(lpDCRect),         // nDestHeight
                   lpDIBRect->left,              // SrcX
                   lpDIBRect->top,               // SrcY
                   RECTWIDTH(lpDIBRect),         // wSrcWidth
                   RECTHEIGHT(lpDIBRect),        // wSrcHeight
       XY2PTR(0,0, LayerIndex),              // lpBits
                   _apBitmapInfo[LayerIndex],    // lpBitsInfo
                   DIB_RGB_COLORS,               // wUsage
                   SRCCOPY);                     // dwROP
  }
  EndPaint(hWnd, &ps);
}

/*********************************************************************
*
*       LCDSIM_PaintAt
*/
void LCDSIM_PaintAt(HWND hWnd, int x, int y) {
  RECT rDest, rSrc;
  int MagX, MagY;
  int LayerIndex = GetWindowLong(hWnd, GWL_USERDATA);
  MagX = SIM_GetMagX();
  MagY = SIM_GetMagY();
  rDest.top =0;
  rDest.bottom= _aYSize[LayerIndex] * MagY - 1;
  rDest.left  = 0;
  rDest.right = _aXSize[LayerIndex] * MagX - 1;
  rSrc.top =0;
  rSrc.bottom= _aYSize[LayerIndex] - 1;
  rSrc.left  = 0;
  rSrc.right = _aXSize[LayerIndex] - 1;
  rDest.left   += x;
  rDest.right  += x;
  rDest.top    += y;
  rDest.bottom += y;
  LCDSIM_PaintEx(hWnd, &rDest, &rSrc);
}

/*********************************************************************
*
*       LCDSIM_Paint
*/
void LCDSIM_Paint(HWND hWnd) { LCDSIM_PaintAt(hWnd, 0,0); }

/*********************************************************************
*
*       LCDSIM_GetModifyCnt
*/
int  LCDSIM_GetModifyCnt(int LayerIndex)     { 
  if (_apFix[LayerIndex]) {
    return *(int*)(_apFix[LayerIndex] + LCDSIM_OFF_MODIFY_CNT);
  } 
  return 0;
};

/*********************************************************************
*
*       LCDSIM_GetModifyCntInfo
*/
int  LCDSIM_GetModifyCntInfo(int LayerIndex) { return _LUT_ModifyCnt; };

/*********************************************************************
*
*       LCDSIM_Index2Color
*/
int LCDSIM_Index2Color(int Index, int LayerIndex) {
  U32 r,g,b;
  RETURN_IF_NOT_INITIALIZED(0);
  if (_aBPP[LayerIndex] <= 8) {
    r = _apBitmapInfo[LayerIndex]->bmiColors[Index].rgbRed;
    g = _apBitmapInfo[LayerIndex]->bmiColors[Index].rgbGreen;
    b = _apBitmapInfo[LayerIndex]->bmiColors[Index].rgbBlue;
  } 
  return (r | (g<<8) | (b<<16));
}

/*********************************************************************
*
*       LCDSIM_SetPixelIndex
*/
void LCDSIM_SetPixelIndex(int x, int y, int Index, int LayerIndex)  {
  RETURN_IF_NOT_INITIALIZED(;);
  #ifdef _DEBUG
    _CheckBreak(x, y, LayerIndex);
  #endif
  ASSERT(x >= 0);
  ASSERT(x < _aVXSize[LayerIndex]);
  ASSERT(y >= 0);
  ASSERT(y < _aVYSize[LayerIndex]);
  if (_aBPP[LayerIndex] <= 8) {
    *XY2PTR(x,y, LayerIndex) = Index;
  } else {
    U32 Index32 = _ColorIndex2COLORREF(Index, LayerIndex);
    *XY2PTR_DWORD(x, y, LayerIndex) = Index32;
  }
  MARK_MODIFIED(LayerIndex);
}

/*********************************************************************
*
*       LCDSIM_SetPixelColor
*/
void LCDSIM_SetPixelColor(int x, int y, LCD_COLOR PixelColor, int LayerIndex)  {
  RETURN_IF_NOT_INITIALIZED(;);
  #ifdef _DEBUG
    _CheckBreak(x, y, LayerIndex);
  #endif
  ASSERT(x >= 0);
  ASSERT(x < _aVXSize[LayerIndex]);
  ASSERT(y >= 0);
  ASSERT(y < _aVYSize[LayerIndex]);
  {
    COLORREF Index32 = PixelColor;
    *XY2PTR_DWORD(x, y, LayerIndex) = Index32;
  }
  MARK_MODIFIED(LayerIndex);
}

/*********************************************************************
*
*       LCDSIM_FillRect()
*/
void LCDSIM_FillRect(int x0, int y0, int x1, int y1, int Index, int LayerIndex)  {
  int x, y;
  RETURN_IF_NOT_INITIALIZED(;);
  if (x1 >= _aXSize[LayerIndex])
    x1 = _aXSize[LayerIndex] - 1;
  if (y1 >= _aYSize[LayerIndex])
    y1 = _aYSize[LayerIndex] - 1;
  if (_aBPP[LayerIndex] <= 8) {
    U8 * pOffset = XY2PTR(x0, y0, LayerIndex);
    for (y = y1 - y0; y >= 0; y--) {
      for (x = x1 - x0; x >= 0; x--) {
        *(pOffset + x) = Index;
      }
      pOffset += _aBytesPerLine[LayerIndex];
    }
  } else {
    U32 Index32 = _ColorIndex2COLORREF(Index, LayerIndex);
    U32 *pOffset = XY2PTR_DWORD(x0, y0, LayerIndex);
    for (y = y1 - y0; y >= 0; y--) {
      for (x = x1 - x0; x >= 0; x--) {
        *(pOffset + x) = Index32;
      }
      pOffset += _aBytesPerLine[LayerIndex] >> 2;
    }
  }
  MARK_MODIFIED(LayerIndex);
}

/*********************************************************************
*
*       LCDSIM_GetPixelIndex
*/
int LCDSIM_GetPixelIndex(int x, int y, int LayerIndex)  {
  RETURN_IF_NOT_INITIALIZED(0);
  ASSERT(x >= 0);
  ASSERT(x < _aVXSize[LayerIndex]);
  ASSERT(y >= 0);
  ASSERT(y < _aVYSize[LayerIndex]);
  if (_aBPP[LayerIndex] <= 8)
    return(*XY2PTR(x,y, LayerIndex));
  return _COLORREF2Index(*XY2PTR_DWORD(x,y, LayerIndex));
}

/*********************************************************************
*
*       LCDSIM_GetPixelColor
*/
int LCDSIM_GetPixelColor(int x, int y, int LayerIndex)  {
  if (_aBPP[LayerIndex] <= 8) {
    int Index = LCDSIM_GetPixelIndex(x, y, LayerIndex);
    return LCDSIM_Index2Color(Index, LayerIndex);
  }
  return *XY2PTR_DWORD(x,y, LayerIndex);

}

/*********************************************************************
*
*       LCDSIM_SetLUTEntry
*/
void LCDSIM_SetLUTEntry(U8 Pos, LCD_COLOR color, int LayerIndex) {
  RETURN_IF_NOT_INITIALIZED(;);
  color = _FilterColor(color, LCDSIM_aLCDColorBlack[0], LCDSIM_aLCDColorWhite[0]);
        _apBitmapInfo[LayerIndex]->bmiColors[Pos].rgbRed   = (BYTE)color;
        _apBitmapInfo[LayerIndex]->bmiColors[Pos].rgbGreen = (BYTE)(color>>8);
        _apBitmapInfo[LayerIndex]->bmiColors[Pos].rgbBlue  = (BYTE)(color>>16);
        MARK_LUT_MODIFIED(LayerIndex);
        MARK_MODIFIED(LayerIndex);
}

/*********************************************************************
*
*       LCDSIM_GetMouseState
*/
int LCDSIM_GetMouseState(LCD_tMouseState *pState) {
  int x = *(int*)(_apFix[0]+LCDSIM_OFF_XPOS);
  int y = *(int*)(_apFix[0]+LCDSIM_OFF_YPOS);
  int KeyStat = *(int*)(_apFix[0]+LCDSIM_OFF_KEYSTAT);
  pState->KeyStat = KeyStat;
  pState->x =   x;
  pState->y =   y;
  return 0;
}

/*********************************************************************
*
*       LCDSIM_CheckMouseState
*/
void LCDSIM_CheckMouseState(void) {
  int x = *(int*)(_apFix[0]+LCDSIM_OFF_XPOS);
  int y = *(int*)(_apFix[0]+LCDSIM_OFF_YPOS);
  int KeyStat = *(int*)(_apFix[0]+LCDSIM_OFF_KEYSTAT);
  if ((_State.x != x) | (_State.y != y) | (_State.Pressed != KeyStat)) {
    _State.x = x;
    _State.y = y;
    _State.Pressed = KeyStat;
    _NotifyMouseState();
  }
}

/*********************************************************************
*
*       LCDSIM_SetMouseState
*/
void LCDSIM_SetMouseState(int x, int y, int KeyStat) {
  *(int*)(_apFix[0]+LCDSIM_OFF_XPOS) = x;
  *(int*)(_apFix[0]+LCDSIM_OFF_YPOS) = y;
  *(int*)(_apFix[0]+LCDSIM_OFF_KEYSTAT) = KeyStat;
  LCDSIM_CheckMouseState();
}

/*************************** End of file ****************************/

⌨️ 快捷键说明

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