コード例 #1
0
void ServerConnectionView::pullChanges() {
	SDL_Event e;
	while (SDL_PollEvent(&e) != 0) {

		if (e.type == SDL_QUIT) {
			shouldQuit = true;
			return;
		}
		if (!showingWait) {
			// Detect what is clicking
			if (e.type == SDL_MOUSEBUTTONDOWN) {
				// Get mouse position
				SDL_Point clickPoint = { 0, 0 };
				SDL_GetMouseState(&clickPoint.x, &clickPoint.y);

				if (pointInsideRect(clickPoint, killAllButton)) {
					this->objetivo = KILL_ALL;
				} else if (pointInsideRect(clickPoint, flagButton)) {
					this->objetivo = FLAG;
				} else if (pointInsideRect(clickPoint, kingButton)) {
					this->objetivo = KING;
				} else if (pointInsideRect(clickPoint, submitButton)) {
					shouldQuit = true;
				}
			}
		}
	}
}
コード例 #2
0
ファイル: bqt_gui_button.cpp プロジェクト: JadeMatrix/BQTDraw
 bool button::acceptEvent( window_event& e )
 {
     scoped_lock< mutex > slock_b( element_mutex );
     
     switch( e.type )
     {
     case STROKE:
         // TODO: Consider using a series of if statements here, as in
         // the very unlikely case that the event.stroke's position and
         // prev_pos are the same & both outside the button (window::
         // acceptEvent() should prevent this) as the button state will bug
         // out.
         
         if( ( state == OFF_DOWN
               || state == ON_DOWN )
             && e.stroke.dev_id != captured_dev )                            // Ignore but accept other devices wile capturing another
         {
             return true;
         }
         
         switch( state )
         {
         case OFF_UP:
             if( ( e.stroke.click & CLICK_PRIMARY )
                 && pointInsideRect( e.stroke.position[ 0 ] - e.offset[ 0 ],
                                     e.stroke.position[ 1 ] - e.offset[ 1 ],
                                     position[ 0 ],
                                     position[ 1 ],
                                     dimensions[ 0 ],
                                     dimensions[ 1 ] ) )
             {
                 state = OFF_DOWN;
                 parent.associateDevice( e.stroke.dev_id, this, e.offset[ 0 ], e.offset[ 1 ] );
                 captured_dev = e.stroke.dev_id;
                 parent.requestRedraw();
             }
             break;
         case OFF_DOWN:
             if( pointInsideRect( e.stroke.position[ 0 ] - e.offset[ 0 ],
                                  e.stroke.position[ 1 ] - e.offset[ 1 ],
                                  position[ 0 ],
                                  position[ 1 ],
                                  dimensions[ 0 ],
                                  dimensions[ 1 ] ) )
             {
                 if( !( e.stroke.click & CLICK_PRIMARY ) )
                 {
                     state = ON_UP;
                     parent.deassociateDevice( e.stroke.dev_id );
                     parent.requestRedraw();
                 }
             }
             else                                                            // Works because we still get strokes that have just gone out of the mask
             {
                 state = OFF_UP;                                             // Cancel the button press
                 parent.deassociateDevice( e.stroke.dev_id );
                 parent.requestRedraw();
             }
             break;
         case ON_UP:
             if( ( e.stroke.click & CLICK_PRIMARY )
                 && pointInsideRect( e.stroke.position[ 0 ] - e.offset[ 0 ],
                                     e.stroke.position[ 1 ] - e.offset[ 1 ],
                                     position[ 0 ],
                                     position[ 1 ],
                                     dimensions[ 0 ],
                                     dimensions[ 1 ] ) )
             {
                 state = ON_DOWN;
                 parent.associateDevice( e.stroke.dev_id, this, e.offset[ 0 ], e.offset[ 1 ] );
                 captured_dev = e.stroke.dev_id;
                 parent.requestRedraw();
             }
             break;
         case ON_DOWN:
             if( pointInsideRect( e.stroke.position[ 0 ] - e.offset[ 0 ],
                                  e.stroke.position[ 1 ] - e.offset[ 1 ],
                                  position[ 0 ],
                                  position[ 1 ],
                                  dimensions[ 0 ],
                                  dimensions[ 1 ] ) )
             {
                 if( !( e.stroke.click & CLICK_PRIMARY ) )
                 {
                     state = OFF_UP;
                     parent.deassociateDevice( e.stroke.dev_id );
                     parent.requestRedraw();
                 }
             }
             else
             {
                 state = ON_UP;
                 parent.deassociateDevice( e.stroke.dev_id );
                 parent.requestRedraw();
             }
             break;
         default:
             throw exception( "button::acceptEvent(): Unknown button state" );
         }
         return true;
     default:
         return false;
     }
 }