Example #1
0
			void entityGUIChat::render(float oX,float oY){
			ALLEGRO_MOUSE_STATE mState; //Mouse state
			al_get_mouse_state(&mState); //Get the state of the mouse

			al_hold_bitmap_drawing(true);
			al_draw_bitmap(chatBoxCache,x,y-31-al_get_bitmap_height(chatBoxCache),0);

			if (resizingChatVertical || gameEngine::globalFunctions::pointInRegion(mState.x,mState.y,x,y-31-(drawLines*lineHeight)-7,x+chatWidth,y-31-(drawLines*lineHeight)+2)) {
				al_draw_line(x,y-31-al_get_bitmap_height(chatBoxCache),x+chatWidth,y-31-al_get_bitmap_height(chatBoxCache),al_map_rgb(255,255,255),1);
				al_draw_line(x,y-31-al_get_bitmap_height(chatBoxCache)+2,x+chatWidth,y-31-al_get_bitmap_height(chatBoxCache)+2,al_map_rgb(255,255,255),1);
			}

			al_draw_bitmap(chatTypeBG,x,y-26,0);
			textEntryBox->render(x+99,y-26,1);
			al_hold_bitmap_drawing(false);
				
			}
Example #2
0
int main(void)
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_BITMAP *cursor;
   ALLEGRO_MOUSE_STATE msestate;
   ALLEGRO_KEYBOARD_STATE kbdstate;
   int i;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }

   al_init_primitives_addon();
   al_install_mouse();
   al_install_keyboard();
   al_init_image_addon();

   display = al_create_display(640, 480);
   if (!display) {
      abort_example("Error creating display\n");
   }

   al_hide_mouse_cursor(display);

   cursor = al_load_bitmap("data/cursor.tga");
   if (!cursor) {
      abort_example("Error loading cursor.tga\n");
   }

   do {
      al_get_mouse_state(&msestate);
      al_get_keyboard_state(&kbdstate);

      al_clear_to_color(al_map_rgb(0xff, 0xff, 0xc0));
      for (i = 1; i <= NUM_BUTTONS; i++) {
         draw_mouse_button(i, al_mouse_button_down(&msestate, i));
      }
      al_draw_bitmap(cursor, msestate.x, msestate.y, 0);
      al_flip_display();

      al_rest(0.005);
   } while (!al_key_down(&kbdstate, ALLEGRO_KEY_ESCAPE));

   return 0;
}
Example #3
0
BaseGame::BaseGame(Vector2 windowSize, ScreenType screenType, string screenTitle, double fps) : fps(fps),
                   windowSize(windowSize), running(true)
{
	initScreen(screenType, screenTitle);
	initModules();

	al_get_keyboard_state(&keyState);
	al_get_mouse_state(&mouseState);

	eventQueue = al_create_event_queue();
	timer = al_create_timer(1/this->fps);

	//Events to read
	al_register_event_source(eventQueue, al_get_keyboard_event_source());
	al_register_event_source(eventQueue, al_get_timer_event_source(timer));
	al_register_event_source(eventQueue, al_get_display_event_source(display));
	al_register_event_source(eventQueue, al_get_mouse_event_source());
}
Example #4
0
Mouse::Mouse() : AllowBoxing(false), ClickFidelity(3), isBoxing(false), DoubleClickFidelity(0.4), blockBoxing(false)
{
	mouseQueue = al_create_event_queue();
	al_register_event_source( mouseQueue, al_get_mouse_event_source() );

	al_init_user_event_source( &mouseEventSource );
	al_register_event_source( EventQueue, &mouseEventSource );

	ALLEGRO_MOUSE_STATE state;
	al_get_mouse_state( &state );
	
	Position.X = state.x;
	Position.Y = state.y;
	mouseDownAt.X = 0;
	mouseDownAt.Y = 0;
	mouseDownButton = 0;
	lastClickTime = 0;
}
void Menu_Screen::Handling_Mouse( ALLEGRO_EVENT &events )
{
	//EVENT MYSZKI
	if(events.type == ALLEGRO_EVENT_MOUSE_AXES)
	{
		x = events.mouse.x ;
		y = events.mouse.y ;

		//START
		if( x < 350 && x > 150 && y < 500 && y > 400 )
			Select_Options   = 0 ;
		//EXIT
		else if( x < 650 && x > 450 && y < 500 && y > 400 )
			Select_Options   = 1 ;
		
	}//if(events.type == ALLEGRO_EVENT_MOUSE_AXES)

	//OBSLUGA KLIKNIECIA MYSZKI
	if(events.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
	{
		//POBIERAMY STAN MYSZKI
		al_get_mouse_state(&state);

		//KLIKNIECIE LEWY PRZYCISK MYSZKI
		if( state.buttons & 1 )
		{
			//START
			if( x < 350 && x > 150 && y < 500 && y > 400 )
			{
				End_Menu_ = true ;
				STATE = GAME ;
			}

			//EXIT
			if( x < 650 && x > 450 && y < 500 && y > 400 )
			{
				End_Menu_ = true ;
				Game_ = false ;
			}
		}
	}//if(events.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
}
Example #6
0
void check_for_button_events(BUTTONPTR currentptr)
{
    const int MOUSEL = 1;// MOUSER = 2, MOUSEM = 3;
    static int mx, my;
    static _Bool mdown = false;
    ALLEGRO_MOUSE_STATE mouse;
    al_get_mouse_state(&mouse);

    set_bflags_on_button(currentptr, BDRAW);
    if(al_mouse_button_down(&mouse, MOUSEL) && !mdown)
    {
        mx = mouse.x;
        my = mouse.y;
        mdown = true;
    }
    if(!al_mouse_button_down(&mouse, MOUSEL))
    {
        mdown = false;
    }
    if(is_point_over_button(mx, my, currentptr))
    {
        if(is_mouse_over_button(&mouse, currentptr))
        {
            set_bflags_on_button(currentptr, BMOUSEOVER);
        }
        if(al_mouse_button_down(&mouse, MOUSEL) && (currentptr->bdata.bflags & BMOUSEOVER))
        {
            set_bflags_on_button(currentptr, BLPRESSED);
        }
        if(!al_mouse_button_down(&mouse, MOUSEL) && (currentptr->bdata.bflags & BLPRESSED))
        {
            set_bflags_on_button(currentptr, BLRELEASED);
        }
    }
    else
    {
        if(is_mouse_over_button(&mouse, currentptr))
        {
            set_bflags_on_button(currentptr, BMOUSEOVER);
        }
    }
}
Example #7
0
struct mouse_coord *
get_mouse_coord (struct mouse_coord *m)
{
  mr_save_origin (&m->mr);

  int w = al_get_display_width (display);
  int h = al_get_display_height (display);
  int sw, sh;
  mr_get_resolution (&sw, &sh);

  al_get_mouse_state (&mouse_state);
  m->sx = mouse_state.x;
  m->sy = mouse_state.y;
  int x = (mouse_state.x * (sw - 1)) / w;
  int y = (mouse_state.y * (sh - 1)) / h;

  int flags = screen_flags | potion_flags;

  if (flags & ALLEGRO_FLIP_HORIZONTAL)
    x = (sw - 1) - x;

  if (flags & ALLEGRO_FLIP_VERTICAL)
    y = (sh - 1) - y;

  m->c.l = &global_level;

  if (y < 3 || y >= sh - 8 || x < 0 || x > sw - 1) {
    m->x = m->y = -1;
    invalid_coord (&m->c);
  } else {
    m->x = x / ORIGINAL_WIDTH;
    m->y = (y - 3) / ROOM_HEIGHT;
    m->c.room = mr.cell[m->x][m->y].room;
    m->c.room = (m->c.room > 0) ? m->c.room : 0;
  }

  m->c.x = x % ORIGINAL_WIDTH;
  m->c.y = ((y - 3) % ROOM_HEIGHT) + 3;

  return m;
}
Example #8
0
static void handle_mouse_capture(bool down, HWND hWnd)
{
   int i;
   bool any_button_down = false;
   ALLEGRO_MOUSE_STATE state;

   if (!al_is_mouse_installed())
      return;

   al_get_mouse_state(&state);
   for (i = 1; i <= 5; i++) {
      any_button_down |= al_mouse_button_down(&state, i);
   }

   if (down && GetCapture() != hWnd) {
      SetCapture(hWnd);
   }
   else if (!any_button_down) {
      ReleaseCapture();
   }
}
Example #9
0
  inline void				updateBehavior(float, const ALLEGRO_EVENT &) throw()

  {
    ALLEGRO_MOUSE_STATE			state;
    glm::vec3				pos;

    al_get_mouse_state(&state);
    pos = glm::vec3(state.x, state.y, 0.0f);
    this->focus_ -= pos;

    this->theta_ -= (float)this->focus_.x * this->sensitivity_;
    this->phi_ -= (float)this->focus_.y * this->sensitivity_;

    this->focus_ = pos;

    this->updateVectors();

    glRotatef(this->phi_, 1.0f, 0.0f, 0.0f);
    glRotatef(this->theta_, 0.0f, 1.0f, 0.0f);
    glTranslatef(-this->position_.x, -this->position_.y, -this->position_.z);
    this->rotation_ = glm::vec3(this->phi_, this->theta_, 0.0f);
  }
Example #10
0
void InputHandler::getEvent(ALLEGRO_EVENT *ev)
{
	this->ev = ev;
	pressedKey = NULL;
	releasedKey = NULL;

	lastButton = mst.buttons;
	al_get_mouse_state(&mst);
	if (ev->type == ALLEGRO_EVENT_KEY_DOWN)
	{
		keys[ev->keyboard.keycode] = true;
		pressedKey = ev->keyboard.keycode;
	}
	else if (ev->type == ALLEGRO_EVENT_KEY_UP)
	{
		keys[ev->keyboard.keycode] = false;
		releasedKey = ev->keyboard.keycode;
	}
	else if (ev->type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT)
		focus = false;
	else if (ev->type == ALLEGRO_EVENT_DISPLAY_SWITCH_IN)
		focus = true;
}
Example #11
0
void mapEditor::render() {
	ALLEGRO_MOUSE_STATE mS;
	al_get_mouse_state(&mS);
	al_clear_to_color(al_map_rgb(68,255,68));
	al_draw_filled_rectangle(mHandler->mData->left-viewX, mHandler->mData->top-viewY, -viewX+mHandler->mData->right,-viewY+ mHandler->mData->bottom,al_map_rgb(68,68,68));
	this->mHandler->render(-viewX,-viewY,1000,1000);

	collisionLine* closest = getNearestCollisionLine(mS.x+viewX,mS.y+viewY,8);


	for (collisionLineListNode* i = this->mHandler->mData->getRootCollisionLine(); i!=NULL; i=i->next) { //Iterate through all the lines
		collisionLine* line = i->line;

		ALLEGRO_COLOR drawColor = al_map_rgb(255,255,255);
		
		if (!line->jumpthrough) {
			drawColor = al_map_rgb(255,255,128);
		}
		if (line==closest) {
			drawColor = al_map_rgb(255,0,0);
		}
			al_draw_line(line->p1.x-viewX,line->p1.y-viewY,line->p2.x-viewX,line->p2.y-viewY,drawColor,2);

	}
	
	int placeX, placeY;
	getGridSnapPositon(&placeX, &placeY);
	if (startedLine) {
		al_draw_line(startX-viewX,startY-viewY,placeX-viewX,placeY-viewY,al_map_rgb(255,255,255),2);
	}

	tSelector->render();
	al_flip_display();


}
Example #12
0
bool handle_input(ALLEGRO_EVENT_QUEUE *ev_queue, Camera *cam)
{
	ALLEGRO_EVENT ev;
	ALLEGRO_MOUSE_STATE state;

	while (al_get_next_event(ev_queue, &ev))
	{
		switch (ev.type)
		{
		case ALLEGRO_EVENT_DISPLAY_CLOSE:
			return false;
			break;
		case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
			//al_show_mouse_cursor(dpy);
			//al_ungrab_mouse();
			break;
		case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
			//al_hide_mouse_cursor(dpy);
			//al_grab_mouse(dpy);
			break;
		case ALLEGRO_EVENT_MOUSE_AXES:
			if (ev.mouse.dz != 0)
				cam_dolly(cam, ev.mouse.dz);
			al_get_mouse_state(&state);

			/* The y coordinate needs to be inverted because OpenGL has
			 * the origin in the lower-left and Allegro the upper-left */
			if (state.buttons & 1)
				cam_orbit(cam, ev.mouse.dx, -ev.mouse.dy);
			else if (state.buttons & 2)
				cam_rotate(cam, ev.mouse.dx, -ev.mouse.dy);
			break;
		case ALLEGRO_EVENT_KEY_CHAR:
			if (ev.keyboard.unichar == 'w')
			{
				wireframe = !wireframe;
				if (wireframe)
				{
					glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
					glDisable(GL_CULL_FACE);
				}
				else
				{
					glPolygonMode(GL_FRONT, GL_FILL);
					glEnable(GL_CULL_FACE);
				}
			} else if (ev.keyboard.unichar == 'c')
			{
				Vec3 upv = quat_transform(cam->orientation, (Vec3){0, 1, 0});
				cam_lookat(cam, cam->position, cam->target, upv);
			}
			break;
		case ALLEGRO_EVENT_DISPLAY_RESIZE:
			cam->width = ev.display.width;
			cam->height = ev.display.height;
			glmLoadIdentity(glmProjectionMatrix);
			cam_projection_matrix(cam, glmProjectionMatrix);
			glViewport(cam->left, cam->bottom, cam->width, cam->height);
		default:
			break;
		}
	}

	return true;
}
Example #13
0
void doMouse()
{
    al_get_mouse_state(&mouse);
    al_get_keyboard_state(&keyboard);
    int32_t keymod = getKeyMods(&keyboard);

    char stepsize = ((keymod&ALLEGRO_KEYMOD_SHIFT) ? MAPNAVIGATIONSTEPBIG : MAPNAVIGATIONSTEP);
    //mouse_callback = mouseProc;
    static int last_mouse_z;
    if(mouse.z < last_mouse_z) {
        action_decrZ(keymod);
        last_mouse_z = mouse.z;
    }
    if(mouse.z > last_mouse_z) {
        action_incrZ(keymod);
        last_mouse_z = mouse.z;
    }
    if( mouse.buttons & 2 ) {
        ssConfig.track_mode = GameConfiguration::TRACKING_NONE;
        int x, y;
        x = mouse.x;
        y = mouse.y;
        int tilex,tiley,tilez;
        ScreenToPoint(x,y,tilex,tiley,tilez);
        int diffx = tilex - ssState.Size.x/2;
        int diffy = tiley - ssState.Size.y/2;
        /*we use changeRelativeToRotation directly, and not through moveViewRelativeToRotation
        because we don't want to move the offset with the mouse. It just feels weird. */
        // changing to +1,+1 which moves the clicked point to one of the 4 surrounding the center of rotation
        changeRelativeToRotation(ssState.Position.x, ssState.Position.y, diffx+1, diffy+1 );
        //moveViewRelativeToRotation(diffx+1, diffy+1);
        timeToReloadSegment = true;
        //rest(50);
    }
    if( mouse.buttons & 1 ) {
        ssConfig.follow_DFcursor = false;
        int x, y;
        x = mouse.x;//pos >> 16;
        y = mouse.y; //pos & 0x0000ffff;
        if(x >= MiniMapTopLeftX && x <= MiniMapBottomRightX && y >= MiniMapTopLeftY && y <= MiniMapBottomRightY) { // in minimap
            ssState.Position.x = (x-MiniMapTopLeftX-MiniMapSegmentWidth/2)/oneTileInPixels;
            ssState.Position.y = (y-MiniMapTopLeftY-MiniMapSegmentHeight/2)/oneTileInPixels;
        } else {
            int tilex,tiley,tilez;

            //get the point in the segment
            ScreenToPoint(x,y,tilex,tiley,tilez);

            //then remove the segment rotation
            correctForRotation(
                tilex, tiley,
                (4 - ssState.Rotation) % 4,
                ssState.Size.x, ssState.Size.y);

            //Convert to zero as top layer convention
            tilez = tilez - (ssState.Size.z-2);

            //add on the segment offset
            tilex = tilex + ssState.Position.x;
            tiley = tiley + ssState.Position.y;
            tilez = tilez + ssState.Position.z - 1;

            ssState.dfCursor.x = tilex;
            ssState.dfCursor.y = tiley;
            ssState.dfCursor.z = tilez;
        }
        timeToReloadSegment = true;
    }
}
Example #14
0
void InputManager::update()
{
	al_get_mouse_state(mpMouseState);
	al_get_keyboard_state(mpKeyboardState);


	for (int i = 0; i < (int)NUM_KEYS; i++)
	{
		mPreviousKeys[i] = mCurrentKeys[i];
	}
	for (int i = 0; i < (int)NUM_BUTTONS; i++)
	{
		mPreviousMouseButtons[i] = mCurrentMouseButtons[i];
	}

	mCurrentKeys[(int)F1_KEY] = al_key_down(mpKeyboardState, ALLEGRO_KEY_F1);
	mCurrentKeys[(int)H_KEY] = al_key_down(mpKeyboardState, ALLEGRO_KEY_H);
	mCurrentKeys[(int)A_KEY] = al_key_down(mpKeyboardState, ALLEGRO_KEY_A);
	mCurrentKeys[(int)C_KEY] = al_key_down(mpKeyboardState, ALLEGRO_KEY_C);

	mCurrentMouseButtons[(int)LEFT_CLICK] = al_mouse_button_down(mpMouseState, 1);
	mCurrentMouseButtons[(int)RIGHT_CLICK] = al_mouse_button_down(mpMouseState, 2);

	mCursorLocation.setX(mpMouseState->x);
	mCursorLocation.setY(mpMouseState->y);

	for (int i = 0; i < (int)NUM_KEYS; i++)
	{
		mReleasedKeys[i] = !mCurrentKeys[i] && mPreviousKeys[i];
	}

	if ((mReleasedKeys[(int)C_KEY]))
	{
		GameMessage* pMessage = new DrawVisitedMessage();
		dynamic_cast<GameApp*>(gpGame)->getMessageManager()->addMessage(pMessage, 0);
	}
	if ((mReleasedKeys[(int)H_KEY]) || (mReleasedKeys[(int)F1_KEY]))
	{
		GameMessage* pMessage = new ToggleHelpMessage();
		dynamic_cast<GameApp*>(gpGame)->getMessageManager()->addMessage(pMessage, 0);
	}

	static Vector2D lastLeftPos(0.0f, 0.0f);
	static Vector2D lastRightPos(0.0f, 0.0f);


	if ((!mCurrentMouseButtons[(int)LEFT_CLICK] && mPreviousMouseButtons[(int)LEFT_CLICK]) )//||	
	{
		//checkForPortal;
		Vector2D pos(mpMouseState->x, mpMouseState->y);
		//if (lastLeftPos.getX() != pos.getX() || lastLeftPos.getY() != lastLeftPos.getY())
		//{
		//	GameMessage* pMessage = new PathToMessage(pos, lastRightPos);
		//	dynamic_cast<GameApp*>(gpGame)->getMessageManager()->addMessage(pMessage, 0);
		//	lastLeftPos = pos;
		//}
		GameMessage* pMessage = new ChangeMapMessage(mpMouseState->x, mpMouseState->y, true);
		dynamic_cast<GameApp*>(gpGame)->getMessageManager()->addMessage(pMessage, 0);

	}

	if (!mCurrentMouseButtons[(int)RIGHT_CLICK] && mPreviousMouseButtons[(int)RIGHT_CLICK])
	{
		GameMessage* pMessage = new ChangeMapMessage(mpMouseState->x, mpMouseState->y, false);
		dynamic_cast<GameApp*>(gpGame)->getMessageManager()->addMessage(pMessage, 0);
		//Vector2D pos(mpMouseState->x, mpMouseState->y);
		//if (lastRightPos.getX() != pos.getX() || lastRightPos.getY() != pos.getY())
		//{
		//	GameMessage* pMessage = new PathToMessage(lastLeftPos, pos);
		//	dynamic_cast<GameApp*>(gpGame)->getMessageManager()->addMessage(pMessage, 0);
		//	lastRightPos = pos;
		//}
	}

}
Example #15
0
static LRESULT CALLBACK window_callback(HWND hWnd, UINT message, 
    WPARAM wParam, LPARAM lParam)
{
   ALLEGRO_DISPLAY *d = NULL;
   ALLEGRO_DISPLAY_WIN *win_display = NULL;
   unsigned int i;
   ALLEGRO_EVENT_SOURCE *es = NULL;
   ALLEGRO_SYSTEM *system = al_get_system_driver();

   if (message == _al_win_msg_call_proc) {
      ((void (*)(void*))wParam) ((void*)lParam);
      return 0;
   }

   if (!system) {
      return DefWindowProc(hWnd,message,wParam,lParam); 
   }

   if (message == _al_win_msg_suicide && wParam) {
      win_display = (ALLEGRO_DISPLAY_WIN*)wParam;
      break_window_message_pump(win_display, hWnd);
      DestroyWindow(hWnd);
      return 0;
   }

   for (i = 0; i < system->displays._size; i++) {
      ALLEGRO_DISPLAY **dptr = _al_vector_ref(&system->displays, i);
      d = *dptr;
      win_display = (void*)d;
      if (win_display->window == hWnd) {
         es = &d->es;
         break;
      }
   }

   if (i == system->displays._size)
      return DefWindowProc(hWnd,message,wParam,lParam); 

   if (message == _al_win_msg_suicide) {
      break_window_message_pump(win_display, hWnd);
      DestroyWindow(hWnd);
      return 0;
   }

   switch (message) {
      case WM_INPUT: 
      {
         /* RAW Input is currently unused. */
          UINT dwSize;
          LPBYTE lpb;
          RAWINPUT* raw;

          /* We can't uninstall WM_INPUT mesages. */
          if (!al_is_mouse_installed())
             break;

          GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, 
                          sizeof(RAWINPUTHEADER));
          lpb = al_malloc(sizeof(BYTE)*dwSize);
          if (lpb == NULL) 
              break;

          GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER));
          raw = (RAWINPUT*)lpb;

          if (raw->header.dwType != RIM_TYPEMOUSE) {
             al_free(lpb); 
             break;
          }

       {
          RAWMOUSE *rm = &raw->data.mouse;
          int x = raw->data.mouse.lLastX;
          int y = raw->data.mouse.lLastY;
          bool abs = (rm->usFlags & (MOUSE_MOVE_ABSOLUTE
                                    | MOUSE_VIRTUAL_DESKTOP)) != 0;
          if (abs || x || y)
             _al_win_mouse_handle_move(x, y, abs, win_display);

          if (rm->usButtonFlags & RI_MOUSE_BUTTON_1_DOWN)
             _al_win_mouse_handle_button(1, true, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_1_UP)
             _al_win_mouse_handle_button(1, false, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_2_DOWN)
             _al_win_mouse_handle_button(2, true, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_2_UP)
             _al_win_mouse_handle_button(2, false, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_3_DOWN)
             _al_win_mouse_handle_button(3, true, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_3_UP)
             _al_win_mouse_handle_button(3, false, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_4_DOWN)
             _al_win_mouse_handle_button(4, true, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_4_UP)
             _al_win_mouse_handle_button(4, false, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_5_DOWN)
             _al_win_mouse_handle_button(5, true, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_5_UP)
             _al_win_mouse_handle_button(5, false, x, y, abs, win_display);

          if (rm->usButtonFlags & RI_MOUSE_WHEEL) {
             SHORT z = (SHORT)rm->usButtonData;
             _al_win_mouse_handle_wheel(z / WHEEL_DELTA, false, win_display);
          }
       }

          al_free(lpb); 
          break;
      }
      case WM_LBUTTONDOWN:
      case WM_LBUTTONUP: {
         int mx = GET_X_LPARAM(lParam);
         int my = GET_Y_LPARAM(lParam);
         bool down = (message == WM_LBUTTONDOWN);
         _al_win_mouse_handle_button(1, down, mx, my, true, win_display);
         handle_mouse_capture(down, hWnd);
         break;
      }
      case WM_MBUTTONDOWN:
      case WM_MBUTTONUP: {
         int mx = GET_X_LPARAM(lParam);
         int my = GET_Y_LPARAM(lParam);
         bool down = (message == WM_MBUTTONDOWN);
         _al_win_mouse_handle_button(3, down, mx, my, true, win_display);
         handle_mouse_capture(down, hWnd);
         break;
      }
      case WM_RBUTTONDOWN:
      case WM_RBUTTONUP: {
         int mx = GET_X_LPARAM(lParam);
         int my = GET_Y_LPARAM(lParam);
         bool down = (message == WM_RBUTTONDOWN);
         _al_win_mouse_handle_button(2, down, mx, my, true, win_display);
         handle_mouse_capture(down, hWnd);
         break;
      }
      case WM_XBUTTONDOWN:
      case WM_XBUTTONUP: {
         int mx = GET_X_LPARAM(lParam);
         int my = GET_Y_LPARAM(lParam);
         int button = HIWORD(wParam);
         bool down = (message == WM_XBUTTONDOWN);
         if (button == XBUTTON1)
            _al_win_mouse_handle_button(4, down, mx, my, true, win_display);
         else if (button == XBUTTON2)
            _al_win_mouse_handle_button(5, down, mx, my, true, win_display);
         handle_mouse_capture(down, hWnd);
         return TRUE;
      }
      case WM_MOUSEWHEEL: {
         int d = GET_WHEEL_DELTA_WPARAM(wParam);
         _al_win_mouse_handle_wheel(d / WHEEL_DELTA, false, win_display);
         return TRUE;
      }
      case WM_MOUSEHWHEEL: {
         int d = GET_WHEEL_DELTA_WPARAM(wParam);
         _al_win_mouse_handle_hwheel(d / WHEEL_DELTA, false, win_display);
         return TRUE;
      }
      case WM_MOUSEMOVE: {
         TRACKMOUSEEVENT tme;
         int mx = GET_X_LPARAM(lParam);
         int my = GET_Y_LPARAM(lParam);

         if (win_display->mouse_cursor_shown && we_hid_the_mouse) {
            we_hid_the_mouse = false;
            win_display->display.vt->hide_mouse_cursor((void*)win_display);
         }

         _al_win_mouse_handle_move(mx, my, true, win_display);
         if (mx >= 0 && my >= 0 && mx < d->w && my < d->h) {
            tme.cbSize = sizeof(tme);
            tme.dwFlags = TME_QUERY;
            if (TrackMouseEvent(&tme) && !tme.hwndTrack) {
               tme.dwFlags = TME_LEAVE;
               tme.hwndTrack = hWnd;
               tme.dwHoverTime = 0;
               TrackMouseEvent(&tme);
               _al_win_mouse_handle_enter(win_display);
            }
         }

         /* WM_SETCURSOR messages are not received while the mouse is
          * captured.  We call SetCursor here so that changing the mouse
          * cursor has an effect while the user is holding down the mouse
          * button.
          */
         if (GetCapture() == hWnd && win_display->mouse_cursor_shown) {
            SetCursor(win_display->mouse_selected_hcursor);
         }

         break;
      }
      case WM_MOUSELEAVE: {
         _al_win_mouse_handle_leave(win_display);
         break;
      }
      case WM_CAPTURECHANGED: {
         if (al_is_mouse_installed()) {
            int i;
            ALLEGRO_MOUSE_STATE state;
            if (!lParam || (HWND)lParam == hWnd)
               break;
            al_get_mouse_state(&state);
            for (i = 1; i <= 5; i++) {
               if (al_mouse_button_down(&state, i))
                  _al_win_mouse_handle_button(i, 0, 0, 0, true, win_display);
            }
         }
         break;
      }
      case WM_NCMOUSEMOVE: {
         if (!win_display->mouse_cursor_shown) {
            we_hid_the_mouse = true;
            win_display->display.vt->show_mouse_cursor((void*)win_display);
         }
         break;
      }
      case WM_SYSKEYDOWN: {
         int vcode = wParam;
         bool extended = (lParam >> 24) & 0x1;
         bool repeated  = (lParam >> 30) & 0x1;
         _al_win_kbd_handle_key_press(0, vcode, extended, repeated, win_display);
         break;
      }
      case WM_KEYDOWN: {
         int vcode = wParam; 
         int scode = (lParam >> 16) & 0xff;
         bool extended = (lParam >> 24) & 0x1;
         bool repeated = (lParam >> 30) & 0x1;
         /* We can't use TranslateMessage() because we don't know if it will
            produce a WM_CHAR or not. */
         _al_win_kbd_handle_key_press(scode, vcode, extended, repeated, win_display);
         break;
      }
      case WM_SYSKEYUP:
      case WM_KEYUP: {
         int vcode = wParam;
         int scode = (lParam >> 16) & 0xff;
         bool extended = (lParam >> 24) & 0x1;
         _al_win_kbd_handle_key_release(scode, vcode, extended, win_display);
         break;
      }
      case WM_SYSCOMMAND: {
         if (_al_win_disable_screensaver &&
               ((wParam & 0xfff0) == SC_MONITORPOWER || (wParam & 0xfff0) == SC_SCREENSAVE)) {
            return 0;
         }
         else if ((wParam & 0xfff0) == SC_KEYMENU) {
            /* Prevent Windows from intercepting the ALT key.
               (Disables opening menus via the ALT key.) */
            return 0;
         }
         break;
      }
      case WM_PAINT: {
         if (win_display->display.flags & ALLEGRO_GENERATE_EXPOSE_EVENTS) {
            RECT r;
            HRGN hrgn;
            GetWindowRect(win_display->window, &r);
            hrgn = CreateRectRgn(r.left, r.top, r.right, r.bottom);
            if (GetUpdateRgn(win_display->window, hrgn, false) != ERROR) {
               PAINTSTRUCT ps;
               DWORD size;
               LPRGNDATA rgndata;
               int n;
               int i;
               RECT *rects;
               BeginPaint(win_display->window, &ps);
               size = GetRegionData(hrgn, 0, NULL);
               rgndata = al_malloc(size);
               GetRegionData(hrgn, size, rgndata);
               n = rgndata->rdh.nCount;
               rects = (RECT *)rgndata->Buffer;
               _al_event_source_lock(es);
               if (_al_event_source_needs_to_generate_event(es)) {
                  ALLEGRO_EVENT event;
                  event.display.type = ALLEGRO_EVENT_DISPLAY_EXPOSE;
                  event.display.timestamp = al_get_time();
                  for (i = 0; i < n; i++) {
                     event.display.x = rects[i].left;
                     event.display.y = rects[i].top;
                     event.display.width = rects[i].right - rects[i].left;
                     event.display.height = rects[i].bottom - rects[i].top;
                     _al_event_source_emit_event(es, &event);
                  }
               }
               _al_event_source_unlock(es);
               al_free(rgndata);
               EndPaint(win_display->window, &ps);
               DeleteObject(hrgn);
            }
            return 0;
         }
         break;
      }

      case WM_SETCURSOR:
         switch (LOWORD(lParam)) {
            case HTLEFT:
            case HTRIGHT:
               SetCursor(LoadCursor(NULL, IDC_SIZEWE));
               break;
            case HTBOTTOM:
            case HTTOP:
               SetCursor(LoadCursor(NULL, IDC_SIZENS));
               break;
            case HTBOTTOMLEFT:
            case HTTOPRIGHT:
               SetCursor(LoadCursor(NULL, IDC_SIZENESW));
               break;
            case HTBOTTOMRIGHT:
            case HTTOPLEFT:
               SetCursor(LoadCursor(NULL, IDC_SIZENWSE));
               break;
            default:
               if (win_display->mouse_cursor_shown) {
                  SetCursor(win_display->mouse_selected_hcursor);
               }
               else {
                  SetCursor(NULL);
               }
               break;
         }
         return 1;
      case WM_ACTIVATE:
         if (HIWORD(wParam) && LOWORD(wParam) != WA_INACTIVE)
            break;

         if (HIWORD(wParam))
            d->flags |= ALLEGRO_MINIMIZED;
         else
            d->flags &= ~ALLEGRO_MINIMIZED;

         if (LOWORD(wParam) != WA_INACTIVE) {
            // Make fullscreen windows TOPMOST again
            if (d->flags & ALLEGRO_FULLSCREEN_WINDOW) {
               SetWindowPos(win_display->window, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
            }
            if (d->vt->switch_in)
               d->vt->switch_in(d);
            _al_win_fix_modifiers();
            _al_event_source_lock(es);
            if (_al_event_source_needs_to_generate_event(es)) {
               ALLEGRO_EVENT event;
               memset(&event, 0, sizeof(event));
               event.display.type = ALLEGRO_EVENT_DISPLAY_SWITCH_IN;
               event.display.timestamp = al_get_time();
               _al_event_source_emit_event(es, &event);
            }
            _al_event_source_unlock(es);
            _al_win_grab_input(win_display);
            return 0;
         }
         else {
            // Remove TOPMOST flag from fullscreen windows so we can alt-tab. Also must raise the new activated window
            if (d->flags & ALLEGRO_FULLSCREEN_WINDOW) {
               SetWindowPos(win_display->window, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
               SetWindowPos(GetForegroundWindow(), HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
            }
            // Show the taskbar in case we hid it
            SetWindowPos(FindWindow("Shell_traywnd", ""), 0, 0, 0, 0, 0, SWP_SHOWWINDOW);
            if (d->flags & ALLEGRO_FULLSCREEN) {
               d->vt->switch_out(d);
            }
            _al_event_source_lock(es);
            if (_al_event_source_needs_to_generate_event(es)) {
               ALLEGRO_EVENT event;
               memset(&event, 0, sizeof(event));
               event.display.type = ALLEGRO_EVENT_DISPLAY_SWITCH_OUT;
               event.display.timestamp = al_get_time();
               _al_event_source_emit_event(es, &event);
            }
            _al_event_source_unlock(es);
            return 0;
         }
         break;
      case WM_MENUCHAR :
         return (MNC_CLOSE << 16) | (wParam & 0xffff);
      case WM_CLOSE:
         _al_event_source_lock(es);
         if (_al_event_source_needs_to_generate_event(es)) {
            ALLEGRO_EVENT event;
            memset(&event, 0, sizeof(event));
            event.display.type = ALLEGRO_EVENT_DISPLAY_CLOSE;
            event.display.timestamp = al_get_time();
            _al_event_source_emit_event(es, &event);
         }
         _al_event_source_unlock(es);
         return 0;
      case WM_SIZE:
         if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED || wParam == SIZE_MINIMIZED) {
            /*
             * Delay the resize event so we don't get bogged down with them
             */
            if (!resize_postponed) {
               resize_postponed = true;
               _beginthread(postpone_thread_proc, 0, (void *)d);
            }
         }
         return 0;
      case WM_ENTERSIZEMOVE:
         /* DefWindowProc for WM_ENTERSIZEMOVE enters a modal loop, which also
          * ends up blocking the loop in d3d_display_thread_proc (which is
          * where we are called from, if using D3D).  Rather than batching up
          * intermediate resize events which the user cannot acknowledge in the
          * meantime anyway, make it so only a single resize event is generated
          * at WM_EXITSIZEMOVE.
          */
         if (d->flags & ALLEGRO_DIRECT3D) {
            resize_postponed = true;
         }
         break;
      case WM_EXITSIZEMOVE:
         if (resize_postponed) {
            win_generate_resize_event(win_display);
            win_display->ignore_resize = false;
            resize_postponed = false;
            win_display->can_acknowledge = true;
         }
         break;
   } 

   return DefWindowProc(hWnd,message,wParam,lParam); 
}
Example #16
0
static LRESULT CALLBACK window_callback(HWND hWnd, UINT message, 
    WPARAM wParam, LPARAM lParam)
{
   ALLEGRO_DISPLAY *d = NULL;
   ALLEGRO_DISPLAY_WIN *win_display = NULL;
   WINDOWINFO wi;
   int w;
   int h;
   int x;
   int y;
   unsigned int i;
   ALLEGRO_EVENT_SOURCE *es = NULL;
   ALLEGRO_SYSTEM *system = al_get_system_driver();

   wi.cbSize = sizeof(WINDOWINFO);

   if (message == _al_win_msg_call_proc) {
      ((void (*)(void*))wParam) ((void*)lParam);
      return 0;
   }

   if (!system) {
      return DefWindowProc(hWnd,message,wParam,lParam); 
   }

   if (message == _al_win_msg_suicide && wParam) {
      win_display = (ALLEGRO_DISPLAY_WIN*)wParam;
      win_display->end_thread = true;
      DestroyWindow(hWnd);
      return 0;
   }

   for (i = 0; i < system->displays._size; i++) {
      ALLEGRO_DISPLAY **dptr = _al_vector_ref(&system->displays, i);
      d = *dptr;
      win_display = (void*)d;
      if (win_display->window == hWnd) {
         es = &d->es;
         break;
      }
   }

   if (i == system->displays._size)
      return DefWindowProc(hWnd,message,wParam,lParam); 

   if (message == _al_win_msg_suicide) {
      win_display->end_thread = true;
      DestroyWindow(hWnd);
      return 0;
   }

   switch (message) {
      case WM_INPUT: 
      {
          UINT dwSize;
          LPBYTE lpb;
          RAWINPUT* raw;

          /* We can't uninstall WM_INPUT mesages. */
          if (!al_is_mouse_installed())
             break;

          GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, 
                          sizeof(RAWINPUTHEADER));
          lpb = malloc(sizeof(BYTE)*dwSize);
          if (lpb == NULL) 
              break;

          GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER));
          raw = (RAWINPUT*)lpb;

          if (raw->header.dwType != RIM_TYPEMOUSE) {
             free(lpb); 
             break;
          }

       {
          RAWMOUSE *rm = &raw->data.mouse;
          int x = raw->data.mouse.lLastX;
          int y = raw->data.mouse.lLastY;
          bool abs = rm->usFlags & (MOUSE_MOVE_ABSOLUTE
                                 || MOUSE_VIRTUAL_DESKTOP);
          if (abs || x || y)
             _al_win_mouse_handle_move(x, y, abs, win_display);

          if (rm->usButtonFlags & RI_MOUSE_BUTTON_1_DOWN)
             _al_win_mouse_handle_button(1, true, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_1_UP)
             _al_win_mouse_handle_button(1, false, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_2_DOWN)
             _al_win_mouse_handle_button(2, true, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_2_UP)
             _al_win_mouse_handle_button(2, false, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_3_DOWN)
             _al_win_mouse_handle_button(3, true, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_3_UP)
             _al_win_mouse_handle_button(3, false, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_4_DOWN)
             _al_win_mouse_handle_button(4, true, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_4_UP)
             _al_win_mouse_handle_button(4, false, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_5_DOWN)
             _al_win_mouse_handle_button(5, true, x, y, abs, win_display);
          if (rm->usButtonFlags & RI_MOUSE_BUTTON_5_UP)
             _al_win_mouse_handle_button(5, false, x, y, abs, win_display);

          if (rm->usButtonFlags & RI_MOUSE_WHEEL) {
             SHORT z = (SHORT)rm->usButtonData;
             _al_win_mouse_handle_wheel(z / WHEEL_DELTA, false, win_display);
          }
       }

          free(lpb); 
          break;
      }
      case WM_LBUTTONDOWN:
      case WM_LBUTTONUP: {
         int mx = GET_X_LPARAM(lParam);
         int my = GET_Y_LPARAM(lParam);
         bool down = (message == WM_LBUTTONDOWN);
         _al_win_mouse_handle_button(1, down, mx, my, true, win_display);
         handle_mouse_capture(down, hWnd);
         break;
      }
      case WM_MBUTTONDOWN:
      case WM_MBUTTONUP: {
         int mx = GET_X_LPARAM(lParam);
         int my = GET_Y_LPARAM(lParam);
         bool down = (message == WM_MBUTTONDOWN);
         _al_win_mouse_handle_button(3, down, mx, my, true, win_display);
         handle_mouse_capture(down, hWnd);
         break;
      }
      case WM_RBUTTONDOWN:
      case WM_RBUTTONUP: {
         int mx = GET_X_LPARAM(lParam);
         int my = GET_Y_LPARAM(lParam);
         bool down = (message == WM_RBUTTONDOWN);
         _al_win_mouse_handle_button(2, down, mx, my, true, win_display);
         handle_mouse_capture(down, hWnd);
         break;
      }
      case WM_XBUTTONDOWN:
      case WM_XBUTTONUP: {
         int mx = GET_X_LPARAM(lParam);
         int my = GET_Y_LPARAM(lParam);
         int button = HIWORD(wParam);
         bool down = (message == WM_XBUTTONDOWN);
         if (button == XBUTTON1)
            _al_win_mouse_handle_button(4, down, mx, my, true, win_display);
         else if (button == XBUTTON2)
            _al_win_mouse_handle_button(5, down, mx, my, true, win_display);
         handle_mouse_capture(down, hWnd);
         return TRUE;
      }
      case WM_MOUSEWHEEL: {
         int d = GET_WHEEL_DELTA_WPARAM(wParam);
         _al_win_mouse_handle_wheel(d / WHEEL_DELTA, false, win_display);
         return TRUE;
      }
      case WM_MOUSEMOVE: {
         TRACKMOUSEEVENT tme;
         int mx = GET_X_LPARAM(lParam);
         int my = GET_Y_LPARAM(lParam);

         if (win_display->mouse_cursor_shown && we_hid_the_mouse) {
            we_hid_the_mouse = false;
            win_display->display.vt->hide_mouse_cursor((void*)win_display);
         }

         _al_win_mouse_handle_move(mx, my, true, win_display);
         if (mx >= 0 && my >= 0 && mx < d->w && my < d->h) {
            tme.cbSize = sizeof(tme);
            tme.dwFlags = TME_QUERY;
            if (TrackMouseEvent(&tme) && !tme.hwndTrack) {
               tme.dwFlags = TME_LEAVE;
               tme.hwndTrack = hWnd;
               tme.dwHoverTime = 0;
               TrackMouseEvent(&tme);
               _al_win_mouse_handle_enter(win_display);
            }
         }

         break;
      }
      case WM_MOUSELEAVE: {
          _al_win_mouse_handle_leave(win_display);
          break;
      }
      case WM_CAPTURECHANGED: if (al_is_mouse_installed()) {
         int i;
         ALLEGRO_MOUSE_STATE state;
         if (!lParam || (HWND)lParam == hWnd)
            break;
         al_get_mouse_state(&state);
         for (i = 1; i <= 5; i++) {
            if (al_mouse_button_down(&state, i))
               _al_win_mouse_handle_button(i, 0, 0, 0, true, win_display);
         }
         break;
      }
      case WM_NCMOUSEMOVE: {
         if (!win_display->mouse_cursor_shown) {
            we_hid_the_mouse = true;
            win_display->display.vt->show_mouse_cursor((void*)win_display);
         }
         break;
      }
      case WM_SYSKEYDOWN: {
         int vcode = wParam; 
         bool repeated  = (lParam >> 30) & 0x1;
         _al_win_kbd_handle_key_press(0, vcode, repeated, win_display);
         break;
      }
      case WM_KEYDOWN: {
         int vcode = wParam; 
         int scode = (lParam >> 16) & 0xff;
         bool repeated  = (lParam >> 30) & 0x1;
         /* We can't use TranslateMessage() because we don't know if it will
            produce a WM_CHAR or not. */
         _al_win_kbd_handle_key_press(scode, vcode, repeated, win_display);
         break;
      }
      case WM_SYSKEYUP:
      case WM_KEYUP: {
         int vcode = wParam;
         _al_win_kbd_handle_key_release(vcode, win_display);
         break;
      }
      case WM_SYSCOMMAND: {
         if (_al_win_disable_screensaver &&
               ((wParam & 0xfff0) == SC_MONITORPOWER || (wParam & 0xfff0) == SC_SCREENSAVE)) {
            return 0;
         }
         else if ((wParam & 0xfff0) == SC_KEYMENU) {
            /* Prevent Windows from intercepting the ALT key.
               (Disables opening menus via the ALT key.) */
            return 0;
         }
         break;
      }
      case WM_PAINT: {
         if ((win_display->display.flags & ALLEGRO_GENERATE_EXPOSE_EVENTS) &&
                  _al_event_source_needs_to_generate_event(es)) {
            RECT r;
            HRGN hrgn;
            GetWindowRect(win_display->window, &r);
            hrgn = CreateRectRgn(r.left, r.top, r.right, r.bottom);
            if (GetUpdateRgn(win_display->window, hrgn, false) != ERROR) {
               PAINTSTRUCT ps;
               DWORD size;
               LPRGNDATA rgndata;
               int n;
               int i;
               RECT *rects;
               BeginPaint(win_display->window, &ps);
               size = GetRegionData(hrgn, 0, NULL);
               rgndata = _AL_MALLOC(size);
               GetRegionData(hrgn, size, rgndata);
               n = rgndata->rdh.nCount;
               rects = (RECT *)rgndata->Buffer;
               //GetWindowInfo(win_display->window, &wi);
               _al_event_source_lock(es);
               for (i = 0; i < n; i++) {
                  ALLEGRO_EVENT event;
                  event.display.type = ALLEGRO_EVENT_DISPLAY_EXPOSE;
                  event.display.timestamp = al_current_time();
                  event.display.x = rects[i].left;
                  event.display.y = rects[i].top;
                  event.display.width = rects[i].right - rects[i].left;
                  event.display.height = rects[i].bottom - rects[i].top;
                  _al_event_source_emit_event(es, &event);
               }
               _al_event_source_unlock(es);
               _AL_FREE(rgndata);
               EndPaint(win_display->window, &ps);
               DeleteObject(hrgn);
            }
            return 0;
         }
         break;
      }

      case WM_SETCURSOR:
         switch (LOWORD(lParam)) {
            case HTLEFT:
            case HTRIGHT:
               SetCursor(LoadCursor(NULL, IDC_SIZEWE));
               break;
            case HTBOTTOM:
            case HTTOP:
               SetCursor(LoadCursor(NULL, IDC_SIZENS));
               break;
            case HTBOTTOMLEFT:
            case HTTOPRIGHT:
               SetCursor(LoadCursor(NULL, IDC_SIZENESW));
               break;
            case HTBOTTOMRIGHT:
            case HTTOPLEFT:
               SetCursor(LoadCursor(NULL, IDC_SIZENWSE));
               break;
            default:
               if (win_display->mouse_cursor_shown) {
                  SetCursor(win_display->mouse_selected_hcursor);
               }
               else {
                  SetCursor(NULL);
               }
               break;
         }
         return 1;
      case WM_ACTIVATE:
         if (LOWORD(wParam) != WA_INACTIVE) {
            /* This SetWindowPos is for faux-fullscreen windows that lost focus
             * so they can get placed back on top
             */
             // FIXME: this doesn't seem to work
            //SetWindowPos(win_display->window, HWND_TOP, 0, 0, 0, 0,
            //   SWP_NOMOVE | SWP_NOSIZE);
            if (d->vt->switch_in)
            	  d->vt->switch_in(d);
            _al_event_source_lock(es);
            if (_al_event_source_needs_to_generate_event(es)) {
               ALLEGRO_EVENT event;
               event.display.type = ALLEGRO_EVENT_DISPLAY_SWITCH_IN;
               event.display.timestamp = al_current_time();
               _al_event_source_emit_event(es, &event);
            }
            _al_event_source_unlock(es);
            _al_win_grab_input(win_display);
            return 0;
         }
         else {
            if (d->flags & ALLEGRO_FULLSCREEN) {
               d->vt->switch_out(d);
            }
            _al_event_source_lock(es);
            if (_al_event_source_needs_to_generate_event(es)) {
               ALLEGRO_EVENT event;
               event.display.type = ALLEGRO_EVENT_DISPLAY_SWITCH_OUT;
               event.display.timestamp = al_current_time();
               _al_event_source_emit_event(es, &event);
            }
            _al_event_source_unlock(es);
            return 0;
         }
         break;
      case WM_MENUCHAR :
         return (MNC_CLOSE << 16) | (wParam & 0xffff);
      case WM_CLOSE:
         _al_event_source_lock(es);
         if (_al_event_source_needs_to_generate_event(es)) {
            ALLEGRO_EVENT event;
            event.display.type = ALLEGRO_EVENT_DISPLAY_CLOSE;
            event.display.timestamp = al_current_time();
            _al_event_source_emit_event(es, &event);
         }
         _al_event_source_unlock(es);
         return 0;
      case WM_SIZE:
         if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED || wParam == SIZE_MINIMIZED) {
            /*
             * Delay the resize event so we don't get bogged down with them
             */
            if (!resize_postponed) {
               resize_postponed = true;
               postpone_resize(win_display->window);
            }
         }
         return 0;
      case WM_USER+0:
         /* Generate a resize event if the size has changed. We cannot asynchronously
          * change the display size here yet, since the user will only know about a
          * changed size after receiving the resize event. Here we merely add the
          * event to the queue.
          */
         GetWindowInfo(win_display->window, &wi);
         x = wi.rcClient.left;
         y = wi.rcClient.top;
         w = wi.rcClient.right - wi.rcClient.left;
         h = wi.rcClient.bottom - wi.rcClient.top;
         if (d->w != w || d->h != h) {
            _al_event_source_lock(es);
            if (_al_event_source_needs_to_generate_event(es)) {
               ALLEGRO_EVENT event;
               event.display.type = ALLEGRO_EVENT_DISPLAY_RESIZE;
               event.display.timestamp = al_current_time();
               event.display.x = x;
               event.display.y = y;
               event.display.width = w;
               event.display.height = h;
               _al_event_source_emit_event(es, &event);
            }

            /* Generate an expose event. */
            if (_al_event_source_needs_to_generate_event(es)) {
               ALLEGRO_EVENT event;
               event.display.type = ALLEGRO_EVENT_DISPLAY_EXPOSE;
               event.display.timestamp = al_current_time();
               event.display.x = x;
               event.display.y = y;
               event.display.width = w;
               event.display.height = h;
               _al_event_source_emit_event(es, &event);
            }
            _al_event_source_unlock(es);
         }
         resize_postponed = false;
         win_display->can_acknowledge = true;
         return 0;
   } 

   return DefWindowProc(hWnd,message,wParam,lParam); 
}
Example #17
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 #18
0
void ShopState::update(Engine* engine){
    ALLEGRO_EVENT events;
    al_wait_for_event(event_queue, &events);

    if(events.type == ALLEGRO_EVENT_DISPLAY_CLOSE){
        engine->quit();
    }

    if(events.type == ALLEGRO_EVENT_TIMER){

        al_get_mouse_state(&mouseState);

        al_get_keyboard_state(&keyState);

        //Update Mouse Variables +
        mouseX = al_get_mouse_state_axis(&mouseState,0);
        mouseY = al_get_mouse_state_axis(&mouseState,1);

        if(al_mouse_button_down(&mouseState, 1)){
            if(!mouseButtonLeft)
                mouseButtonLeftClick = true;
            else
                mouseButtonLeftClick = false;
            mouseButtonLeft = true;
        }else{
            mouseButtonLeft = false;
        }
        //Update Mouse Variables -

        //Player Input +
        if(al_key_down(&keyState, ALLEGRO_KEY_W)){
            playerDeltaY = -playerMovementSpeed;
        }else if(al_key_down(&keyState, ALLEGRO_KEY_S)){
            playerDeltaY = playerMovementSpeed;
        }if(al_key_down(&keyState, ALLEGRO_KEY_A)){
            playerDeltaX = -playerMovementSpeed;
        }else if(al_key_down(&keyState, ALLEGRO_KEY_D)){
            playerDeltaX = playerMovementSpeed;
        }

        if(al_key_down(&keyState, ALLEGRO_KEY_ESCAPE)){
            if(lastKeyPress != ALLEGRO_KEY_ESCAPE){
                engine->popState();
                lastKeyPress = ALLEGRO_KEY_ESCAPE;
            }
        }
        //Player Input -

        //Update Player Variables +

        if(mouseButtonLeft){
            if(playerFiringSpeedHelper >= playerFiringSpeed){
                playerFiringSpeedHelper = 0;

                int x, y, width, height, damage;
                float moveSpeed, angle = 0;

                width = 8, height = 8, x = playerCenterX - width/2, y = playerCenterY - height/2, damage = 1;
                moveSpeed = playerBulletSpeed;

                for(int i = 0; i < playerShots; i++){
                    //Shots Angle Calculation -- START
                    if(playerShots != 1){
                        angle = (-atan2(playerCenterX - mouseX, playerCenterY - mouseY)) + (-playerBulletSpread/2+(playerBulletSpread/(playerShots-1))*i);
                    }else{
                        angle = -atan2(playerCenterX - mouseX, playerCenterY - mouseY);
                    }

                    int spread = round(playerBulletSpread*100);

                    angle += (-spread/2+rand()%spread)/100.0;

                    //Shots Angle Calculation -- END

                    Bullet *newBullet = new Bullet();
                    newBullet->setPos(x, y);
                    newBullet->setDimensions(width, height);
                    newBullet->setDamage(damage);
                    newBullet->setAngleSpeed(moveSpeed, angle);
                    newBullet->setPlayerShot(true);

                    addBulletToList(newBullet);
                }
            }
        }

        if(playerX+playerDeltaX >= 0 && playerX+playerDeltaX + playerWidth < 400 && playerY >= 0 && playerY + playerHeight < 400){
            playerX += playerDeltaX;
        }
        if(playerX >= 0 && playerX + playerWidth < 400 && playerY+playerDeltaY >= 0 && playerY+playerDeltaY + playerHeight < 400){
            playerY += playerDeltaY;
        }

        playerCenterX = playerX + playerWidth/2, playerCenterY = playerY + playerHeight/2;

        playerDeltaX = 0;
        playerDeltaY = 0;
        //Update Player Variables -

        //Update Entities +
        for(int i = 0; i < MAX_BUTTONS; i++){
            if(buttonList[i] != NULL && buttonList[i]->checkActive()){
                buttonList[i]->update();
                if(buttonList[i]->clicked){
                    switch(buttonList[i]->buttonId){
                        case 0:
                            engine->popState();
                            break;

                        case 1:
                            engine->changeState(PlayState::instance());
                            break;

                        case 2:
                            engine->changeState(EditorState::instance());
                            break;

                        case 3:
                            engine->quit();
                            break;
                    }
                }
            }
        }

        for(int i = 0; i < MAX_BULLETS; i++){
            if(bulletList[i] != NULL && bulletList[i]->checkActive()){
                bulletList[i]->update();
            }
        }
        //Update Entities -

        //Rest +
        if(!al_key_down(&keyState, lastKeyPress)){
            lastKeyPress = NULL;
        }

        playerFiringSpeedHelper++;
        //Rest -

        engine->draw();
    }
}
Example #19
0
void MouseHandler::refreshState() {
    al_get_mouse_state(&state);
}
Example #20
0
void TEnterprise::draw_engineering()
{
	int nStartX = m_pEngine->m_nScreenMidX-500;

	al_draw_bitmap(g_pEngineeringBitmap, nStartX, 100, 0);
	ALLEGRO_COLOR BarCol;
	for ( size_t i=0; i<m_lstHealth.size();i++)
	{
		int Xpos = (i*80)+(nStartX+160);

		ALLEGRO_MOUSE_STATE state;
		al_get_mouse_state(&state);
		if (state.buttons & 1)
		{
			if ((state.y>610)&&(state.y<660))
			{
				if ((state.x>Xpos)&&(state.x<Xpos+20))
				{
					SoundManager::PlaySound(SOUND::ON,0.2);
					m_nRepairItem= i;
				}
			}
		}

		if (m_lstHealth[i] > 60)
		{
			BarCol=m_pEngine->m_clGREEN;
		}
		else if (m_lstHealth[i] > 30)
		{
			BarCol=m_pEngine->m_clYELLOW;
		}
		else
		{
			BarCol=m_pEngine->m_clRED;
		}


		al_draw_filled_rectangle(Xpos, 608, Xpos+20, 608-(m_lstHealth[i]*2),BarCol);

		if (m_nRepairItem == (int)i)
		{
			al_draw_bitmap(g_pSwitchBitmap, Xpos+2, 611, ALLEGRO_FLIP_VERTICAL);
		}
		else
		{
			al_draw_bitmap(g_pSwitchBitmap, Xpos+2, 630, 0);
		}

	}

	nStartX+=194;
	al_draw_filled_rectangle(nStartX, 688, nStartX+(m_nEnergy/20), 708,m_pEngine->m_clGREEN);
	al_draw_filled_rectangle(nStartX, 716, nStartX+(m_nShieldEnergy*5), 736,m_pEngine->m_clGREEN);

    for (int i=0;i < m_nTorpedoes;i++)
    {
        al_draw_bitmap(g_pPhotonCasing, 100+(20*i), 20, 0);
    }
	al_draw_text(FontManager::GetFont(FONT::SMALL),m_pEngine->m_clWHITE, 35, 20, 0,"Torpedoes");

	for (int i=0;i < m_nProbes;i++)
    {
        al_draw_bitmap(g_pProbeCasing, 700 +(24*i), 20, 0);
    }
	al_draw_text(FontManager::GetFont(FONT::SMALL),m_pEngine->m_clWHITE, 650, 20, 0,"Probes");

	al_draw_text(FontManager::GetFont(FONT::SMALL),m_pEngine->m_clWHITE, 35, 80, 0,"Crew");
	for (int i=0; i < (m_nCrew/2); i++)
    {
        ALLEGRO_COLOR col = m_pEngine->m_clGREEN;
        if (i< 150) col = m_pEngine->m_clYELLOW;
        if (i< 60) col = m_pEngine->m_clRED;

        al_draw_line(100+(2*i),80,100+(2*i),95, col,1);
    }

}
Example #21
0
int main(int argc, char **argv) {
	A.x = 0;
	A.y = 0;
	B.x = 400;
	B.y = 0;
	C.x = 400;
	C.y = 350;
	D.x = 0;
	D.y = 350;

	if (!al_install_system(ALLEGRO_VERSION_INT, NULL)) {
		printf("could not init Allegro\n");
		return 1;
	}

	ALLEGRO_DISPLAY *display = al_create_display(800, 600);

	if (!display) {
		printf("could not create display\n");
		return 1;
	}

	if (!al_init_primitives_addon()) {
		printf("could not init primitives\n");
		return 1;
	}

	if (!al_install_keyboard()) {
		printf("could not install keybaord\n");
		return 1;
	}

	if (!al_install_mouse()) {
		printf("could not install mouse\n");
		return 1;
	}

	ALLEGRO_BITMAP *bitmap = al_create_bitmap(800, 600);

	if (bitmap == NULL) {
		printf("could not create bitmap\n");
		return 1;
	}

	al_set_target_bitmap(bitmap);
	al_clear_to_color(al_map_rgb(255, 255, 255));
	al_draw_rectangle(A.x + xOfs, A.y + yOfs, C.x + xOfs, C.y + yOfs, al_map_rgb(0, 0, 0), 2.0);

	al_set_target_backbuffer(display);
	al_draw_bitmap(bitmap, 0, 0, 0);
	al_flip_display();

	int pair1 = 0;
	int pair2 = 0;

	ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue();
	ALLEGRO_EVENT event;
	al_register_event_source(queue, al_get_mouse_event_source());
	al_register_event_source(queue, al_get_keyboard_event_source());
	al_register_event_source(queue, al_get_display_event_source(display));

	while (input_counter < 4) {
		al_wait_for_event(queue, &event);
		if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN && event.mouse.button == 1) {
			input_points[input_counter].x = event.mouse.x;
			input_points[input_counter].y = event.mouse.y;

			input_counter++;

			if (input_counter > 1) {
				pair1 = input_counter - 2;
				pair2 = input_counter - 1;

				al_set_target_bitmap(bitmap);
				al_draw_line(input_points[pair1].x, input_points[pair1].y, input_points[pair2].x, input_points[pair2].y, al_map_rgb(0, 150, 0), 3.0);
				al_set_target_backbuffer(display);
				al_draw_bitmap(bitmap, 0, 0, 0);
				al_flip_display();
			}

			if (input_counter == 4) {
				pair1 = 3;
				pair2 = 0;

				al_set_target_bitmap(bitmap);
				al_draw_line(input_points[pair1].x, input_points[pair1].y, input_points[pair2].x, input_points[pair2].y, al_map_rgb(0, 150, 0), 3.0);
				al_set_target_backbuffer(display);
				al_draw_bitmap(bitmap, 0, 0, 0);
				al_flip_display();
			}
		}
	}

	VECTOR AAPrime = getCornerOffset(input_points[0], A);
	VECTOR BBPrime = getCornerOffset(input_points[1], B);
	VECTOR CCPrime = getCornerOffset(input_points[2], C);
	VECTOR DDPrime = getCornerOffset(input_points[3], D);

	VECTOR AAPrimeS, BBPrimeS, CCPrimeS, DDPrimeS;

	ALLEGRO_MOUSE_STATE state;

	POINT p;
	POINT PPPrime;

	POINT center;
	center.x = 0;
	center.y = 0;

	for (int i = 0; i < 4; i++) {
		center.x += input_points[i].x;
		center.y += input_points[i].y;
	}

	center.x /= 4;
	center.y /= 4;

	float total;

	al_flush_event_queue(queue);

	while (1) {
		al_wait_for_event(queue, &event);

		if (event.type != ALLEGRO_EVENT_MOUSE_AXES) {
			if (event.type == ALLEGRO_EVENT_KEY_DOWN || event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
				break;
			}

			continue;
		}

		al_draw_bitmap(bitmap, 0, 0, 0);

		// get the input point

		al_get_mouse_state(&state);

		p.x = state.x;
		p.y = state.y;

		// calculate the distances
		float ADistance = distance(p, input_points[0]);
		float BDistance = distance(p, input_points[1]);
		float CDistance = distance(p, input_points[2]);
		float DDistance = distance(p, input_points[3]);

		float AB = ADistance / BDistance;
		float BA = BDistance / ADistance;
		total = AB + BA;
		AB /= total;
		BA /= total;

		float topVec = AAPrime.y * BA + BBPrime.y * AB;

		float ACurs = fabs(p.y - input_points[0].y);
		float BCurs = fabs(p.y - input_points[1].y);
		float topCurs = ACurs * BA + BCurs * AB;

		al_draw_line(p.x, p.y, p.x, p.y + topVec, al_map_rgb(0, 255, 0), 4.0);
		al_draw_circle(p.x, p.y + topVec, 5, al_map_rgb(0, 0, 0), 2.0);

		float CD = CDistance / DDistance;
		float DC = DDistance / CDistance;
		total = DC + CD;
		CD /= total;
		DC /= total;

		float bottomVec = CCPrime.y * DC + DDPrime.y * CD;

		float DCurs = fabs(p.y - input_points[3].y);
		float CCurs = fabs(p.y - input_points[2].y);
		float bottomCurs = DCurs * CD + CCurs * DC;

		al_draw_line(p.x, p.y, p.x, p.y + bottomVec, al_map_rgb(0, 255, 0), 4.0);
		al_draw_circle(p.x, p.y + bottomVec, 5, al_map_rgb(0, 0, 0), 2.0);

		float topBottom = topCurs / bottomCurs;
		float bottomTop = bottomCurs / topCurs;
		total = topBottom + bottomTop;
		topBottom /= total;
		bottomTop /= total;

		float BC = BDistance / CDistance;
		float CB = CDistance / BDistance;
		total = BC + CB;
		BC /= total;
		CB /= total;

		float rightVec = BBPrime.x * CB + CCPrime.x * BC;

		BCurs = fabs(p.x - input_points[1].x);
		CCurs = fabs(p.x - input_points[2].x);
		float rightCurs= BCurs * CB + CCurs * BC;

		al_draw_line(p.x, p.y, p.x + rightVec, p.y, al_map_rgb(0, 255, 0), 4.0);
		al_draw_circle(p.x + rightVec, p.y, 5, al_map_rgb(0, 0, 0), 2.0);

		float DA = DDistance / ADistance;
		float AD = ADistance / DDistance;
		total = DA + AD;
		DA /= total;
		AD /= total;

		float leftVec = DDPrime.x * AD + AAPrime.x * DA;

		ACurs = fabs(p.x - input_points[0].x);
		DCurs = fabs(p.x - input_points[3].x);
		float leftCurs = ACurs * DA + DCurs * AD;

		al_draw_line(p.x, p.y, p.x + leftVec, p.y, al_map_rgb(0, 255, 0), 4.0);
		al_draw_circle(p.x + leftVec, p.y, 5, al_map_rgb(0, 0, 0), 2.0);

		float leftRight = leftCurs / rightCurs;
		float rightLeft = rightCurs / leftCurs;
		total = leftRight + rightLeft;
		leftRight /= total;
		rightLeft /= total;

		// draw the main corner vectors
/*		al_draw_line(input_points[0].x, input_points[0].y, input_points[0].x + AAPrime.x, input_points[0].y + AAPrime.y, al_map_rgb(0, 0, 0), 2.0);*/
/*		al_draw_line(input_points[1].x, input_points[1].y, input_points[1].x + BBPrime.x, input_points[1].y + BBPrime.y, al_map_rgb(0, 0, 0), 2.0);*/
/*		al_draw_line(input_points[2].x, input_points[2].y, input_points[2].x + CCPrime.x, input_points[2].y + CCPrime.y, al_map_rgb(0, 0, 0), 2.0);*/
/*		al_draw_line(input_points[3].x, input_points[3].y, input_points[3].x + DDPrime.x, input_points[3].y + DDPrime.y, al_map_rgb(0, 0, 0), 2.0);*/

		// draw the corner vector components
/*		al_draw_line(input_points[0].x, input_points[0].y, input_points[0].x + AAPrime.x, input_points[0].y, al_map_rgb(255, 0, 0), 1.0);*/
/*		al_draw_line(input_points[0].x, input_points[0].y, input_points[0].x, input_points[0].y + AAPrime.y, al_map_rgb(255, 0, 0), 1.0);*/

/*		al_draw_line(input_points[1].x, input_points[1].y, input_points[1].x + BBPrime.x, input_points[1].y, al_map_rgb(255, 0, 0), 1.0);*/
/*		al_draw_line(input_points[1].x, input_points[1].y, input_points[1].x, input_points[1].y + BBPrime.y, al_map_rgb(255, 0, 0), 1.0);*/

/*		al_draw_line(input_points[2].x, input_points[2].y, input_points[2].x + CCPrime.x, input_points[2].y, al_map_rgb(255, 0, 0), 1.0);*/
/*		al_draw_line(input_points[2].x, input_points[2].y, input_points[2].x, input_points[2].y + CCPrime.y, al_map_rgb(255, 0, 0), 1.0);*/

/*		al_draw_line(input_points[3].x, input_points[3].y, input_points[3].x + DDPrime.x, input_points[3].y, al_map_rgb(255, 0, 0), 1.0);*/
/*		al_draw_line(input_points[3].x, input_points[3].y, input_points[3].x, input_points[3].y + DDPrime.y, al_map_rgb(255, 0, 0), 1.0);*/

		// draw the processed point

		PPPrime.y = topVec * bottomTop + bottomVec * topBottom;
		PPPrime.x = rightVec * leftRight + leftVec * rightLeft;

		al_draw_line(p.x, p.y, p.x + PPPrime.x, p.y, al_map_rgb(0, 0, 255), 2.0);
		al_draw_line(p.x, p.y, p.x, p.y + PPPrime.y, al_map_rgb(0, 0, 255), 2.0);

		al_draw_circle(p.x + xOfs + PPPrime.x, p.y + yOfs + PPPrime.y, 5, al_map_rgb(0, 255, 0), 2.0);
		al_draw_circle(p.x + xOfs + PPPrime.x, p.y + yOfs + PPPrime.y, 1, al_map_rgb(0, 0, 0), 1.0);

		al_flip_display();
	}

	return 0;
}
Example #22
0
int MouseHandler :: getY()
{
    al_get_mouse_state (&state);
    return (state.y);
}
static int mallegro_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz, int *bp)
{
static int mz; 
static int hidingmouse;
  
  if (!al_is_mouse_installed()) return 0;
  

int buttons = 0;
int mickeyz = 0;

    al_get_next_event(a_event_queue_m, &a_event); //remove from queue

switch(a_event.type){
    case ALLEGRO_EVENT_MOUSE_AXES:
    case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
    case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
        break; 
    case ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY:        
    case ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY:
    default:
        return 0;
}

	al_get_mouse_state_axis(&mstate, 2); // 2= read z-axis vertical wheel	
	//calculate wheel button (up/down)
	if(mstate.z != mz)
	    mickeyz = mstate.z - mz;
	else
	    mickeyz = 0;
	mz = mstate.z;
	
	al_get_mouse_state(&mstate); //call above returns no button press
	//microwindows expects the mouse position at the unzoomed position - so divide
	*dx=mstate.x/zoomfactor; 
	*dy=mstate.y/zoomfactor;
    *dz = 0; //unused
	*bp = 0;

if (mstate.buttons & 1) {
    /* Primary (e.g. left) mouse button is held. */
    buttons |= MWBUTTON_L;
}
if (mstate.buttons & 2) {
    buttons |= MWBUTTON_R;
    /* Secondary (e.g. right) mouse button is held. */
}
if (mstate.buttons & 4) {
    /* Tertiary (e.g. middle) mouse button is held. */
    buttons |= MWBUTTON_M;
}

if (mickeyz > 0)
    buttons |= MWBUTTON_U;  
if (mickeyz < 0)
    buttons |= MWBUTTON_D;  

*bp = buttons;

return 2; //2=absolute mouse position

}
Example #24
0
int main(){
    srand(time(0));

	Engine engine;

    fitnessFile << "Current Generation|Best Fitness|Average Fitness" << endl;

	//Initialize the Engine
	engine.init("Neural Network", screenWidth, screenHeight, false);

    if(!loadConfiguration()){
        al_show_native_message_box(display,
            "File not found",
            "File not found",
            "Check if the file config.ini exist inside the config folder",
            NULL,
        ALLEGRO_MESSAGEBOX_ERROR);
        engine.quit();
    }

	//Load the Menu
	engine.changeState(PlayState::instance());

    //Timestep Variables
    double t = 0.0;
    double dt = 1/logicSpeed;

    double currentTime = 0.0;
    double newTime = 0.0;
    double frameTime = 0.0;

    double accumulator = 0.0;

	//Main Loop
    while(engine.running()){
        ALLEGRO_EVENT events;
        al_wait_for_event(event_queue, &events);

        timerEvent = false;

        if(events.type == ALLEGRO_EVENT_DISPLAY_CLOSE){
            engine.quit();
        }

        if(events.type == ALLEGRO_EVENT_TIMER){
            timerEvent = true;
        }
        //Main Timer Event +
        if(timerEvent){
            al_get_mouse_state(&mouseState);

            al_get_keyboard_state(&keyState);

            //Update Mouse Variables +
            mouseX = al_get_mouse_state_axis(&mouseState,0);
            mouseY = al_get_mouse_state_axis(&mouseState,1);
            mouseWheel = al_get_mouse_state_axis(&mouseState, 2);

            if(al_mouse_button_down(&mouseState, 1)){
                mouseButtonLeft = true;
                mouseButtonLeftClick = false;
            }else if(mouseButtonLeft){
                mouseButtonLeftClick = true;
                mouseButtonLeft = false;
            }else{
                mouseButtonLeftClick = false;
            }

            if(al_mouse_button_down(&mouseState, 2)){
                mouseButtonRight = true;
                mouseButtonRightClick = false;
            }else if(mouseButtonRight){
                mouseButtonRightClick = true;
                mouseButtonRight = false;
            }else{
                mouseButtonRightClick = false;
            }
            //Update Mouse Variables -

            //Rest +
            if(!al_key_down(&keyState, lastKeyPress)){
                lastKeyPress = 0;
            }
            //Rest -

            if(events.timer.source == timer){
                newTime = al_get_time();
                frameTime = newTime - currentTime;
                if(frameTime > 0.25)
                    frameTime = 0.25;	  // note: max frame time to avoid spiral of death
                currentTime = newTime;

                accumulator += frameTime;

                while(accumulator >= dt){
                    engine.update(); //Call the gameState specfic update
                    dt = 1/logicSpeed;
                    t += dt;
                    accumulator -= dt;
                }

                engine.draw();

                al_draw_bitmap(cursorImage, mouseX-4, mouseY-4, 0);

                al_flip_display();
                al_clear_to_color(al_map_rgb(0, 0, 0));
            }
        }
        //Main Timer Event -
    }
	// cleanup the engine
	engine.cleanup();

    fitnessFile.close();
}
Example #25
0
void init::get_events() {

    do {
        al_get_mouse_state(&this->mState);

        al_wait_for_event(this->event_queue, &this->ev);

        if (this->ev.type == ALLEGRO_EVENT_TIMER) {
            this->redraw = true;
        }

        else if(this->ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
            this->play = false;
        }/*
	else if(this->ev.type == ALLEGRO_EVENT_MOUSE_AXES ||
			  this->ev.type == ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY) {

			  //player.x = ev.mouse.x;
			  //player.y = ev.mouse.y;
	}
	else if(this->ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
				this->teleport = true;
	}*/ // toto sa riesi cez mouse_state
        else if(this->ev.type == ALLEGRO_EVENT_KEY_DOWN) {
            switch(this->ev.keyboard.keycode) {
            case ALLEGRO_KEY_UP:
                this->keys[KEY_UP] = true;
                break;

            case ALLEGRO_KEY_W:
                this->keys[KEY_UP] = true;
                break;

            case ALLEGRO_KEY_DOWN:
                this->keys[KEY_DOWN] = true;
                break;

            case ALLEGRO_KEY_S:
                this->keys[KEY_DOWN] = true;
                break;

            case ALLEGRO_KEY_LEFT:
                this->keys[KEY_LEFT] = true;
                break;

            case ALLEGRO_KEY_A:
                this->keys[KEY_LEFT] = true;
                break;

            case ALLEGRO_KEY_RIGHT:
                this->keys[KEY_RIGHT] = true;
                break;

            case ALLEGRO_KEY_D:
                this->keys[KEY_RIGHT] = true;
                break;
            }
        }
        else if(ev.type == ALLEGRO_EVENT_KEY_UP) {
            switch(ev.keyboard.keycode) {
            case ALLEGRO_KEY_UP:
                this->keys[KEY_UP] = false;
                break;

            case ALLEGRO_KEY_W:
                this->keys[KEY_UP] = false;
                break;

            case ALLEGRO_KEY_DOWN:
                this->keys[KEY_DOWN] = false;
                break;

            case ALLEGRO_KEY_S:
                this->keys[KEY_DOWN] = false;
                break;

            case ALLEGRO_KEY_LEFT:
                this->keys[KEY_LEFT] = false;
                break;

            case ALLEGRO_KEY_A:
                this->keys[KEY_LEFT] = false;
                break;

            case ALLEGRO_KEY_RIGHT:
                this->keys[KEY_RIGHT] = false;
                break;

            case ALLEGRO_KEY_D:
                this->keys[KEY_RIGHT] = false;
                break;
            }
        }
    } while (!al_is_event_queue_empty(this->event_queue));
}
Example #26
0
int main()
{          
	const float FPS = 60.0;

	if(!al_init())
	{
		al_show_native_message_box(NULL, "Fatal Error", NULL, "No se pudo inicializar Allegro", NULL, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}
	
	al_set_new_display_flags(ALLEGRO_WINDOWED); // Pone la ventana en modo Windowed
	ALLEGRO_DISPLAY *display = al_create_display(ScreenWidth, ScreenHeight);

	// Pone la posición en la que debe salir l`a ventana
	//al_set_window_position(display, 0, 30);

	// Pone el título de la ventana
	al_set_window_title(display, "Killer Bunny");

	if(!display)	// Si no se pudo crear la ventana, entonces pone un mensaje de error
	{
		al_show_native_message_box(NULL, "Error", NULL, "No se pudo crear la pantalla", NULL, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	al_install_keyboard();
	al_install_mouse();
	al_init_image_addon();
	al_init_font_addon();
	al_init_ttf_addon();
	al_init_primitives_addon();

	// -----------------------------------------------------------------

	ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
	ALLEGRO_TIMER *timer = al_create_timer(1.0/FPS);
	ALLEGRO_KEYBOARD_STATE keyState;

	// Utilizado para debugging
	ALLEGRO_FONT *font = al_load_font("sprites/DroidSans.ttf", 10, 0);

	
	ALLEGRO_BITMAP *fondo1 = al_load_bitmap("sprites/fondo1.png");
	
	
	bool done = false;

	// ---------Estructuras del juego-----------------------------------

	struct Player player;
	player.image = al_load_bitmap("sprites/player.png");
	al_convert_mask_to_alpha(player.image, al_map_rgb(255,255,255));
	player.x = ScreenWidth / 2;
	player.y = ScreenHeight / 2;
	player.w = al_get_bitmap_width(player.image);
	player.h = al_get_bitmap_height(player.image);
	player.moveSpeed = 3;
	player.degrees = -ALLEGRO_PI/2;
   	player.alive = true;
   	player.clip = 6;
   	player.vida = 100;

	
	struct Bala bala;
	
	//~ void Bala::update()
	//~ {
		//~ bala.dx = cosf(player.xmouse - player.x);
		//~ bala.dy = senf(player.ymouse - player.y);
		//~ 
		//~ if(bala.shot){
			//~ 
			//~ bala.x += bala.dx;
			//~ bala.y += bala.dy;
			//~ }
		//~ 
	//~ }
	
	bala.image = al_load_bitmap("sprites/bullet.png");
	bala.x = player.x+50;
	bala.y = player.y+25;
	bala.shot = false;
	
	
	struct Enemigo robot;
	robot.image = al_load_bitmap("sprites/Robot_sprites.png");
	robot.death = al_load_bitmap("sprites/explosiondelrobot.png");
	al_convert_mask_to_alpha(robot.death, al_map_rgb(255, 255, 255));
	//al_convert_mask_to_alpha(robot.image, al_map_rgb(255,255,255));
	robot.x = 50;
	robot.y = 50;
	robot.w = al_get_bitmap_width(robot.image);
	robot.h = al_get_bitmap_height(robot.image);
	robot.velocidad_x = 0.23;
	robot.velocidad_y = 0.23;
	robot.fuerza= 0.5;
	robot.vida=50;
	
	//~ void Weapon::recargar()
	//~ {
		//~ for(int i = 0; i < 6; i++)
		//~ {
			//~ bullets[i] = bala;
		//~ }
	//~ }
	
	// -----------------------------------------------------------------

	// Esta variable guardará los eventos del mouse
	ALLEGRO_MOUSE_STATE mouseState;
	
	// Registro varias fuentes de eventos
	al_register_event_source(event_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_display_event_source(display));
	al_register_event_source(event_queue, al_get_timer_event_source(timer));
	al_register_event_source(event_queue, al_get_mouse_event_source());

	// Inicializo el temporizador principal
	al_start_timer(timer);

	while(!done)
	{
		// La variable de los eventos
		ALLEGRO_EVENT ev;
		al_wait_for_event(event_queue, &ev); // Y aquí espero por los eventos


		if(ev.type == ALLEGRO_EVENT_TIMER)
		{
			// Dos funciones para pasar eventos del mouse y del teclado
			al_get_keyboard_state(&keyState);
			al_get_mouse_state(&mouseState);
			
			// Esto detecta la posición del mouse y lo guarda a un par de variables
			player.xmouse = al_get_mouse_state_axis(&mouseState, 0);
			player.ymouse = al_get_mouse_state_axis(&mouseState, 1);

			// Si presiono Esc entonces me saca del juego
			if(al_key_down(&keyState, ALLEGRO_KEY_ESCAPE))
			{
				done = true;
			}
			// Si presiono A entonces el valor x se reduce, osea, se va a la izquierda
			if(al_key_down(&keyState, ALLEGRO_KEY_A))
			{
				player.x -= player.moveSpeed;
			}
			// Si... meh, ya sabes lo que sigue
			if(al_key_down(&keyState, ALLEGRO_KEY_D))
			{
				player.x += player.moveSpeed;
			}
			// ...
			if(al_key_down(&keyState, ALLEGRO_KEY_W))
			{
				player.y -= player.moveSpeed;
			}
			// ...
			if(al_key_down(&keyState, ALLEGRO_KEY_S))
			{
				player.y += player.moveSpeed;
			}
			// Mata al robot
			if(al_key_down(&keyState, ALLEGRO_KEY_K))
			{
                robot.vida -= 10;
            }
					
		}
		
		// Esto permite que el jugador se mueva con el mouse
		player.degrees = atan2((player.ymouse-player.y),(player.xmouse-player.x));
					
		// La Inteligencia Artificial del enemigo
		if(robot.alive && player.alive){
			if(robot.x < player.x) robot.x += robot.velocidad_x;
			if(robot.x > player.x) robot.x -= robot.velocidad_x;
			if(robot.y > player.y) robot.y -= robot.velocidad_y;
			if(robot.y < player.y) robot.y += robot.velocidad_y;
		}
		// Uso de las funciones para las colisiones
		//if(Collision(player.x, player.y, 50, 50, robot.x, robot.y, 34, 34)) player.alive = false;
		if(PixelCol(player.image, robot.image, player.x-(player.w/2), player.y-(player.h/2), player.w, player.h, robot.x, robot.y, robot.w/7, robot.h)) player.vida -= robot.fuerza;

		if(player.vida==0) player.alive = false;
		
		if(robot.vida<=0){
			robot.vida = 0;
			robot.alive = false;
		}

		al_clear_to_color(al_map_rgb(255, 255, 255));	// Se pinta todo a negro
		al_draw_scaled_bitmap(fondo1,0, 0, 256, 256, 0, 0, ScreenWidth, ScreenHeight, 0);	// Se dibuja el fondo
		if(player.alive){	// Si el jugador está vivo
			al_draw_rotated_bitmap(player.image, 25, 25, player.x, player.y, player.degrees, 0); // Dibujo el jugador
			al_draw_rotated_bitmap(bala.image, 0, 0, player.x+5, player.y+5, player.degrees, 0); // Dibujo la bala (esto hay que quitarlo)
		}
		if(robot.alive){
			al_draw_bitmap_region(robot.image, 0, 0, 60, 52, robot.x, robot.y, 0); // Dibujo el robot
			}
		else
		{
			robot.w = al_get_bitmap_width(robot.death);
			robot.h = al_get_bitmap_width(robot.death);
			al_draw_bitmap_region(robot.death, 0, 0, robot.w/4, robot.h, robot.x, robot.y, 0);
        }
        
        // Esto es para el debugging
        
        // Dibujo rectángulos para las colisiones
        al_draw_rectangle(player.x-(player.w/2), player.y-(player.h/2), (player.x+player.w)-(player.w/2), (player.y+player.h)-(player.h/2), al_map_rgb(0, 255, 0), 1.0);
        al_draw_rectangle(robot.x, robot.y, robot.x+(robot.w/7), robot.y+robot.h, al_map_rgb(0, 255, 0), 1.0);
        
        // Escribo en una esquina de la pantalla, información respecto al personaje
		al_draw_textf(font, al_map_rgb(255,255,255), ScreenWidth-10, 2, ALLEGRO_ALIGN_RIGHT, "Player x, y : %.1f %.1f", player.x, player.y);
		al_draw_textf(font, al_map_rgb(255,255,255), ScreenWidth-10, 12, ALLEGRO_ALIGN_RIGHT, "Rotation (rad): %.5f", player.degrees);
		al_draw_textf(font, al_map_rgb(255,255,255), ScreenWidth-10, 22, ALLEGRO_ALIGN_RIGHT, "Rotation (degrees): %.2f", (player.degrees*180)/ALLEGRO_PI);
		
		// Status bar
		al_draw_filled_rectangle(0,0,player.vida*2,15, al_map_rgb(0,255,0));
		
		// Actualizo la pantalla (flip)
		al_flip_display();
		
		
	}
	
	//-----After party (hay que limpiar)--------------------------------
	
	// A destruirlo todo!! BAM BAM BAM, KABOOM!!
	al_destroy_font(font);
	al_destroy_bitmap(fondo1);
	al_destroy_bitmap(robot.image);
	al_destroy_display(display);
	al_destroy_event_queue(event_queue);
	al_destroy_bitmap(player.image);
	al_destroy_timer(timer);

	return 0;
}
void ImGui_ImplA5_NewFrame()
{
    if (!g_Texture) 
        Imgui_ImplA5_CreateDeviceObjects();

    ImGuiIO &io = ImGui::GetIO();

    // Setup display size (every frame to accommodate for window resizing)
    int w, h;
    w = al_get_display_width(g_Display);
    h = al_get_display_height(g_Display);
    io.DisplaySize = ImVec2((float)w, (float)h);

    // Setup time step
    double current_time = al_get_time();
    io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f);
    g_Time = current_time;

    // Setup inputs
    ALLEGRO_KEYBOARD_STATE keys;
    al_get_keyboard_state(&keys);
    io.KeyCtrl = al_key_down(&keys, ALLEGRO_KEY_LCTRL) || al_key_down(&keys, ALLEGRO_KEY_RCTRL);
    io.KeyShift = al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT);
    io.KeyAlt = al_key_down(&keys, ALLEGRO_KEY_ALT) || al_key_down(&keys, ALLEGRO_KEY_ALTGR);

    ALLEGRO_MOUSE_STATE mouse;
    if (keys.display == g_Display) 
    {
        al_get_mouse_state(&mouse);
        io.MousePos = ImVec2((float)mouse.x, (float)mouse.y);
    }
    else 
    {
        io.MousePos = ImVec2(-1, -1);
    }

    al_get_mouse_state(&mouse);
    io.MouseDown[0] = mouse.buttons & (1 << 0);
    io.MouseDown[1] = mouse.buttons & (1 << 1);
    io.MouseDown[2] = mouse.buttons & (1 << 2);

    // Hide OS mouse cursor if ImGui is drawing it
    if (io.MouseDrawCursor)
    {
        al_set_mouse_cursor(g_Display, g_MouseCursorInvisible);
    }
    else
    {
        ALLEGRO_SYSTEM_MOUSE_CURSOR cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_DEFAULT;
        switch (ImGui::GetMouseCursor())
        {
        case ImGuiMouseCursor_TextInput:    cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_EDIT; break;
        case ImGuiMouseCursor_Move:         cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_MOVE; break;
        case ImGuiMouseCursor_ResizeNS:     cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_N; break;
        case ImGuiMouseCursor_ResizeEW:     cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_E; break;
        case ImGuiMouseCursor_ResizeNESW:   cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_NE; break;
        case ImGuiMouseCursor_ResizeNWSE:   cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_NW; break;
        }
        al_set_system_mouse_cursor(g_Display, cursor_id);
    }

    // Start the frame
    ImGui::NewFrame();
}
Example #28
0
bool MouseHandler :: isButtonDown(int btn)
{
    al_get_mouse_state (&state);
    return (al_mouse_button_down (&state, btn));
}
int main(int argc, char **argv )
{
	//inits
    al_init();
    al_init_ttf_addon();
    al_install_keyboard();
    al_install_mouse();
    al_install_audio();
    al_init_acodec_addon();
    al_init_primitives_addon();
    al_reserve_samples(1000);
    al_init_image_addon();
    ALLEGRO_KEYBOARD_STATE key;
    ALLEGRO_MOUSE_STATE mouse;
    
    ALLEGRO_DISPLAY *display;
    al_set_new_display_flags(ALLEGRO_WINDOWED);
    
    display = al_create_display(1024, 768);
    
    al_hide_mouse_cursor(display);

	//
    ALLEGRO_EVENT_QUEUE *event_queue = NULL;
    ALLEGRO_TIMER *timer = NULL;
    bool redraw = true;
    timer = al_create_timer(1.0/fps);
    event_queue = al_create_event_queue();
    
    //SAMPLES
    
    
    ///OBJECTS
    cPlayer oPlayer;
    oPlayer.create();
    
    cLevel oLevel;
    oLevel.init();
    
    ////
    al_clear_to_color(al_map_rgb(0,0,0));
    al_flip_display();
    al_register_event_source(event_queue, al_get_display_event_source(display));
    al_register_event_source(event_queue, al_get_timer_event_source(timer));
    al_start_timer(timer);
    al_reserve_samples(1000);
    
    //RUN
    while(1<2)
    {  
        ALLEGRO_EVENT ev;
        al_wait_for_event(event_queue, &ev);
        al_get_keyboard_state(&key);
        al_get_mouse_state(&mouse);
        al_get_mouse_state_axis(&mouse,0);
        al_get_mouse_state_axis(&mouse,1);
        if(ev.type == ALLEGRO_EVENT_TIMER)
        {
			
			//Runny tunny
			{
				oLevel.createLevel();
				oPlayer.run(&key);
				//player collision check
				for(int i = 0;i<oLevel.blocknum;i++)
				{
					oPlayer.checkCollision(oLevel.oBlock[i].x,oLevel.oBlock[i].y,&key);
				}
				if(al_key_down(&key,ALLEGRO_KEY_ESCAPE))
				{
					return 0;
				}
			
			
			}
            redraw = true;
        }
        else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
        {
            break;   
        }
        if(redraw && al_is_event_queue_empty(event_queue))
        {
			//draw
			al_clear_to_color(al_map_rgb(0,0,0));
		
			oPlayer.draw();
			oLevel.draw();
			//////
		
            redraw = false;
            //
            al_flip_display();
        }
    }
    return 0;
};
Example #30
0
void mapEditor::update() {
	ALLEGRO_MOUSE_STATE mS;
	al_get_mouse_state(&mS);
	
		if (tSelector->transition ==transitionStatus::sIN && panning==false) {
			if (mS.x < 32) {
				tSelector->transition = transitionStatus::sFLYOUT;
			}
		}
		if (tSelector->transition ==transitionStatus::sOUT && !tSelector->panning) {
			if (mS.x > tSelector->panelW) {
				tSelector->transition = transitionStatus::sFLYIN;
			}
		}
	int placeX, placeY;
	getGridSnapPositon(&placeX, &placeY);


	ALLEGRO_KEYBOARD_STATE kS;
	al_get_keyboard_state(&kS);

	ALLEGRO_EVENT ev;
	if (al_get_next_event(eventQueue,&ev)) {
		if (tSelector->handleEvent(ev)==false) {

			switch (ev.type) {

			case ALLEGRO_EVENT_KEY_UP: {

						if (ev.keyboard.keycode==ALLEGRO_KEY_LEFT) {
							this->mHandler->mData->left -= 64;
						}
						if (ev.keyboard.keycode==ALLEGRO_KEY_RIGHT) {
							this->mHandler->mData->right += 64;
						}

						if (ev.keyboard.keycode==ALLEGRO_KEY_UP) {
							this->mHandler->mData->top -= 64;
						}
						if (ev.keyboard.keycode==ALLEGRO_KEY_DOWN) {
							this->mHandler->mData->bottom += 64;
						}

						if (ev.keyboard.keycode==ALLEGRO_KEY_S) {
							if (al_key_down(&kS,ALLEGRO_KEY_LCTRL)) {
								this->saveMap();
							}
						}
						if (ev.keyboard.keycode==ALLEGRO_KEY_O) {
							if (al_key_down(&kS,ALLEGRO_KEY_LCTRL)) {
								this->loadMap(0);
							}
						}

						if (ev.keyboard.keycode==ALLEGRO_KEY_B) {
							if (al_key_down(&kS,ALLEGRO_KEY_LCTRL)) {
								//mapBackground* nBG = new mapBackground();
								//nBG->xPos = 0;
								//nBG->yPos = 0;
								//nBG->bgHandle = backgroundManager::loadBackground(3);
								
								//mapBackground* buf = this->mHandler->mData->backgroundLayers[1];
								this->mHandler->mData->backgroundLayers[3]->yPos = 0;
								//this->mHandler->mData->backgroundLayers[2] = buf;
								//this->mHandler->mData->backgroundLayers.insert(this->mHandler->mData->backgroundLayers.begin(),nBG);
							}
						}
				break;
									   }

				case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN: {
						if (ev.mouse.button==3) {
							panning = true;
							panStartX = viewX+ev.mouse.x;
							panStartY = viewY+ev.mouse.y;
						}
						if (ev.mouse.button==2) { //Right click

							if (al_key_down(&kS,ALLEGRO_KEY_SPACE)) { //If we are in "collision line edit mode" (eg. space being held)
								collisionLine* closest = getNearestCollisionLine(ev.mouse.x+viewX,ev.mouse.y+viewY,8);
										this->mHandler->mData->removeCollisionLine(closest); //Remove the collision line
							}else{
								for (unsigned int i=0; i<this->mHandler->mData->tileLayers[tSelector->currentLayer]->layouts.size(); i++) { //ITerate all layouts on current layer
									tileLayout *currentLayout = this->mHandler->mData->tileLayers[tSelector->currentLayer]->layouts[i];
									bool doBreak = false;
									for(unsigned int ti=currentLayout->tilePositions.size()-1; ti>0; ti--) { //For each tile
										tile* tFound = currentLayout->tilePositions[ti];
										if (ev.mouse.x>tFound->mapX-viewX && ev.mouse.x<tFound->mapX+currentLayout->tilesetData->tileWidth-viewX  && ev.mouse.y>tFound->mapY-viewY && ev.mouse.y<tFound->mapY+currentLayout->tilesetData->tileHeight-viewY) {
											currentLayout->tilePositions.erase(currentLayout->tilePositions.begin()+ti);
											 doBreak = true;
											break;
										}

									}
									if ( doBreak) {
										break;
									}
								}

							}
						}
						if (ev.mouse.button==1) { //Left Click
							if (al_key_down(&kS,ALLEGRO_KEY_SPACE)) { //If we are placing a collision line
								if (startedLine==false) {
									startX = placeX;
									startY = placeY;
									startedLine = true;
								}
							}else{
								placingTile = true;

								bool foundLayout = false;
								for (unsigned int i=0; i<this->mHandler->mData->tileLayers[tSelector->currentLayer]->layouts.size(); i++) {
									if (this->mHandler->mData->tileLayers[tSelector->currentLayer]->layouts[i]->tilesetData->tilesetID == tSelector->tileList[tSelector->selectedTileSet]->tilesetID)
									{
									
										tile* newTile = new tile();
										newTile->mapX = placeX;
										newTile->mapY = placeY;
										newTile->tileSetX = tSelector->selectedTileX/tSelector->selectTileW;
										newTile->tileSetY = tSelector->selectedTileY/tSelector->selectTileH;
										tileDrag = newTile;
										this->mHandler->mData->tileLayers[tSelector->currentLayer]->layouts[i]->tilePositions.push_back(newTile);
										foundLayout = true;

										break;
									}
								}
								if (!foundLayout) {
									tileLayout* newLayout = new tileLayout();
									newLayout->tilesetData = tSelector->tileList[tSelector->selectedTileSet];
									tile* newTile = new tile();
									newTile->mapX = placeX;
									newTile->mapY = placeY;
									newTile->tileSetX = tSelector->selectedTileX/tSelector->selectTileW;
									newTile->tileSetY = tSelector->selectedTileY/tSelector->selectTileH;
									tileDrag = newTile;
									newLayout->tilePositions.push_back(newTile);
									this->mHandler->mData->tileLayers[tSelector->currentLayer]->layouts.push_back(newLayout);
								}
							}
						}
					break;
													  }
				case ALLEGRO_EVENT_MOUSE_BUTTON_UP: {
						if (ev.mouse.button==3) {
							panning = false;
						}
						if (ev.mouse.button==1) { //LEft click
							if (al_key_down(&kS,ALLEGRO_KEY_SPACE)) { //If we are placing a collision line
								if (startedLine==true) {
									collisionLine* newLine = new collisionLine();
									newLine->p1.x = this->startX;
									newLine->p1.y = this->startY;
									newLine->p2.x = placeX;
									newLine->p2.y = placeY;
									if (al_key_down(&kS,ALLEGRO_KEY_ALT)) {
										newLine->jumpthrough = false;
									}else{
										newLine->jumpthrough = true;
									}

									if (!(newLine->p1==newLine->p2))
									{
										this->mHandler->mData->addCollisionLine(newLine);
									}else{
										delete newLine;
									}
									startedLine = false;
								}
							}else{

							placingTile = false;
							}
						}
					break;
													  }
			}

		}
	}

	if (panning) {
		
		viewX = panStartX-mS.x;
		viewY = panStartY-mS.y;
	}

	if (placingTile) {
		tileDrag->mapX = placeX;
		tileDrag->mapY = placeY;
	}
	tSelector->update();
}