ucgui在windows上的移植,及爲go語言打造簡易跨平臺GUI的想法

go語言缺乏官方GUI的支持,這點有時候很不方便。

雖然網上有很多開源的實現,但都不太滿意,不太好用。

網上開源的有哪些?參見《2019,Go GUI項目爆發的一年?》https://studygolang.com/articles/21525?fr=sidebar

近來出現了很多跨平臺的Go GUI項目。

雖說用井噴之勢形容有些過了,但是的確有加速的跡象。難道Go語言將要開闢出另一大塊疆土?

忙中偷閒,整理了一份目前GUI/圖形/圖像相關的Go項目列表。見下。歡迎補充。

原生GUI綁定

dlgs是一個跨平臺的顯示對話框和輸入框的Go代碼庫。

glfw是一個GLFW3綁定庫。

go-mobile支持移動平臺應用開發(Android和iOS)。(其中包含OpenGL ES 2.0和ES 3.0綁定庫。)

go-sdl2是一個SDL2綁定庫。

go-gtk是一個GTK2綁定庫。

gotk3是一個GTK+3綁定庫。

GXUI,Google員工出品,但已經停止維護很久了。

。。。。。。

突然想起來曾經很火的嵌入式GUI,UCGUI多麼的小巧靈活,且是使用100%的標準C代碼編寫的,跨平臺當然很好移植和使用。

官方還有模擬器  emWin(UCGUI)模擬器。在電腦上有模擬器啊,這是不是很贊。

且圖形界面可以在電腦上拖拽設計,這點兒更贊。

爲什麼網上沒有go語言的ucgui的綁定?於是就萌生了用go語言封裝ucgui的想法。

那麼既然是爲go語言打造的簡易GUI,跨平臺是必須的吧,至少Windows,linux和嵌入式linux都要支持的吧。

這不,以下先讓ucgui在windows上的移植跑起來,是第一步。

ucgui在linux上的移植,參見博文:https://blog.csdn.net/yyz_1987/article/details/78380007

後續計劃,ucgui的go語言封裝

UCGUI簡介:

UCGUI是一種嵌入式應用中的圖形支持系統。

它設計用於爲任何使用LCD圖形顯示的應用提供高效的獨立於處理器及LCD控制器的圖形用戶接口。

它適用單任務或是多任務系統環境, 並適用於任意LCD控制器和CPU下任何尺寸的真實顯示或虛擬顯示。

它的設計架構是模塊化的,由不同的模塊中的不同層組成,由一個LCD驅動層來包含所有對LCD的具體圖形操作。

UCGUI可以在任何的CPU上運行,因爲它是100%的標準C代碼編寫的。

UCGUI能夠適應大多數的使用黑白或彩色LCD的應用,它提供非常好的允許處理灰度的顏色管理。

還提供一個可擴展的2D圖形庫及佔用極少RAM的窗口管理體系。

在Windows上的移植:,移植好的demo放在的我的github上了,

地址:https://github.com/yongzhena

https://github.com/yongzhena/ucgui-windows.git

使用方法:  
首先,windows上必須有GCC的環境。  
推薦安裝mingwgcc  
我安裝的是x86_64-810gcc-posix-seh-npMingw64v75.7z這個壓縮包,直接解壓。再配置環境變量即可。  
跟移植相關的,都在ucgui/GUI_X文件夾中。  
在ucgui/GUI文件夾中,有寫好的makefile文件,直接make即可編譯出libucgui.a庫。  
然後需要把這個庫放到GUIDemo_windows文件夾裏。  
同時,裏面有幾個windows上需要依賴的庫在裏面。libGDI32.LIB,libWINMM.lib,   
同時多了兩個文件MainTask.c和WinMain.c,其中windows程序的入口在WinMain.c中。  
這個裏面也有一個makefile文件,可執行make命令,直接就生成了demo,test.exe可執行程序。   

//LCDSIM.c
#include <windows.h>
#include <memory.h>
#include <math.h>

#include "LCD.h"
#include "GUI.h"
#include "LCDConf.h"

unsigned int LCD_Buffer[LCD_YSIZE][LCD_XSIZE];
BITMAPINFO bmp; 

void LCDSIM_Init(void) 
{
	//初始化位圖結構	
	ZeroMemory(&bmp,   sizeof(BITMAPINFO));  

	bmp.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bmp.bmiHeader.biWidth = LCD_XSIZE;   //位圖寬度
	bmp.bmiHeader.biHeight = -LCD_YSIZE;  //位圖高度  //當圖像是倒立顯示的時候,把biHeight改爲對應的負值
	bmp.bmiHeader.biPlanes   =   1;   
	bmp.bmiHeader.biBitCount   =   32;   //一個像素32Bit
	bmp.bmiHeader.biCompression   =   BI_RGB; 
}


void UpdataShow(HDC _hdc)
{
	SetDIBitsToDevice(_hdc,
								0, 0,  //在屏幕中的起始座標
								LCD_XSIZE, LCD_YSIZE,  //顯示的屏幕的寬,高
								0 , 0,   //位圖左下角的座標
								0,  //DIB中的起始掃描線
								LCD_YSIZE,  // DIB掃描線數目
								(BYTE*)LCD_Buffer,  //位圖數據區起始指針,是BYTE*類型
								&bmp,  //位圖的BITMAPINFO指針
								DIB_RGB_COLORS);  //顏色使用類型
}

void LCDSIM_SetPixelIndex(int x, int y, int Index, int LayerIndex)  
{
#if 0
	int R = (Index & 0xF800) >> 11;
	int G = (Index & 0x07E0) >> 5;
	int B = Index & 0x001F;

	LCD_Buffer[y][x] = R << 3 << 16 | G << 2 << 8 | B << 3;
#endif

#if (LCD_BITSPERPIXEL == 8)
	unsigned char R = 1.164 * (Index - 16);
	LCD_Buffer[y][x] = R << 16 | R << 8 | R ;
#elif (LCD_BITSPERPIXEL == 16) && (LCD_FIXEDPALETTE == 565)
	LCD_Buffer[y][x] = ((Index & 0xF800) << 3 >> 11 << 16) | ((Index & 0x07E0) << 2 >> 5 << 8) | (Index & 0x1F)<<3;
#else if (LCD_BITSPERPIXEL == 1)
	if (Index == 0)
	{
		LCD_Buffer[y][x] = 0x00000000;
	}
	else
	{
		LCD_Buffer[y][x] = 0x00FFFFFF;
	}
#endif
}


void LCDSIM_FillRect(int x0, int y0, int x1, int y1, int Index, int LayerIndex)
{

}


int LCDSIM_GetPixelIndex(int x, int y, int LayerIndex)
{
	return LCD_Buffer[y][x];
}

void LCDSIM_SetLUTEntry(U8 Pos, LCD_COLOR color, int LayerIndex) 
{

}



GUI_PID_STATE Touch_Status;
void Touch_Pressed(int x, int y)  //觸摸按下  x,y 爲按下是的鼠標在窗體中的座標
{
	Touch_Status.Pressed = 1;
	Touch_Status.x = x;
	Touch_Status.y = y;
	GUI_TOUCH_StoreStateEx(&Touch_Status);
}

void Touch_Release(void)  //觸摸釋放
{
	Touch_Status.Pressed = 0;
	Touch_Status.x = -1;
	Touch_Status.y = -1;
	GUI_TOUCH_StoreStateEx(&Touch_Status);
}


//LCD_Win.c
#if defined(_WIN32) || defined(WIN32) || defined(WIN64)
#include <windows.h>
#endif

#include "LCD.h"
#include "LCD_Private.h"              /* include LCDConf.h */
#include "LCDSIM.h"
#include "GUI_Private.h"

#include "memory.h"

/*********************************************************************
*
*       Defines
*
**********************************************************************
*/

#if LCD_BITSPERPIXEL <= 8
  #define PIXELINDEX U8
#else
  #define PIXELINDEX WORD
#endif

#ifdef WIN32
  #ifndef ASSERT
    #define ASSERT(Val) \
    if (!(Val)) \
      MessageBox(NULL,"...in file "__FILE__,"Assertion failed...",MB_OK);
  #endif
#endif

#ifdef LCD_ASSERT
  #undef LCD_ASSERT
#endif
#define LCD_ASSERT(v) ASSERT(v)

#ifndef LCD_DISPLAY_INDEX
  #define LCD_DISPLAY_INDEX 0
#endif

/*********************************************************************
*
*       Macros for internal use
*/
#if 0
static int _CheckBound(unsigned int c) {
  unsigned int NumColors = LCD_BITSPERPIXEL > 8 ? (LCD_BITSPERPIXEL > 16) ? 0xffffffff : 0xffff : (1 << LCD_BITSPERPIXEL) - 1;
  if (c > NumColors) {
    GUI_DEBUG_ERROROUT("LCDWin::SETPIXEL: parameters out of bounds");
    return 1;
  }
  return 0;
}

  #define SETPIXEL(x, y, c) \
    if (!_CheckBound(c)) { \
      LCDSIM_SetPixelIndex(x, y, c, LCD_DISPLAY_INDEX); \
    }
#else
  #define SETPIXEL(x, y, c) LCDSIM_SetPixelIndex(x, y, c, LCD_DISPLAY_INDEX)
#endif
#define XORPIXEL(x, y)    _XorPixel(x,y)

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/

/*********************************************************************
*
*       _XorPixel
*/
static void _XorPixel(int x, int y) 
{
	unsigned int Index = LCD_L0_GetPixelIndex(x,y);
	LCDSIM_SetPixelIndex(x, y, LCD_NUM_COLORS-1-Index, LCD_DISPLAY_INDEX);
}

/*********************************************************************
*
*       _DrawBitLine1BPP
*/
static void _DrawBitLine1BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) {
  LCD_PIXELINDEX Index0, Index1;
  #if (GUI_USE_MEMDEV_1BPP_FOR_SCREEN == 1)
    const LCD_PIXELINDEX aTrans[2] = {0, 1};
    if (!pTrans) {
      pTrans = aTrans;
    }
  #endif
  Index0 = *(pTrans + 0);
  Index1 = *(pTrans + 1);
  x+=Diff;
  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS|LCD_DRAWMODE_XOR)) {
  case 0:    /* Write mode */
    do {
      LCDSIM_SetPixelIndex(x++,y, (*p & (0x80>>Diff)) ? Index1 : Index0, LCD_DISPLAY_INDEX);
			if (++Diff==8) {
        Diff=0;
				p++;
			}
		} while (--xsize);
    break;
  case LCD_DRAWMODE_TRANS:
    do {
  		if (*p & (0x80>>Diff))
        LCDSIM_SetPixelIndex(x,y, Index1, LCD_DISPLAY_INDEX);
      x++;
			if (++Diff==8) {
        Diff=0;
				p++;
			}
		} while (--xsize);
    break;
  case LCD_DRAWMODE_XOR | LCD_DRAWMODE_TRANS:
  case LCD_DRAWMODE_XOR:
    do {
  		if (*p & (0x80>>Diff)) {
        int Pixel = LCDSIM_GetPixelIndex(x,y, LCD_DISPLAY_INDEX);
        LCDSIM_SetPixelIndex(x,y, LCD_NUM_COLORS-1-Pixel, LCD_DISPLAY_INDEX);
      }
      x++;
			if (++Diff==8) {
        Diff=0;
				p++;
			}
		} while (--xsize);
    break;
	}
}

/*********************************************************************
*
*       _DrawBitLine2BPP
*/
#if (LCD_MAX_LOG_COLORS > 2)
static void _DrawBitLine2BPP(int x, int y, U8 const * p, int Diff, int xsize, const LCD_PIXELINDEX * pTrans) {
  LCD_PIXELINDEX Pixels = *p;
  int CurrentPixel = Diff;
  x += Diff;
  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
    case 0:
      if (pTrans) {
        do {
          int Shift = (3 - CurrentPixel) << 1;
          int Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
          LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
          SETPIXEL(x++, y, PixelIndex);
          if (++CurrentPixel == 4) {
            CurrentPixel = 0;
            Pixels = *(++p);
          }
		    } while (--xsize);
      } else {
        do {
          int Shift = (3 - CurrentPixel) << 1;
          int Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
          SETPIXEL(x++, y, Index);
          if (++CurrentPixel == 4) {
            CurrentPixel = 0;
            Pixels = *(++p);
          }
		    } while (--xsize);
      }
      break;
    case LCD_DRAWMODE_TRANS:
      if (pTrans) {
        do {
          int Shift = (3 - CurrentPixel) << 1;
          int Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
          if (Index) {
            LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
            SETPIXEL(x, y, PixelIndex);
          }
          x++;
          if (++CurrentPixel == 4) {
            CurrentPixel = 0;
            Pixels = *(++p);
          }
		    } while (--xsize);
      } else {
        do {
          int Shift = (3 - CurrentPixel) << 1;
          int Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
          if (Index) {
            SETPIXEL(x, y, Index);
          }
          x++;
          if (++CurrentPixel == 4) {
            CurrentPixel = 0;
            Pixels = *(++p);
          }
		    } while (--xsize);
      }
      break;
  }
}
#endif

/*********************************************************************
*
*       _DrawBitLine4BPP
*/
#if (LCD_MAX_LOG_COLORS > 4)
static void _DrawBitLine4BPP(int x, int y, U8 const * p, int Diff, int xsize, const LCD_PIXELINDEX * pTrans) {
  LCD_PIXELINDEX Pixels = *p;
  int CurrentPixel = Diff;
  x += Diff;
  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
    case 0:
      if (pTrans) {
        do {
          int Shift = (1 - CurrentPixel) << 2;
          int Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
          LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
          SETPIXEL(x++, y, PixelIndex);
          if (++CurrentPixel == 2) {
            CurrentPixel = 0;
            Pixels = *(++p);
          }
		    } while (--xsize);
      } else {
        do {
          int Shift = (1 - CurrentPixel) << 2;
          int Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
          SETPIXEL(x++, y, Index);
          if (++CurrentPixel == 2) {
            CurrentPixel = 0;
            Pixels = *(++p);
          }
		    } while (--xsize);
      }
      break;
    case LCD_DRAWMODE_TRANS:
      if (pTrans) {
        do {
          int Shift = (1 - CurrentPixel) << 2;
          int Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
          if (Index) {
            LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
            SETPIXEL(x, y, PixelIndex);
          }
          x++;
          if (++CurrentPixel == 2) {
            CurrentPixel = 0;
            Pixels = *(++p);
          }
		    } while (--xsize);
      } else {
        do {
          int Shift = (1 - CurrentPixel) << 2;
          int Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
          if (Index) {
            SETPIXEL(x, y, Index);
          }
          x++;
          if (++CurrentPixel == 2) {
            CurrentPixel = 0;
            Pixels = *(++p);
          }
		    } while (--xsize);
      }
      break;
  }
}
#endif

/*********************************************************************
*
*       _DrawBitLine8BPP
*/
#if (LCD_MAX_LOG_COLORS > 16)
static void _DrawBitLine8BPP(int x, int y, U8 const*p, int xsize, const LCD_PIXELINDEX*pTrans) {
  LCD_PIXELINDEX pixel;
  if ((GUI_Context.DrawMode & LCD_DRAWMODE_TRANS)==0) {
    if (pTrans) {
      for (;xsize > 0; xsize--,x++,p++) {
        pixel = *p;
        SETPIXEL(x, y, *(pTrans+pixel));
      }
    } else {
      for (;xsize > 0; xsize--,x++,p++) {
        SETPIXEL(x, y, *p);
      }
    }
  } else {   /* Handle transparent bitmap */
    if (pTrans) {
      for (; xsize > 0; xsize--, x++, p++) {
        pixel = *p;
        if (pixel) {
          SETPIXEL(x+0, y, *(pTrans+pixel));
        }
      }
    } else {
      for (; xsize > 0; xsize--, x++, p++) {
        pixel = *p;
        if (pixel) {
          SETPIXEL(x+0, y, pixel);
        }
      }
    }
  }
}
#endif

/*********************************************************************
*
*       _DrawBitLine16BPP
*/
#if (LCD_BITSPERPIXEL > 8)
static void _DrawBitLine16BPP(int x, int y, U16 const * p, int xsize) {
  LCD_PIXELINDEX pixel;
  if ((GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) == 0) {
    for (;xsize > 0; xsize--,x++,p++) {
      SETPIXEL(x, y, *p);
    }
  } else {   /* Handle transparent bitmap */
    for (; xsize > 0; xsize--, x++, p++) {
      pixel = *p;
      if (pixel) {
        SETPIXEL(x + 0, y, pixel);
      }
    }
  }
}
#endif

/*********************************************************************
*
*       _DrawBitLine24BPP
*/
#if (LCD_BITSPERPIXEL > 16)
static void _DrawBitLine24BPP(int x, int y, U32 const * p, int xsize) {
  LCD_PIXELINDEX pixel;
  if ((GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) == 0) {
    for (;xsize > 0; xsize--, x++, p++) {
      SETPIXEL(x, y, *p);
    }
  } else {   /* Handle transparent bitmap */
    for (; xsize > 0; xsize--, x++, p++) {
      pixel = *p;
      if (pixel) {
        SETPIXEL(x+0, y, pixel);
      }
    }
  }
}
#endif

/*********************************************************************
*
*       Exported code
*
**********************************************************************
*/

/*********************************************************************
*
*       LCD_L0_DrawPixel
*
*  Purpose:  Writes 1 pixel into the display.
*/
void LCD_L0_DrawPixel(int x, int y) {
  if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
    XORPIXEL(x, y);
  } else {
    SETPIXEL(x, y, LCD_COLORINDEX);
  }
}

/*********************************************************************
*
*       LCD_L0_DrawHLine
*/
void LCD_L0_DrawHLine(int x0, int y,  int x1) {
  if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
    for (;x0 <= x1; x0++) {
      XORPIXEL(x0, y);
    }
  } else {
    for (;x0 <= x1; x0++) {
      SETPIXEL(x0, y, LCD_COLORINDEX);
    }
  }
}

/*********************************************************************
*
*       LCD_L0_DrawVLine
*/
void LCD_L0_DrawVLine(int x, int y0,  int y1) {
  if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
    while (y0 <= y1) {
      XORPIXEL(x, y0);
      y0++;
    }
  } else {
    while (y0 <= y1) {
      SETPIXEL(x, y0, LCD_COLORINDEX);
      y0++;
    }
  }
}

/*********************************************************************
*
*       LCD_L0_FillRect
*/
void LCD_L0_FillRect(int x0, int y0, int x1, int y1) {
  for (; y0 <= y1; y0++) {
    LCD_L0_DrawHLine(x0,y0, x1);
  }
}

/*********************************************************************
*
*       LCD_L0_DrawBitmap
*/
void LCD_L0_DrawBitmap(int x0, int y0,
                       int xsize, int ysize,
                       int BitsPerPixel, 
                       int BytesPerLine,
                       const U8* pData, int Diff,
                       const LCD_PIXELINDEX* pTrans)
{
  int i;
  /*
     Use DrawBitLineXBPP
  */
  for (i=0; i<ysize; i++) {
    switch (BitsPerPixel) {
    case 1:
      _DrawBitLine1BPP(x0, i + y0, pData, Diff, xsize, pTrans);
      break;
    #if (LCD_MAX_LOG_COLORS > 2)
      case 2:
        _DrawBitLine2BPP(x0, i + y0, pData, Diff, xsize, pTrans);
        break;
    #endif
    #if (LCD_MAX_LOG_COLORS > 4)
      case 4:
        _DrawBitLine4BPP(x0, i + y0, pData, Diff, xsize, pTrans);
        break;
    #endif
    #if (LCD_MAX_LOG_COLORS > 16)
      case 8:
        _DrawBitLine8BPP(x0, i + y0, pData, xsize, pTrans);
        break;
    #endif
    #if (LCD_BITSPERPIXEL > 8)
      case 16:
        _DrawBitLine16BPP(x0, i + y0, (const U16 *)pData, xsize);
        break;
    #endif
    #if (LCD_BITSPERPIXEL > 16)
      case 24:
        _DrawBitLine24BPP(x0, i + y0, (const U32 *)pData, xsize);
        break;
    #endif
    }
    pData += BytesPerLine;
  }
}

/*********************************************************************
*
*       LCD_L0_SetOrg
*
*  Purpose:
*    Sets the original position of the virtual display.
*    Has no function at this point with the PC-driver.
*/
void LCD_L0_SetOrg(int x, int y) {
  //LCDSIM_SetOrg(x, y, LCD_DISPLAY_INDEX);
}

/*********************************************************************
*
*       Support for verification
*
*  Purpose:
*    The following routines are implemented, but have no functionility
*    at this point. The reason is that these functions are supposed
*    to supervise the hardware, which for obvious reasons can not be
*    done in a simulation.
*/
#if LCD_VERIFY
int  LCD_GetErrStat(void) {
  return 0;
}
void LCD_ClrErrStat(void) {
}
int  LCD_GetErrCnt (void) {
  return 0;
}
#endif  

/*********************************************************************
*
*       LCD_On
*       LCD_Off
*
*  (Not supported in Simulation)
*/
void LCD_Off          (void) {}
void LCD_On           (void) {}

/*********************************************************************
*
*       LCD_L0_SetLUTEntry
*/
void LCD_L0_SetLUTEntry(U8 Pos, LCD_COLOR color) {
  LCDSIM_SetLUTEntry(Pos, color, LCD_DISPLAY_INDEX);
}

/*********************************************************************
*
*       LCD_L0_Init
*/
int  LCD_L0_Init(void) {
	LCDSIM_Init();  //初始化LCDSIM
	return 0;
}

int  LCD_L0_CheckInit(void) {
  return 0;
} 

/*********************************************************************
*
*       LCD_L0_ReInit
*
*  Purpose:
*    This routine is supplied for compatibility and interchangability of
*    "C"-sources with embedded versions of the driver. It has no real
*    effect in the PC-version as there is simply no need to re-initialize
*    the LCD since it is just simulated anyhow.
*/
void LCD_L0_ReInit       (void) {}

unsigned LCD_L0_GetPixelIndex(int x, int y)  {
  return LCDSIM_GetPixelIndex(x,y, LCD_DISPLAY_INDEX);
}

/*********************************************************************
*
*       LCD_L0_XorPixel
*
*  Purpose:
*    Inverts 1 pixel of the display.
*/
void LCD_L0_XorPixel(int x, int y) {
  XORPIXEL(x, y);
}

/*********************************************************************
*
*       LCD_L0_SetPixelIndex
*
*  Purpose:
*    Writes 1 pixel into the display.
*/
void LCD_L0_SetPixelIndex(int x, int y, int ColorIndex) {
  SETPIXEL(x, y, ColorIndex);
}

/*********************************************************************
*
*       LCD_L0_GetDevFunc
*/
void * LCD_L0_GetDevFunc(int Index) {
  GUI_USE_PARA(Index);
  return NULL;
}


  void LCDWin_c(void);
  void LCDWin_c(void) { } /* avoid empty object files */



	 	 			 		    	 				 	  			   	 	 	 	 	 	  	  	      	   		 	 	 		  		  	 		 	  	  			     			       	   	 			  		    	 	     	 				  	 					 	 			   	  	  			 				 		 	 	 			     			 
//GUI_X_Win.c
#include "GUI_X.h"
#include <windows.h>


/*********************************************************************
*
*       GUI_X_Init()
*/
void GUI_X_Init(void)
{

}

/*********************************************************************
*
*       GUI_X_ExecIdle()
*/
void GUI_X_ExecIdle(void)
{
	Sleep(1);
};


/*********************************************************************
*
*      Timing:
*                 GUI_GetTime()
*                 GUI_Delay(int)

Some timing dependent routines of uC/GUI require a GetTime
and delay funtion. Default time unit (tick), normally is
1 ms.
*/
int StartTime;  //程序開始運行時的時間 該時間爲從系統開啓算起所經過的時間 單位爲毫秒
int GUI_X_GetTime(void) 
{
	return (timeGetTime() - StartTime);
}

void GUI_X_Delay(int Period) 
{
	Sleep(Period);
}

/*********************************************************************
*
*      Multitask interface for Win32
*
*  The folling section consisting of 4 routines is used to make
*  the GUI software thread safe with WIN32
*/

static HANDLE hMutex;
static int _EntranceCnt;   // For debugging only ... Not required

void GUI_X_InitOS(void) 
{
	StartTime = timeGetTime();  //需要添加winmm.lib庫
	//創建一個互斥量對象
	hMutex = CreateMutex(NULL, 0, "GUI Simulation - Mutex");
}

U32 GUI_X_GetTaskId(void)
{
	return GetCurrentThreadId();
}

void GUI_X_Lock(void) 
{
	WaitForSingleObject(hMutex, INFINITE);
	if (++_EntranceCnt > 1)
	{
		//SIM_ErrorOut("Error in GUITASK.c module ...");
	}
}

void GUI_X_Unlock(void)
{
	_EntranceCnt--;
	ReleaseMutex(hMutex);
}


/*********************************************************************
*
*      Text output for Logging, warnings and errors

Logging - required only for higher debug levels
*/
void GUI_X_Log     (const char *s)     { /*SIM_Log(s); */}
void GUI_X_Warn    (const char *s)     { /*SIM_Warn(s); */}
void GUI_X_ErrorOut(const char *s)     { /*SIM_ErrorOut(s);*/ }







 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章