📄 window.cpp
字号:
}
} } event->source = control; // 座標変換 ((MouseEvent *)event)->x -= (x + INSETS_LEFT); ((MouseEvent *)event)->y -= (y + INSETS_TOP); control->postEvent(event); // 部品以外でイベントが起こった } else { // 部品をフォーカスアウト状態にする
LinkedItem *item = _controlList->firstItem; // NULLチェック if (item != NULL) { Control *c = (Control *)item->data; c->setFocused(false);
while (item->next != NULL) {
item = item->next; c = (Control *)item->data;
c->setFocused(false);
} } onEvent(event); } // マウスリリース } else if (event->type == MOUSE_RELEASED) { // マウスイベントが起こった部品を探す int ex = ((MouseEvent *)event)->x; int ey = ((MouseEvent *)event)->y; Control *control = findChild(ex, ey); // 部品でイベントが起こった if (control != NULL) { event->source = control; // 座標変換 ((MouseEvent *)event)->x -= (x + INSETS_LEFT); ((MouseEvent *)event)->y -= (y + INSETS_TOP); control->postEvent(event); // 部品以外でイベントが起こった } else { onEvent(event); } // マウスドラッグ } else if (event->type == MOUSE_DRAGGED) { Control *control = findChild(); // 部品でイベントが起こった if (control != NULL) { event->source = control; // 座標変換 ((MouseEvent *)event)->x -= (x + INSETS_LEFT); ((MouseEvent *)event)->y -= (y + INSETS_TOP); control->postEvent(event); // 部品以外でイベントが起こった } else { onEvent(event); } } else { onEvent(event); }}/** 再描画 */void Window::repaint(){ int i, j; if (firstpaint == false) firstpaint = true; if (iconified == true) { // 外枠 _g->setColor(0,0,0); _g->drawRect(0, 0, width, INSETS_TOP - 1); _g->setColor(200,200,200); _g->fillRect(1, 1, width - 2, INSETS_TOP - 2); // 輪郭線 _g->setColor(255,255,255); _g->drawLine(1, 1, width - 1, 1); _g->drawLine(1, 1, 1, INSETS_TOP - 2); _g->setColor(128,128,128); _g->drawLine(width - 1, 2, width - 1, INSETS_TOP - 2); _g->drawLine(2, INSETS_TOP - 2, width - 1, INSETS_TOP - 2); } else { // 外枠 _g->setColor(0,0,0); _g->drawRect(0, 0, width, height); _g->setColor(200,200,200); _g->fillRect(1, 1, width - 2, height - 2); // 内枠 _g->setColor(0,0,0); _g->drawRect(5, 21, width - 10, height - 26); // 輪郭線 _g->setColor(255,255,255); _g->drawLine(1, 1, width - 1, 1); _g->drawLine(1, 1, 1, height - 1); _g->drawLine(width - 4, 21, width - 4, height - 4); _g->drawLine(5, height - 4, width - 4, height - 4); _g->setColor(128,128,128); _g->drawLine(width - 1, 2, width - 1, height - 1); _g->drawLine(2, height - 1, width - 1, height - 1); _g->drawLine(4, 20, width - 5, 20); _g->drawLine(4, 20, 4, height - 5); } if (focused == true) { // タイトルライン for (i = 5; i <= 15; i = i + 2) { _g->setColor(128,128,128); _g->drawLine(20, i, width - 21, i); _g->setColor(255,255,255); _g->drawLine(21, i + 1, width - 22, i + 1); } // 閉じるアイコン、最小化アイコン for (i = 0; i < 13; i++) { for (j = 0; j < 13; j++) { _g->drawPixel(4 + j, 5 + i, closeIcon[i][j]); _g->drawPixel(width - 16 + j, 5 + i, minimizeIcon[i][j]); } } } else { // NOP } // タイトル int fw = FontManager::getInstance()->getWidth(title); int fh = FontManager::getInstance()->getHeight(); _g->setColor(200,200,200); _g->fillRect(((width - fw) / 2) - 4, 2, fw + 8, INSETS_TOP - 4); if (focused == true) { _g->setColor(0,0,0); } else { _g->setColor(128,128,128); } _g->drawText(title, ((width - fw) / 2), ((INSETS_TOP - fh) / 2)); //_g->drawText(title, ((width - fw) / 2) + 1, ((INSETS_TOP - fh) / 2));//太字 if (iconified == false) { // 子部品も更新 for(i = 0; i < _controlList->getLength(); i++) { Control *control = (Control *)_controlList->getItem(i)->data; control->repaint(); } onPaint(__g); }}/** スレッド開始 */void Window::run(){ // 実行中フラグ bool isRunning = false; // ウィンドウ追加メッセージを投げる MessageInfo info; if (MonAPI::Message::send(guisvrID, MSG_GUISERVER_ADD, threadID, (x << 16 | y), (width << 16 | height), NULL)) { //printf("Window->WindowManager: MSG_GUISERVER_ADD failed %d\n", threadID); } else { //printf("Window->WindowManager: MSG_GUISERVER_ADD sended %d\n", threadID); setFocused(true); repaint(); isRunning = true; } while (isRunning) { if (!MonAPI::Message::receive(&info)) { //if (!MonAPI::Message::peek(&info, 0, PEEK_REMOVE)) { // draw mouse_cursor monapi_call_mouse_set_cursor(0); switch(info.header){ case MSG_GUISERVER_ONKEYPRESS: //printf("WindowManager->Window MSG_GUISERVER_ONKEYPRESS received %d,%d,%d\n", info.arg1, info.arg2, info.arg3); _keyEvent->type = KEY_PRESSED; _keyEvent->keycode = info.arg1; _keyEvent->modifiers = info.arg2; postEvent(_keyEvent); break; case MSG_GUISERVER_ONKEYRELEASE: //printf("WindowManager->Window MSG_GUISERVER_ONKEYRELEASE received %d,%d,%d\n", info.arg1, info.arg2, info.arg3); _keyEvent->type = KEY_RELEASED; _keyEvent->keycode = info.arg1; _keyEvent->modifiers = info.arg2; postEvent(_keyEvent); break; case MSG_GUISERVER_ONMOUSEPRESS: //printf("WindowManager->Window MSG_GUISERVER_ONMOUSEPRESS received %d,%d,%d\n", info.arg1, info.arg2, info.arg3); _mouseEvent->type = MOUSE_PRESSED; _mouseEvent->x = info.arg1; _mouseEvent->y = info.arg2; postEvent(_mouseEvent); break; case MSG_GUISERVER_ONMOUSEDRAG: //printf("WindowManager->Window MSG_GUISERVER_ONMOUSEDRAG received %d,%d,%d\n", info.arg1, info.arg2, info.arg3); _mouseEvent->type = MOUSE_DRAGGED; _mouseEvent->x = info.arg1; _mouseEvent->y = info.arg2; postEvent(_mouseEvent); break; case MSG_GUISERVER_ONMOUSERELEASE: //printf("WindowManager->Window MSG_GUISERVER_ONMOUSERELEASE received %d,%d,%d\n", info.arg1, info.arg2, info.arg3); _mouseEvent->type = MOUSE_RELEASED; _mouseEvent->x = info.arg1; _mouseEvent->y = info.arg2; postEvent(_mouseEvent); break; case MSG_GUISERVER_ONMOUSEMOVE: //printf("WindowManager->Window MSG_GUISERVER_ONMOUSEMOVE received %d,%d,%d\n", info.arg1, info.arg2, info.arg3); _mouseEvent->type = MOUSE_MOVED; _mouseEvent->x = info.arg1; _mouseEvent->y = info.arg2; postEvent(_mouseEvent); break; case MSG_GUISERVER_ONTIMER: //printf("TimerThread->Window MSG_GUISERVER_ONTIMER received\n"); postEvent(_timerEvent); break; case MSG_GUISERVER_SETRECT: { int x = info.arg1 >> 16; int y = info.arg1 & 0xFFFF; int w = info.arg2 >> 16; int h = info.arg2 & 0xFFFF; setRect(x, y, w, h); //printf("WindowManager->Window MSG_GUISERVER_SETRECT received %d,%d,%d,%d\n", x, y, w, h); } //MonAPI::Message::reply(&info); break; case MSG_GUISERVER_REPAINT: //printf("WindowManager->Window MSG_GUISERVER_REPAINT received %d\n", threadID); repaint(); MonAPI::Message::reply(&info); break; case MSG_GUISERVER_ENABLED: //printf("WindowManager->Window MSG_GUISERVER_ENABLED received %d\n", threadID); setEnabled(true); MonAPI::Message::reply(&info); //MonAPI::Message::reply(&info); break; case MSG_GUISERVER_DISABLED: //printf("WindowManager->Window MSG_GUISERVER_DISABLED received %d\n", threadID); setEnabled(false); MonAPI::Message::reply(&info); //MonAPI::Message::reply(&info); break; case MSG_GUISERVER_FOCUSED: //printf("WindowManager->Window MSG_GUISERVER_FOCUSED received %d\n", threadID); setFocused(true); repaint(); MonAPI::Message::reply(&info); break; case MSG_GUISERVER_DEFOCUSED: //printf("WindowManager->Window MSG_GUISERVER_DEFOCUSED received %d\n", threadID); setFocused(false); MonAPI::Message::reply(&info); { // 部品をフォーカスアウト状態にする // NULLチェック if (_controlList->firstItem == NULL) break; // 前からチェックしていく
LinkedItem *item = _controlList->firstItem; Control *c = (Control *)item->data; c->setFocused(false);
while (item->next != NULL) {
item = item->next; c = (Control *)item->data;
c->setFocused(false);
} } break; case MSG_GUISERVER_ICONIFIED: //printf("WindowManager->Window MSG_GUISERVER_ICONIFIED received %d\n", threadID); setIconified(true); MonAPI::Message::reply(&info); break; case MSG_GUISERVER_DEICONIFIED: //printf("WindowManager->Window MSG_GUISERVER_DEICONIFIED received %d\n", threadID); setIconified(false); MonAPI::Message::reply(&info); break; case MSG_GUISERVER_REMOVE: //printf("WindowManager->Window MSG_GUISERVER_REMOVE received %d\n", threadID); MonAPI::Message::reply(&info); // タイマースレッド停止 syscall_kill_thread(timerID); // フラグ変更 isRunning = false; break; default: break; } // draw mouse_cursor monapi_call_mouse_set_cursor(1); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -