bool CameraController::handle_mouse_button_press_event(const QMouseEvent* event) { if (m_controller.is_dragging()) return false; if (!(event->modifiers() & Qt::ControlModifier)) return false; const Vector2d position = get_mouse_position(event); switch (event->button()) { case Qt::LeftButton: emit signal_camera_change_begin(); m_controller.begin_drag( (event->modifiers() & Qt::AltModifier) ? ControllerType::Track : ControllerType::Tumble, position); return true; case Qt::MidButton: emit signal_camera_change_begin(); m_controller.begin_drag(ControllerType::Track, position); return true; case Qt::RightButton: emit signal_camera_change_begin(); m_controller.begin_drag(ControllerType::Dolly, position); return true; } return false; }
void tlabel::signal_handler_left_button_click(const event::tevent /* event */, bool & handled) { DBG_GUI_E << "label click" << std::endl; if (!get_link_aware()) { return; // without marking event as "handled". } if (!desktop::open_object_is_supported()) { gui2::show_message(get_window()->video(), "", _("Opening links is not supported, contact your packager"), gui2::tmessage::auto_close); handled = true; return; } tpoint mouse = get_mouse_position(); mouse.x -= get_x(); mouse.y -= get_y(); std::string link = get_label_link(mouse); if (link.length() == 0) { return ; // without marking event as "handled" } DBG_GUI_E << "Clicked Link:\"" << link << "\"\n"; const int res = gui2::show_message(get_window()->video(), _("Confirm"), _("Do you want to open this link?") + std::string("\n\n") + link, gui2::tmessage::yes_no_buttons); if(res == gui2::twindow::OK) { desktop::open_object(link); } handled = true; }
void tlabel::signal_handler_right_button_click(const event::tevent /* event */, bool & handled) { DBG_GUI_E << "label right click" << std::endl; if (!get_link_aware()) { return ; // without marking event as "handled". } tpoint mouse = get_mouse_position(); mouse.x -= get_x(); mouse.y -= get_y(); std::string link = get_label_link(mouse); if (link.length() == 0) { return ; // without marking event as "handled" } DBG_GUI_E << "Right Clicked Link:\"" << link << "\"\n"; desktop::clipboard::copy_to_clipboard(link, false); gui2::show_message(get_window()->video(), "", _("Copied link!"), gui2::tmessage::auto_close); handled = true; }
// ----------------------------------------------------------------------- // handle the resurrection spell // ----------------------------------------------------------------------- bool t_resurrection_spell::left_click( t_screen_point const& point ) { t_map_point_2d map_point; t_combat_creature_list creatures; bool defender = get_caster()->belongs_to_defender(); creatures = get_targets( point ); if (creatures.empty()) return false; eliminate_duplicates( creatures ); if (creatures.size() == 1) { resurrect( creatures.front().get() ); return true; } t_combat_creature_list::iterator index; t_combat_creature_ptr creature; t_handler handler; t_window* window = t_window::get_modal_window(); m_menu = new t_scroll_menu( window ); for (index = creatures.begin(); index != creatures.end(); index++) { creature = *index; handler = add_argument( bound_handler( *this, &t_resurrection_spell::resurrect ), creature ); m_menu->add_item( get_text( creature ), handler ); } m_menu->open( get_mouse_position( window ) ); m_battlefield.get_window()->set_help_balloon_text( "" ); return true; }
static void init_position(Client *c) { int x, y; int xmax = DisplayWidth(dpy, screen); int ymax = DisplayHeight(dpy, screen); if (c->size->flags & USSize) { c->width = c->size->width; c->height = c->size->height; } if (c->width < MINSIZE) c->width = MINSIZE; if (c->height < MINSIZE) c->height = MINSIZE; if (c->width > xmax) c->width = xmax; if (c->height > ymax) c->height = ymax; if (c->size->flags & USPosition) { c->x = c->size->x; c->y = c->size->y; if (c->x < 0 || c->y < 0 || c->x > xmax || c->y > ymax) c->x = c->y = c->border; } else { get_mouse_position(&x, &y); c->x = (int) ((x / (float)xmax) * (xmax - c->border - c->width)); c->y = (int) ((y / (float)ymax) * (ymax - c->border - c->height)); } }
math::Vector2i Input::get_mouse_delta() const { if( _mouse_visible ) return get_mouse_position() - _last_mouse_position; return {0, 0}; }
static void update_mouse_overlay(const Cursor* cursor) { mouse_cursor = cursor; if (mouse_cursor && mouse_scares == 0) { if (!mouse_cursor_overlay) { mouse_cursor_overlay = new Overlay( mouse_cursor->getSurface(), get_mouse_position(), Overlay::MouseZOrder); OverlayManager::instance()->addOverlay(mouse_cursor_overlay); } else { mouse_cursor_overlay->setSurface(mouse_cursor->getSurface()); update_cursor_overlay(); } } else if (mouse_cursor_overlay) { OverlayManager::instance()->removeOverlay(mouse_cursor_overlay); mouse_cursor_overlay->setSurface(NULL); delete mouse_cursor_overlay; mouse_cursor_overlay = NULL; } }
// ------------------------------------------------------------------------ // window to display an adventure map // determine correct cursor to display // ------------------------------------------------------------------------ void t_adventure_map_window::update_cursor() { t_screen_point point = get_mouse_position( this ); t_screen_rect rect = get_client_rect(); if (!is_point_in_rect( point, rect )) return; update_cursor( point ); }
void update_cursor_overlay() { if (mouse_cursor_overlay != NULL && mouse_scares == 0) { gfx::Point newPos = get_mouse_position() - mouse_cursor->getFocus(); if (newPos != mouse_cursor_overlay->position()) { mouse_cursor_overlay->moveOverlay(newPos); } } }
void tmouse_motion::mouse_enter(twidget* mouse_over) { DBG_GUI_E << LOG_HEADER << "Firing: " << event::MOUSE_ENTER << ".\n"; assert(mouse_over); mouse_focus_ = mouse_over; owner_.fire(event::MOUSE_ENTER, *mouse_over); hover_shown_ = false; start_hover_timer(mouse_over, get_mouse_position()); }
bool CameraController::handle_mouse_move_event(const QMouseEvent* event) { if (!m_controller.is_dragging()) return false; const Vector2d position = get_mouse_position(event); m_controller.update_drag(position); emit signal_camera_changed(); return true; }
void rclick_taskbar(int x) { XEvent ev; int mousex, mousey; Rect bounddims; unsigned int current_item = UINT_MAX; Window constraint_win; XSetWindowAttributes pattr; get_mouse_position(&mousex, &mousey); bounddims.x = 0; bounddims.y = 0; bounddims.width = DisplayWidth(dsply, screen); bounddims.height = BARHEIGHT(); constraint_win = XCreateWindow(dsply, root, bounddims.x, bounddims.y, bounddims.width, bounddims.height, 0, CopyFromParent, InputOnly, CopyFromParent, 0, &pattr); XMapWindow(dsply, constraint_win); if (!(XGrabPointer(dsply, root, False, MouseMask, GrabModeAsync, GrabModeAsync, constraint_win, None, CurrentTime) == GrabSuccess)) { XDestroyWindow(dsply, constraint_win); return; } draw_menubar(); update_menuitem(INT_MAX); // force initial highlight current_item = update_menuitem(x); do { XMaskEvent(dsply, MouseMask|KeyMask, &ev); switch (ev.type) { case MotionNotify: current_item = update_menuitem(ev.xmotion.x); break; case ButtonRelease: if (current_item != UINT_MAX) { fork_exec(menuitems[current_item].command); } break; case KeyPress: XPutBackEvent(dsply, &ev); break; } } while (ev.type != ButtonPress && ev.type != ButtonRelease && ev.type != KeyPress); redraw_taskbar(); XUnmapWindow(dsply, constraint_win); XDestroyWindow(dsply, constraint_win); ungrab(); }
// ------------------------------------------------------------------------ // window to display an adventure map // ------------------------------------------------------------------------ void t_adventure_map_window::mouse_move( t_mouse_event const& event ) { if (!m_dragging) { if ( get_mouse_position( this ) != event.client_point ) return; update_cursor( event.client_point ); return; } if (!event.left_button) { release_mouse(); m_dragging = false; return; } // check event message against current mouse position. if ( get_mouse_position( this ) != event.client_point ) return; drag( event.screen_point ); }
void ttext_box::signal_handler_left_button_down(const event::tevent event, bool& handled) { DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n"; /* * Copied from the base class see how we can do inheritance with the new * system... */ get_window()->keyboard_capture(this); get_window()->mouse_capture(); handle_mouse_selection(get_mouse_position(), true); handled = true; }
void Input::end_frame() { auto device = core::get_subsystem<graphics::WindowDevice>(); // _window_size = core::get_subsystem<graphics::WindowDevice>()->get_window_size(); _last_mouse_position = get_mouse_position(); // check for focus change this frame if( device->get_window_flags() & SDL_WINDOW_INPUT_FOCUS ) { if( !_input_focus ) { reset_state(); if( !_mouse_visible ) SDL_ShowCursor(SDL_FALSE); } _input_focus = true; } else { if( _input_focus ) { reset_state(); SDL_ShowCursor(SDL_TRUE); } _input_focus = false; } // recenter mouse if no mouse visibility if( _input_focus && !_mouse_visible && !_touch_emulation ) { SDL_WarpMouseInWindow((SDL_Window*)device->get_window_object(), _window_size[0]/2, _window_size[1]/2); } }
void lclick_taskbar(int x) { XEvent ev; int mousex, mousey; Rect bounddims; Window constraint_win; XSetWindowAttributes pattr; float button_width; unsigned int button_clicked, old_button_clicked, i; Client *c, *exposed_c, *old_c; if (head_client != NULL) { remember_hidden(); get_mouse_position(&mousex, &mousey); bounddims.x = 0; bounddims.y = 0; bounddims.width = DisplayWidth(dsply, screen); bounddims.height = BARHEIGHT(); constraint_win = XCreateWindow(dsply, root, bounddims.x, bounddims.y, bounddims.width, bounddims.height, 0, CopyFromParent, InputOnly, CopyFromParent, 0, &pattr); XMapWindow(dsply, constraint_win); if (!(XGrabPointer(dsply, root, False, MouseMask, GrabModeAsync, GrabModeAsync, constraint_win, None, CurrentTime) == GrabSuccess)) { XDestroyWindow(dsply, constraint_win); return; } button_width = get_button_width(); button_clicked = (unsigned int)(x / button_width); for (i = 0, c = head_client; i < button_clicked; i++) { c = c->next; } lclick_taskbutton(NULL, c); do { XMaskEvent(dsply, ExposureMask|MouseMask|KeyMask, &ev); switch (ev.type) { case Expose: exposed_c = find_client(ev.xexpose.window, FRAME); if (exposed_c) { redraw(exposed_c); } break; case MotionNotify: old_button_clicked = button_clicked; button_clicked = (unsigned int)(ev.xmotion.x / button_width); if (button_clicked != old_button_clicked) { old_c = c; for (i = 0, c = head_client; i < button_clicked; i++) { c = c->next; } lclick_taskbutton(old_c, c); } break; case KeyPress: XPutBackEvent(dsply, &ev); break; } } while (ev.type != ButtonPress && ev.type != ButtonRelease && ev.type != KeyPress); XUnmapWindow(dsply, constraint_win); XDestroyWindow(dsply, constraint_win); ungrab(); forget_hidden(); } }
void stdcalc() { double u=0,v=0; /* u:输入的第1个数, v:输入的第2个数 */ int flag=0; /* 输入数据是否有小数点标志:0-无 1-有 */ int sign=0; /* 是否单击了运算符:0-无 其他-运算符字符 */ int x,y; /* (x,y)鼠标当前位置 (xx,yy)鼠标前一位置 */ char s[9]; /* 存储输入的数字符号(含小数点) */ int fget=4; /* 前一次单击的按钮标签 */ int d,dn; /* 当前单击的按钮标签 */ int pn=0; /* 当前键盘输入的标签 */ int i=0,j; standard(); save_as_old_mouse(0,0); outtextxy(OUTX-15,OUTY,"0"); outtextxy(OUTX,OUTY,"."); while(1) /* 单击右键则退出简单计算器 */ { if (kbhit()!=0) pn=bioskey(0); if (rightpress()==1||pn==0x11b) {mode=-1;break;} if(leftpress()!=1 && pn==0) /* 鼠标左键未单击的处理 */ { move_mouse(); } else if(MouseLeftFlag==1||pn!=0) /* 鼠标左键单击的处理 */ { if(MouseLeftFlag==1){ MouseLeftFlag=0; /* 置标志为0,防止单击1次左键而多次进入 */ get_mouse_position(&x,&y); d=returnstdkey(x,y); /* 得到单击按钮的标签 */ } else { d=stdgetKey(pn); pn=0; } if(d==-1) continue; if(d==20||d==21||d==22||d==23) {if(d==20) mode=1;if(d==21) mode=2;if(d==22) mode=3;if(d==23) mode=4; break;} show(std[d][0],std[d][2],std[d][1],std[d][3]); if(d==4) /* 单击C开始使用 */ { clearscreen(); outtextxy(OUTX-15,OUTY,"0"); outtextxy(OUTX,OUTY,"."); v=u=0; sign=0; flag=0; i=0; } else if((dn=checknum(d,0))!=-1) /* 单击'0'-'9'数字键的处理 */ { if(dn==0&&u==0&&flag==0) /* 开始时始终单击'0',就显示0 */ { i=0; s[i++]=itoc(dn); s[i++]='.'; s[i]='\0'; u=atof(s); outch(u); } else { if(fget==4||fget==19||fget==3||fget==9) { clearscreen(); i=0; s[i++]=itoc(dn); s[i++]='.'; s[i]='\0'; u=atof(s); outch(u); } if(checknum(fget,0)!=-1) { if(sign==0) /* 未单击运算符,处理第1个数u */ { if(flag==0) /* 输入数据无小数点 */ { clearscreen(); u=u*10+d-'0'; if((u>0&&u<1e8)||(u<0&&u>-1e8)) { s[--i]=itoc(dn); s[++i]='.'; s[++i]='\0'; u=atof(s); outch(u); } else outch(u); } if(flag==1) /* 输入数据有小数点 */ { if(i<=8) { clearscreen(); s[i]=itoc(dn); s[++i]='\0'; u=atof(s); outch(u); } } } if(sign!=0) /* 单击了运算符,处理第2个数v */ { if(flag==0) { clearscreen(); v=v*10+d-'0'; if((v>0&&v<1e8)||(v<0&&v>-1e8)) { s[--i]=itoc(dn); s[++i]='.'; s[++i]='\0'; v=atof(s); outch(v); } else outch(v); } if(flag==1) { if(i<=8) { clearscreen(); s[i++]=itoc(dn); s[i]='\0'; v=atof(s); outch(v); } } } } if(fget==8||fget==13||fget==14||fget==18) { clearscreen(); i=0; s[i++]=itoc(dn); s[i++]='.'; s[i]='\0'; v=atof(s); outch(v); } if(fget==17) /* 前一次单击的是小数点按钮 */ { clearscreen(); s[i]=itoc(dn); s[++i]='\0'; if(sign==0) { u=atof(s); outch(u); } if(sign!=0) { v=atof(s); outch(v); } } } } else if(d==8||d==13||d==14||d==18) { /* 单击加,减,乘,除按钮的处理 */ if(sign!=0) { if(fget==8||fget==13||fget==14||fget==18); else { if(sign==14&&v==0) { clearscreen(); outtextxy(OUTX-15,OUTY,"Err"); } else{ u=calculate(u,v,sign); outch(u); } } } sign=d; flag=0; i=0; } else if(d==19) /* 单击等号按钮的处理 */ { if(sign!=0) { if(sign=='/'&&fabs(v)<1e-6) { clearscreen(); outtextxy(OUTX-15,OUTY,"Err"); } else { u=calculate(u,v,sign); outch(u); } } flag=0; sign=0; i=0; } else if(d==17) /* 单击小数点按钮的处理 */ { if(flag==0) flag=1; } else if(d==3) /* 单击1/x按钮的处理 */ { if(sign==0) /* 如果是第1个数,输出u的百分数 */ {if(fabs(u)>1e-6) {u=1/u; outch(u);} else {clearscreen(); outtextxy(OUTX-15,OUTY,"Err");}} if(sign!=0) /* 是第2个数(单击过运算符),输出v的百分数 */ {if(fabs(v)>1e-6) {v=1/v; outch(v);} else {clearscreen(); outtextxy(OUTX-15,OUTY,"Err");}} i=0; } else if(d==9) /* 单击求平方根按钮的处理 */ { if(sign==0) /*对输入的第1个数求平方根 */ { if(u<0) { clearscreen(); outtextxy(OUTX-15,OUTY,"Err"); } else{ u=sqrt(u); outch(u); } } if(sign!=0) /*对输入的第2个数求平方根 */ { if(v<0) { clearscreen(); outtextxy(OUTX-15,OUTY,"Er"); } else{ v=sqrt(v); outch(v); } } i=0; } else if(d==16) /* 单击+/-按钮的处理 */ { if(sign==0) { u=-u; outch(u); } else { v=-v; outch(v); } } else continue; fget=d; /* 保存上次单击按钮的标签 */ } /* End of else if(MouseLeftFlag==1) */ } /* End of while(rightpress()!=2) */ }
void help_display(struct world *mzx_world, char *help, int offs, char *file, char *label) { // Display a help file int pos = offs, old_pos; // Where int key = 0; int t1; char mclick; // allow_help = 0; // Draw screen save_screen(); dialog_fadein(); scroll_edging_ext(mzx_world, 3, 256, 16); // Loop file[0] = label[0] = 0; do { // Display scroll help_frame(mzx_world, help, pos); mclick = 0; update_screen(); update_event_status_delay(); if(get_mouse_press()) { int mouse_x, mouse_y; get_mouse_position(&mouse_x, &mouse_y); // Move to line clicked on if mouse is in scroll, else exit if((mouse_y >= 6) && (mouse_y <= 18) && (mouse_x >= 8) && (mouse_x <= 71)) { mclick = 1; t1 = mouse_y - 12; if(t1 == 0) goto option; //t1<0 = PGUP t1 lines //t1>0 = PGDN t1 lines if(t1 < 0) goto pgup; goto pgdn; } key = IKEY_ESCAPE; } key = get_key(keycode_internal); old_pos = pos; switch(key) { case IKEY_F1: { if(get_alt_status(keycode_internal)) { // Jump to label 072 in MAIN.HLP strcpy(file,"MAIN.HLP"); strcpy(label,"072"); } else { // Jump to label 000 in HELPONHE.HLP strcpy(file, "HELPONHE.HLP"); strcpy(label, "000"); } goto ex; } case IKEY_UP: { // Go back a line (if possible) if(help[pos - 1] == 1) break; // Can't. pos--; // Go to start of this line. do { pos--; } while((help[pos] != '\n') && (help[pos] != 1)); pos++; // Done. break; } case IKEY_DOWN: { // Go forward a line (if possible) while(help[pos] != '\n') pos++; // At end of current. Is there a next line? pos++; if(help[pos] == 0) { // Nope. pos = old_pos; break; } // Yep. Done. break; } case IKEY_RETURN: { option: // Option? if((help[pos] == 255) && ((help[pos + 1] == '>') || (help[pos + 1] == '<'))) { // Yep! pos++; if(help[pos] == '<') { // Get file and label and exit t1 = 0; pos++; do { pos++; file[t1] = help[pos]; t1++; } while(help[pos] != ':'); file[t1 - 1] = 0; strcpy(label, help + pos + 1); goto ex; } // Get label and jump strcpy(label, help + pos + 2); // Search backwards for a 1 do { pos--; } while(help[pos] != 1); // Search for label OR a \n followed by a \0 do { pos++; if(help[pos] == 255) if(help[pos + 1] == ':') if(!strcmp(help + pos + 3, label)) // pos is correct! goto labdone; if(help[pos] == '\n') if(help[pos + 1] == 0) break; } while(1); } // If there WAS an option, any existing label was found. labdone: break; } case IKEY_PAGEDOWN: { for(t1 = 6; t1 > 0; t1--) { pgdn: // Go forward a line (if possible) old_pos = pos; while(help[pos] != '\n') pos++; // At end of current. Is there a next line? pos++; if(help[pos] == 0) { // Nope. pos = old_pos; break; } // Yep. Done. } if(mclick) goto option; break; } case IKEY_PAGEUP: { for(t1 = -6; t1 < 0; t1++) { pgup: // Go back a line (if possible) if(help[pos - 1] == 1) break; // Can't. pos--; // Go to start of this line. do { pos--; } while((help[pos] != '\n') && (help[pos] != 1)); pos++; // Done. } if(mclick) goto option; break; } case IKEY_HOME: { // FIXME - :( t1 = -30000; goto pgup; } case IKEY_END: { t1 = 30000; goto pgdn; } default: { break; } } } while(key != IKEY_ESCAPE); // Restore screen and exit ex: dialog_fadeout(); restore_screen(); }
void scroll_edit(struct world *mzx_world, struct scroll *scroll, int type) { // Important status vars (insert kept in intake.cpp) unsigned int pos = 1, old_pos; // Where IN scroll? int currx = 0; // X position in line int key; // Key returned by intake() int t1, t2 = -1, t3; char *where; // Where scroll is char line[80]; // For editing int scroll_base_color = mzx_world->scroll_base_color; bool editing = (type == 2); // Draw screen save_screen(); dialog_fadein(); if(editing) scroll_edging_ext(mzx_world, type, 256, 16); else scroll_edging_ext(mzx_world, type, 0, 16); // Loop where = scroll->mesg; do { // If the user wants to mask, and we're in the editor.. bool mask = mzx_world->conf.mask_midchars && editing; // Display scroll scroll_frame(mzx_world, scroll, pos, mask); update_screen(); if(editing) { // Figure length for(t1 = 0; t1 < 80; t1++) { if(where[pos + t1] == '\n') break; } // t1 == length // Edit line where[pos + t1] = 0; strcpy(line, where + pos); where[pos + t1] = '\n'; key = intake(mzx_world, line, 64, 8, 12, scroll_base_color, 2, 0, &currx, 0, NULL); // Modify scroll to hold new line (give errors here) t2 = (int)strlen(line); // Get length of NEW line // Resize and move t3 = scroll->mesg_size; if(t2 - t1 > 0) { reallocate_scroll(scroll, t3 + t2 - t1); where = scroll->mesg; memmove(where + pos + t2, where + pos + t1, t3 - pos - t1); } else if(t2 - t1 < 0) { memmove(where + pos + t2, where + pos + t1, t3 - pos - t1); reallocate_scroll(scroll, t3 + t2 - t1); where = scroll->mesg; } // Copy in new line strcpy(where + pos, line); where[pos + t2] = '\n'; } else { update_event_status_delay(); key = get_key(keycode_internal); } old_pos = pos; if(get_mouse_press() || (key == -1)) { int mouse_x, mouse_y; get_mouse_position(&mouse_x, &mouse_y); if((mouse_y >= 6) && (mouse_y <= 18) && (mouse_x >= 8) && (mouse_x <= 71)) { t1 = mouse_y - 12; if(t1) { if(t1 < 0) goto pgdn; else goto pgup; } } key = IKEY_ESCAPE; } switch(key) { case IKEY_UP: { // Go back a line (if possible) if(where[pos - 1] == 1) break; // Can't. pos--; // Go to start of this line. do { pos--; } while((where[pos] != '\n') && (where[pos] != 1)); pos++; // Done. break; } case IKEY_DOWN: { // Go forward a line (if possible) while(where[pos] != '\n') pos++; // At end of current. Is there a next line? pos++; if(where[pos] == 0) { // Nope. pos = old_pos; break; } // Yep. Done. break; } case IKEY_RETURN: { if(type < 2) { key = IKEY_ESCAPE; } else { // Add in new line below. Need only add one byte. t3 = scroll->mesg_size; reallocate_scroll(scroll, t3 + 1); where = scroll->mesg; // Move all at pos + currx up a space memmove(where + pos + currx + 1, where + pos + currx, t3 - pos - currx); // Insert a \n where[pos + currx] = '\n'; // Change pos and currx pos = pos + currx + 1; currx = 0; scroll->num_lines++; } break; } case IKEY_BACKSPACE: { if(type < 2) break; // We are at the start of the current line and we are trying to // append it to the end of the previous line. First, remember // the size of the current line is in t2. Now we go back a line, // if there is one. if(where[pos - 1] == 1) break; // Nope. pos--; // Go to start of this line, COUNTING CHARACTERS. t1 = 0; do { pos--; t1++; } while((where[pos] != '\n') && (where[pos] != 1)); // pos is at one before the start of this line. WHO CARES!? :) // Now we have to see if the size, t2, is over 64 characters. // t2 + t1 is currently one too many so check for >65 for error. if((t2 + t1) > 65) { pos = old_pos; break; // Too long. Reset position. } // OKAY! Just copy backwards over the \n in the middle to // append... t3 = scroll->mesg_size; memmove(where + (old_pos - 1), where + old_pos, t3 - (old_pos + 1)); // ...and reallocate to one space less! reallocate_scroll(scroll, t3 - 1); where = scroll->mesg; // pos is one before this start. Fix to the start of this new // line. Set currx to the length of the old line this was. pos++; currx = (int)t1 - 1; scroll->num_lines--; // FIXME - total hack! scroll->mesg[scroll->mesg_size - 1] = 0; // Done. break; } case IKEY_PAGEDOWN: { for(t1 = 6; t1 > 0; t1--) { pgdn: // Go forward a line (if possible) old_pos = pos; while(where[pos] != '\n') pos++; // At end of current. Is there a next line? pos++; if(where[pos] == 0) { // Nope. pos = old_pos; break; } // Yep. Done. } break; } case IKEY_PAGEUP: { for(t1 = -6; t1 < 0; t1++) { pgup: // Go back a line (if possible) if(where[pos - 1] == 1) break; // Can't. pos--; // Go to start of this line. do { pos--; } while((where[pos] != '\n') && (where[pos] != 1)); pos++; // Done. } break; } case IKEY_HOME: { // FIXME - This is so dirty. Please replace it. t1 = -30000; goto pgup; } case IKEY_END: { // FIXME - See above. t1 = 30000; goto pgdn; } default: case IKEY_ESCAPE: case 0: break; } // Continue? } while(key != IKEY_ESCAPE); // Restore screen and exit restore_screen(); dialog_fadeout(); }
/* * BEE::get_mouse_y() - Return the mouse x-coordinate relative to the viewport */ int BEE::get_mouse_y() const { return get_mouse_position().second; }
/* * BEE::get_mouse_x() - Return the mouse x-coordinate relative to the viewport */ int BEE::get_mouse_x() const { return get_mouse_position().first; }
bool Input::initialize() { _window_size = core::get_subsystem<graphics::WindowDevice>()->get_window_size(); _last_mouse_position = get_mouse_position(); return true; }
int main(int argc, char** argv) { if(!depth_open()) { printf("Unable to open libkipr_link_depth_sensor\n"); return 1; } int depth_image_height = -1; int depth_image_width = -1; int mouse_x; int mouse_y; int last_max_depth = 6000 /* mm */; int max_depth; if(set_depth_camera_resolution(DEPTH_CAMERA_RESOLUTION_640_480) == 0) { printf("Failed to set the depth camera resolution to 640 x 480\n"); return 1; } #ifdef CAMERA_IS_UPSIDE_DOWN if(set_depth_camera_orientation(DEPTH_CAMERA_ORIENTATION_UPSIDE_DOWN) == 0) { printf("Failed to set the depth camera orientation\n"); return 1; } #endif printf("Press 'Q' to stop\n"); while(!get_key_state('Q')) { if(depth_update()) { if(depth_image_height == -1) { // initialize the graphics output depth_image_height = depth_image_get_height(); depth_image_width = depth_image_get_width(); graphics_open(depth_image_width, depth_image_height); } get_mouse_position(&mouse_x, &mouse_y); max_depth = 0; // display depth image for(int y = 0; y < depth_image_height; y++) { for(int x = 0; x < depth_image_width; x++) { int depth = get_depth_value(x, y); // save max depth if(depth > max_depth) { max_depth = depth; } // color invalid depth pixel red if((depth != INVALID_COORDINATE) && last_max_depth) { int r; int g; int b; HSVtoRGB(360*0xFF*depth/last_max_depth, &r, &g, &b); graphics_pixel(x, y, r, g, b); } else { graphics_pixel(x, y, 0xFF, 0xFF, 0xFF); } #ifdef SHOW_DEPTH_UNDER_MOUSE if(mouse_x == x && mouse_y == y) { console_clear(); if(depth != INVALID_COORDINATE) { printf("(%d, %d): Depth: %d mm; World coordinate: (%d, %d, %d)\n", x, y, depth, get_world_x(x, y), get_world_y(x, y), get_world_z(x, y)); } else { printf("(%d, %d): No information available\n", x, y); } } #endif } } last_max_depth = max_depth; graphics_update(); } else { printf("No depth image received yet\n"); msleep(2000); } } graphics_close(); depth_close(); return 0; }
int intake(struct world *mzx_world, char *string, int max_len, int x, int y, char color, int exit_type, int filter_type, int *return_x_pos, bool robo_intk, char *macro) { int currx, curr_len, macro_position = -1; int done = 0, place = 0; char cur_char = 0; char temp_char; int in_macro; int use_mask = mzx_world->conf.mask_midchars; int mouse_press; int key; if(macro != NULL) macro_position = 0; // Activate cursor if(insert_on) cursor_underline(); else cursor_solid(); // Put cursor at the end of the string... currx = curr_len = (int)strlen(string); // ...unless return_x_pos says not to. if((return_x_pos) && (*return_x_pos < currx)) currx = *return_x_pos; if(robo_intk && (currx > 75)) move_cursor(77, y); else move_cursor(x + currx, y); if(insert_on) cursor_underline(); else cursor_solid(); do { if(!robo_intk) { if(use_mask) write_string_mask(string, x, y, color, 0); else write_string_ext(string, x, y, color, 0, 0, 16); } else { draw_char('\x11', color, 79, y); if((curr_len < 76) || (currx < 76)) { draw_char('\x10', color, 0, y); if(curr_len < 76) { if(use_mask) write_line_mask(string, x, y, color, 0); else write_line_ext(string, x, y, color, 0, 0, 16); fill_line(76 - curr_len, x + curr_len, y, 32, color); } else { temp_char = string[76]; string[76] = 0; if(use_mask) write_line_mask(string, x, y, color, 0); else write_line_ext(string, x, y, color, 0, 0, 16); string[76] = temp_char; draw_char('\xaf', color, 79, y); } } else { draw_char('\x20', color, 77, y); if(strlen(string + currx - 75) > 78) { temp_char = string[currx + 1]; string[currx + 1] = 0; if(use_mask) { write_line_mask(string + currx - 75, x, y, color, 0); } else { write_line_ext(string + currx - 75, x, y, color, 0, 0, 16); } string[currx + 1] = temp_char; } else { if(use_mask) { write_line_mask(string + currx - 75, x, y, color, 0); } else { write_line_ext(string + currx - 75, x, y, color, 0, 0, 16); } } draw_char('\xae', color, 0, y); if(currx < curr_len) draw_char('\xaf', color, 79, y); } draw_char('\x20', color, 78, y); } if(!robo_intk) { fill_line(max_len + 1 - curr_len, x + curr_len, y, 32, color); } else { write_number(currx + 1, 79, 32, 0, 3, 0, 10); write_number(curr_len + 1, 79, 36, 0, 3, 0, 10); } in_macro = 0; // Get key if(macro_position != -1) { key = macro[macro_position]; cur_char = key; macro_position++; if(macro[macro_position] == 0) macro_position = -1; if(key == '^') key = IKEY_RETURN; } else { update_screen(); update_event_status_delay(); key = get_key(keycode_internal); place = 0; cur_char = get_key(keycode_unicode); } mouse_press = get_mouse_press_ext(); if(get_mouse_press_ext()) { int mouse_x, mouse_y; get_mouse_position(&mouse_x, &mouse_y); if((mouse_y == y) && (mouse_x >= x) && (mouse_x <= (x + max_len)) && (mouse_press <= MOUSE_BUTTON_RIGHT)) { // Yep, reposition cursor. currx = mouse_x - x; if(currx > curr_len) currx = curr_len; } else { key = -1; done = 1; } } // Handle key cases switch(key) { case IKEY_ESCAPE: { // ESC if(exit_type > 0) { done = 1; } break; } case IKEY_RETURN: { // Enter done = 1; break; } case IKEY_HOME: { if(get_alt_status(keycode_internal) && robo_intk) { done = 1; } else { // Home currx = 0; } break; } case IKEY_END: { if(get_alt_status(keycode_internal) && robo_intk) { done = 1; } else { // End currx = curr_len; } break; } case IKEY_LEFT: { if(get_ctrl_status(keycode_internal)) { // Find nearest space to the left if(currx) { char *current_position = string + currx; if(currx) current_position--; if(!isalnum((int)*current_position)) { while(currx && !isalnum((int)*current_position)) { current_position--; currx--; } } do { current_position--; currx--; } while(currx && isalnum((int)*current_position)); if(currx < 0) currx = 0; } } else { // Left if(currx > 0) currx--; } break; } case IKEY_RIGHT: { if(get_ctrl_status(keycode_internal)) { // Find nearest space to the right if(currx < curr_len) { char *current_position = string + currx; char current_char = *current_position; if(!isalnum((int)current_char)) { do { current_position++; currx++; current_char = *current_position; } while(current_char && !isalnum((int)current_char)); } while(current_char && isalnum((int)current_char)) { current_position++; currx++; current_char = *current_position; } } } else { // Right if(currx < curr_len) currx++; } break; } case IKEY_F1: case IKEY_F2: case IKEY_F3: case IKEY_F4: case IKEY_F5: case IKEY_F6: case IKEY_F7: case IKEY_F8: case IKEY_F9: case IKEY_F10: case IKEY_F11: case IKEY_F12: case IKEY_UP: case IKEY_DOWN: case IKEY_TAB: case IKEY_PAGEUP: case IKEY_PAGEDOWN: { done = 1; break; } case IKEY_INSERT: { if(get_alt_status(keycode_internal) && robo_intk) { done = 1; } else { // Insert if(insert_on) cursor_solid(); else cursor_underline(); insert_on ^= 1; } break; } case IKEY_BACKSPACE: { // Backspace, at 0 it might exit if(get_alt_status(keycode_internal)) { // Alt-backspace, erase input curr_len = currx = 0; string[0] = 0; } else if(get_ctrl_status(keycode_internal)) { // Find nearest space to the left if(currx) { int old_position = currx; if(!isalnum((int)string[currx])) { while(currx && !isalnum((int)string[currx])) { currx--; } } while(currx && isalnum((int)string[currx])) { currx--; } curr_len -= old_position - currx; memmove(string + currx, string + old_position, strlen(string + old_position) + 1); } } else if(currx == 0) { if(exit_type == 2) { done = 1; } } else { // Move all back 1, decreasing string length memmove(string + currx - 1, string + currx, curr_len - currx + 1); curr_len--; // Cursor back one currx--; } break; } case IKEY_DELETE: { // Delete, at the end might exit if(currx == curr_len) { if(exit_type == 2) done = 1; } else { if(curr_len) { // Move all back 1, decreasing string length memmove(string + currx, string + currx + 1, curr_len - currx); curr_len--; } } break; } case IKEY_c: { if(get_ctrl_status(keycode_internal) && robo_intk) { done = 1; } else if(get_alt_status(keycode_internal) && !filter_type) { // If alt - C is pressed, choose character int new_char = char_selection(last_char); if(new_char >= 32) { cur_char = new_char; last_char = new_char; place = 1; } else { place = 0; } } else { place = 1; } break; } case IKEY_t: { if(get_alt_status(keycode_internal)) { done = 1; } else { place = 1; } break; } case IKEY_l: case IKEY_g: case IKEY_d: case IKEY_f: case IKEY_r: { if(get_ctrl_status(keycode_internal) && robo_intk) { done = 1; } else { place = 1; } break; } case IKEY_i: { if((get_ctrl_status(keycode_internal) || get_alt_status(keycode_internal)) && robo_intk) { done = 1; } else { place = 1; } break; } case IKEY_u: case IKEY_o: case IKEY_x: case IKEY_b: case IKEY_s: case IKEY_e: case IKEY_v: case IKEY_p: case IKEY_h: case IKEY_m: { if(get_alt_status(keycode_internal) && robo_intk) { done = 1; } else { place = 1; } break; } case IKEY_LSHIFT: case IKEY_RSHIFT: case 0: { place = 0; break; } default: { // Place the char place = 1; break; } case -1: { break; } } if(place) { if((cur_char < 32) && (exit_type == 2)) { done = 1; key = cur_char; } else // Keycode.. Filter. if(filter_type & 1) { if((cur_char >= 'a') && (cur_char <= 'z')) cur_char -= 32; } if(filter_type & 2) { if((cur_char >= 'A') && (cur_char <= 'Z')) cur_char += 32; } // Block numbers if((filter_type & 4) && ((cur_char >= '0') && (cur_char <= '9'))) { place = 0; } // Block alpha if((filter_type & 8) && (((cur_char >= 'a') && (cur_char <= 'z')) || ((cur_char >= 'A') && (cur_char <= 'Z')))) { place = 0; } // Block spaces if((filter_type & 16) && (cur_char == ' ')) { place = 0; } // Block high-ASCII if((filter_type & 32) && (cur_char > 126)) { place = 0; } // Block these chars if((filter_type & 64) && ((cur_char == '*') || (cur_char == '[') || (cur_char == ']') || (cur_char == '>') || (cur_char == '<') || (cur_char == ',') || (cur_char == '|') || (cur_char == '?') || (cur_char == '=') || (cur_char == ';') || (cur_char == '\"') || (cur_char =='/'))) { place = 0; } // Block these chars if((filter_type & 128) && ((cur_char == ':') || (cur_char == '\\'))) { place = 0; } // Block these chars if((filter_type & 256) && (((cur_char > ' ') && (cur_char < '0')) || ((cur_char > '9') && (cur_char < 'A')) || ((cur_char > 'Z') && (cur_char < 'a')) || ((cur_char > 'z') && (cur_char < 127)))) { place = 0; } // Now, can it still be placed? if(place && (curr_len != max_len) && (!done) && cur_char) { // Overwrite or insert? if((insert_on) || (currx == curr_len)) { // Insert- Move all ahead 1, increasing string length curr_len++; memmove(string + currx + 1, string + currx, curr_len - currx); } // Add character and move forward one string[currx++] = cur_char; } } // Move cursor if(robo_intk && (currx > 75)) move_cursor(77, y); else move_cursor(x + currx, y); if(insert_on) cursor_underline(); else cursor_solid(); // Loop } while(!done); cursor_off(); if(return_x_pos) *return_x_pos = currx; return key; }
int window::get_mouse_y() const { return get_mouse_position().get_y(); }