|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
5: //
6:
7: //
1.1.1.7 root 8: // LUNA LCD パネル、モニタ
1.1 root 9: //
10:
11: #include "wxlcdwindow.h"
12: #include "wxcolor.h"
1.1.1.4 root 13: #include "wxuimessage.h"
1.1 root 14: #include "lcd.h"
15:
1.1.1.7 root 16: //
17: // LUNA 前面 LCD パネル
18: //
1.1 root 19:
1.1.1.7 root 20: // BitmapPanel の継承で十分だが FontChanged() に連動させるため、
21: // TextPanel からの継承としている。
22: //
23: // 全体図。横16文字 x 縦2行
24: // □ は1キャラクタ分。5x8ピクセル。
25: // _ は1ピクセル分のアキ。
1.1 root 26: //
1.1.1.7 root 27: // +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +a +b +c +d +e +f
28: // 横 _□_□_□_□_□_□_□_□_□_□_□_□_□_□_□_□_
29: // _□_□_□_□_□_□_□_□_□_□_□_□_□_□_□_□_
1.1 root 30: //
1.1.1.7 root 31: // 1 2
32: // 縦 _□_□_
1.1 root 33:
34: // コンストラクタ
35: WXLCDPanel::WXLCDPanel(wxWindow *parent)
1.1.1.7 root 36: : inherited(parent)
1.1 root 37: {
1.1.1.7 root 38: u_width = 5 * 16 + 17;
39: u_height = 8 * 2 + 3;
40:
41: lcd = GetLCDDevice();
42: ddram = lcd->GetDDRAM();
1.1 root 43:
1.1.1.4 root 44: // VM からの通知を受け取る
45: WXUIMessage::Connect(UIMessage::LCD, this,
46: wxCommandEventHandler(WXLCDPanel::OnLCDChanged));
1.1.1.5 root 47:
1.1.1.7 root 48: FontChanged();
1.1.1.5 root 49: SetBitmapBGColor(UD_CREAM);
1.1.1.7 root 50: Fill();
1.1 root 51: }
52:
53: // デストラクタ
54: WXLCDPanel::~WXLCDPanel()
55: {
1.1.1.7 root 56: WXUIMessage::Disconnect(UIMessage::LCD, this,
1.1.1.4 root 57: wxCommandEventHandler(WXLCDPanel::OnLCDChanged));
1.1 root 58: }
59:
1.1.1.7 root 60: // フォントサイズ変更通知
61: void
62: WXLCDPanel::FontChanged()
63: {
64: inherited::FontChanged();
65:
66: // このパネル内の描画の基本単位。
67: // 12, 16, 24 を 2, 3, 4 にする。
68: unit = (font_height + 5) / 6;
69:
70: // コントロールの大きさを変更
71: wxSize size(u_width * unit, u_height * unit);
72: SetClientSize(size);
73: SetMinClientSize(size);
74: }
75:
1.1.1.4 root 76: // LCD 状態変更イベント (UIMessage)
1.1 root 77: void
1.1.1.4 root 78: WXLCDPanel::OnLCDChanged(wxCommandEvent& event)
1.1 root 79: {
1.1.1.4 root 80: Refresh();
1.1 root 81: }
82:
83: // バックグラウンドバッファに描画
84: void
1.1.1.5 root 85: WXLCDPanel::Draw()
1.1 root 86: {
87: for (int y = 0; y < 2; y++) {
88: for (int x = 0; x < 16; x++) {
89: uint8 ch = ddram[0x40 * y + x];
1.1.1.5 root 90: DrawChar(x, y, ch);
1.1 root 91: }
92: }
93: }
94:
95: // 1文字描画
96: void
1.1.1.5 root 97: WXLCDPanel::DrawChar(int x, int y, uint8 ch)
1.1 root 98: {
1.1.1.5 root 99: const Color pal[2] = { UD_YELLOW_GREEN, UD_BROWN };
1.1 root 100: const uint8 *font;
101:
1.1.1.7 root 102: font = lcd->GetFont(ch);
1.1.1.5 root 103: BitmapI1 src(font, 5, 8);
1.1 root 104:
1.1.1.8 ! root 105: int dx = (1 + x * 6) * unit;
! 106: int dy = (1 + y * 9) * unit;
! 107: bitmap.DrawBitmapI1Scale(dx, dy, src, pal, unit);
1.1 root 108: }
109:
1.1.1.5 root 110:
1.1 root 111: //
1.1.1.7 root 112: // LUNA 前面 LCD ウィンドウ
1.1 root 113: //
114:
115: // コンストラクタ
1.1.1.3 root 116: WXLCDWindow::WXLCDWindow(wxWindow *parent)
117: : inherited(parent, wxID_ANY, _("Front LCD"))
1.1 root 118: {
119: panel = new WXLCDPanel(this);
120:
1.1.1.5 root 121: DoSize();
1.1 root 122: }
123:
124: // デストラクタ
125: WXLCDWindow::~WXLCDWindow()
126: {
127: }
128:
1.1.1.5 root 129:
1.1 root 130: //
1.1.1.7 root 131: // モニタの LCD キャラクタ部パネル
1.1 root 132: //
133:
1.1.1.7 root 134: // BitmapPanel の継承で十分だが FontChanged() に連動させるため、
135: // TextPanel からの継承としている。
136: //
137: // 全体図。横16文字 + 横16文字の2段組。
138: // □ は1キャラクタ分。5x8ピクセル。
139: // _ は1ピクセル分のアキ。
140: //
141: // 余白
142: // +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +a +b +c +d +e +f +0 +1 +f
143: // 横 _□_□_□_□_□_□_□_□_□_□_□_□_□_□_□_□□□_□ … □_
144: //
145: // 00 10 20 30 40 50 60 70
146: // 縦 _□_□_□_□_□_□_□_□_
1.1 root 147:
148: // コンストラクタ
149: WXLCDCharPanel::WXLCDCharPanel(wxWindow *parent)
1.1.1.7 root 150: : inherited(parent)
1.1 root 151: {
1.1.1.7 root 152: lcd = GetLCDDevice();
153:
154: u_width = 5 * 33 + 32; // 横 5px * (32+1)文字、余白が計 32
155: u_height = 8 * 8 + 9; // 縦 8px * 8行、余白が計 9
156:
157: FontChanged();
1.1 root 158: }
159:
160: // デストラクタ
161: WXLCDCharPanel::~WXLCDCharPanel()
162: {
163: }
164:
1.1.1.7 root 165: // フォントサイズ変更通知
166: void
167: WXLCDCharPanel::FontChanged()
168: {
169: inherited::FontChanged();
170:
171: // このパネル内の描画の基本単位。
172: // 12, 16, 24 を 2, 3, 4 にする。
173: unit = (font_height + 5) / 6;
174:
175: // コントロールの大きさを変更
176: wxSize size(u_width * unit, u_height * unit);
177: SetClientSize(size);
178: SetMinClientSize(size);
179: }
180:
1.1 root 181: // バックグラウンドバッファに描画
182: void
1.1.1.5 root 183: WXLCDCharPanel::Draw()
1.1 root 184: {
1.1.1.5 root 185: const Color pal[2] = { UD_WHITE, UD_BLACK };
1.1 root 186:
187: // フォントは 5x8 (最下行はカーソル用に空けてあるので実際は 5x7)。
188: // 実際には 0xe0 以降には 5x10 フォントが混在しているのだが、その
189: // モードはサポートしていないので今の所全部 5x8 としてある。
190:
1.1.1.2 root 191: // cx, cy はこの文字の左上座標 (スケール前)
1.1.1.7 root 192: int cx = 1;
193: int cy = 1;
1.1.1.2 root 194: for (int ch = 0; ch < 256; ch++) {
1.1.1.7 root 195: const uint8 *font = lcd->GetFont(ch);
1.1.1.5 root 196: BitmapI1 src(font, 5, 8);
1.1.1.8 ! root 197: bitmap.DrawBitmapI1Scale(cx * unit, cy * unit, src, pal, unit);
1.1.1.2 root 198:
199: cx += 6;
200: if (ch % 16 == 15) {
201: if (ch == 127) {
1.1.1.7 root 202: // 0x80 以降は右側に作る。
203: // 余白も含めた 6px ずつ加算してきたが中間のアキは計 5px
204: // なので、過剰分の 1 引く必要がある。
205: cx += 5 - 1;
1.1.1.2 root 206: cy = 1;
1.1.1.7 root 207: } else {
208: // 行折り返し
209: cx -= 6 * 16;
210: cy += 9;
1.1.1.2 root 211: }
212: }
1.1 root 213: }
214: }
215:
1.1.1.5 root 216:
1.1 root 217: //
218: // LCD モニタウィンドウ
219: //
220:
221: // コンストラクタ
1.1.1.3 root 222: WXLCDMonitor::WXLCDMonitor(wxWindow *parent)
1.1.1.7 root 223: : inherited(parent, wxID_ANY, "LCD (HD44780)")
1.1 root 224: {
1.1.1.5 root 225: // +------------+
226: // | TextScreen |
227: // +------------+
228: // | CharPanel |
229: // +------------+
230: auto *topsizer = new wxBoxSizer(wxVERTICAL);
231:
232: // 上段、テキストスクリーン
1.1.1.6 root 233: monpanel = new WXMonitorPanel(this, gMonitorManager->Get(ID_MONITOR_LCD));
1.1.1.5 root 234: // 下辺は CharPanel の上余白が隣接しているため、自分のほうは付けない。
235: monpanel->SetPadding(-1, -1, -1, 0);
236: topsizer->Add(monpanel, 0, wxEXPAND);
1.1 root 237:
1.1.1.5 root 238: // 下段、キャラクタパネル
1.1 root 239: chrpanel = new WXLCDCharPanel(this);
1.1.1.5 root 240: topsizer->Add(chrpanel, 0, wxEXPAND);
1.1 root 241:
242: SetSizer(topsizer);
243:
244: // 大きさをそれに固定
1.1.1.5 root 245: SetClientSize(GetSizer()->GetMinSize());
1.1 root 246: }
247:
248: // デストラクタ
249: WXLCDMonitor::~WXLCDMonitor()
250: {
251: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.