int ActionButton::handleMouse() { POINT pos; int button; button = mouse_status(&pos); if (!contains(pos.x, pos.y)) return 0; select(); mouse_off(); draw(); mouse_on(); while (contains(pos.x, pos.y)) { if (button == 1) { mouse_wait_for_release(1, &pos); leftClicked(); } else if (button == 2) { mouse_wait_for_release(2, &pos); rightClicked(); } button = mouse_status(&pos); } deselect(); mouse_off(); draw(); mouse_on(); return 0; }
/* ------------------ */ void mn_action(void) { register int i, l; register char *m_entry; mouse_on(); i = 0; while (i < M_POINTS && msg[4] != menu_id[i]) i++; m_entry = menu_adr[msg[4]].ob_spec.free_string; l = strlen(m_entry); if (m_entry[l - 3] == 'F') if (m_entry[l - 1] == '0') funk_blink(9); else funk_blink(m_entry[l - 2] - '1'); if (i < M_POINTS) (*rout[i])(); menu_tnormal(menu_adr, msg[3], TRUE); }
Sint32 vbutton::leftclick(Sint32 whichbutton) { Sint32 retvalue=0; Uint8* mousekeys = query_keyboard(); if (whichbutton == 1) // hotkeys { if (mousekeys[hotkey]) { myscreen->soundp->play_sound(SOUND_BOW); vdisplay(1); vdisplay(); if (myfunc) { retvalue = do_call(myfunc, arg); } while (mousekeys[hotkey]) get_input_events(WAIT); return retvalue; } } else { if (mouse_on()) { myscreen->soundp->play_sound(SOUND_BOW); vdisplay(1); vdisplay(); if (myfunc) { retvalue = do_call(myfunc, arg); } //else // retvalue = fun(arg); //while (mousekeys[hotkey]) // (void)1; return retvalue; //vdisplay(); } } return -1; // wasn't focused on us }
Sint32 vbutton::rightclick(Sint32 whichbutton) { Sint32 retvalue=0; if (whichbutton) whichbutton = 1; if (mouse_on()) { myscreen->soundp->play_sound(SOUND_BOW); vdisplay(1); vdisplay(); if (myfunc) { retvalue = do_call_right(myfunc, arg); } return retvalue; } return -1; // wasn't focused on us }
Sint32 vbutton::leftclick(Sint32 whichbutton) { if(hidden) return -1; Sint32 retvalue=0; if (whichbutton == 1) // hotkeys { if (keystates[hotkey]) { myscreen->soundp->play_sound(SOUND_BOW); vdisplay(1); vdisplay(); if (myfunc) { retvalue = do_call(myfunc, arg); } while (keystates[hotkey]) get_input_events(WAIT); return retvalue; } } else if(whichbutton == 2) // Normal click { if (mouse_on()) { myscreen->soundp->play_sound(SOUND_BOW); vdisplay(1); vdisplay(); if (myfunc) { retvalue = do_call(myfunc, arg); } return retvalue; } } return -1; // wasn't focused on us }
/* ---------------- */ void main(void) { register int which; register long calc; int w1, w2, w3, w4; int wfx, wfy, wfw, wfh; install_prg(); do { menu_on(); which = evnt_multi(MU_KEYBD|MU_MESAG|MU_BUTTON|MU_TIMER, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, msg, 50, 0, &mousex, &mousey, &mousek, &keyst, &key, &clicks); if (which & MU_TIMER) { if (mousex != old_mx || mousey != old_my) mouse_on(); if (akt_id > -1) do_slider_calc(); } if (which & MU_MESAG) { if ( msg[0] == MN_SELECTED ) mn_action(); else switch( msg[0] ) { case WM_REDRAW: redraw(msg[3], msg[4], msg[5], msg[6], msg[7]); break; case WM_CLOSED: erase_wind(msg[3]); wind_get(0, WF_TOP, &w1, &w2, &w3, &w4); akt_id = get_whandle(w1); get_eline(); break; case WM_FULLED: wind_get(msg[3], WF_CURRXYWH, &w1, &w2, &w3, &w4); wind_get(msg[3], WF_FULLXYWH, &wfx, &wfy, &wfw, &wfh); if (w1 == wfx && w2 == wfy && w3 == wfw && w4 == wfh) wind_get(msg[3], WF_PREVXYWH, &wfx, &wfy, &wfw, &wfh); wind_set(msg[3], WF_CURRXYWH, wfx, wfy, wfw, wfh); w_koor[akt_id][0] = wfx; w_koor[akt_id][1] = wfy; w_koor[akt_id][2] = wfw; w_koor[akt_id][3] = wfh; break; case WM_ARROWED: switch(msg[4]) { case 0: /* Seite nach oben */ beg_pgup(); break; case 1: /* Seite nach unten */ beg_pgdwn(); break; case 2: /* Zeile nach oben */ beg_oneup(); break; case 3: /* Zeile nach unten */ beg_onedown(); break; } break; case WM_HSLID: break; case WM_VSLID: go_vpos(msg[4]); break; case WM_SIZED: wind_set(msg[3], WF_CURRXYWH, msg[4], msg[5], msg[6], msg[7]); w_koor[akt_id][2] = msg[6]; w_koor[akt_id][3] = msg[7]; break; case WM_MOVED: wind_set(msg[3], WF_CURRXYWH, msg[4], msg[5], msg[6], msg[7]); w_koor[akt_id][0] = msg[4]; w_koor[akt_id][1] = msg[5]; break; case WM_TOPPED: case WM_NEWTOP: akt_id = get_whandle(msg[3]); wind_set(msg[3], WF_TOP, 0, 0, 0, 0); get_eline(); break; } } if (which & MU_KEYBD) key_mesag(); if ((which & MU_BUTTON) && akt_id > -1) button_mesag(); }while(!exit_flg); leave_prg(); }
void MapEditor() { int key; clear(); ShowEditorWindow(); editing_terrain=FALSE; FillMap(); editing_terrain=TRUE; FillMap(); LoadLevel(); ShowEditorMap(); ShowEditorWindow(); mouse_on(ALL_MOUSE_EVENTS); nodelay(stdscr,TRUE); cbreak(); for(;;) { key=getch(); request_mouse_pos(); if (mouse_active && (MOUSE_X_POS!=cursor_x || MOUSE_Y_POS!=cursor_y)) { curs_set(0); EditorMoveCursor(MOUSE_X_POS,MOUSE_Y_POS); curs_set(2); } switch(key) { case KEY_F0+1: editing_terrain=TRUE; ShowEditorWindow(); break; case KEY_F0+2: editing_terrain=FALSE; ShowEditorWindow(); break; case KEY_F0+5: clear(); PlayLevel(); ClearAfterPlaying(); ShowEditorWindow(); mouse_on(ALL_MOUSE_EVENTS); nodelay(stdscr,TRUE); cbreak(); break; case KEY_F0+8: SaveLevel(); break; case KEY_F0+9: LoadLevel(); ShowEditorMap(); ShowEditorWindow(); break; case KEY_F0+12: FillMap(); break; case KEY_MOVE_LEFT: EditorMoveCursor(cursor_x-1,cursor_y); break; case KEY_MOVE_RIGHT: EditorMoveCursor(cursor_x+1,cursor_y); break; case KEY_MOVE_UP: EditorMoveCursor(cursor_x,cursor_y-1); break; case KEY_MOVE_DOWN: EditorMoveCursor(cursor_x,cursor_y+1); break; case KEY_MOUSE: case KEY_ACTION: curs_set(0); EditorAction(); move(cursor_y,cursor_x); curs_set(2); } } }
void WorkArea::load(FILE *f) { delete items; struct viewporttype vp; getviewsettings(&vp); setviewport(x1, y1, x2, y2, 1); items = new List(); clearviewport(); int fig, i, a[200]; char *stream = (char*) malloc(1000*sizeof(char)); char *n, *temp; while (fgets(stream, 1000, f)) { i = -1; temp = stream; while ((n = strtok(temp, " ")) != NULL) { if (i == -1) { i = 0; fig = atoi(n); } else a[i++] = atoi(n); temp = NULL; } switch (fig) { case LINE_ID: items->add(new Node(new Line(a))); break; case POLYLINE_ID: items->add(new Node(new Polyline(a))); break; case CIRCLE_ID: items->add(new Node(new Circle(a))); break; case ELLIPSE_ID: items->add(new Node(new Ellipse(a))); break; case RECTANGLE_ID: items->add(new Node(new Rectangle(a))); break; case FILLED_CIRCLE_ID: items->add(new Node(new FilledCircle(a))); break; case FILLED_ELLIPSE_ID: items->add(new Node(new FilledEllipse(a))); break; case FILLED_RECTANGLE_ID: items->add(new Node(new FilledRectangle(a))); break; } } free(stream); mouse_off(); items->drawAll(); mouse_on(); setviewport(vp.left, vp.top, vp.right, vp.bottom, vp.clip); }
void WorkArea::handleMouse() { POINT pos; int button; struct viewporttype vp; getviewsettings(&vp); setviewport(x1, y1, x2, y2, 1); button = mouse_status(&pos); if (!contains(pos.x, pos.y)) return; while (contains(pos.x, pos.y)) { switch (action) { case 0: // object selection/movement/deletion if (button == 1) { int xs1 = pos.x; int ys1 = pos.y; int tst = 1; do { if ((xs1 != pos.x) || (ys1 != pos.y)) { tst = 0; // we do movement mouse_off(); items->drawAllBlack(); items->moveAllSelected(pos.x-xs1, pos.y-ys1); items->drawAll(); mouse_on(); xs1 = pos.x; ys1 = pos.y; } button = mouse_status(&pos); } while (button == 1); if (tst) // we do status change { items->changeStatus(pos.x-x1, pos.y-y1); mouse_off(); items->drawAll(); mouse_on(); } } else { if (kbhit()) { if (getch() == 0) if (getch() == 83) { mouse_off(); items->drawAllBlack(); items->removeAllSelected(); items->drawAll(); mouse_on(); } } } break; case 1: // handles line drawing if (button == 1) { int xl1 = pos.x-x1, yl1 = pos.y-y1; int xl2 = xl1, yl2 = yl1; setwritemode(XOR_PUT); setcolor(col->getFgColor()); mouse_off(); line(xl1, yl1, xl2, yl2); mouse_on(); mouse_restrict(x1, y1, x2, y2); mouse_wait_for_release(1, &pos); do { button = mouse_status(&pos); if ((pos.x-x1 != xl2) || (pos.y-y1 != yl2)) { mouse_off(); line(xl1, yl1, xl2, yl2); xl2 = pos.x-x1; yl2 = pos.y-y1; line(xl1, yl1, xl2, yl2); mouse_on(); } } while (button != 1); mouse_wait_for_release(1, &pos); mouse_free(getmaxx(), getmaxy()); setwritemode(COPY_PUT); Line *newLine = new Line(xl1, yl1, xl2, yl2, col->getFgColor()); items->add(new Node(newLine)); mouse_off(); items->drawAll(); mouse_on(); } break; case 2: // hadles polyline drawing if (button == 1) { int points[200]; int idx = 0; points[idx++] = pos.x-x1; points[idx++] = pos.y-y1; int xl = pos.x-x1, yl = pos.y-y1; setwritemode(XOR_PUT); setcolor(col->getFgColor()); mouse_restrict(x1, y1, x2, y2); mouse_wait_for_release(1, &pos); do { do { button = mouse_status(&pos); if ((pos.x-x1 != xl) || (pos.y-y1 != yl)) { mouse_off(); line(points[idx-2], points[idx-1], xl, yl); xl = pos.x-x1; yl = pos.y-y1; line(points[idx-2], points[idx-1], xl, yl); mouse_on(); } } while ((button != 1) && (button != 2)); mouse_wait_for_release(button, &pos); points[idx++] = xl; points[idx++] = yl; } while (button != 2); mouse_wait_for_release(2, &pos); mouse_free(getmaxx(), getmaxy()); setwritemode(COPY_PUT); Polyline *newPolyLine = new Polyline(idx/2, points, col->getFgColor()); items->add(new Node(newPolyLine)); mouse_off(); items->drawAll(); mouse_on(); } break; case 3: // hadles polygon drawing if (button == 1) { int points[200]; int idx = 0; points[idx++] = pos.x-x1; points[idx++] = pos.y-y1; int xl = pos.x-x1, yl = pos.y-y1; setwritemode(XOR_PUT); setcolor(col->getFgColor()); mouse_restrict(x1, y1, x2, y2); mouse_wait_for_release(1, &pos); do { do { button = mouse_status(&pos); if ((pos.x-x1 != xl) || (pos.y-y1 != yl)) { mouse_off(); line(points[idx-2], points[idx-1], xl, yl); xl = pos.x-x1; yl = pos.y-y1; line(points[idx-2], points[idx-1], xl, yl); mouse_on(); } } while ((button != 1) && (button != 2)); mouse_wait_for_release(button, &pos); points[idx++] = xl; points[idx++] = yl; } while (button != 2); mouse_wait_for_release(2, &pos); points[idx++] = points[0]; points[idx++] = points[1]; mouse_free(getmaxx(), getmaxy()); setwritemode(COPY_PUT); Polyline *newPolyLine = new Polyline(idx/2, points, col->getFgColor()); items->add(new Node(newPolyLine)); mouse_off(); items->drawAll(); mouse_on(); } break; case 4: // hadles circle drawing if (button == 1) { int xl1 = pos.x-x1, yl1 = pos.y-y1; int xl2 = xl1, yl2 = yl1; setcolor(col->getFgColor()); mouse_off(); int radius; if (abs(xl1-xl2)/2 < abs(yl1-yl2)/2) radius = abs(yl1-yl2)/2; else radius = abs(xl1-xl2)/2; circle((xl1+xl2)/2, (yl1+yl2)/2, radius); mouse_on(); mouse_restrict(x1, y1, x2, y2); mouse_wait_for_release(1, &pos); do { button = mouse_status(&pos); if ((pos.x-x1 != xl2) || (pos.y-y1 != yl2)) { mouse_set_position(&pos); mouse_off(); setcolor(BLACK); if (abs(xl1-xl2)/2 < abs(yl1-yl2)/2) radius = abs(yl1-yl2)/2; else radius = abs(xl1-xl2)/2; circle((xl1+xl2)/2, (yl1+yl2)/2, radius); items->drawAll(); setcolor(col->getFgColor()); xl2 = pos.x-x1; yl2 = pos.y-y1; if (abs(xl1-xl2)/2 < abs(yl1-yl2)/2) radius = abs(yl1-yl2)/2; else radius = abs(xl1-xl2)/2; circle((xl1+xl2)/2, (yl1+yl2)/2, radius); mouse_on(); } } while (button != 1); mouse_wait_for_release(1, &pos); mouse_free(getmaxx(), getmaxy()); if (abs(xl1-xl2)/2 < abs(yl1-yl2)/2) radius = abs(yl1-yl2)/2; else radius = abs(xl1-xl2)/2; Circle *newCircle = new Circle((xl1+xl2)/2, (yl1+yl2)/2, radius, col->getFgColor()); items->add(new Node(newCircle)); mouse_off(); items->drawAll(); mouse_on(); } break; case 5: // hadles filled circle drawing if (button == 1) { int xl1 = pos.x-x1, yl1 = pos.y-y1; int xl2 = xl1, yl2 = yl1; setcolor(col->getFgColor()); mouse_off(); int radius; if (abs(xl1-xl2)/2 < abs(yl1-yl2)/2) radius = abs(yl1-yl2)/2; else radius = abs(xl1-xl2)/2; circle((xl1+xl2)/2, (yl1+yl2)/2, radius); mouse_on(); mouse_restrict(x1, y1, x2, y2); mouse_wait_for_release(1, &pos); do { button = mouse_status(&pos); if ((pos.x-x1 != xl2) || (pos.y-y1 != yl2)) { mouse_set_position(&pos); mouse_off(); setcolor(BLACK); if (abs(xl1-xl2)/2 < abs(yl1-yl2)/2) radius = abs(yl1-yl2)/2; else radius = abs(xl1-xl2)/2; circle((xl1+xl2)/2, (yl1+yl2)/2, radius); items->drawAll(); setcolor(col->getFgColor()); xl2 = pos.x-x1; yl2 = pos.y-y1; if (abs(xl1-xl2)/2 < abs(yl1-yl2)/2) radius = abs(yl1-yl2)/2; else radius = abs(xl1-xl2)/2; circle((xl1+xl2)/2, (yl1+yl2)/2, radius); mouse_on(); } } while (button != 1); mouse_wait_for_release(1, &pos); mouse_free(getmaxx(), getmaxy()); if (abs(xl1-xl2)/2 < abs(yl1-yl2)/2) radius = abs(yl1-yl2)/2; else radius = abs(xl1-xl2)/2; FilledCircle *newFilledCircle = new FilledCircle( (xl1+xl2)/2, (yl1+yl2)/2, radius, col->getFgColor(), col->getBgColor()); items->add(new Node(newFilledCircle)); mouse_off(); items->drawAll(); mouse_on(); } break; case 6: // hadles ellipse drawing if (button == 1) { int xl1 = pos.x-x1, yl1 = pos.y-y1; int xl2 = xl1, yl2 = yl1; setcolor(col->getFgColor()); mouse_off(); ellipse((xl1+xl2)/2, (yl1+yl2)/2, 0, 360, abs(xl1-xl2)/2, abs(yl1-yl2)); mouse_on(); mouse_restrict(x1, y1, x2, y2); mouse_wait_for_release(1, &pos); do { button = mouse_status(&pos); if ((pos.x-x1 != xl2) || (pos.y-y1 != yl2)) { mouse_set_position(&pos); mouse_off(); setcolor(BLACK); ellipse((xl1+xl2)/2, (yl1+yl2)/2, 0, 360, abs(xl1-xl2)/2, abs(yl1-yl2)); items->drawAll(); setcolor(col->getFgColor()); xl2 = pos.x-x1; yl2 = pos.y-y1; ellipse((xl1+xl2)/2, (yl1+yl2)/2, 0, 360, abs(xl1-xl2)/2, abs(yl1-yl2)); mouse_on(); } } while (button != 1); mouse_wait_for_release(1, &pos); mouse_free(getmaxx(), getmaxy()); Ellipse *newEllipse = new Ellipse((xl1+xl2)/2, (yl1+yl2)/2, abs(xl1-xl2)/2, abs(yl1-yl2), col->getFgColor()); items->add(new Node(newEllipse)); mouse_off(); items->drawAll(); mouse_on(); } break; case 7: // hadles filled ellipse drawing if (button == 1) { int xl1 = pos.x-x1, yl1 = pos.y-y1; int xl2 = xl1, yl2 = yl1; setcolor(col->getFgColor()); mouse_off(); ellipse((xl1+xl2)/2, (yl1+yl2)/2, 0, 360, abs(xl1-xl2)/2, abs(yl1-yl2)); mouse_on(); mouse_restrict(x1, y1, x2, y2); mouse_wait_for_release(1, &pos); do { button = mouse_status(&pos); if ((pos.x-x1 != xl2) || (pos.y-y1 != yl2)) { mouse_set_position(&pos); mouse_off(); setcolor(BLACK); ellipse((xl1+xl2)/2, (yl1+yl2)/2, 0, 360, abs(xl1-xl2)/2, abs(yl1-yl2)); items->drawAll(); setcolor(col->getFgColor()); xl2 = pos.x-x1; yl2 = pos.y-y1; ellipse((xl1+xl2)/2, (yl1+yl2)/2, 0, 360, abs(xl1-xl2)/2, abs(yl1-yl2)); mouse_on(); } } while (button != 1); mouse_wait_for_release(1, &pos); mouse_free(getmaxx(), getmaxy()); FilledEllipse *newFilledEllipse = new FilledEllipse( (xl1+xl2)/2, (yl1+yl2)/2, abs(xl1-xl2)/2, abs(yl1-yl2), col->getFgColor(), col->getBgColor()); items->add(new Node(newFilledEllipse)); mouse_off(); items->drawAll(); mouse_on(); } break; case 8: // handles rectangle drawing if (button == 1) { int xl1 = pos.x-x1, yl1 = pos.y-y1; int xl2 = xl1, yl2 = yl1; setwritemode(XOR_PUT); setcolor(col->getFgColor()); mouse_off(); rectangle(xl1, yl1, xl2, yl2); mouse_on(); mouse_restrict(x1, y1, x2, y2); mouse_wait_for_release(1, &pos); do { button = mouse_status(&pos); if ((pos.x-x1 != xl2) || (pos.y-y1 != yl2)) { mouse_off(); rectangle(xl1, yl1, xl2, yl2); xl2 = pos.x-x1; yl2 = pos.y-y1; rectangle(xl1, yl1, xl2, yl2); mouse_on(); } } while (button != 1); mouse_wait_for_release(1, &pos); mouse_free(getmaxx(), getmaxy()); setwritemode(COPY_PUT); Rectangle *newRectangle = new Rectangle(xl1, yl1, xl2, yl2, col->getFgColor()); items->add(new Node(newRectangle)); mouse_off(); items->drawAll(); mouse_on(); } break; case 9: // handles rectangle drawing if (button == 1) { int xl1 = pos.x-x1, yl1 = pos.y-y1; int xl2 = xl1, yl2 = yl1; setwritemode(XOR_PUT); setcolor(col->getFgColor()); mouse_off(); rectangle(xl1, yl1, xl2, yl2); mouse_on(); mouse_restrict(x1, y1, x2, y2); mouse_wait_for_release(1, &pos); do { button = mouse_status(&pos); if ((pos.x-x1 != xl2) || (pos.y-y1 != yl2)) { mouse_off(); rectangle(xl1, yl1, xl2, yl2); xl2 = pos.x-x1; yl2 = pos.y-y1; rectangle(xl1, yl1, xl2, yl2); mouse_on(); } } while (button != 1); mouse_wait_for_release(1, &pos); mouse_free(getmaxx(), getmaxy()); setwritemode(COPY_PUT); FilledRectangle *newFilledRectangle = new FilledRectangle(xl1, yl1, xl2, yl2, col->getFgColor(), col->getBgColor()); items->add(new Node(newFilledRectangle)); mouse_off(); items->drawAll(); mouse_on(); } break; } button = mouse_status(&pos); } setviewport(vp.left, vp.top, vp.right, vp.bottom, vp.clip); }