Example #1
0
void
set_mouse_coord (struct mouse_coord *m)
{
  if (m->c.x < 0 || m->c.x >= ORIGINAL_WIDTH
      || m->c.y < 0 || m->c.y >= ORIGINAL_HEIGHT)
    return;

  int x, y;

  mr_restore_origin (&m->mr);

  if (! m->c.room) {
    al_set_mouse_xy (display, m->sx, m->sy);
    return;
  }

  if (! mr_coord (m->c.room, -1, &x, &y)) {
    mr_center_room (m->c.room);
    x = mr.x;
    y = mr.y;
  }

  struct mouse_coord m0;
  get_mouse_coord (&m0);
  if (m0.x >= 0 && m0.y >= 0 &&
      mr.cell[m0.x][m0.y].room == m->c.room) {
    x = m0.x;
    y = m0.y;
  }

  int tw, th;
  mr_get_resolution (&tw, &th);

  int w = al_get_display_width (display);
  int h = al_get_display_height (display);

  int mx = ((ORIGINAL_WIDTH * x + m->c.x + 1) * w) / tw;
  int my = ((ROOM_HEIGHT * y + m->c.y + 1) * h) / th;

  mx = min_int (mx, w - 1);
  my = min_int (my, h - 1);

  int flags = screen_flags | potion_flags;

  if (flags & ALLEGRO_FLIP_HORIZONTAL)
    mx = (w - 1) - mx;

  if (flags & ALLEGRO_FLIP_VERTICAL)
    my = (h - 1) - my;

  if (! al_set_mouse_xy (display, mx, my))
    error (0, 0, "%s (%p): cannot set mouse xy coordinates (%i,%i)",
           __func__, m, mx, my);

  do {
    al_get_mouse_state (&mouse_state);
  } while (mouse_state.x != mx || mouse_state.y != my);

  mr.select_cycles = SELECT_CYCLES;
}
Example #2
0
void UIScreen::primary_timer_func()
{
   if (use_joystick_as_mouse)
   {
      if (Framework::joystick)
      {
         float sensitivity = 8.0;

         ALLEGRO_MOUSE_STATE mouse_state;
         al_get_mouse_state(&mouse_state);

         ALLEGRO_JOYSTICK_STATE joystick_state;
         al_get_joystick_state(Framework::joystick, &joystick_state);

         // TODO:
         // right now the joystick axis to use for the mouse emulation is static,
         // this should be fixed so that an axis might be chosen by the user
         // and/or multiple joysticks could also be used
         if (joystick_state.stick[0].axis[0] != 0.0 || joystick_state.stick[0].axis[1] != 0.0)
         {
            al_set_mouse_xy(display->al_display,
                  mouse_state.x + joystick_state.stick[0].axis[0]*sensitivity,
                  mouse_state.y + joystick_state.stick[0].axis[1]*sensitivity);
         }
      }
   }

   // call the parent's usual functions

   UIWidget::primary_timer_func();
   UIWidget::draw_func();

   on_draw_after_children();
}
Example #3
0
static int allua_mouse_set_xy(lua_State * L)
{
   ALLUA_display display = allua_check_display(L, 1);
   int x = luaL_checkint(L, 2);
   int y = luaL_checkint(L, 3);
   lua_pushboolean(L, al_set_mouse_xy(display, x, y));
   return 1;
}
 NotificationBubbleTestProject(Display *display)
    : UIScreen(display)
    , mouse_x(display->width()/2)
    , mouse_y(display->height()/2)
    , bubble_count_text(NULL)
 {
    al_set_mouse_xy(display->al_display, mouse_x, mouse_y);
    new UIText(this, 40, 30, "Move the mouse and press any key to spawn a NotificationBubble.");
    bubble_count_text = new UIText(this, 40, 60, "Number of active bubbles: 0");
 }
Example #5
0
void
set_mouse_room (int room)
{
  struct mouse_coord m;

  int x, y;
  if (mr_coord (room, -1, &x, &y))
    mr_set_origin (room, x, y);

  mr_save_origin (&m.mr);
  new_coord (&m.c, &global_level, room, ORIGINAL_WIDTH / 2, ORIGINAL_HEIGHT / 2);
  set_mouse_coord (&m);

  if (! room) {
    mr_center_room (0);
    mr.select_cycles = 0;
    int w = al_get_display_width (display);
    int h = al_get_display_height (display);
    al_set_mouse_xy (display, w / 2, h / 2);
  }
}
Example #6
0
void Gamestate_Start(struct Game *game, struct RocketsResources* data) {
	  data->rockets_left = NULL;
		data->rockets_right = NULL;

		data->timelimit = 400 * game->data->mediator.modificator;
		data->spawnspeed = 80 / game->data->mediator.modificator;
		data->currentspawn = data->spawnspeed;
		data->spawncounter = data->spawnspeed - 20;

		data->lost = false;
		data->won = false;
		data->hearts = 0;

		data->flash = 0;
		data->zadyma = 16;

		SetCharacterPosition(game, data->usa_flag, 185, 80, 0);
		SetCharacterPosition(game, data->ru_flag, 25, 80, 0);

		SetCharacterPosition(game, data->cursor, 320/2, 50, 0);

		SetCharacterPosition(game, data->riot, 0, 0, 0);
		SelectSpritesheet(game, data->riot, "riot");

		SelectSpritesheet(game, data->usa_flag, "legia");
		SelectSpritesheet(game, data->ru_flag, "lech");

		SelectSpritesheet(game, data->cursor, "hand");

		data->counter = 0;
		data->cloud_rotation = 0;

		data->mousemove.bottom = false;
		data->mousemove.top = false;
		data->mousemove.left = false;
		data->mousemove.right = false;

		al_set_mouse_xy(game->display, al_get_display_width(game->display) / 2, al_get_display_height(game->display) / 2);

}
Example #7
0
static void generate_touch_input_event(int type, double timestamp, int id, float x, float y, float dx, float dy, bool primary, ALLEGRO_DISPLAY_WIN *win_disp)
{
   ALLEGRO_EVENT event;

   bool want_touch_event           = _al_event_source_needs_to_generate_event(&touch_input.es);
   bool want_mouse_emulation_event = _al_event_source_needs_to_generate_event(&touch_input.mouse_emulation_es) && primary && al_is_mouse_installed();

   if (touch_input.mouse_emulation_mode == ALLEGRO_MOUSE_EMULATION_NONE)
      want_mouse_emulation_event = false;
   else if (touch_input.mouse_emulation_mode == ALLEGRO_MOUSE_EMULATION_INCLUSIVE)
      want_touch_event = want_mouse_emulation_event ? (want_touch_event && !primary) : want_touch_event;
   else if (touch_input.mouse_emulation_mode == ALLEGRO_MOUSE_EMULATION_EXCLUSIVE)
      want_touch_event = want_mouse_emulation_event ? false : want_touch_event;

   if (!want_touch_event && !want_mouse_emulation_event)
      return;

   if (want_touch_event) {

      event.touch.type      = type;
      event.touch.display   = (ALLEGRO_DISPLAY*)win_disp;
      event.touch.timestamp = timestamp;
      event.touch.id        = id;
      event.touch.x         = x;
      event.touch.y         = y;
      event.touch.dx        = dx;
      event.touch.dy        = dy;
      event.touch.primary   = primary;

      _al_event_source_lock(&touch_input.es);
      _al_event_source_emit_event(&touch_input.es, &event);
      _al_event_source_unlock(&touch_input.es);
   }

   if (want_mouse_emulation_event) {

      ALLEGRO_MOUSE_STATE state;

      switch (type) {
         case ALLEGRO_EVENT_TOUCH_BEGIN: type = ALLEGRO_EVENT_MOUSE_BUTTON_DOWN; break;
         case ALLEGRO_EVENT_TOUCH_CANCEL:
         case ALLEGRO_EVENT_TOUCH_END:   type = ALLEGRO_EVENT_MOUSE_BUTTON_UP;   break;
         case ALLEGRO_EVENT_TOUCH_MOVE:  type = ALLEGRO_EVENT_MOUSE_AXES;        break;
      }

      al_get_mouse_state(&state);

      event.mouse.type      = type;
      event.mouse.timestamp = timestamp;
      event.mouse.display   = (ALLEGRO_DISPLAY*)win_disp;
      event.mouse.x         = (int)x;
      event.mouse.y         = (int)y;
      event.mouse.z         = state.z;
      event.mouse.w         = state.w;
      event.mouse.dx        = (int)dx;
      event.mouse.dy        = (int)dy;
      event.mouse.dz        = 0;
      event.mouse.dw        = 0;
      event.mouse.button    = 1;
      event.mouse.pressure  = state.pressure;

      al_set_mouse_xy(event.mouse.display, event.mouse.x, event.mouse.y);

      _al_event_source_lock(&touch_input.mouse_emulation_es);
      _al_event_source_emit_event(&touch_input.mouse_emulation_es, &event);
      _al_event_source_unlock(&touch_input.mouse_emulation_es);
   }
}
Example #8
0
void Mouse::SetPosition(double x, double y, double z, double w) {
    al_set_mouse_xy(_parent_display, x, y);
    al_set_mouse_z(x);
    al_set_mouse_w(w);
    _position = a2de::Vector4D(x, y, z, w);
}
Example #9
0
void Renderer::run()
{
	NBT_Debug("begin");

	al_hide_mouse_cursor(dpy_);

	al_identity_transform(&camera_transform_);

	float x = -camera_pos_.x, y = -camera_pos_.y, z = -camera_pos_.z;
	//x = -dim0_->spawnX();
	//z = -dim0_->spawnZ();

	al_translate_transform_3d(&camera_transform_, x, y, z);

	al_rotate_transform_3d(&camera_transform_, 0.0, 1.0, 0.0, DEG_TO_RAD(180));

	memset(key_state_, 0, sizeof(key_state_) * sizeof(key_state_[0]));

	al_start_timer(tmr_);

	NBT_Debug("run!");

	//al_use_shader(nullptr);

	/*ALLEGRO_TRANSFORM trans;
	al_identity_transform(&trans);
	al_orthographic_transform(&trans, 0, 0, -1, al_get_display_width(dpy_), al_get_display_height(dpy_), 1);
	al_set_projection_transform(dpy_, &trans);
	al_identity_transform(&trans);
	al_use_transform(&trans);

	if(!resManager_->getAtlas()->getSheet(0)->alBitmap())
		NBT_Debug("no sheet bitmap????");
	*/
	//al_draw_bitmap(resManager_->getAtlas()->getSheet(0)->alBitmap(), 0, 0, 0);

	//al_flip_display();
	//sleep(10);

	bool redraw = false;
	bool doUpdateLookPos = false;
	bool cleared = false;
	
	while(1)
	{
		ALLEGRO_EVENT ev;
      al_wait_for_event(queue_, &ev);

      if(ev.type == ALLEGRO_EVENT_TIMER)
		{
         redraw = true;
			//cam_.rx = 1.0;
			float x = 0.0, y = 0.0, z = 0.0;
			float translate_diff = 0.3;
			float ry = 0.0;
			float rotate_diff = 0.04;
			bool changeTranslation = false;
			bool changeRotation = false;

			if(key_state_[ALLEGRO_KEY_W])
			{
				z += translate_diff;
				changeTranslation = true;
			}

			if(key_state_[ALLEGRO_KEY_S])
			{
				z -= translate_diff;
				changeTranslation = true;
			}

			if(key_state_[ALLEGRO_KEY_A])
			{
				x += translate_diff;
				changeTranslation = true;
			}

			if(key_state_[ALLEGRO_KEY_D])
			{
				x -= translate_diff;
				changeTranslation = true;
			}

			if(key_state_[ALLEGRO_KEY_SPACE])
			{
				y -= translate_diff;
				changeTranslation = true;
			}

			if(key_state_[ALLEGRO_KEY_LSHIFT])
			{
				y += translate_diff;
				changeTranslation = true;
			}

			if(key_state_[ALLEGRO_KEY_LEFT])
			{
				ry += rotate_diff;
				changeRotation = true;
			}

			if(key_state_[ALLEGRO_KEY_RIGHT])
			{
				ry -= rotate_diff;
				changeRotation = true;
			}

			if(changeTranslation)
			{
				//camera_pos_.translate(x, y, z);
				al_translate_transform_3d(&camera_transform_, x, y, z);
				doUpdateLookPos = true;
			}

			if(changeRotation)
			{
				al_rotate_transform_3d(&camera_transform_, 0.0, 1.0, 0.0, ry);
				doUpdateLookPos = true;
			}

			if(doUpdateLookPos)
				updateLookPos();

      }
      else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
		{
			NBT_Debug("display close");
         break;
      }
      else if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
		{
			//NBT_Debug("key down");
			//NBT_Debug("pos: %fx%f", -camera_transform_.m[2][0], -camera_transform_.m[2][2]);
			key_state_[ev.keyboard.keycode] = true;

			if (ev.keyboard.keycode == ALLEGRO_KEY_Q)
			{
				break;
			}
			else if(ev.keyboard.keycode == ALLEGRO_KEY_C)
			{
				NBT_Debug("CLEAR CHUNKS");
				glBindVertexArray(vao_);
				for(auto ch: chunkData_)
				{
					delete ch.second;
				}
				glBindVertexArray(0);
				chunkData_.clear();

				glDeleteBuffers(1, &vao_);
				
				cleared = true;
			}
			else if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
			{
				grab_mouse_ = !grab_mouse_;
			}
		}
		else if(ev.type == ALLEGRO_EVENT_KEY_UP)
		{
			//NBT_Debug("pos: %fx%f", -camera_transform_.m[2][0], -camera_transform_.m[2][2]);
			key_state_[ev.keyboard.keycode] = false;
		}
		else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP)
		{
				grab_mouse_ = true;
		}
		else if(ev.type == ALLEGRO_EVENT_MOUSE_AXES && grab_mouse_)
		{
			float dx = ev.mouse.dx, dy = ev.mouse.dy;

			if(dy > 0 && dy < 1.5)
				dy = 0.0;

			if(dy < 0 && dy > -1.5)
				dy = 0.0;

			if(dx > 0 && dx < 1.5)
				dy = 0.0;

			if(dx < 0 && dx > -1.5)
				dx = 0.0;

			float ry = dx / al_get_display_width(dpy_), rx = dy / al_get_display_height(dpy_);

			rx_look += rx;
			al_rotate_transform_3d(&camera_transform_, 0.0, 1.0, 0.0, ry);
//			al_rotate_transform_3d(&camera_transform_, 1.0, 0.0, 0.0, rx);

			//cam_.rx += dy / al_get_display_height(dpy_);

			al_set_mouse_xy(dpy_, al_get_display_width(dpy_)/2.0, al_get_display_height(dpy_)/2.0);

			doUpdateLookPos = true;
		}

      if(redraw && al_is_event_queue_empty(queue_))
		{
			if(!loadChunkQueue.empty())
			{
				NBT_Debug("%i chunks to load", loadChunkQueue.size());

				std::pair<int32_t, int32_t> pos = loadChunkQueue.front();
				loadChunkQueue.pop();

				processChunk(pos.first, pos.second);
			}
			else
			{
				if(!cleared)
				{
					//NBT_Debug("pos: %fx%fx%f", camera_pos_.getX(), camera_pos_.getZ(), camera_pos_.getY());
					autoLoadChunks(camera_pos_.getX() / 16.0, camera_pos_.getZ() / 16.0);
				}
			}

			ALLEGRO_STATE state;
			al_store_state(&state, ALLEGRO_STATE_ALL);
			al_set_projection_transform(dpy_, &al_proj_transform_);

			glClear(GL_DEPTH_BUFFER_BIT);

         redraw = false;
			al_clear_to_color(al_map_rgb(255,255,255));
         draw();

			al_restore_state(&state);
			al_set_projection_transform(dpy_, &al_proj_transform_);

			drawHud();

			al_restore_state(&state);
         al_flip_display();
      }


	}

	NBT_Debug("stop timer");
	al_stop_timer(tmr_);

	NBT_Debug("end");


	NBT_Debug("sizeof GL_FLOAT: %i", sizeof(GLfloat));
}
int main(void)
{
   ALLEGRO_FONT *font;
   ALLEGRO_DISPLAY *display;
   ALLEGRO_EVENT_QUEUE *event_queue;
   ALLEGRO_EVENT event;
   bool right_button_down = false;
   bool redraw = true;
   int fake_x = 0, fake_y = 0;
   ALLEGRO_COLOR white;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }
   al_init_primitives_addon();
   al_init_font_addon();
   al_init_image_addon();
   al_install_mouse();
   al_install_keyboard();

   al_set_new_display_flags(ALLEGRO_WINDOWED);
   display = al_create_display(width, height);
   if (!display) {
      abort_example("Could not create display.\n");
      return 1;
   }

   memset(&event, 0, sizeof(event));

   event_queue = al_create_event_queue();
   al_register_event_source(event_queue, al_get_display_event_source(display));
   al_register_event_source(event_queue, al_get_mouse_event_source());
   al_register_event_source(event_queue, al_get_keyboard_event_source());

   font = al_load_font("data/fixed_font.tga", 0, 0);
   white = al_map_rgb_f(1, 1, 1);

   while (1) {      
      if (redraw && al_is_event_queue_empty(event_queue)) {
         int th = al_get_font_line_height(font);
         
         al_clear_to_color(al_map_rgb_f(0, 0, 0));
         
         if (right_button_down) {
            al_draw_line(width / 2, height / 2, fake_x, fake_y,
               al_map_rgb_f(1, 0, 0), 1);
            al_draw_line(fake_x - 5, fake_y, fake_x + 5, fake_y,
               al_map_rgb_f(1, 1, 1), 2);
            al_draw_line(fake_x, fake_y - 5, fake_x, fake_y + 5,
               al_map_rgb_f(1, 1, 1), 2);
         }
         
         al_draw_textf(font, white, 0, 0, 0, "x: %i y: %i dx: %i dy %i",
            event.mouse.x, event.mouse.y,
            event.mouse.dx, event.mouse.dy);
         al_draw_textf(font, white, width / 2, height / 2 - th, ALLEGRO_ALIGN_CENTRE,
            "Left-Click to warp pointer to the middle once.");
         al_draw_textf(font, white, width / 2, height / 2, ALLEGRO_ALIGN_CENTRE,
            "Hold right mouse button to constantly move pointer to the middle.");
         al_flip_display();
         redraw = false;
      }

      al_wait_for_event(event_queue, &event);

      if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
         break;
      }
      if (event.type == ALLEGRO_EVENT_KEY_DOWN) {
         if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
            break;
      }
      if (event.type == ALLEGRO_EVENT_MOUSE_WARPED) {
         printf("Warp\n");

      }
      if (event.type == ALLEGRO_EVENT_MOUSE_AXES) {
         if (right_button_down) {
            al_set_mouse_xy(display, width / 2, height / 2);
            fake_x += event.mouse.dx;
            fake_y += event.mouse.dy;
         }
         redraw = true;
      }
      if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
         if (event.mouse.button == 1)
            al_set_mouse_xy(display, width / 2, height / 2);
         if (event.mouse.button == 2) {
            right_button_down = true;
            fake_x = width / 2;
            fake_y = height / 2;
         }
      }
      if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
         if (event.mouse.button == 2) {
            right_button_down = false;
         }
      }
   }

   al_destroy_event_queue(event_queue);
   al_destroy_display(display);

   return 0;
}
Example #11
0
void m_set_mouse_xy(ALLEGRO_DISPLAY *display, int x, int y)
{
	al_set_mouse_xy(display, x, y);
}