コード例 #1
0
ファイル: display.cpp プロジェクト: kiiyanatz/collector
void Display::on_selection(Selection* s)
{
	//replace the current selection
	state.replace_selection(s);

	//let the components update themselves
	cli.display->on_selection();
	subtags.display->on_selection();
	info.display->on_selection();
	grid.display->on_selection();

	//the new selection's layout must be computed
	/*
		TODO:
		This should really be moved to the Thumbs class,
		but the viewport must be set by this Display manager.
		Consider using a dirty state for layout
		(as well as the one for graphics).
	*/
	resize_child(thumbs); 
	thumbs.display->on_selection();

	//kick the current DisplayObject to consider the mouse again
	update_mouse();
}
コード例 #2
0
ファイル: cloth.c プロジェクト: Wisellama/OpenGL-Cloth
void main_loop()
{
  // the time of the previous frame
  double old_time = glfwGetTime();
  // point that the mouse grabs
  Point *mouse_point = malloc(sizeof(Point)); // temporary
  int mouse_held = 0; // boolean
  // this just loops as long as the program runs
  while(1)
    {
      // calculate time elapsed
      double current_time = glfwGetTime(),
	delta_time = (current_time - old_time);
      old_time = current_time;
      // escape to quit, arrow keys to rotate view
      if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS) {
	break;
      }
      if (glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS) {
	rotate_y += delta_time*30;
      }
      if (glfwGetKey(GLFW_KEY_RIGHT) == GLFW_PRESS) {
	rotate_y -= delta_time*30;
      }
      //randomly push the mesh in a random direction with SPACE
      if(glfwGetKey(GLFW_KEY_SPACE) == GLFW_PRESS) {
	int random_point = rand()%(NUM_POINTS-NUM_POINTS_X-1) + NUM_POINTS_X+1;
	Point *p = point_array[random_point];
	p->x += rand()%10000 / 10000.0 - .5;
	p->y += rand()%10000 / 10000.0 - .5;
	p->z += rand()%10000 / 10000.0 - .5;
      }

      //update link constraints multiple times
      for(int q = 0; q < 3; q++) {
	for(int i = 0; i < NUM_LINKS; i++) {
	  if(!link_array[i]->broken) {
	    update_link(link_array[i]);
	  }
	}      
      }

      //update all points except top row (fixed points)
      for(int i = 0; i < NUM_POINTS; i++) {
	if(!point_array[i]->anchor) {
	  update_point(point_array[i], delta_time);
	}
      }

      // clear the buffer
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      // draw the figure
      draw(link_array);
      // mouse stuffs
      update_mouse(&mouse_point, &mouse_held);
      // swap back and front buffers
      glfwSwapBuffers();
    }
}
コード例 #3
0
ファイル: mouse.c プロジェクト: AntonLanghoff/whitecatlib
/* position_mouse_w:
 *  Sets the mouse fourth axis to position w.
 */
void position_mouse_w(int w)
{
   if (!mouse_driver)
      return;

   _mouse_w = w;
   update_mouse();
}
コード例 #4
0
ファイル: mouse.c プロジェクト: AntonLanghoff/whitecatlib
/* position_mouse_z:
 *  Sets the mouse third axis to position z.
 */
void position_mouse_z(int z)
{
   if (!mouse_driver)
      return;

   _mouse_z = z;
   update_mouse();
}
コード例 #5
0
void
Slider::on_mouse_move(const CL_InputEvent& event)
{
  if (pressed)
  {
    update_mouse(event);
  }
}
コード例 #6
0
ファイル: utils.c プロジェクト: morenko/sven
void sven_exit (GtkMenuItem *menuitem,Sven *sven)
{
	update_kbd(sven);
	update_mouse(sven);
	sven_plugin_shutdown(sven);
	sven_write_config(sven);
	gtk_main_quit();
	exit (1);
}
コード例 #7
0
void
Slider::on_mouse_down(const CL_InputEvent& event)
{
  if (event.id == CL_MOUSE_LEFT)
  {
    pressed = true;
    capture_mouse();
    update_mouse(event);
  }
}
コード例 #8
0
void
Slider::on_mouse_up  (const CL_InputEvent& event)
{
  if (event.id == CL_MOUSE_LEFT)
  {
    pressed = false;
    release_mouse();
    update_mouse(event);
  }
}
コード例 #9
0
ファイル: display.cpp プロジェクト: kiiyanatz/collector
void Display::on_wheel(SDL_MouseWheelEvent &e)
{
	if(current != NULL)
	{
		current->display->on_wheel(e);

		//kick the current DisplayObject to consider the mouse again
		update_mouse();
	}
}
コード例 #10
0
ファイル: mouse.c プロジェクト: AntonLanghoff/whitecatlib
/* poll_mouse:
 *  Polls the current mouse state, and updates the user-visible information
 *  accordingly. On some drivers this is actually required to get the
 *  input, while on others it is only present to keep compatibility with
 *  systems that do need it. So that people can test their polling code
 *  even on platforms that don't strictly require it, after this function
 *  has been called once, the entire system will switch into polling mode 
 *  and will no longer operate asynchronously even if the driver actually
 *  does support that.
 */
int poll_mouse(void)
{
   if (!mouse_driver)
      return -1;

   if (mouse_driver->poll)
      mouse_driver->poll();

   update_mouse();

   mouse_polled = TRUE;

   return 0;
}
コード例 #11
0
ファイル: display.cpp プロジェクト: kiiyanatz/collector
void Display::on_motion(SDL_MouseMotionEvent &e)
{
	mouse = e;

	SDL_Point p = { e.x, e.y };
	if(point_in_rect(&p, &grid.rect))
		current = &grid;
	else if(point_in_rect(&p, &thumbs.rect))
		current = &thumbs;
	else
		current = NULL;

	update_mouse();
}
コード例 #12
0
ファイル: mouse.c プロジェクト: AntonLanghoff/whitecatlib
/* mouse_move:
 *  Timer interrupt handler for redrawing the mouse pointer.
 */
static void mouse_move(void)
{
   if (mouse_semaphore)
      return;

   mouse_semaphore = TRUE;

   /* periodic poll */
   if (mouse_driver->timer_poll) {
      mouse_driver->timer_poll();
      if (!mouse_polled)
	 update_mouse();
   }

   /* redraw pointer */
   if ((!freeze_mouse_flag) && (_mouse_screen) && ((mx != _mouse_x) || (my != _mouse_y) || (mon != _mouse_on))) {
      acquire_bitmap(_mouse_screen);

      if (gfx_capabilities & GFX_HW_CURSOR) {
	 if (_mouse_on) {
	    gfx_driver->move_mouse(mx=_mouse_x, my=_mouse_y);
	    mon = TRUE;
	 }
	 else {
	    gfx_driver->move_mouse(mx=MOUSE_OFFSCREEN, my=MOUSE_OFFSCREEN);
	    mon = FALSE;
	 }
      }
      else {
#ifdef ALLEGRO_DOS
	 /* bodge to avoid using non legacy 386 asm code inside a timer handler */
	 int old_capabilities = cpu_capabilities;
	 cpu_capabilities = 0;
#endif
	 draw_mouse(TRUE, TRUE);
#ifdef ALLEGRO_DOS
	 cpu_capabilities = old_capabilities;
#endif
      }

      release_bitmap(_mouse_screen);
   }

   mouse_semaphore = FALSE;
}
コード例 #13
0
ファイル: mouse.c プロジェクト: AntonLanghoff/whitecatlib
/* set_mouse_range:
 *  Sets the screen area within which the mouse can move. Pass the top left 
 *  corner and the bottom right corner (inclusive). If you don't call this 
 *  function the range defaults to (0, 0, SCREEN_W-1, SCREEN_H-1).
 */
void set_mouse_range(int x1, int y1, int x2, int y2)
{
   BITMAP *old_mouse_screen = _mouse_screen;
   ASSERT(x1 >= 0);
   ASSERT(y1 >= 0);
   ASSERT(x2 >= x1);
   ASSERT(y2 >= y2);

   if (!mouse_driver)
      return;

   if (_mouse_screen)
      show_mouse(NULL);

   if (mouse_driver->set_range)
      mouse_driver->set_range(x1, y1, x2, y2);

   update_mouse();

   if (old_mouse_screen)
      show_mouse(old_mouse_screen);
}
コード例 #14
0
ファイル: game.c プロジェクト: tivervac/UGentProjects
void mouse_move(MouseMoveEvent * ev, GameState * state) {
	Mouse * mouse = &state->mouse;

	/* Update mouse pointer location */
	update_mouse(state, ev->screen_x, ev->screen_y);

	if (in_world_screen(mouse->screen_x, mouse->screen_y)) {
		if (state->action == BUILD_TOWER) {
			//er is op een tower-knop geklikt; toon de blueprint
			state->blueprint.entity.all.world_x = mouse->world_x;
			state->blueprint.entity.all.world_y = mouse->world_y;
			state->blueprint.valid = (state->world.entities[mouse->tile_x][mouse->tile_y].type == EMPTY && state->money >= state->blueprint.entity.tower.cost);
			init_tower_blueprint(&state->blueprint.entity, state->blueprint.entity.tower.tower_type);
		}
		/* Already implemented code to reset buttons after hovering. DO NOT CHANGE */
		reset_all_buttons_action(state);
	}

	else { /* Outside of world frame => buttons */
		set_button_hover_state(state); /* DO NOT CHANGE */
	}
}
コード例 #15
0
ファイル: chipmunk.c プロジェクト: rlofc/cage
/* Mouse handling is a bit tricky. We want the user to move
 * tiles using the mouse but because tiles are dynamic bodies
 * managed by Chipmunk2D, we cannot directly control them.
 * This is resolved by creating a pivot joint between an
 * invisible mouse body that we can control and the tile body
 * that we cannot directly control.
 */
static void apply_mouse_motion(struct state* state)
{
    struct mouse m;
    update_mouse(&m);
    int w, h;
    get_screen_size(&w, &h);
    int x = m.x_position * w;
    int y = m.y_position * h;
    cpVect mouse_pos = cpv(x, y);
    cpVect new_point =
        cpvlerp(cpBodyGetPosition(state->mouse_body), mouse_pos, 0.25f);
    cpBodySetVelocity(
        state->mouse_body,
        cpvmult(cpvsub(new_point, cpBodyGetPosition(state->mouse_body)),
                60.0f));
    cpBodySetPosition(state->mouse_body, new_point);
    if (m.left_click && state->mouse_joint == NULL) {
        cpFloat radius = 5.0;
        cpPointQueryInfo info = { 0 };
        cpShape* shape = cpSpacePointQueryNearest(state->space, mouse_pos,
                                                  radius, GRAB_FILTER, &info);
        if (shape && cpBodyGetMass(cpShapeGetBody(shape)) < INFINITY) {
            cpVect nearest = (info.distance > 0.0f ? info.point : mouse_pos);
            cpBody* body = cpShapeGetBody(shape);
            state->mouse_joint =
                cpPivotJointNew2(state->mouse_body, body, cpvzero,
                                 cpBodyWorldToLocal(body, nearest));
            cpConstraintSetMaxForce(state->mouse_joint, 5000000.0f);
            cpConstraintSetErrorBias(state->mouse_joint,
                                     cpfpow(1.0f - 0.15f, 60.0f));
            cpSpaceAddConstraint(state->space, state->mouse_joint);
        }
    }
    if (m.left_click == false && state->mouse_joint != NULL) {
        cpSpaceRemoveConstraint(state->space, state->mouse_joint);                                                 
        cpConstraintFree(state->mouse_joint);                                                               
        state->mouse_joint = NULL;  
    }
}
コード例 #16
0
ファイル: mouse.c プロジェクト: AntonLanghoff/whitecatlib
/* position_mouse:
 *  Moves the mouse to screen position x, y. This is safe to call even
 *  when a mouse pointer is being displayed.
 */
void position_mouse(int x, int y)
{
   BITMAP *old_mouse_screen = _mouse_screen;

   if (!mouse_driver)
      return;

   if (_mouse_screen)
      show_mouse(NULL);

   if (mouse_driver->position) {
      mouse_driver->position(x, y);
   }
   else {
      _mouse_x = x;
      _mouse_y = y;
   }

   update_mouse();

   if (old_mouse_screen)
      show_mouse(old_mouse_screen);
}
コード例 #17
0
ファイル: main.cpp プロジェクト: bothemasterofall/bayou
int main()
{
    //shell vars
    bool render = false;

    //allegro vars
    ALLEGRO_DISPLAY *display = NULL;
    ALLEGRO_EVENT_QUEUE *event_queue = NULL;
    ALLEGRO_TIMER *timer = NULL;

    //allegro init functions
    printf ("Initializing allegro\n");
    if (!al_init())
    {
        al_show_native_message_box(NULL, NULL, NULL, "failed", NULL, 0);
        return -1;
    }

    printf("Creating display\n");
    display = al_create_display(WIDTH, HEIGHT);
    if (!display)
    {
        al_show_native_message_box(NULL, NULL, NULL, "failed", NULL, 0);
        return -1;
    }

    printf("Installing addons\n");
    al_init_font_addon();
    al_init_ttf_addon();
    al_init_primitives_addon();
    al_init_image_addon();
    al_install_keyboard();
    al_install_mouse();
    al_install_audio();
    al_init_acodec_addon();
    al_reserve_samples(10);

    //project inits
    srand(time(NULL));

    printf("Initializing timer\n");
    event_queue = al_create_event_queue();
    timer = al_create_timer(1.0 / FPS);

    printf("Registering event sources\n");
    al_register_event_source(event_queue, al_get_display_event_source(display));
    al_register_event_source(event_queue, al_get_keyboard_event_source());
    al_register_event_source(event_queue, al_get_timer_event_source(timer));
    al_start_timer(timer);

    printf("Init mouse and keyboard\n");
    init_keyboard();
    init_mouse();

    printf("Loading assets\n");
    load_bitmaps();
    load_fonts();
    load_samples();

    printf ("Creating manager\n");
    push_state(new TitleMenu());
    
    printf("Beginning game\n");
    while (!is_game_over())
    {
        //declare an event
        ALLEGRO_EVENT event;

        //monitor event sources
        al_wait_for_event(event_queue, &event);
        if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
        {
            end_game();
        }
        else if (event.type == ALLEGRO_EVENT_TIMER)
        {
            render = true;

            update_mouse();
            update_keyboard();

            handle_key();
            update_game();
        }

        // Render screen
        if (render && al_event_queue_is_empty(event_queue))
        {
            render = false;
            render_game();
            al_flip_display();
        }
    }

    unload_assets();
    al_destroy_event_queue(event_queue);
    al_destroy_display(display);
    al_destroy_timer(timer);

    return 0;
}
コード例 #18
0
ファイル: mouse.c プロジェクト: AntonLanghoff/whitecatlib
/* _handle_mouse_input:
 *  Callback for an asynchronous driver to tell us when it has changed the
 *  position.
 */
void _handle_mouse_input(void)
{
   if (!mouse_polled)
      update_mouse();
}
コード例 #19
0
ファイル: wininput.c プロジェクト: Jactry/mintty
void
win_update_mouse(void)
{ update_mouse(get_mods()); }
コード例 #20
0
ファイル: macdriver_console.c プロジェクト: digarok/gsplus
void check_input_events()      {
  OSStatus err;
  EventTargetRef target;
  EventRef event;
  UInt32 event_class, event_kind;
  byte mac_keycode;
  UInt32 keycode;
  UInt32 modifiers;
  Point mouse_point, mouse_delta_point;
  WindowRef window_ref;
  int button, button_state;
  EventMouseButton mouse_button;
  int handled;
  int mouse_events;
  int is_up;
  int in_win;
  int ignore;

  if(g_quit_seen) {
    exit(0);
  }

  SetPortWindowPort(g_main_window);

  mouse_events = 0;
  target = GetEventDispatcherTarget();
  while(1) {
    err = ReceiveNextEvent(0, NULL, kEventDurationNoWait,
                           true, &event);

    if(err == eventLoopTimedOutErr) {
      break;
    }
    if(err != noErr) {
      printf("ReceiveNextEvent err: %d\n", (int)err);
      break;
    }

    event_class = GetEventClass(event);
    event_kind = GetEventKind(event);
    handled = 0;
    switch(event_class) {
      case kEventClassKeyboard:
        handled = 1;
        keycode = 0;
        modifiers = 0;
        GetEventParameter(event, kEventParamKeyMacCharCodes,
                          typeChar, NULL, sizeof(byte), NULL,
                          &mac_keycode);
        GetEventParameter(event, kEventParamKeyCode,
                          typeUInt32, NULL, sizeof(UInt32), NULL,
                          &keycode);
        GetEventParameter(event, kEventParamKeyModifiers,
                          typeUInt32, NULL, sizeof(UInt32), NULL,
                          &modifiers);

        mac_update_modifiers((word32)modifiers);

        // Key up/down event
        is_up = -1;
        switch(event_kind) {
          case kEventRawKeyDown:
            is_up = 0;
            //printf("key down: %02x, %08x\n",
            //	(int)mac_keycode, (int)keycode);
            break;
          case kEventRawKeyUp:
            is_up = 1;
            //printf("key up: %02x, %08x\n",
            //	(int)mac_keycode, (int)keycode);
            break;
          case kEventRawKeyModifiersChanged:
            is_up = -1;
            //printf("key xxx: %08x\n", (int)modifiers);
            break;
        }
        if(is_up >= 0) {
          adb_physical_key_update((int)keycode, is_up);
        }
        break;
      case kEventClassMouse:
        handled = 2;
        mouse_events++;
        GetEventParameter(event, kEventParamMouseLocation,
                          typeQDPoint, NULL, sizeof(Point), NULL,
                          &mouse_point);
        GetWindowRegion(g_main_window, kWindowContentRgn,
                        g_event_rgnhandle);
        in_win =  PtInRgn(mouse_point, g_event_rgnhandle);
        // in_win = 1 if it was in the contect region of window
        err = GetEventParameter(event, kEventParamMouseDelta,
                                typeQDPoint, NULL, sizeof(Point), NULL,
                                &mouse_delta_point);
        button = 0;
        button_state = -1;
        switch(event_kind) {
          case kEventMouseDown:
            button_state = 7;
            handled = 3;
            break;
          case kEventMouseUp:
            button_state = 0;
            handled = 3;
            break;
        }
        if(button_state >= 0) {
          GetEventParameter(event, kEventParamMouseButton,
                            typeMouseButton, NULL,
                            sizeof(EventMouseButton), NULL,
                            &mouse_button);
          button = mouse_button;
          if(button > 1) {
            button = 4 - button;
            button = 1 << button;
          }
          ignore = (button_state != 0) &&
                   (!in_win || g_ignore_next_click);
          ignore = ignore || !g_mainwin_active;
          if(ignore) {
            // Outside of A2 window, ignore clicks
            button = 0;
          }
          if(button_state == 0) {
            g_ignore_next_click = 0;
          }
        }

        GlobalToLocal(&mouse_point);

        if(g_warp_pointer) {
          if(err == 0) {
            g_mac_mouse_x += mouse_delta_point.h;
            g_mac_mouse_y += mouse_delta_point.v;
          }
          mac_warp_mouse();
        } else {
          g_mac_mouse_x = mouse_point.h -
                          g_video_act_margin_left;
          g_mac_mouse_y = mouse_point.v -
                          g_video_act_margin_top;
        }

#if 0
        printf("Mouse %d at: %d,%d button:%d, button_st:%d\n",
               mouse_events, g_mac_mouse_x, g_mac_mouse_y,
               button, button_state);
        printf("Mouse deltas: err:%d, %d,%d\n", (int)err,
               mouse_delta_point.h, mouse_delta_point.v);
#endif

        update_mouse(g_mac_mouse_x, g_mac_mouse_y,
                     button_state, button & 7);
        if(g_warp_pointer) {
          g_mac_mouse_x = A2_WINDOW_WIDTH/2;
          g_mac_mouse_y = A2_WINDOW_HEIGHT/2;
          update_mouse(g_mac_mouse_x, g_mac_mouse_y,0,-1);
        }
        break;
      case kEventClassApplication:
        switch(event_kind) {
          case kEventAppActivated:
            handled = 1;
            g_mainwin_active = 1;
            window_ref = 0;
            GetEventParameter(event, kEventParamWindowRef,
                              typeWindowRef, NULL, sizeof(WindowRef),
                              NULL, &window_ref);
            if(window_ref == g_main_window) {
              g_ignore_next_click = 1;
            }
            break;
          case kEventAppDeactivated:
            handled = 1;
            g_mainwin_active = 0;
            g_ignore_next_click = 1;
            break;
        }
        break;
    }
    //	show_event(event_class, event_kind, handled);
    if(handled != 1) {
      (void)SendEventToEventTarget(event, target);
    }
    ReleaseEvent(event);
  }

  return;
}