|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2022 nono project
4: // Licensed under nono-license.txt
5: //
6:
7: //
8: // パレットモニターウィンドウ
9: //
10:
11: #include "wxpalettemonitor.h"
12: #include "wxcolor.h"
13: #include "wxtextscreen.h"
14: #include "wxuimessage.h"
15: #include "bt45x.h"
1.1.1.3 ! root 16: #include "mainapp.h"
1.1 root 17: #include "videoctlr.h"
18:
19: //
20: // パレットビットマップ
21: //
22: //
23: // 情報欄は WXTextScreen 同様に上下と左に DefaultPadding を手動で入れてある。
24: //
25: //
26: // +------------ DefaultPadding (情報欄の左側)
27: // |
28: // +-|------
29: // | v <- DefaultPadding (情報欄の上側)
30: // | "Text"
31: // | <- DefaultPadding (情報欄の下側、パレット欄の区切り)
32: // | "+0 +1 …"
33: // |-------- <- pal_y0 (ここから以下がパレット領域)
34: // | □‥
35: // : :
36: // | □‥
37: // | <- DefaultPadding (パレットの下側)
38: // +-^-------^
39: // | |
40: // +-------+---- DefaultPadding (パレットの左右)
41: //
42: // パレット欄は1マスが横 font_height (= font_width * 2)、縦 font_height [px]
43: // で、マスの右端と左端の1ピクセルを BGPANEL 色にして罫線にする。
44:
45: // イベントテーブル
46: wxBEGIN_EVENT_TABLE(WXPalettePanel, inherited)
47: EVT_MOUSE_EVENTS(WXPalettePanel::OnMouse)
48: wxEND_EVENT_TABLE()
49:
50: // コンストラクタ
51: WXPalettePanel::WXPalettePanel(wxWindow *parent)
52: : inherited(parent)
53: {
54: // デバイスを取得
55: bt45x = gMainApp.FindObject<BT45xDevice>(OBJ_BT45x);
56: videoctlr = gMainApp.FindObject<VideoCtlrDevice>(OBJ_VIDEOCTLR);
57:
58: cursor = -1;
59:
60: // パレットは1行に16個で、行数 (1 or 16) が可変。
61: // ここではサイズだけ確定させる。
1.1.1.2 root 62: const std::vector<Color> *hpal;
1.1 root 63: if (videoctlr) {
64: hpal = &videoctlr->GetHostPalette();
65: } else {
66: hpal = &bt45x->GetHostPalette();
67: }
68: rows = hpal->size() / 16;
69:
70: FontChanged();
71: PaletteChanged();
72:
73: // VM からの通知を受け取る
74: WXUIMessage::Connect(UIMessage::PALETTE, this,
75: wxCommandEventHandler(WXPalettePanel::OnPaletteChanged));
76: }
77:
78: // デストラクタ
79: WXPalettePanel::~WXPalettePanel()
80: {
81: WXUIMessage::Disconnect(UIMessage::PALETTE, this,
82: wxCommandEventHandler(WXPalettePanel::OnPaletteChanged));
83: }
84:
85: void
86: WXPalettePanel::FontChanged()
87: {
88: inherited::FontChanged();
89:
90: pal0x = WXTextScreen::DefaultPadding; // 左余白
91: pal0x += font_width * 4; // "$00:"
92:
93: pal0y = WXTextScreen::DefaultPadding; // 上余白
94: pal0y += font_height * 2; // テキスト
95: pal0y += WXTextScreen::DefaultPadding; // テキストとパレットの境界余白
96: pal0y += font_height; // ヘッダ("+0+1"…)
97:
98: wxSize size;
99: size.x = pal0x; // パレットより左全部
100: size.x += 16 * font_height; // パレット部
101: size.x += WXTextScreen::DefaultPadding; // 右余白
102:
103: size.y = pal0y; // パレットより上全部
104: size.y += rows * font_height; // パレット部
105: size.y += WXTextScreen::DefaultPadding; // 下余白
106:
107: SetClientSize(size);
108: SetMinClientSize(size);
109: }
110:
111: // VM からのパレット変更通知
112: void
113: WXPalettePanel::OnPaletteChanged(wxCommandEvent& event)
114: {
115: PaletteChanged();
116: }
117:
118: void
119: WXPalettePanel::PaletteChanged()
120: {
121: // ホストパレットをここでコピー。
122: if (videoctlr) {
123: pal = videoctlr->GetHostPalette();
124: ipal = videoctlr->GetIntPalette();
125: } else {
126: pal = bt45x->GetHostPalette();
127: ipal = bt45x->GetIntPalette();
128: }
129: Refresh();
130: }
131:
132: void
133: WXPalettePanel::Draw()
134: {
135: bitmap.Fill(BGPANEL);
136:
137: // テキスト (2行)
138: // XXX snprintf が色々うるさくてアレ…
139: char text1[36 + 1 + 40];
140: char text2[36 + 1];
141: if (cursor < 0) {
142: strlcpy(text1, "[ ]", sizeof(text1));
143: strlcpy(text2, "Host R: G: B:", sizeof(text2));
144: } else {
145: // この位置のパレット情報を取得
146: __assume(cursor <= 0xff);
147: snprintf(text1, sizeof(text1), "[$%02x]", cursor);
148: if (videoctlr) {
149: uint r = (ipal[cursor] >> 6) & 0x1f;
150: uint g = (ipal[cursor] >> 11) & 0x1f;
151: uint b = (ipal[cursor] >> 1) & 0x1f;
152: uint i = ipal[cursor] & 1;
153: snprintf(text1 + 5, sizeof(text1) - 5,
154: " $%04x R:%02x G:%02x B:%02x I:%d",
155: ipal[cursor], r, g, b, i);
156: text1[36] = '\0';
157: } else {
158: if (rows == 1) {
159: // Bt454
160: uint r = ipal[cursor] >> 8;
161: uint g = (ipal[cursor] >> 4) & 0xf;
162: uint b = ipal[cursor] & 0xf;
163: snprintf(text1 + 5, sizeof(text1) - 5,
164: " Guest R:%x G:%x B:%x", r, g, b);
165: } else {
166: // Bt458
167: uint r = ipal[cursor] >> 16;
168: uint g = (ipal[cursor] >> 8) & 0xff;
169: uint b = ipal[cursor] & 0xff;
170: snprintf(text1 + 5, sizeof(text1) - 5,
171: " Guest R:%02x G:%02x B:%02x", r, g, b);
172: }
173: }
174: snprintf(text2, sizeof(text2), "Host R:%02x G:%02x B:%02x",
175: pal[cursor].r,
176: pal[cursor].g,
177: pal[cursor].b);
178: }
179: const int padding = WXTextScreen::DefaultPadding;
180: DrawStringSJIS(padding, padding, text1);
181: DrawStringSJIS(padding + font_width * 6, padding + font_height, text2);
182:
183: // ヘッダ
184: DrawStringSJIS(pal0x, pal0y - font_height,
185: "+0+1+2+3+4+5+6+7+8+9+a+b+c+d+e+f");
186: for (int y = 0; y < rows; y++) {
187: char buf[8];
188: __assume(y < 16); // XXX snprintf 対策。うーん
189: snprintf(buf, sizeof(buf), "$%02x:", y * 16);
190: DrawStringSJIS(padding, pal0y + y * font_height, buf);
191: }
192:
193: // パレット
194: Rect rect(0, 0, font_height - 1, font_height - 1);
195: for (int y = 0; y < rows; y++) {
196: for (int x = 0; x < 16; x++) {
197: int cc = y * 16 + x;
198: rect.x = pal0x + x * font_height;
199: rect.y = pal0y + y * font_height;
1.1.1.2 root 200: bitmap.FillRect(pal[cc], rect);
1.1 root 201: }
202: }
203: }
204:
205: void
206: WXPalettePanel::OnMouse(wxMouseEvent& event)
207: {
208: wxPoint pt = event.GetPosition();
209: int new_cursor = -1;
210:
211: // pt がパネル内の座標なのに Leaving() になることがある。
212: // pt がパネル外の座標なのに Leaving() にならないことがある。
213: if (event.Leaving() == false && GetClientRect().Contains(pt)) {
214: // マウスカーソルがパネル上にある
215:
216: int x = pt.x - pal0x;
217: int y = pt.y - pal0y;
218: if (x < 0 || y < 0) {
219: // パレット外
220: goto next;
221: }
222: x /= font_height;
223: y /= font_height;
224: if (x >= 16 || y >= rows) {
225: // パレット外
226: goto next;
227: }
228:
229: new_cursor = y * 16 + x;
230: }
231:
232: next:
233: if (new_cursor != cursor) {
234: cursor = new_cursor;
235: Refresh();
236: }
237: }
238:
239:
240: //
241: // パレットウィンドウ
242: //
243:
244: // コンストラクタ
245: WXPaletteWindow::WXPaletteWindow(wxWindow *parent, const wxString& name)
246: : inherited(parent, wxID_ANY, name)
247: {
248: new WXPalettePanel(this);
249: DoSize();
250: }
251:
252: // デストラクタ
253: WXPaletteWindow::~WXPaletteWindow()
254: {
255: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.