📄 gui_basic.lst
字号:
C51 COMPILER V7.50 GUI_BASIC 03/30/2011 19:43:24 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE GUI_BASIC
OBJECT MODULE PLACED IN GUI_Basic.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Source\LYGUI\GUI_Basic.c LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.\GUI_Basic.
-lst) OBJECT(GUI_Basic.obj)
line level source
1 /*
2 ================================================================================
3 File Name : GUI_Basic.c
4 Author : LiYOng
5 Date : 2008-12-12 15:51
6 Version : 1.0
7 Decription: This file contains some basic functions for GUI, It need the LCD
8 Drive functions
9 ================================================================================
10 */
11 #include "GUI_Basic.H"
12 #include "GUI_Type.H"
13 #include "fontlib.h"
14 /*
15 ================================================================================
16 Function : GUI_DrawRectangle( )
17 Description : Draw a rectangle
18 Input : -pRect, point to a rectangle structure
19 output : None
20 ================================================================================
21 */
22 void GUI_DrawRectangle( RECT* pRect )
23 {
24 1 LINE line;
25 1
26 1 line.xs = pRect->xs;
27 1 line.xe = pRect->xe;
28 1 line.ys = pRect->ys;
29 1 line.ye = pRect->ys;
30 1 line.Color = pRect->Color;
31 1 LCDDrawHRLine( &line );
32 1
33 1 line.xe = pRect->xs;
34 1 line.ye = pRect->ye;
35 1 LCDDrawHRLine( &line );
36 1
37 1 line.xs = pRect->xe;
38 1 line.ys = pRect->ye;
39 1 LCDDrawHRLine( &line );
40 1
41 1 line.xe = pRect->xe;
42 1 line.ye = pRect->ys;
43 1 LCDDrawHRLine( &line );
44 1 }
45 /*
46 ================================================================================
47 Function : GUI_DrawLine( )
48 Description : Draw a line
49 Input : -pLine, point to a line structure
50 output : None
51 ================================================================================
52 */
53 void GUI_DrawLine( LINE* pLine )
54 {
C51 COMPILER V7.50 GUI_BASIC 03/30/2011 19:43:24 PAGE 2
55 1 INT32S dx; // 直线x轴差值变量
56 1 INT32S dy; // 直线y轴差值变量
57 1 INT32S dx_sym; // x轴增长方向,为-1时减值方向,为1时增值方向
58 1 INT32S dy_sym; // y轴增长方向,为-1时减值方向,为1时增值方向
59 1 INT32S dx_x2; // dx*2值变量,用于加快运算速度
60 1 INT32S dy_x2; // dy*2值变量,用于加快运算速度
61 1 INT32S di; // 决策变量
62 1
63 1 POINT point;
64 1 LINE line;
65 1
66 1 line.xs = pLine->xs;
67 1 line.ys = pLine->ys;
68 1 line.xe = pLine->xe;
69 1 line.ye = pLine->ye;
70 1 line.Color = pLine->Color;
71 1
72 1 point.Color = pLine->Color;
73 1
74 1 dx = line.xe - line.xs;
75 1 dy = line.ye - line.ys;
76 1
77 1 /* 判断增长方向,或是否为水平线、垂直线、点 */
78 1 if( dx > 0 ) // 判断x轴方向
79 1 {
80 2 dx_sym = 1; // dx>0,设置dx_sym=1
81 2 }
82 1 else
83 1 {
84 2 if( dx < 0 )
85 2 {
86 3 dx_sym = -1; // dx<0,设置dx_sym=-1
87 3 }
88 2 else
89 2 {
90 3 LCDDrawHRLine( &line );
91 3 return;
92 3 }
93 2 }
94 1
95 1 if( dy > 0 ) // 判断y轴方向
96 1 {
97 2 dy_sym = 1; // dy>0,设置dy_sym=1
98 2 }
99 1 else
100 1 {
101 2 if( dy < 0 )
102 2 {
103 3 dy_sym = -1; // dy<0,设置dy_sym=-1
104 3 }
105 2 else
106 2 { // dy==0,画水平线,或一点
107 3 LCDDrawHRLine( &line );
108 3 return;
109 3 }
110 2 }
111 1
112 1 /* 将dx、dy取绝对值 */
113 1 dx = dx_sym * dx;
114 1 dy = dy_sym * dy;
115 1
116 1 /* 计算2倍的dx及dy值 */
C51 COMPILER V7.50 GUI_BASIC 03/30/2011 19:43:24 PAGE 3
117 1 dx_x2 = dx*2;
118 1 dy_x2 = dy*2;
119 1
120 1 /* 使用Bresenham法进行画直线 */
121 1 if( dx >= dy ) // 对于dx>=dy,则使用x轴为基准
122 1 {
123 2 di = dy_x2 - dx;
124 2 while( line.xs != line.xe )
125 2 {
126 3 point.x = line.xs;
127 3 point.y = line.ys;
128 3 LCDDrawPoint( &point );
129 3 line.xs += dx_sym;
130 3 if( di < 0 )
131 3 {
132 4 di += dy_x2; // 计算出下一步的决策值
133 4 }
134 3 else
135 3 {
136 4 di += dy_x2 - dx_x2;
137 4 line.ys += dy_sym;
138 4 }
139 3 }
140 2 LCDDrawPoint( &point ); // 显示最后一点
141 2 }
142 1 else // 对于dx<dy,则使用y轴为基准
143 1 {
144 2 di = dx_x2 - dy;
145 2 while( line.ys != line.ye )
146 2 {
147 3 point.x = line.xs;
148 3 point.y = line.ys;
149 3 LCDDrawPoint( &point );
150 3 line.ys += dy_sym;
151 3 if(di<0)
152 3 {
153 4 di += dx_x2;
154 4 }
155 3 else
156 3 {
157 4 di += dx_x2 - dy_x2;
158 4 line.xs += dx_sym;
159 4 }
160 3 }
161 2 LCDDrawPoint( &point ); // 显示最后一点
162 2 }
163 1 }
164 /*
165 ================================================================================
166 Name: PrintFont
167 Function: Display a character at a special area
168 Input: 1.Xs : Start position X
169 2.Ys : Start position Y
170 3.pFont : A pointer of a font structure
171 4.Character : The ASCII code of the character.
172 Output: None
173 Note: The start position is inputted as a parameter, And the end position is calculated by the FONT
174 structure.
175 Author: LiYong
176 Date : 2008.08.09
177 ================================================================================
178 */
C51 COMPILER V7.50 GUI_BASIC 03/30/2011 19:43:24 PAGE 4
179 void GUI_DisplayFont( INT8U Xs, INT8U Ys, FONT* pFont, char Character )
180 {
181 1 BitBlock Block;
182 1 INT32U Bytes;
183 1 INT8U DataBuffer[64];
184 1 INT8U i;
185 1 const unsigned char *offset;
186 1
187 1 Block.Height = pFont->Height;
188 1 Block.Width = pFont->Width;
189 1 Block.Color = pFont->Color;
190 1 Block.BackColor = pFont->BackColor;
191 1 Block.xs = Xs;
192 1 Block.ys = Ys;
193 1
194 1 Bytes = pFont->Width >> 3;
195 1 if( pFont->Width & 0x07 )
196 1 {
197 2 Bytes ++;
198 2 }
199 1 Bytes *= pFont->Height;
200 1 Bytes *= Character - ' ';
201 1 offset = (const unsigned char*)&FontLib_14;
202 1 /*
203 1 if( pFont->Height == 18 )
204 1 {
205 1 offset = (const unsigned char*)&FontLib_18;
206 1 }
207 1 else if( pFont->Height == 14 )
208 1 {
209 1 offset = (const unsigned char*)&FontLib_14;
210 1 }
211 1 else
212 1 {
213 1 return;
214 1 }
215 1 */
216 1 offset += Bytes;
217 1 for( i = 0; i < 36; i ++ )
218 1 {
219 2 DataBuffer[i] = *( offset + i );
220 2 }
221 1
222 1
223 1 Block.pData = DataBuffer;
224 1
225 1 PrintBitBlock( &Block );
226 1 }
227 /*
228 ========================================================================================================
229 Name: DisplayStr
230 Function: Display a character at a special area
231 Input:
232 1.Xs : Start position X
233 2.Ys : Start position Y
234 3.pFont : A pointer of a font structure
235 4.Str : The start address of a string
236 Output: None
237 Note: The start position is inputted as a parameter, And the end position is calculated by the FONT
238 structure.
239 Author: LiYong
240 Date : 2008.08.09
C51 COMPILER V7.50 GUI_BASIC 03/30/2011 19:43:24 PAGE 5
241 ========================================================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -