UART通信を用いた組み込みデバッグ用途向けメモリモニタ
Revisão | 33fa799c02906b9432d87987a873c9e2a89c7e07 (tree) |
---|---|
Hora | 2018-04-22 22:03:47 |
Autor | Yasushi Tanaka <tanaka_yasushi2008@yaho...> |
Commiter | Yasushi Tanaka |
スクリーンは完成
@@ -58,7 +58,7 @@ | ||
58 | 58 | <Link> |
59 | 59 | <SubSystem>Windows</SubSystem> |
60 | 60 | <GenerateDebugInformation>true</GenerateDebugInformation> |
61 | - <AdditionalDependencies>imm32.lib;%(AdditionalDependencies)</AdditionalDependencies> | |
61 | + <AdditionalDependencies>imm32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> | |
62 | 62 | </Link> |
63 | 63 | </ItemDefinitionGroup> |
64 | 64 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
@@ -29,34 +29,16 @@ | ||
29 | 29 | #define SCREEN_COLOR_BLACK (RGB(0, 0, 0)) |
30 | 30 | |
31 | 31 | /* |
32 | - * 構造体 | |
32 | + * 仮想キャラクタ構造体 | |
33 | 33 | */ |
34 | -typedef struct _SCREEN_CHR | |
34 | +typedef struct _SCREEN_VIRT_CHR | |
35 | 35 | { |
36 | 36 | /* 現在のキャラクタ */ |
37 | - wchar_t curr_chr; | |
37 | + SCREEN_CHR current; | |
38 | 38 | |
39 | - /* 現在の全角左右フラグ(TRUEで左) */ | |
40 | - BOOL curr_lr; | |
41 | - | |
42 | - /* 現在のフォアグラウンドカラー */ | |
43 | - COLORREF curr_fore; | |
44 | - | |
45 | - /* 現在のバックグラウンドカラー */ | |
46 | - COLORREF curr_back; | |
47 | - | |
48 | - /* 過去のキャラクタ */ | |
49 | - wchar_t prev_chr; | |
50 | - | |
51 | - /* 過去の全角左右フラグ(TRUEで左) */ | |
52 | - BOOL prev_lr; | |
53 | - | |
54 | - /* 過去のフォアグラウンドカラー */ | |
55 | - COLORREF prev_fore; | |
56 | - | |
57 | - /* 過去のバックグラウンドカラー */ | |
58 | - COLORREF prev_back; | |
59 | -} SCREEN_CHR; | |
39 | + /* 描画したキャラクタ */ | |
40 | + SCREEN_CHR draw; | |
41 | +} SCREEN_VIRT_CHR; | |
60 | 42 | |
61 | 43 | /* |
62 | 44 | * static変数 |
@@ -78,7 +60,7 @@ static LONG g_lScreenExtWidth; | ||
78 | 60 | static LONG g_lScreenExtHeight; |
79 | 61 | |
80 | 62 | /* 仮想画面 */ |
81 | -static SCREEN_CHR g_ScreenAry[SCREEN_HEIGHT_MAX][SCREEN_WIDTH_MAX]; | |
63 | +static SCREEN_VIRT_CHR g_ScreenAry[SCREEN_HEIGHT_MAX][SCREEN_WIDTH_MAX]; | |
82 | 64 | |
83 | 65 | /* 現在のフォアグラウンドカラー */ |
84 | 66 | static COLORREF g_ForeTextColor; |
@@ -91,6 +73,74 @@ static BOOL g_bRequestDraw; | ||
91 | 73 | |
92 | 74 | /* |
93 | 75 | * スクリーン |
76 | + * 描画比較 | |
77 | + */ | |
78 | +static BOOL screen_drawcompare(LONG x, LONG y) | |
79 | +{ | |
80 | + BOOL bCompare; | |
81 | + | |
82 | + assert(0 <= x); | |
83 | + assert(SCREEN_WIDTH_MAX > x); | |
84 | + assert(0 <= y); | |
85 | + assert(SCREEN_HEIGHT_MAX > y); | |
86 | + | |
87 | + /* 比較フラグをTRUEに */ | |
88 | + bCompare = TRUE; | |
89 | + | |
90 | + /* キャラクタ */ | |
91 | + if (g_ScreenAry[y][x].current.chr != g_ScreenAry[y][x].draw.chr) | |
92 | + { | |
93 | + bCompare = FALSE; | |
94 | + } | |
95 | + | |
96 | + /* 左右 */ | |
97 | + if (g_ScreenAry[y][x].current.lr != g_ScreenAry[y][x].draw.lr) | |
98 | + { | |
99 | + bCompare = FALSE; | |
100 | + } | |
101 | + | |
102 | + /* フォアグラウンドカラー */ | |
103 | + if (g_ScreenAry[y][x].current.fore != g_ScreenAry[y][x].draw.fore) | |
104 | + { | |
105 | + bCompare = FALSE; | |
106 | + } | |
107 | + | |
108 | + /* バックグラウンドカラー */ | |
109 | + if (g_ScreenAry[y][x].current.back != g_ScreenAry[y][x].draw.back) | |
110 | + { | |
111 | + bCompare = FALSE; | |
112 | + } | |
113 | + | |
114 | + /* 比較結果を返す */ | |
115 | + return bCompare; | |
116 | +} | |
117 | + | |
118 | +/* | |
119 | + * スクリーン | |
120 | + * 描画要求フラグ設定 | |
121 | + */ | |
122 | +static void screen_requestdraw(LONG x, LONG y) | |
123 | +{ | |
124 | + BOOL bCompare; | |
125 | + | |
126 | + assert(0 <= x); | |
127 | + assert(x < SCREEN_WIDTH_MAX); | |
128 | + assert(0 <= y); | |
129 | + assert(y < SCREEN_HEIGHT_MAX); | |
130 | + | |
131 | + /* 比較 */ | |
132 | + bCompare = screen_drawcompare(x, y); | |
133 | + | |
134 | + /* もしFALSEであれば、描画要求フラグを設定 */ | |
135 | + if (FALSE == bCompare) | |
136 | + { | |
137 | + /* 描画要求フラグを設定 */ | |
138 | + g_bRequestDraw = TRUE; | |
139 | + } | |
140 | +} | |
141 | + | |
142 | +/* | |
143 | + * スクリーン | |
94 | 144 | * 文字列セット |
95 | 145 | */ |
96 | 146 | static void screen_settextw(UINT x, UINT y, COLORREF fore, COLORREF back, const wchar_t *format, ...) |
@@ -130,10 +180,13 @@ static void screen_settextw(UINT x, UINT y, COLORREF fore, COLORREF back, const | ||
130 | 180 | if (0x0100 > buf[offset]) |
131 | 181 | { |
132 | 182 | /* 半角 */ |
133 | - g_ScreenAry[y][x].curr_chr = buf[offset]; | |
134 | - g_ScreenAry[y][x].curr_lr = TRUE; | |
135 | - g_ScreenAry[y][x].curr_fore = fore; | |
136 | - g_ScreenAry[y][x].curr_back = back; | |
183 | + g_ScreenAry[y][x].current.chr = buf[offset]; | |
184 | + g_ScreenAry[y][x].current.lr = TRUE; | |
185 | + g_ScreenAry[y][x].current.fore = fore; | |
186 | + g_ScreenAry[y][x].current.back = back; | |
187 | + | |
188 | + /* 描画要求フラグ */ | |
189 | + screen_requestdraw((LONG)x, (LONG)y); | |
137 | 190 | |
138 | 191 | /* 半角は+1 */ |
139 | 192 | x++; |
@@ -144,16 +197,22 @@ static void screen_settextw(UINT x, UINT y, COLORREF fore, COLORREF back, const | ||
144 | 197 | if ((SCREEN_WIDTH_MAX - 1) > x) |
145 | 198 | { |
146 | 199 | /* Leftセット */ |
147 | - g_ScreenAry[y][x + 0].curr_chr = buf[offset]; | |
148 | - g_ScreenAry[y][x + 0].curr_lr = TRUE; | |
149 | - g_ScreenAry[y][x + 0].curr_fore = fore; | |
150 | - g_ScreenAry[y][x + 0].curr_back = back; | |
200 | + g_ScreenAry[y][x + 0].current.chr = buf[offset]; | |
201 | + g_ScreenAry[y][x + 0].current.lr = TRUE; | |
202 | + g_ScreenAry[y][x + 0].current.fore = fore; | |
203 | + g_ScreenAry[y][x + 0].current.back = back; | |
151 | 204 | |
152 | - /* Leftセット */ | |
153 | - g_ScreenAry[y][x + 1].curr_chr = buf[offset]; | |
154 | - g_ScreenAry[y][x + 1].curr_lr = FALSE; | |
155 | - g_ScreenAry[y][x + 1].curr_fore = fore; | |
156 | - g_ScreenAry[y][x + 1].curr_back = back; | |
205 | + /* 描画要求フラグ(Left) */ | |
206 | + screen_requestdraw((LONG)(x + 0), (LONG)y); | |
207 | + | |
208 | + /* Rightセット */ | |
209 | + g_ScreenAry[y][x + 1].current.chr = buf[offset]; | |
210 | + g_ScreenAry[y][x + 1].current.lr = FALSE; | |
211 | + g_ScreenAry[y][x + 1].current.fore = fore; | |
212 | + g_ScreenAry[y][x + 1].current.back = back; | |
213 | + | |
214 | + /* 描画要求フラグ(Right) */ | |
215 | + screen_requestdraw((LONG)(x + 1), (LONG)y); | |
157 | 216 | |
158 | 217 | /* 全角は+2 */ |
159 | 218 | x += 2; |
@@ -167,9 +226,6 @@ static void screen_settextw(UINT x, UINT y, COLORREF fore, COLORREF back, const | ||
167 | 226 | |
168 | 227 | /* 次のオフセットに進む */ |
169 | 228 | offset++; |
170 | - | |
171 | - /* 描画要求あり */ | |
172 | - g_bRequestDraw = TRUE; | |
173 | 229 | } |
174 | 230 | } |
175 | 231 |
@@ -225,10 +281,12 @@ static void screen_calcwidthheight(HWND hWnd) | ||
225 | 281 | * スクリーン |
226 | 282 | * WM_CREATEメッセージハンドラ |
227 | 283 | */ |
228 | -static BOOL screen_oncreate(HWND hWnd, const CREATESTRUCT *lpcs) | |
284 | +static BOOL screen_oncreate(HWND hWnd) | |
229 | 285 | { |
230 | - UINT x; | |
231 | - UINT y; | |
286 | + LONG x; | |
287 | + LONG y; | |
288 | + | |
289 | + assert(NULL != hWnd); | |
232 | 290 | |
233 | 291 | /* 仮想画面を初期化 */ |
234 | 292 | for (y = 0; y < SCREEN_HEIGHT_MAX; y++) |
@@ -236,16 +294,16 @@ static BOOL screen_oncreate(HWND hWnd, const CREATESTRUCT *lpcs) | ||
236 | 294 | for (x = 0; x < SCREEN_WIDTH_MAX; x++) |
237 | 295 | { |
238 | 296 | /* 現在のキャラクタは半角スペース、文字:黒色、背景:白色とする */ |
239 | - g_ScreenAry[y][x].curr_chr = L' '; | |
240 | - g_ScreenAry[y][x].curr_lr = TRUE; | |
241 | - g_ScreenAry[y][x].curr_fore = SCREEN_COLOR_BLACK; | |
242 | - g_ScreenAry[y][x].curr_back = SCREEN_COLOR_WHITE; | |
243 | - | |
244 | - /* 過去のキャラクタはヌル文字とする */ | |
245 | - g_ScreenAry[y][x].prev_chr = L'\0'; | |
246 | - g_ScreenAry[y][x].prev_lr = TRUE; | |
247 | - g_ScreenAry[y][x].prev_fore = SCREEN_COLOR_BLACK; | |
248 | - g_ScreenAry[y][x].prev_back = SCREEN_COLOR_WHITE; | |
297 | + g_ScreenAry[y][x].current.chr = L' '; | |
298 | + g_ScreenAry[y][x].current.lr = TRUE; | |
299 | + g_ScreenAry[y][x].current.fore = SCREEN_COLOR_BLACK; | |
300 | + g_ScreenAry[y][x].current.back = SCREEN_COLOR_WHITE; | |
301 | + | |
302 | + /* 描画したキャラクタはヌル文字とする */ | |
303 | + g_ScreenAry[y][x].draw.chr = L'\0'; | |
304 | + g_ScreenAry[y][x].draw.lr = TRUE; | |
305 | + g_ScreenAry[y][x].draw.fore = SCREEN_COLOR_BLACK; | |
306 | + g_ScreenAry[y][x].draw.back = SCREEN_COLOR_WHITE; | |
249 | 307 | } |
250 | 308 | } |
251 | 309 |
@@ -263,6 +321,12 @@ static void screen_ondestroy(HWND hWnd) | ||
263 | 321 | { |
264 | 322 | assert(NULL != hWnd); |
265 | 323 | assert(hWnd == g_hScreenWnd); |
324 | + | |
325 | + /* ウィンドウが無効であることを示す */ | |
326 | + g_hScreenWnd = NULL; | |
327 | + | |
328 | + /* 描画要求は必要ない */ | |
329 | + g_bRequestDraw = FALSE; | |
266 | 330 | } |
267 | 331 | |
268 | 332 | /* |
@@ -282,65 +346,60 @@ static void screen_onsize(HWND hWnd, LONG cx, LONG cy) | ||
282 | 346 | InvalidateRect(hWnd, NULL, TRUE); |
283 | 347 | |
284 | 348 | /* テスト */ |
285 | - screen_settextw(0, 0, SCREEN_COLOR_WHITE, SCREEN_COLOR_BLACK, L"幅=%d文字 高さ=%d文字", g_lScreenWidth, g_lScreenHeight); | |
349 | + screen_settextw(90, 0, SCREEN_COLOR_WHITE, SCREEN_COLOR_BLACK, L"幅=%d文字 高さ=%d文字", g_lScreenWidth, g_lScreenHeight); | |
286 | 350 | } |
287 | 351 | |
288 | 352 | /* |
289 | 353 | * スクリーン |
290 | 354 | * WM_ERASEBKGNDメッセージハンドラ |
291 | 355 | */ |
292 | -static void screen_onerasebkgnd(HDC hDC) | |
293 | -{ | |
294 | - /* Todo:余り領域があれば描画 */ | |
295 | -} | |
296 | - | |
297 | -/* | |
298 | - * スクリーン | |
299 | - * 描画比較 | |
300 | - */ | |
301 | -static BOOL screen_drawcompare(LONG x, LONG y) | |
356 | +static void screen_onerasebkgnd(HWND hWnd, HDC hDC) | |
302 | 357 | { |
303 | - BOOL bCompare; | |
304 | - | |
305 | - assert(0 <= x); | |
306 | - assert(SCREEN_WIDTH_MAX > x); | |
307 | - assert(0 <= y); | |
308 | - assert(SCREEN_HEIGHT_MAX > y); | |
358 | + HBRUSH hBrush; | |
359 | + RECT rect; | |
309 | 360 | |
310 | - /* 比較フラグをTRUEに */ | |
311 | - bCompare = TRUE; | |
361 | + assert(NULL != hWnd); | |
362 | + assert(NULL != hDC); | |
312 | 363 | |
313 | - /* キャラクタ */ | |
314 | - if (g_ScreenAry[y][x].curr_chr != g_ScreenAry[y][x].prev_chr) | |
364 | + /* 余り領域がなければ何もしない */ | |
365 | + if ((0 == g_lScreenExtWidth) && (0 == g_lScreenExtHeight)) | |
315 | 366 | { |
316 | - bCompare = FALSE; | |
367 | + return; | |
317 | 368 | } |
318 | 369 | |
319 | - /* 左右 */ | |
320 | - if (g_ScreenAry[y][x].curr_lr != g_ScreenAry[y][x].prev_lr) | |
321 | - { | |
322 | - bCompare = FALSE; | |
323 | - } | |
370 | + /* 背景ブラシを取得 */ | |
371 | + hBrush = GetSysColorBrush(COLOR_WINDOW); | |
324 | 372 | |
325 | - /* フォアグラウンドカラー */ | |
326 | - if (g_ScreenAry[y][x].curr_fore != g_ScreenAry[y][x].prev_fore) | |
373 | + /* 右側の余り領域を描画 */ | |
374 | + if (0 != g_lScreenExtWidth) | |
327 | 375 | { |
328 | - bCompare = FALSE; | |
376 | + /* クライアント領域を取得 */ | |
377 | + GetClientRect(hWnd, &rect); | |
378 | + | |
379 | + /* rect.leftのみ修正 */ | |
380 | + rect.left = SCREEN_WIDTH_MAX + g_tm.tmAveCharWidth; | |
381 | + | |
382 | + /* ブラシで塗りつぶす */ | |
383 | + FillRect(hDC, &rect, hBrush); | |
329 | 384 | } |
330 | 385 | |
331 | - /* バックグラウンドカラー */ | |
332 | - if (g_ScreenAry[y][x].curr_back != g_ScreenAry[y][x].prev_back) | |
386 | + /* 下側の余り領域を描画 */ | |
387 | + if (0 != g_lScreenExtHeight) | |
333 | 388 | { |
334 | - bCompare = FALSE; | |
335 | - } | |
389 | + /* クライアント領域を取得 */ | |
390 | + GetClientRect(hWnd, &rect); | |
336 | 391 | |
337 | - /* 比較結果を返す */ | |
338 | - return bCompare; | |
392 | + /* rect.topのみ修正 */ | |
393 | + rect.top = SCREEN_HEIGHT_MAX + g_tmAllHeight; | |
394 | + | |
395 | + /* ブラシで塗りつぶす */ | |
396 | + FillRect(hDC, &rect, hBrush); | |
397 | + } | |
339 | 398 | } |
340 | 399 | |
341 | 400 | /* |
342 | 401 | * スクリーン |
343 | - * 描画1キャラクタ | |
402 | + * キャラクタ描画 | |
344 | 403 | */ |
345 | 404 | static void screen_drawone(HDC hDC, LONG x, LONG y) |
346 | 405 | { |
@@ -355,33 +414,33 @@ static void screen_drawone(HDC hDC, LONG x, LONG y) | ||
355 | 414 | assert(SCREEN_HEIGHT_MAX > y); |
356 | 415 | |
357 | 416 | /* 右側は描画しない */ |
358 | - if (FALSE == g_ScreenAry[y][x].curr_lr) | |
417 | + if (FALSE == g_ScreenAry[y][x].current.lr) | |
359 | 418 | { |
360 | 419 | return; |
361 | 420 | } |
362 | 421 | |
363 | 422 | /* フォアグラウンドカラーを更新 */ |
364 | - if (g_ScreenAry[y][x].curr_fore != g_ForeTextColor) | |
423 | + if (g_ScreenAry[y][x].current.fore != g_ForeTextColor) | |
365 | 424 | { |
366 | - clrPrev = SetTextColor(hDC, g_ScreenAry[y][x].curr_fore); | |
425 | + clrPrev = SetTextColor(hDC, g_ScreenAry[y][x].current.fore); | |
367 | 426 | assert(CLR_INVALID != clrPrev); |
368 | 427 | if (CLR_INVALID == clrPrev) |
369 | 428 | { |
370 | 429 | return; |
371 | 430 | } |
372 | - g_ForeTextColor = g_ScreenAry[y][x].curr_fore; | |
431 | + g_ForeTextColor = g_ScreenAry[y][x].current.fore; | |
373 | 432 | } |
374 | 433 | |
375 | 434 | /* バックグラウンドカラーを更新 */ |
376 | - if (g_ScreenAry[y][x].curr_back != g_BackTextColor) | |
435 | + if (g_ScreenAry[y][x].current.back != g_BackTextColor) | |
377 | 436 | { |
378 | - clrPrev = SetBkColor(hDC, g_ScreenAry[y][x].curr_back); | |
437 | + clrPrev = SetBkColor(hDC, g_ScreenAry[y][x].current.back); | |
379 | 438 | assert(CLR_INVALID != clrPrev); |
380 | 439 | if (CLR_INVALID == clrPrev) |
381 | 440 | { |
382 | 441 | return; |
383 | 442 | } |
384 | - g_BackTextColor = g_ScreenAry[y][x].curr_back; | |
443 | + g_BackTextColor = g_ScreenAry[y][x].current.back; | |
385 | 444 | } |
386 | 445 | |
387 | 446 | /* 担当矩形を選択 */ |
@@ -391,13 +450,13 @@ static void screen_drawone(HDC hDC, LONG x, LONG y) | ||
391 | 450 | rect.bottom = rect.top + g_tmAllHeight; |
392 | 451 | |
393 | 452 | /* 全角文字の場合は幅を2倍にする */ |
394 | - if (0x0100 <= g_ScreenAry[y][x].curr_chr) | |
453 | + if (0x0100 <= g_ScreenAry[y][x].current.chr) | |
395 | 454 | { |
396 | 455 | rect.right += g_tm.tmAveCharWidth; |
397 | 456 | } |
398 | 457 | |
399 | 458 | /* テキストを描画 */ |
400 | - bResult = ExtTextOut(hDC, rect.left, rect.top, ETO_OPAQUE, &rect, (LPWSTR)&g_ScreenAry[y][x].curr_chr, 1, NULL); | |
459 | + bResult = ExtTextOut(hDC, rect.left, rect.top, ETO_OPAQUE, &rect, (LPWSTR)&g_ScreenAry[y][x].current.chr, 1, NULL); | |
401 | 460 | assert(FALSE != bResult); |
402 | 461 | if (FALSE == bResult) |
403 | 462 | { |
@@ -420,31 +479,31 @@ static void screen_drawupate(LONG x, LONG y) | ||
420 | 479 | assert(0 < g_lScreenWidth); |
421 | 480 | |
422 | 481 | /* キャラクタ */ |
423 | - g_ScreenAry[y][x].prev_chr = g_ScreenAry[y][x].curr_chr; | |
482 | + g_ScreenAry[y][x].draw.chr = g_ScreenAry[y][x].current.chr; | |
424 | 483 | |
425 | 484 | /* 左右 */ |
426 | - g_ScreenAry[y][x].prev_lr = g_ScreenAry[y][x].curr_lr; | |
485 | + g_ScreenAry[y][x].draw.lr = g_ScreenAry[y][x].current.lr; | |
427 | 486 | |
428 | 487 | /* フォアグラウンドカラー */ |
429 | - g_ScreenAry[y][x].prev_fore = g_ScreenAry[y][x].curr_fore; | |
488 | + g_ScreenAry[y][x].draw.fore = g_ScreenAry[y][x].current.fore; | |
430 | 489 | |
431 | 490 | /* バックグラウンドカラー */ |
432 | - g_ScreenAry[y][x].prev_back = g_ScreenAry[y][x].curr_back; | |
491 | + g_ScreenAry[y][x].draw.back = g_ScreenAry[y][x].current.back; | |
433 | 492 | |
434 | 493 | /* 描画範囲のx終端以外でなく、かつキャラクタが0x0100以上(全角)で、Lの場合 */ |
435 | - if ((x < (g_lScreenWidth - 1)) && (0x0100 <= g_ScreenAry[y][x].curr_chr) && (TRUE == g_ScreenAry[y][x].curr_lr)) | |
494 | + if ((x < (g_lScreenWidth - 1)) && (0x0100 <= g_ScreenAry[y][x].current.chr) && (TRUE == g_ScreenAry[y][x].current.lr)) | |
436 | 495 | { |
437 | - /* 一つ右側も描画しているので、右のprevを更新 */ | |
438 | - g_ScreenAry[y][x + 1].prev_chr = g_ScreenAry[y][x].curr_chr; | |
496 | + /* 一つ右側も描画しているので、右のdrawを更新 */ | |
497 | + g_ScreenAry[y][x + 1].draw.chr = g_ScreenAry[y][x].current.chr; | |
439 | 498 | |
440 | 499 | /* 左右は右にする */ |
441 | - g_ScreenAry[y][x + 1].prev_lr = FALSE; | |
500 | + g_ScreenAry[y][x + 1].draw.lr = FALSE; | |
442 | 501 | |
443 | 502 | /* フォアグラウンドカラー */ |
444 | - g_ScreenAry[y][x + 1].prev_fore = g_ScreenAry[y][x].curr_fore; | |
503 | + g_ScreenAry[y][x + 1].draw.fore = g_ScreenAry[y][x].current.fore; | |
445 | 504 | |
446 | 505 | /* バックグラウンドカラー */ |
447 | - g_ScreenAry[y][x + 1].prev_back = g_ScreenAry[y][x].curr_back; | |
506 | + g_ScreenAry[y][x + 1].draw.back = g_ScreenAry[y][x].current.back; | |
448 | 507 | } |
449 | 508 | } |
450 | 509 |
@@ -474,25 +533,25 @@ static void screen_drawmain(HWND hWnd, HDC hDC) | ||
474 | 533 | return; |
475 | 534 | } |
476 | 535 | |
477 | - /* フォアグラウンドカラーを選択(黒) */ | |
478 | - clrPrev = SetTextColor(hDC, SCREEN_COLOR_BLACK); | |
536 | + /* 最初のフォアグラウンドカラーを選択(白色) */ | |
537 | + clrPrev = SetTextColor(hDC, SCREEN_COLOR_WHITE); | |
479 | 538 | assert(CLR_INVALID != clrPrev); |
480 | 539 | if (CLR_INVALID == clrPrev) |
481 | 540 | { |
482 | 541 | SelectObject(hDC, hDefFont); |
483 | 542 | return; |
484 | 543 | } |
485 | - g_ForeTextColor = SCREEN_COLOR_BLACK; | |
544 | + g_ForeTextColor = SCREEN_COLOR_WHITE; | |
486 | 545 | |
487 | - /* バックグラウンドカラーを選択(白) */ | |
488 | - clrPrev = SetBkColor(hDC, SCREEN_COLOR_WHITE); | |
546 | + /* 最初のバックグラウンドカラーを選択(黒色) */ | |
547 | + clrPrev = SetBkColor(hDC, SCREEN_COLOR_BLACK); | |
489 | 548 | assert(CLR_INVALID != clrPrev); |
490 | 549 | if (CLR_INVALID == clrPrev) |
491 | 550 | { |
492 | 551 | SelectObject(hDC, hDefFont); |
493 | 552 | return; |
494 | 553 | } |
495 | - g_BackTextColor = SCREEN_COLOR_WHITE; | |
554 | + g_BackTextColor = SCREEN_COLOR_BLACK; | |
496 | 555 | |
497 | 556 | /* ループ */ |
498 | 557 | for (y = 0; y < g_lScreenHeight; y++) |
@@ -505,6 +564,7 @@ static void screen_drawmain(HWND hWnd, HDC hDC) | ||
505 | 564 | /* 一致していない場合、描画と更新 */ |
506 | 565 | if (FALSE == bCompare) |
507 | 566 | { |
567 | + /* このキャラクタは描画する必要がある */ | |
508 | 568 | screen_drawone(hDC, x, y); |
509 | 569 | screen_drawupate(x, y); |
510 | 570 | } |
@@ -513,6 +573,9 @@ static void screen_drawmain(HWND hWnd, HDC hDC) | ||
513 | 573 | |
514 | 574 | /* フォントを戻す */ |
515 | 575 | SelectObject(hDC, hDefFont); |
576 | + | |
577 | + /* 描画要求なし */ | |
578 | + g_bRequestDraw = FALSE; | |
516 | 579 | } |
517 | 580 | |
518 | 581 | /* |
@@ -521,21 +584,21 @@ static void screen_drawmain(HWND hWnd, HDC hDC) | ||
521 | 584 | */ |
522 | 585 | static void screen_onpaint(HWND hWnd) |
523 | 586 | { |
524 | - int x; | |
525 | - int y; | |
587 | + LONG x; | |
588 | + LONG y; | |
526 | 589 | HDC hDC; |
527 | 590 | PAINTSTRUCT ps; |
528 | 591 | |
529 | 592 | assert(NULL != hWnd); |
530 | 593 | |
531 | - /* スクリーンの表示範囲について、過去キャラクタをヌル文字にする */ | |
594 | + /* スクリーンの表示範囲について、描画キャラクタをヌル文字にする */ | |
532 | 595 | assert(0 <= g_lScreenHeight); |
533 | 596 | assert(0 <= g_lScreenWidth); |
534 | 597 | for (y = 0; y < g_lScreenHeight; y++) |
535 | 598 | { |
536 | 599 | for (x = 0; x < g_lScreenWidth; x++) |
537 | 600 | { |
538 | - g_ScreenAry[y][x].prev_chr = L'\0'; | |
601 | + g_ScreenAry[y][x].draw.chr = L'\0'; | |
539 | 602 | } |
540 | 603 | } |
541 | 604 |
@@ -552,21 +615,43 @@ static void screen_onpaint(HWND hWnd) | ||
552 | 615 | |
553 | 616 | /* |
554 | 617 | * スクリーン |
618 | + * アイドル描画 | |
619 | + */ | |
620 | +static void screen_drawidle(void) | |
621 | +{ | |
622 | + HDC hDC; | |
623 | + | |
624 | + assert(NULL != g_hScreenWnd); | |
625 | + | |
626 | + /* デバイスコンテキストを取得 */ | |
627 | + hDC = GetDC(g_hScreenWnd); | |
628 | + assert(NULL != hDC); | |
629 | + if (NULL == hDC) | |
630 | + { | |
631 | + return; | |
632 | + } | |
633 | + | |
634 | + /* 描画共通 */ | |
635 | + screen_drawmain(g_hScreenWnd, hDC); | |
636 | + | |
637 | + /* デバイスコンテキストを解放 */ | |
638 | + ReleaseDC(g_hScreenWnd, hDC); | |
639 | +} | |
640 | + | |
641 | +/* | |
642 | + * スクリーン | |
555 | 643 | * ウィンドウプロシージャ |
556 | 644 | */ |
557 | 645 | static LRESULT CALLBACK screen_proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) |
558 | 646 | { |
559 | 647 | BOOL bResult; |
560 | - const CREATESTRUCT *lpcs; | |
561 | 648 | |
562 | 649 | switch (uMsg) |
563 | 650 | { |
564 | 651 | /* ウィンドウが作成された */ |
565 | 652 | case WM_CREATE: |
566 | 653 | /* ハンドラを呼び出す */ |
567 | - lpcs = (const CREATESTRUCT *)lParam; | |
568 | - assert(NULL != lpcs); | |
569 | - bResult = screen_oncreate(hWnd, lpcs); | |
654 | + bResult = screen_oncreate(hWnd); | |
570 | 655 | assert(FALSE != bResult); |
571 | 656 | |
572 | 657 | /* ハンドラの結果によって、CreateWindowを失敗させる */ |
@@ -577,8 +662,10 @@ static LRESULT CALLBACK screen_proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM | ||
577 | 662 | } |
578 | 663 | |
579 | 664 | /* テスト */ |
580 | - screen_settextw(1, 1, RGB(255, 255, 0), RGB(128, 128, 128), L"文字平均幅=%d", g_tm.tmAveCharWidth); | |
581 | - screen_settextw(1, 2, RGB(128, 128, 128), RGB(255, 255, 0), L"文字最大幅=%d", g_tm.tmMaxCharWidth); | |
665 | + screen_settextw(90, 1, RGB(255, 255, 0), RGB(128, 128, 128), L"文字平均幅 =%d", g_tm.tmAveCharWidth); | |
666 | + screen_settextw(90, 2, RGB(128, 128, 128), RGB(255, 255, 0), L"文字最大幅 =%d", g_tm.tmMaxCharWidth); | |
667 | + screen_settextw(90, 3, RGB(128, 128, 128), RGB(255, 255, 0), L"文字高さ =%d", g_tm.tmHeight + g_tm.tmExternalLeading); | |
668 | + screen_settextw(90, 4, RGB(128, 128, 128), RGB(255, 255, 0), L"文字最大高 =%d", g_tmAllHeight); | |
582 | 669 | |
583 | 670 | /* 正常終了 */ |
584 | 671 | return 0; |
@@ -598,7 +685,7 @@ static LRESULT CALLBACK screen_proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM | ||
598 | 685 | /* 背景を再描画する */ |
599 | 686 | case WM_ERASEBKGND: |
600 | 687 | /* ハンドラを呼び出す */ |
601 | - screen_onerasebkgnd((HDC)wParam); | |
688 | + screen_onerasebkgnd(hWnd, (HDC)wParam); | |
602 | 689 | /* 自力でを背景を描画した場合は非ゼロを返す必要がある */ |
603 | 690 | return 1; |
604 | 691 |
@@ -674,45 +761,45 @@ BOOL screen_init(HWND hParentWnd, LONG lWidth, LONG lHeight) | ||
674 | 761 | BOOL bResult; |
675 | 762 | |
676 | 763 | /* static変数を初期化 */ |
677 | - g_hScreenWnd = NULL; | |
678 | - g_lScreenWidth = 0; | |
679 | - g_lScreenHeight = 0; | |
680 | - g_lScreenExtWidth = 0; | |
681 | - g_lScreenExtHeight = 0; | |
682 | - ZeroMemory(g_ScreenAry, sizeof(g_ScreenAry)); | |
683 | - g_bRequestDraw = TRUE; | |
684 | - | |
685 | - /* ウィンドウクラスの登録 */ | |
686 | - bResult = screen_register(); | |
687 | - assert(FALSE != bResult); | |
688 | - if (FALSE == bResult) | |
689 | - { | |
690 | - return FALSE; | |
691 | - } | |
764 | +g_hScreenWnd = NULL; | |
765 | +g_lScreenWidth = 0; | |
766 | +g_lScreenHeight = 0; | |
767 | +g_lScreenExtWidth = 0; | |
768 | +g_lScreenExtHeight = 0; | |
769 | +ZeroMemory(g_ScreenAry, sizeof(g_ScreenAry)); | |
770 | +g_bRequestDraw = TRUE; | |
771 | + | |
772 | +/* ウィンドウクラスの登録 */ | |
773 | +bResult = screen_register(); | |
774 | +assert(FALSE != bResult); | |
775 | +if (FALSE == bResult) | |
776 | +{ | |
777 | + return FALSE; | |
778 | +} | |
692 | 779 | |
693 | - /* ウィンドウの作成 */ | |
694 | - g_hScreenWnd = CreateWindow( | |
695 | - SCREEN_CLASS_NAME, | |
696 | - L"", | |
697 | - WS_CHILD | WS_VISIBLE, | |
698 | - 0, | |
699 | - 0, | |
700 | - lWidth, | |
701 | - lHeight, | |
702 | - hParentWnd, | |
703 | - NULL, | |
704 | - g_hAppInstance, | |
705 | - NULL); | |
706 | - | |
707 | - /* ウィンドウが作成できたかチェック */ | |
708 | - assert(NULL != g_hScreenWnd); | |
709 | - if (NULL == g_hScreenWnd) | |
710 | - { | |
711 | - return FALSE; | |
712 | - } | |
780 | +/* ウィンドウの作成 */ | |
781 | +g_hScreenWnd = CreateWindow( | |
782 | + SCREEN_CLASS_NAME, | |
783 | + SCREEN_CLASS_NAME, | |
784 | + WS_CHILD | WS_VISIBLE, | |
785 | + 0, | |
786 | + 0, | |
787 | + lWidth, | |
788 | + lHeight, | |
789 | + hParentWnd, | |
790 | + NULL, | |
791 | + g_hAppInstance, | |
792 | + NULL); | |
793 | + | |
794 | +/* ウィンドウが作成できたかチェック */ | |
795 | +assert(NULL != g_hScreenWnd); | |
796 | +if (NULL == g_hScreenWnd) | |
797 | +{ | |
798 | + return FALSE; | |
799 | +} | |
713 | 800 | |
714 | - /* 作成成功 */ | |
715 | - return TRUE; | |
801 | +/* 作成成功 */ | |
802 | +return TRUE; | |
716 | 803 | } |
717 | 804 | |
718 | 805 | /* |
@@ -732,3 +819,80 @@ void screen_resize(LONG lWidth, LONG lHeight) | ||
732 | 819 | return; |
733 | 820 | } |
734 | 821 | } |
822 | + | |
823 | +/* | |
824 | + * スクリーン | |
825 | + * アイドル | |
826 | + */ | |
827 | +void screen_idle(void) | |
828 | +{ | |
829 | + SYSTEMTIME st; | |
830 | + | |
831 | + /* ウィンドウが有効で、描画要求が存在する場合 */ | |
832 | + if ((NULL != g_hScreenWnd) && (FALSE != g_bRequestDraw)) | |
833 | + { | |
834 | + /* アイドル描画 */ | |
835 | + screen_drawidle(); | |
836 | + } | |
837 | + | |
838 | + GetLocalTime(&st); | |
839 | + screen_settextw(90, 5, SCREEN_COLOR_WHITE, SCREEN_COLOR_BLACK, L"%02d:%02d:%02d", st.wHour, st.wMinute, st.wSecond); | |
840 | +} | |
841 | + | |
842 | +/* | |
843 | + * スクリーン | |
844 | + * 矩形コピー | |
845 | + */ | |
846 | +void screen_copyregion(LONG left, LONG top, LONG width, LONG height, const SCREEN_CHR *ptr) | |
847 | +{ | |
848 | + LONG x; | |
849 | + LONG y; | |
850 | + LONG copy_width; | |
851 | + LONG copy_height; | |
852 | + | |
853 | + assert(0 <= left); | |
854 | + assert(0 <= top); | |
855 | + assert(0 <= width); | |
856 | + assert(0 <= height); | |
857 | + assert(NULL != ptr); | |
858 | + | |
859 | + /* コピー幅を算出 */ | |
860 | + copy_width = width; | |
861 | + if ((left + copy_width) > SCREEN_WIDTH_MAX) | |
862 | + { | |
863 | + copy_width = SCREEN_WIDTH_MAX - left; | |
864 | + } | |
865 | + if (0 >= copy_width) | |
866 | + { | |
867 | + /* コピーできる幅が0文字またはマイナス */ | |
868 | + return; | |
869 | + } | |
870 | + | |
871 | + /* コピー高さを算出 */ | |
872 | + copy_height = height; | |
873 | + if ((top + copy_height) > SCREEN_HEIGHT_MAX) | |
874 | + { | |
875 | + copy_height = SCREEN_HEIGHT_MAX - top; | |
876 | + } | |
877 | + if (0 >= copy_height) | |
878 | + { | |
879 | + /* コピーできる高さが0文字またはマイナス */ | |
880 | + return; | |
881 | + } | |
882 | + | |
883 | + /* ループ */ | |
884 | + for (y = 0; y < copy_height; y++) | |
885 | + { | |
886 | + for (x = 0; x < copy_width; x++) | |
887 | + { | |
888 | + /* コピー */ | |
889 | + g_ScreenAry[y + top][x + left].current = ptr[x]; | |
890 | + | |
891 | + /* 比較して描画要求 */ | |
892 | + screen_requestdraw(x + left, y + top); | |
893 | + } | |
894 | + | |
895 | + /* ptrを進める */ | |
896 | + ptr += width; | |
897 | + } | |
898 | +} |
@@ -8,6 +8,24 @@ | ||
8 | 8 | #pragma once |
9 | 9 | |
10 | 10 | /* |
11 | + * キャラクタ構造体 | |
12 | + */ | |
13 | +typedef struct _SCREEN_CHR | |
14 | +{ | |
15 | + /* キャラクタ(0x0100未満は半角、0x0100以上は全角 */ | |
16 | + wchar_t chr; | |
17 | + | |
18 | + /* 全角の左・右フラグ(TRUE:左、FALSE:右)。半角は常にTRUE */ | |
19 | + BOOL lr; | |
20 | + | |
21 | + /* フォアグラウンドカラー(テキスト色) */ | |
22 | + COLORREF fore; | |
23 | + | |
24 | + /* バックグラウンドカラー(背景色) */ | |
25 | + COLORREF back; | |
26 | +} SCREEN_CHR; | |
27 | + | |
28 | +/* | |
11 | 29 | * グローバル関数 |
12 | 30 | */ |
13 | 31 |
@@ -16,3 +34,9 @@ BOOL screen_init(HWND hParentWnd, LONG lWidth, LONG lHeight); | ||
16 | 34 | |
17 | 35 | /* リサイズ */ |
18 | 36 | void screen_resize(LONG lWidth, LONG lHeight); |
37 | + | |
38 | +/* アイドル */ | |
39 | +void screen_idle(void); | |
40 | + | |
41 | +/* 矩形コピー */ | |
42 | +void screen_copyregion(LONG left, LONG top, LONG width, LONG height, const SCREEN_CHR *ptr); |
@@ -23,7 +23,7 @@ | ||
23 | 23 | #define WINDOW_FONT_FACENAME L"MS ゴシック" |
24 | 24 | |
25 | 25 | /* フォントのポイント数 */ |
26 | -#define WINDOW_FONT_POINT 12 | |
26 | +#define WINDOW_FONT_POINT 9 | |
27 | 27 | |
28 | 28 | /* フォントの高さに加えるマージン(%) */ |
29 | 29 | #define WINDOW_FONT_HEIGHT_MERGIN 10 |
@@ -307,9 +307,20 @@ static BOOL OnCreateFont(HWND hWnd) | ||
307 | 307 | */ |
308 | 308 | static BOOL OnCreate(HWND hWnd, const CREATESTRUCT *lpcs) |
309 | 309 | { |
310 | + BOOL bResult; | |
311 | + MMRESULT mmResult; | |
312 | + | |
310 | 313 | assert(NULL != hWnd); |
311 | 314 | assert(NULL != lpcs); |
312 | 315 | |
316 | + /* マルチメディアタイマの最小分解能を設定 */ | |
317 | + mmResult = timeBeginPeriod(1); | |
318 | + assert(TIMERR_NOERROR == mmResult); | |
319 | + if (TIMERR_NOERROR != mmResult) | |
320 | + { | |
321 | + return FALSE; | |
322 | + } | |
323 | + | |
313 | 324 | /* フォントを作成 */ |
314 | 325 | if (FALSE == OnCreateFont(hWnd)) |
315 | 326 | { |
@@ -320,7 +331,12 @@ static BOOL OnCreate(HWND hWnd, const CREATESTRUCT *lpcs) | ||
320 | 331 | CalcSubWidthSize(hWnd); |
321 | 332 | |
322 | 333 | /* スクリーンを作成 */ |
323 | - screen_init(hWnd, g_lScreenWidth, g_lScreenHeight); | |
334 | + bResult = screen_init(hWnd, g_lScreenWidth, g_lScreenHeight); | |
335 | + assert(FALSE != bResult); | |
336 | + if (FALSE == bResult) | |
337 | + { | |
338 | + return FALSE; | |
339 | + } | |
324 | 340 | |
325 | 341 | /* 正常終了 */ |
326 | 342 | return TRUE; |
@@ -341,16 +357,18 @@ static void OnDestroy(HWND hWnd) | ||
341 | 357 | DeleteObject(g_hFont); |
342 | 358 | g_hFont = NULL; |
343 | 359 | } |
360 | + | |
361 | + /* マルチメディアタイマの最小分解能を復元 */ | |
362 | + timeEndPeriod(1); | |
344 | 363 | } |
345 | 364 | |
346 | 365 | /* |
347 | 366 | * WinMain |
348 | 367 | * WM_SIZEメッセージハンドラ |
349 | 368 | */ |
350 | -static void OnSize(HWND hWnd, LONG cx, LONG cy) | |
369 | +static void OnSize(HWND hWnd) | |
351 | 370 | { |
352 | 371 | assert(NULL != hWnd); |
353 | - assert(hWnd == g_hFrameWnd); | |
354 | 372 | |
355 | 373 | /* スクリーンとログのサイズを算出 */ |
356 | 374 | CalcSubWidthSize(hWnd); |
@@ -399,7 +417,7 @@ static LRESULT CALLBACK FrameWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPA | ||
399 | 417 | /* ウィンドウがリサイズされた */ |
400 | 418 | case WM_SIZE: |
401 | 419 | /* ハンドラを呼び出す */ |
402 | - OnSize(hWnd, (LONG)LOWORD(lParam), (LONG)HIWORD(lParam)); | |
420 | + OnSize(hWnd); | |
403 | 421 | return 0; |
404 | 422 | |
405 | 423 | /* その他 */ |
@@ -485,6 +503,7 @@ static BOOL InitInstance(HINSTANCE hInstance) | ||
485 | 503 | ImmDisableIME((DWORD)-1); |
486 | 504 | |
487 | 505 | /* 高DPI対応であることを明示する(Windows Vistaで追加されたAPI) */ |
506 | + /* APIで行うことは推奨されていない。マニフェストで行うのが正しい */ | |
488 | 507 | bResult = SetProcessDPIAware(); |
489 | 508 | assert(FALSE != bResult); |
490 | 509 | if (FALSE == bResult) |
@@ -564,6 +583,9 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine | ||
564 | 583 | else |
565 | 584 | { |
566 | 585 | /* アイドル処理 */ |
586 | + screen_idle(); | |
587 | + | |
588 | + /* 必ずSleepを入れる */ | |
567 | 589 | Sleep(10); |
568 | 590 | } |
569 | 591 | } |