27.2 例子二:AA_HiResPixels 这个例子主要也是演示一下高分辨率,例子所在位置:
例子实际显示效果如下:
下面跟大家分析下这个程序的源码:
- #include "GUI.h"
- #include "WM.h"
-
- /*******************************************************************
- *
- * Defines
- *
- ********************************************************************
- */
- #define AA_FACTOR 4
- #define POLY_SIZE 19
- #define POLY_POINTS 3
-
- #define COORD_0(Plus, AA_Factor) (I16)(((I32)((Plus ? POLY_SIZE : -POLY_SIZE) * AA_Factor * 0.7071f * 10000)) / 10000)
- #define COORD_1(Plus, AA_Factor) (I16)(((I32)((Plus ? POLY_SIZE : -POLY_SIZE) * AA_Factor * 1.2247f * 10000)) / 10000)
- #define COORD_2(Plus, AA_Factor) (I16)(((I32)((Plus ? POLY_SIZE : -POLY_SIZE) * AA_Factor * 1.4142f * 10000)) / 10000)
-
- /*******************************************************************
- *
- * Static variables
- *
- ********************************************************************
- */
- static int _pos_x1 = 30;
- static int _pos_y1 = 30;
- static int _pos_x2 = 125;
- static int _pos_y2 = 30;
- static int _pos_x3 = 220 * AA_FACTOR;
- static int _pos_y3 = 30 * AA_FACTOR;
- static int _color_d = -1;
- static GUI_COLOR _color_a = 0xFF00FE;
- static GUI_COLOR _color_b = 0x00FEFF;
- static GUI_COLOR _color_c = 0xFEFFFE;
-
- static const GUI_POINT _aPolygon_src[] = { (1)
- { 0, COORD_2(0, 1) },
- { COORD_1(1, 1), COORD_0(1, 1) },
- { COORD_1(0, 1), COORD_0(1, 1) }
- };
-
- static const GUI_POINT _aPolygonHiRes_src[] = { (2)
- { 0, COORD_2(0, AA_FACTOR) },
- { COORD_1(1, AA_FACTOR), COORD_0(1, AA_FACTOR) },
- { COORD_1(0, AA_FACTOR), COORD_0(1, AA_FACTOR) }
- };
-
- static GUI_POINT _aPolygon[POLY_POINTS];
- static GUI_POINT _aPolygonHiRes[POLY_POINTS];
-
- /*******************************************************************
- *
- * Static code
- *
- ********************************************************************
- */
- /*******************************************************************
- *
- * _cbWindow
- *
- * Function description
- * This is the callback for the window. A callback was used
- * for memory devices.
- */
- static void _cbWindow(WM_MESSAGE * pMsg) {(3)
- switch (pMsg->MsgId) {
- case WM_PAINT:
- GUI_SetBkColor(_color_a); (4)
- GUI_ClearRect( 0, 0, 250, 14);
- GUI_SetBkColor(_color_b);
- GUI_ClearRect( 0, 15, 250, 29);
- GUI_SetBkColor(GUI_BLACK);
- GUI_ClearRect( 0, 30, 250, 60);
- GUI_SetColor(_color_c);
- GUI_FillPolygon(_aPolygon, POLY_POINTS, _pos_x1, _pos_y1);(5)
- GUI_AA_FillPolygon(_aPolygon, POLY_POINTS, _pos_x2, _pos_y2);(6)
- GUI_AA_EnableHiRes();
- GUI_AA_FillPolygon(_aPolygonHiRes, POLY_POINTS, _pos_x3, _pos_y3);(7)
- GUI_AA_DisableHiRes();
- break;
- default:
- WM_DefaultProc(pMsg);
- }
- }
-
- /*******************************************************************
- *
- * _CalcColor
- *
- * Function description
- * Calculates the color-fading.
- */
- static void _CalcColor(void) {
- _color_a += 0x000002 * _color_d;
- _color_b += 0x000200 * _color_d;
- _color_c += 0x020002 * _color_d;
- if (_color_c == 0xFEFFFE || _color_c == 0x00FF00) {
- _color_d = -_color_d;
- }
- }
-
- /*******************************************************************
- *
- * _ShowHiResPixels
- *
- * Function description
- * This is frame-function for the callback. It creates the window
- * and handles the rotation of polygons and colors.
- */
- static void _ShowHiResPixels(void) {
- const GUI_FONT * FontOld;
- WM_HWIN hWindow;
- float pi;
- float Step;
- float Angle;
- int i;
-
- pi = 3.1415926f;
- Step = pi / 180;
- GUI_SetBkColor(GUI_BLACK);
- GUI_Clear();
- GUI_SetColor(GUI_WHITE);
- GUI_SetTextAlign(GUI_TA_HCENTER);
- FontOld = GUI_SetFont(&GUI_Font24_ASCII);
- GUI_DispStringAt("AA_HiResPixels - Sample", 160, 5);
- GUI_SetFont(FontOld);
- GUI_SetColor(GUI_RED);
- GUI_DispStringHCenterAt("notnantialised", 65, 100);
- GUI_SetColor(GUI_GREEN);
- GUI_DispStringHCenterAt("antialised", 160, 100);
- GUI_SetColor(GUI_BLUE);
- GUI_DispStringHCenterAt("antialisednwith highnresolution", 255, 100);
- hWindow = WM_CreateWindow(35, 140, 250, 60, WM_CF_SHOW | WM_CF_MEMDEV, _cbWindow, 0);
- WM_SelectWindow(hWindow);
- GUI_AA_SetFactor(AA_FACTOR);
- while (1) {
- for (i = 0, Angle = 0; i < 360; i++) {(8)
- Angle += Step;
- GUI_RotatePolygon(_aPolygonHiRes, _aPolygonHiRes_src, POLY_POINTS, Angle);(9)
- GUI_RotatePolygon(_aPolygon, _aPolygon_src, POLY_POINTS, Angle);
- _CalcColor();
- WM_InvalidateWindow(hWindow);(10)
- GUI_Delay(50);
- }
- }
- }
-
- /*********************************************************************
- *
- * Public code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * MainTask
- */
- void MainTask(void) {
- GUI_Init();
- _ShowHiResPixels();
- }
复制代码
1. 多边形的原始坐标。 2. 加入了高分辨率后的坐标点。 3. 所创建窗口的回调函数。 4. 这里主要是实现回调函数中的重绘消息。 5. 绘制多边形。 6. 绘制具有抗锯齿效果的多边形。 7. 绘制具有抗锯齿并支持高分辨率坐标的多边形。 8. 通过for循环实现图像的旋转。 9. 旋转多边形的原始坐标点,得到新的坐标点。详细可以看用户手册上面对这个函数的介绍 10. 通过使窗口无效来执行回调函数。从而实现多边形的旋转效果。
|