void AllegroBitmapWidget::onMouseInput(int msg, int c) { if(msg==MSG_IDLE && lastMouseX==gui_mouse_x() && lastMouseY==gui_mouse_y()) return; MouseInput mi; translateMouseInput(msg, c, x, y, backend->getScale(), mi); backend->onMouseInput(mi); lastMouseX=gui_mouse_x(); lastMouseY=gui_mouse_y(); }
AllegroBitmapWidget::AllegroBitmapWidget(BitmapBackend* be): backend(be), handlingMouseInput(false), underMouse(false), lastMouseX(gui_mouse_x()), lastMouseY(gui_mouse_y()) { backend->setWidget(this); backend->initialize(); }
void translateMouseInput(int msg, int c, int bmpX, int bmpY, int scale, MouseInput& out) { switch(msg) { case MSG_IDLE: out.type=mouse_MOTION; break; case MSG_LPRESS: out.type=mouse_LEFTBUTTONDOWN; break; case MSG_LRELEASE: out.type=mouse_LEFTBUTTONUP; break; case MSG_RPRESS: out.type=mouse_RIGHTBUTTONDOWN; break; case MSG_RRELEASE: out.type=mouse_RIGHTBUTTONUP; break; case MSG_WHEEL: if(c<0) out.type=mouse_WHEELUP; else out.type=mouse_WHEELDOWN; break; default: return; } out.x=(gui_mouse_x()-bmpX)/scale; out.y=(gui_mouse_y()-bmpY)/scale; out.shiftPressed=key[KEY_LSHIFT] || key[KEY_RSHIFT]; out.ctrlPressed=key[KEY_ZC_LCONTROL] || key[KEY_ZC_RCONTROL]; out.altPressed=key[KEY_ALT]||key[KEY_ALTGR]; }
int AllegroBitmapWidget::proc(int msg, DIALOG* d, int c) { AllegroBitmapWidget* bmp=static_cast<AllegroBitmapWidget*>(d->dp); switch(msg) { case MSG_START: bmp->underMouse=dialogUnderMouse(d); bmp->lastMouseX=gui_mouse_x(); bmp->lastMouseY=gui_mouse_y(); break; case MSG_WANTFOCUS: return D_WANTFOCUS; case MSG_GOTMOUSE: bmp->underMouse=true; break; case MSG_LOSTMOUSE: bmp->underMouse=true; break; case MSG_LPRESS: case MSG_LRELEASE: case MSG_RPRESS: case MSG_RRELEASE: case MSG_WHEEL: case MSG_IDLE: // There's no mouse motion event... if(bmp->handlingMouseInput) bmp->onMouseInput(msg, c); break; } return D_O_K; }
/* d_editbox_proc: * A text box object. The dp field points to a char * which is the text * to be displayed in the text box. If the text is long, there will be * a vertical scrollbar on the right hand side of the object which can * be used to scroll through the text. The default is to print the text * with word wrapping, but if the D_SELECTED flag is set, the text will * be printed with character wrapping. The d1 field is used internally * to store the number of lines of text, and d2 is used to store how far * it has scrolled through the text. */ int d_editbox_proc(int msg, DIALOG *d, int c) { EditboxModel *model= (EditboxModel *)d->dp; int ret = D_O_K; static clock_t ticks; bool dontredraw=false; switch(msg) { case MSG_START: { model->getSelection().clearSelection(); model->getView()->initialize(model); break; } case MSG_IDLE: { if ((d->flags & D_GOTFOCUS)&&(clock()>ticks)) { d->flags |= D_DIRTY; ticks=clock()+(CLOCKS_PER_SEC/2); model->getCursor().invertVisibility(); } break; } case MSG_DRAW: { model->getView()->draw(); break; } case MSG_WANTFOCUS: { ret = D_WANTFOCUS; break; } case MSG_CHAR: { //handle selecting (bah) switch(c>>8) { case KEY_LEFT: case KEY_RIGHT: case KEY_UP: case KEY_DOWN: case KEY_HOME: case KEY_END: case KEY_PGUP: case KEY_PGDN: if (key[KEY_LSHIFT]||key[KEY_RSHIFT]) { model->getSelection().ensureSelecting(model->getCursor()); } else { model->getSelection().clearSelection(); } } //normal event handling switch(c>>8) { case KEY_LEFT: model->getCursor()--; ret = D_USED_CHAR; break; case KEY_RIGHT: model->getCursor()++; ret = D_USED_CHAR; break; case KEY_UP: model->getView()->lineUp(); ret = D_USED_CHAR; break; case KEY_DOWN: model->getView()->lineDown(); ret = D_USED_CHAR; break; case KEY_HOME: model->getView()->lineHome(); ret = D_USED_CHAR; break; case KEY_END: model->getView()->lineEnd(); ret = D_USED_CHAR; break; case KEY_PGDN: model->getView()->pageDown(); ret = D_USED_CHAR; break; case KEY_PGUP: model->getView()->pageUp(); ret = D_USED_CHAR; break; case KEY_ENTER: case KEY_ENTER_PAD: model->clear(); model->getCursor().insertNewline(); ret = D_USED_CHAR; break; case KEY_TAB: { model->clear(); int ch = Unicode::getCharAtOffset(uconvert_ascii("\t",NULL),0); model->getCursor().insertChar(ch); ret = D_USED_CHAR; break; } case KEY_DEL: case KEY_DEL_PAD: if(model->getSelection().hasSelection()) model->clear(); else model->getCursor().deleteChar(); ret = D_USED_CHAR; break; case KEY_BACKSPACE: if(model->getSelection().hasSelection()) model->clear(); else if(model->getCursor().getPosition() != 0) { model->getCursor()--; model->getCursor().deleteChar(); } ret = D_USED_CHAR; break; case KEY_C: if (key[KEY_LCONTROL]||key[KEY_RCONTROL]) { model->copy(); ret = D_USED_CHAR; break; } ret = D_O_K; break; case KEY_X: if (key[KEY_LCONTROL]||key[KEY_RCONTROL]) { model->cut(); ret = D_USED_CHAR; break; } ret = D_O_K; break; case KEY_V: if(key[KEY_LCONTROL]||key[KEY_RCONTROL]) { model->clear(); model->paste(); ret = D_USED_CHAR; break; } ret = D_O_K; break; case KEY_ESC: return D_EXIT; case KEY_F1: model->doHelp(); ret = D_USED_CHAR; dontredraw=true; break; } //selection post-processing if (key[KEY_LSHIFT]||key[KEY_RSHIFT]) { switch(c>>8) { case KEY_LEFT: case KEY_RIGHT: case KEY_UP: case KEY_DOWN: case KEY_HOME: case KEY_END: case KEY_PGUP: case KEY_PGDN: model->getSelection().adjustSelection(model->getCursor()); } } break; } case MSG_UCHAR: { ret = D_USED_CHAR; if ((c >= ' ') && (uisok(c))) { model->clear(); model->getCursor().insertChar(c); } } break; case MSG_CLICK: { bool redraw = model->getView()->mouseClick(gui_mouse_x(), gui_mouse_y()); if(model->getCursor().isVisible()) model->getCursor().invertVisibility(); if(redraw) { object_message(d, MSG_DRAW, 0); } while(gui_mouse_b()) { if(model->getView()->mouseDrag(gui_mouse_x(), gui_mouse_y())) { scare_mouse(); object_message(d, MSG_DRAW, 0); unscare_mouse(); } } model->getView()->mouseRelease(gui_mouse_x(), gui_mouse_y()); if(!model->getCursor().isVisible()) model->getCursor().invertVisibility(); d->flags |= D_DIRTY; break; } case MSG_WHEEL: { if(c>0) model->getView()->scrollUp(); else model->getView()->scrollDown(); d->flags |= D_DIRTY; break; } } if(ret == D_USED_CHAR && !dontredraw) { //redraw if(!model->getCursor().isVisible()) model->getCursor().invertVisibility(); ticks=clock()+(CLOCKS_PER_SEC/2); model->getView()->ensureCursorOnScreen(); d->flags |= D_DIRTY; } return ret; }
int AllegroTabBar::proc(int msg, DIALOG* d, int c) { if(msg==MSG_CLICK) static_cast<AllegroTabBar*>(d->dp)->onClick(gui_mouse_x()); return D_O_K; }