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

📄 memdev_printing.c

📁 最新IAR6.4软集成开发环境及破解文件
💻 C
📖 第 1 页 / 共 2 页
字号:

/********************************************************************
*
*       Static data, test picture 1bpp
*
*********************************************************************
*/

GUI_CONST_STORAGE GUI_COLOR ColorsTestPicture1[] = {
     0xFFFFFF,0x000000
};

GUI_CONST_STORAGE GUI_LOGPALETTE PalTestPicture1 = {
  2,	/* number of entries */
  0, 	/* Has transparency */
  &ColorsTestPicture1[0]
};

GUI_CONST_STORAGE unsigned char acTestPicture1[] = {
  XXXXXXXX, XXXXXXXX, XXXXXXXX,
  XXXXXXXX, XXXXXXXX, X______X,
  XX______, _______X, XXXXXXXX,
  XX______, _____X_X, X______X,
  XX______, ___XXX_X, XXXXXXXX,
  XX______, _XXXXX_X, X______X,
  XX_____X, XXXXX__X, XXXXXXXX,
  XX___XXX, XXXX___X, X______X,
  XX_XXXXX, XXX__X_X, XXXXXXXX,
  XX_XXXXX, X___XX_X, X______X,
  XX_XXXX_, ___XXX_X, XXXXXXXX,
  XX_XX___, __XXX__X, X______X,
  XX______, _XXX___X, XXXXXXXX,
  XX______, XXX____X, X______X,
  XX______, _______X, XXXXXXXX,
  XXXXXXXX, XXXXXXXX, X______X,
  XXXXXXXX, XXXXXXXX, XXXXXXXX,
  X_X_X_X_, X_X_X_X_, XX_X_X_X,
  X_X_X_X_, X_X_X_X_, X_X_X_XX,
  X_X_X_X_, X_X_X_X_, XX_X_X_X,
  X_X_X_X_, X_X_X_X_, X_X_X_XX,
  X_X_X_X_, X_X_X_X_, XX_X_X_X,
  X_X_X_X_, X_X_X_X_, X_X_X_XX,
  XXXXXXXX, XXXXXXXX, XXXXXXXX
};

GUI_CONST_STORAGE GUI_BITMAP bmTestPicture1 = {
 24, /* XSize */
 24, /* YSize */
 3, /* BytesPerLine */
 1, /* BitsPerPixel */
 acTestPicture1,  /* Pointer to picture data (indices) */
 &PalTestPicture1  /* Pointer to palette */
};

/********************************************************************
*
*       Static code
* 
*********************************************************************
*/
/********************************************************************
*
*       _DrawBitmap
*/
static _DrawBitmap(const GUI_BITMAP* pBitmap, int x, int y, int Trans, int XOr) {
  GUI_LOGPALETTE Pal;
  GUI_BITMAP Bitmap;
  int PrevDM;
  memcpy(&Bitmap, pBitmap, sizeof(GUI_BITMAP));
  memcpy(&Pal, Bitmap.pPal, sizeof(GUI_LOGPALETTE));
  Bitmap.pPal  = &Pal;
  Pal.HasTrans = Trans;
  PrevDM = GUI_SetDrawMode((XOr) ? GUI_DM_XOR : 0);
  GUI_DrawBitmap(&Bitmap, x, y);
  GUI_SetDrawMode(PrevDM);
}

/********************************************************************
*
*       _Draw
*
* Function description
*   Draws some coloured output to the current device (display or memory device)
*/
static void _Draw(void) {
  int i;
  GUI_SetBkColor(GUI_YELLOW);
  GUI_ClearRect(0, 75, 319, 138);
  GUI_SetColor(GUI_RED);
  GUI_SetFont(&GUI_Font32B_ASCII);
  GUI_DispStringHCenterAt("Printing demo", 160, 75);
  for (i = 0; i < 12; i += 2) {
    GUI_SetColor(GUI_GREEN);
    GUI_DrawRect(5 + i, 80 + i, 50 - i, 101 - i);
    GUI_SetColor(GUI_BLUE);
    GUI_DrawRect(269 + i, 80 + i, 314 - i, 101 - i);
  }
  for (i = 0; i < 32; i += 8) {
    GUI_SetColor(GUI_BLUE);
    GUI_FillRect(0, 107 + i, 319, 110 + i);
    GUI_SetColor(GUI_YELLOW);
    GUI_FillRect(0, 111 + i, 319, 114 + i);
  }
  i = 8;
  _DrawBitmap(&bmTestPicture1, i +   0, 111, 0, 0);
  _DrawBitmap(&bmTestPicture1, i +  35, 111, 1, 0);
  _DrawBitmap(&bmTestPicture1, i +  70, 111, 0, 1);
  _DrawBitmap(&bmTestPicture2, i + 105, 111, 0, 0);
  _DrawBitmap(&bmTestPicture2, i + 140, 111, 1, 0);
  _DrawBitmap(&bmTestPicture4, i + 175, 111, 0, 0);
  _DrawBitmap(&bmTestPicture4, i + 210, 111, 1, 0);
  _DrawBitmap(&bmTestPicture8, i + 245, 111, 0, 0);
  _DrawBitmap(&bmTestPicture8, i + 280, 111, 1, 0);
}

/********************************************************************
*
*       _SendToPrinter
*
* Function description
*   Shows the contents of a memory device on the display
*   In "real life", this routine would send the contents of the memory
*   device to the printer.
*/
static void _SendToPrinter(GUI_MEMDEV_Handle hMem, int yOff) {
  int xSize, ySize, x, y, Offset, Bit;
  U8 * pData;
  /* Get the size of the memory device */
  xSize = GUI_MEMDEV_GetXSize(hMem);
  ySize = GUI_MEMDEV_GetYSize(hMem);
  pData = (U8 *)GUI_MEMDEV_GetDataPtr(hMem); /* Get the data pointer of the memory device */
  /* Draw the pixels of the memory device on the screen */
  for (y = 0; y < ySize; y++) {
    for (x = 0; x < xSize; x++) {
      U8 Index;
      Offset = x >> 3;
      Bit    = 7 - (x & 7);
      Index  = *(pData + Offset);
      Index &= (1 << Bit);
      /* The index could be 0 or 1, so use black and white */
      if (Index == 0 ) {
        GUI_SetColor(GUI_BLACK);
      } else {
        GUI_SetColor(GUI_WHITE);
      }
       /* Draw the pixel. At this point for example a printer output routine can be called */              
      GUI_DrawPixel(x, y + yOff);
    }
    pData += (xSize + 7) / 8;
  }
}

/********************************************************************
*
*       _Explain
*/
static void _Explain(void) {
  int i;
  GUI_SetTextMode(GUI_TM_XOR);
  GUI_SetFont(&GUI_Font16B_ASCII);
  GUI_DispStringHCenterAt("MEMDEV_Printing", 160, 0);
  GUI_GotoXY(0,20);
  GUI_SetFont(&GUI_Font6x8);
  for (i = 0; i < GUI_COUNTOF(_acText); i++) {
    GUI_DispString(_acText[i]);
    GUI_DispNextLine();
  }
  GUI_SetTextMode(GUI_TM_TRANS);
}

/********************************************************************
*
*       Exported code
*
*********************************************************************
*/
/********************************************************************
*
*       MainTask
*/
void MainTask(void) {
  GUI_MEMDEV_Handle hMem;
  GUI_Init();

  _Explain();     /* Explain the sample */

  GUI_SetFont(&GUI_Font16B_ASCII);
  GUI_SetColor(GUI_WHITE);
  GUI_DispStringAt("Screen output:", 5, 59);
  _Draw();        /* Draw "Preview" on the screen */

  /* Create and select a memory device with 1bpp color conversion (B/W) */
  hMem = GUI_MEMDEV_CreateFixed(0, 75, 320, 64, 0, 
                                GUI_MEMDEV_APILIST_1, /* Used API list */
                                GUI_COLOR_CONV_1);    /* Black/white color conversion */
  GUI_MEMDEV_Select(hMem);
  _Draw();                  /* Call the same routine as before for drawing into memory device */
  GUI_MEMDEV_Select(0);     /* Switch back from memory device to the display */

  GUI_SetFont(&GUI_Font16B_ASCII);
  GUI_SetColor(GUI_WHITE);
  GUI_DispStringAt("Printer output:", 5, 154);
  _SendToPrinter(hMem, 170);

  /* Cleanup, end-of sample */
  GUI_MEMDEV_Delete(hMem);
  while(1) {
    GUI_Exec();
  }
}

/************************** end of file ****************************/

⌨️ 快捷键说明

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