Skip to content

Commit

Permalink
Added Mouse support to Windows version
Browse files Browse the repository at this point in the history
Created a new function in Application called Application::hasMultitouch.
Useful for deciding between checking Touch functions or Mouse functions.

Also fixed some tabbing in AttackTemplates
  • Loading branch information
lufinkey committed Nov 14, 2014
1 parent 8932267 commit 48dce46
Show file tree
Hide file tree
Showing 8 changed files with 549 additions and 390 deletions.
83 changes: 78 additions & 5 deletions Source/GameEngine/Actor/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#include "../Util/PixelIterator.h"
#include "../View.h"
#include "../Output/Console.h"
#include "../Input/Mouse.h"

#if defined(__APPLE__)
#include "TargetConditionals"
#endif

namespace GameEngine
{
Expand Down Expand Up @@ -447,7 +452,24 @@ namespace GameEngine
onmouseenter = true;
}
}
if(!prevMouseOver && !Application::checkPrevTouchActive(touchId))

bool clicking = false;
if(Application::hasMultitouch())
{
if(!prevMouseOver && !Application::checkPrevTouchActive(touchId))
{
clicking = true;
}
}
else
{
if(Application::MouseState(Mouse::LEFTCLICK) && !Application::PrevMouseState(Mouse::LEFTCLICK))
{
clicking = true;
}
}

if(clicking)
{
clicked = true;
if(isEventEnabled(EVENT_MOUSECLICK))
Expand All @@ -464,7 +486,24 @@ namespace GameEngine
onmouseleave = true;
}
}
if(clicked && prevMouseover && !Application::checkTouchActive(prevTouchId))

bool releasing = false;
if(Application::hasMultitouch())
{
if(clicked && prevMouseover && !Application::checkTouchActive(prevTouchId))
{
releasing = true;
}
}
else
{
if(clicked && !Application::MouseState(Mouse::LEFTCLICK))
{
releasing = true;
}
}

if(releasing)
{
clicked = false;
if(isEventEnabled(EVENT_MOUSERELEASE))
Expand All @@ -473,9 +512,12 @@ namespace GameEngine
}
}

if(clicked && !Application::checkTouchActive(touchId))
if(Application::hasMultitouch())
{
clicked = false;
if(clicked && !Application::checkTouchActive(touchId))
{
clicked = false;
}
}

currentTouchId = touchId;
Expand Down Expand Up @@ -684,16 +726,31 @@ namespace GameEngine

bool Actor::mouseOver()
{
#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR) || defined(__ANDROID__)
if(mouseover)
{
if(Application::checkTouchActive(currentTouchId))
{
if(checkHover((float)Application::TouchX(currentTouchId), (float)Application::TouchY(currentTouchId)))
float mousex = 0;
float mousey = 0;
if(relative)
{
mousex = (float)Application::TouchX(currentTouchId) + View::x;
mousey = (float)Application::TouchY(currentTouchId) + View::y;
}
else
{
mousex = (float)Application::TouchX(currentTouchId);
mousey = (float)Application::TouchY(currentTouchId);
}

if(checkHover(mousex, mousey))
{
return true;
}
}
}

ArrayList<TouchPoint> points = Application::getTouchPoints();
for(int i=0; i<points.size(); i++)
{
Expand All @@ -705,6 +762,22 @@ namespace GameEngine
}
}
return false;
#else
float mousex = 0;
float mousey = 0;
if(relative)
{
mousex = (float)Application::MouseX() + View::x;
mousey = (float)Application::MouseY() + View::y;
}
else
{
mousex = (float)Application::MouseX();
mousey = (float)Application::MouseY();
}

return checkHover(mousex, mousey);
#endif
}

void Actor::onMouseEnter() //When mouse enters Actor
Expand Down
14 changes: 14 additions & 0 deletions Source/GameEngine/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,15 @@ namespace GameEngine
return prevTouchPoints;
}
}

bool Application::hasMultitouch()
{
#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR) || defined(__ANDROID__)
return true;
#else
return false;
#endif
}

void Application::keyPressed(int keycode)
{
Expand Down Expand Up @@ -1107,6 +1116,11 @@ namespace GameEngine
void Application::incrementLoad(float incr)
{
game->updateEvents();
if(closing)
{
return;
}

loadCurrent+=incr;
//graphics->reset();
/*window->clear();
Expand Down
5 changes: 3 additions & 2 deletions Source/GameEngine/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ namespace GameEngine
{
class Application
{
private:
friend class View;
friend class BufferedImage;
friend class BatchLoader;
friend int ApplicationEventHandler(void*,SDL_Event*);
friend void private_updateAppEvents(void);
private:
static SDL_Window*window;
static SDL_Renderer*renderer;
static Application*game;
Expand Down Expand Up @@ -147,6 +147,7 @@ namespace GameEngine
static bool checkPrevTouchActive(long touchID);
static ArrayList<TouchPoint> getTouchPoints();
static ArrayList<TouchPoint> getPrevTouchPoints();
static bool hasMultitouch();

static void setUpdatesPerFrame(int total);
static long getFrame();
Expand Down
8 changes: 8 additions & 0 deletions Source/GameEngine/BatchLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@ namespace GameEngine
{
AssetManager::loadImage(Images.get(i));
Application::incrementLoad(1);
if(Application::closing)
{
return;
}
}
for(int i=0; i<Fonts.size(); i++)
{
AssetManager::loadFont(Fonts.get(i));
Application::incrementLoad(1);
if(Application::closing)
{
return;
}
}
Images.clear();
Fonts.clear();
Expand Down
113 changes: 81 additions & 32 deletions Source/GameEngine/ScreenManager/MenuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "MenuScreen.h"
#include "../Application.h"
#include "ScreenManager.h"
#include "../Input/Mouse.h"

namespace GameEngine
{
Expand All @@ -24,55 +25,103 @@ namespace GameEngine

void MenuScreen::Update(long gameTime)
{
long prevTouchId = -1;
if(selectedIndex>-1)
{
prevTouchId = Items.get(selectedIndex)->getTouchId();
}
Screen::Update(gameTime);
ArrayList<TouchPoint> touchPoints = Application::getTouchPoints();
ArrayList<TouchPoint> prevTouchPoints = Application::getPrevTouchPoints();
if(touchPoints.size()>0)

if(Application::hasMultitouch())
{
selecting = true;
long prevTouchId = -1;
if(selectedIndex>-1)
{
prevTouchId = Items.get(selectedIndex)->getTouchId();
}
Screen::Update(gameTime);
ArrayList<TouchPoint> touchPoints = Application::getTouchPoints();
ArrayList<TouchPoint> prevTouchPoints = Application::getPrevTouchPoints();
if(touchPoints.size()>0)
{
selecting = true;
}
else
{
selecting = false;
}

bool canBeSelected = true;
int prevSelectedIndex = selectedIndex;
selectedIndex = -1;
for(int i=(Items.size()-1); i>=0; i--)
{
MenuItem*currentItem = Items.get(i);
currentItem->Update(gameTime);
if(canBeSelected)
{
if(currentItem->MouseOver())
{
currentItem->setSelected(true);
selectedIndex = i;
canBeSelected = false;
}
else
{
currentItem->setSelected(false);
}
}
else
{
currentItem->setSelected(false);
}
}

if(prevSelectedIndex>=0 && !Application::checkTouchActive(prevTouchId))
{
Items.get(prevSelectedIndex)->OnRelease();
Items.get(prevSelectedIndex)->setSelected(false);
prevSelectedIndex = -1;
}
}
else
{
selecting = false;
}
if(Application::MouseState(Mouse::LEFTCLICK))
{
selecting = true;
}
else
{
selecting = false;
}

bool canBeSelected = true;
int prevSelectedIndex = selectedIndex;
selectedIndex = -1;
for(int i=(Items.size()-1); i>=0; i--)
{
MenuItem*currentItem = Items.get(i);
currentItem->Update(gameTime);
if(canBeSelected)
bool canBeSelected = true;
selectedIndex = -1;
for(int i=(Items.size()-1); i>=0; i--)
{
if(currentItem->MouseOver())
MenuItem*currentItem = Items.get(i);
currentItem->Update(gameTime);
if(canBeSelected)
{
currentItem->setSelected(true);
selectedIndex = i;
canBeSelected = false;
if(currentItem->MouseOver())
{
currentItem->setSelected(true);
selectedIndex = i;
canBeSelected = false;
}
else
{
currentItem->setSelected(false);
}
}
else
{
currentItem->setSelected(false);
}
}
else

if(selectedIndex>=0 && !Application::MouseState(Mouse::LEFTCLICK) && Application::PrevMouseState(Mouse::LEFTCLICK))
{
currentItem->setSelected(false);
Items.get(selectedIndex)->OnRelease();
Items.get(selectedIndex)->setSelected(false);
selectedIndex = -1;
}
}

if(prevSelectedIndex>=0 && !Application::checkTouchActive(prevTouchId))
{
Items.get(prevSelectedIndex)->OnRelease();
Items.get(prevSelectedIndex)->setSelected(false);
prevSelectedIndex = -1;
}
}

void MenuScreen::Draw(Graphics2D& g, long gameTime)
Expand Down
Loading

0 comments on commit 48dce46

Please sign in to comment.