int GLUI_Scrollbar::mouse_held_down_handler( int local_x, int local_y, bool new_inside) { int new_state; if ( state == GLUI_SCROLL_STATE_NONE ) return false; /* printf("spinner: mouse held: %d/%d inside: %d\n",local_x,local_y, new_inside); */ if ( state == GLUI_SCROLL_STATE_SCROLL) { /* dragging? */ do_drag( local_x-x_abs, local_y-y_abs ); } else { /* not dragging */ new_state = find_arrow( local_x, local_y ); if ( new_state == state ) { /** Still in same arrow **/ do_click(); } } redraw(); return false; }
int GLUI_Spinner::mouse_held_down_handler( int local_x, int local_y, int new_inside) { int new_state; if ( state == GLUI_SPINNER_STATE_NONE ) return false; /* printf("spinner: mouse held: %d/%d inside: %d\n",local_x,local_y, new_inside); */ if ( state == GLUI_SPINNER_STATE_BOTH ) { /* dragging? */ do_drag( local_x, local_y ); } else { /* not dragging */ new_state = find_arrow( local_x, local_y ); if ( new_state == state ) { /** Still in same arrow **/ do_click(); } else { if ( new_inside OR 1) { /** The state changed, but we're still inside - that means we moved off the arrow: begin dragging **/ state = GLUI_SPINNER_STATE_BOTH; } else { /*** Here check y of mouse position to determine whether to drag ***/ /* ... */ } } /*** We switched to up/down dragging ***/ if ( state == GLUI_SPINNER_STATE_BOTH ) { glutSetCursor( GLUT_CURSOR_UP_DOWN ); last_x = local_x; last_y = local_y; /** If the spinner has limits, we reset the growth value, since reset_growth() will compute a new growth value for dragging vs. clicking. If the spinner has no limits, then we just let the growth remain at whatever the user has incremented it up to **/ if ( edittext->has_limits != GLUI_LIMIT_NONE ) reset_growth(); } if ( can_draw() ) draw_arrows(); } return false; }
/*---------------------------------------------------------------*/ void do_mouse(HWND hwnd, DWORD wParam, DWORD lParam, int msg) { int o,x,y,n,i; static int mox,moy; static char mf2; static char lf2; #ifdef NOCAPT static char wmf; static int mux,muy; #endif switch (msg) { case WM_MOUSEMOVE: //move if ((wParam & MK_RBUTTON)!=0) { #ifdef NOCAPT mox=(short)LOWORD(lParam); moy=(short)HIWORD(lParam); if (wmf==0) { wmf=1,mux=mox,muy=moy; return; } MoveWindow(hwnd,wx0+mox-mux,wy0+moy-muy,wxl,wyl,TRUE); #endif return; } if (clickflag) return; if ((wParam & MK_LBUTTON)==0 || edp==NULL) { mox=(short)LOWORD(lParam); moy=(short)HIWORD(lParam); getmouxy(mox,moy,&x,&y); if (edp==NULL) i=1; else i=inmark(x+clft,y); SetCursor(i?pointC:hCurs); return; } if (lf2==0) return; #ifndef MV_DandD mm3: #endif if (drag) { setdragc(2+(0!=(GetAsyncKeyState(VK_CONTROL)&0x8000))); } n=((wParam & MK_SHIFT)!=0 || 0==moumrk); if (n==0) { mf2=0; goto mm1; } if (mf2) goto mm1; mf2=1; goto mm2; case WM_LBUTTONDBLCLK: lf2=0; if (edp) { o=getkword(fpos, tmpbuff); if (tmpbuff[0]) { ed_cmd(EK_MARK,o, o+strlen(tmpbuff)); return; } } goto drag_cancel; case WM_LBUTTONDOWN: lf2=1; resetmsg(hwnd); if (clickflag && --clickflag) return; //#ifndef MV_DandD SetCapture(hwnd); //#endif n=2; mm1: mox=(short)LOWORD(lParam); moy=(short)HIWORD(lParam); mm2: if (edp==NULL) return; o=getmoupos(mox,moy); if (o) { settimer(hwnd,o,SCROLL_INTERVAL); return; } ed_cmd(EK_SETVAR); getmouxy(mox,moy,&x,&y); if (n==2 && inmark(x+clft,y)) { #ifndef MV_DandD drag=1; goto mm3; #else char *get_block(void); char *get_vblock(void); char *p,*q; int n; p=vmark ? get_vblock() : get_block(); if (p!=NULL) { q = m_alloc(entab (NULL, p, n=strlen(p), tabs)+1); q[entab (q, p, n, tabs)]=0; i=do_drag(q), m_free(q); m_free(p); if (i==1) ed_cmd(KEY_DELETE); } return; #endif } if (drag && linmrk && vmark==0 && fixline(*ma) != fixline(*me)) curx=0; if (drag && n!=2 && dragmove<2) dragmove++; if (n==2) unmark(); if (drag==0) setvmark(n==1); return; case WM_LBUTTONUP: lf2=0; if (dragmove==2) { ed_cmd(drag==3 ? EK_DRAG_COPY : EK_DRAG_MOVE); SetCursor(hCurs); } else if (drag) unmark(); drag_cancel: mf2=drag=dragmove=0; settimer(hwnd,0,0); #ifndef MV_DandD ReleaseCapture(); #endif return; case WM_RBUTTONDOWN: #if 0 if (NULL!=ShortCut) { POINT pt; GetCursorPos(&pt); TrackPopupMenu(ShortCut,TPM_CENTERALIGN|TPM_RIGHTBUTTON, pt.x, pt.y ,0,hwnd,NULL ); return; } #endif #ifdef NOCAPT SetCapture(hwnd); mox=(short)LOWORD(lParam); moy=(short)HIWORD(lParam); wmf=1,mux=mox,muy=moy; #endif return; case WM_RBUTTONUP: #ifdef NOCAPT wmf=0; if (NULL==ShortCut) ReleaseCapture(); #endif return; } }
bool mouse_drag_listener::process_event(const SDL_Event& event, bool claimed) { Sint32 pos[2]; Sint16 rel[2]; Uint8 state; Uint8 button_change_state; SDLMod mod; SDLMod mod_change_state; bool was_capturing = is_capturing_; if(claimed) { is_capturing_ = false; return claimed; } switch(event.type) { case SDL_MOUSEMOTION: pos[0] = event.motion.x; pos[1] = event.motion.y; rel[0] = event.motion.xrel; rel[1] = event.motion.yrel; state = event.motion.state; mod = SDL_GetModState(); button_change_state = 0; mod_change_state = KMOD_NONE; break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: pos[0] = event.button.x; pos[1] = event.button.y; rel[0] = 0; rel[1] = 0; state = SDL_GetMouseState(NULL,NULL); mod = SDL_GetModState(); button_change_state = get_button_change_state(event.button.button) & target_state_mask(); mod_change_state = KMOD_NONE; break; case SDL_KEYDOWN: case SDL_KEYUP: state = SDL_GetMouseState(&(pos[0]), &(pos[1])); rel[0] = 0; rel[1] = 0; mod = event.key.keysym.mod; button_change_state = 0; mod_change_state = (SDLMod) (get_mod_change_state(event.key.keysym.sym) & target_mod_mask()); break; default: return claimed; } if(!matches_target_state(state)) { is_capturing_ = false; return claimed; } else if(!matches_target_mod(mod)) { is_capturing_ = false; return claimed; } if(!is_capturing_) { /* to start a gesture, we must be in the target area (if one is defined) AND this must be a mouse state change event if buttons are involved OR this must be a key state change event if keys are involved */ if(target_state() != 0) { /* if we have a target state, this must have been an event which indicated an unmasked button was pressed */ if(button_change_state == 0) { return claimed; } } else if(target_mod() != 0) { /* if we don't have a target state, but do have target modifiers, this must have been an event that indicated an unmasked modifier was pressed */ if(mod_change_state == 0) { return claimed; } } if(target_area_enabled() && !in_target_area(pos[0], pos[1])) { return claimed; } } is_capturing_ = true; claimed = true; pos_[0] = pos[0]; pos_[1] = pos[1]; state_ = state; mod_ = mod; rel_[0] = rel[0]; rel_[1] = rel[1]; if(was_capturing) { total_rel_[0] += rel[0]; total_rel_[1] += rel[1]; } else { total_rel_[0] = rel[0]; total_rel_[1] = rel[1]; start_pos_[0] = pos[0]; start_pos_[1] = pos[1]; } do_drag(); return claimed; }