From c9e997c794b552f699bb0a21ba0a92789ebb244d Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sun, 22 Apr 2018 20:44:29 -0700 Subject: [PATCH] Added mouse cursors --- content/cursor.png | Bin 0 -> 599 bytes main.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 content/cursor.png diff --git a/content/cursor.png b/content/cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..229081cad9286cb90931826b6416fa0e856d92c5 GIT binary patch literal 599 zcmeAS@N?(olHy`uVBq!ia0vp^0U*r51|<6gKdl8)jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucLCF%=h?3y^w370~qEv>0#LT=By}Z;C1rt33 zJtM=93Yk-ZrXKfnaSW-5dwbz_Uz3A~OW^!RpDWDfSM#@=kAx zVC`9UIKzsj#Eg^gJLhYyf1ksdtX9vQW2bzKTf+FJ@q-l~nU48vkeyPressed(SDL_RIGHT_MOUSE_KEY)) { - ui->window()->setMouseVisible(false); + showMouse = false; app->window()->setRelativeMousePosition(app->window()->width()/2, app->window()->height()/2); mouseMovedBeginMotion = true; } else if(ui->keyReleased(SDL_RIGHT_MOUSE_KEY)) { - ui->window()->setMouseVisible(true); + showMouse = true; app->debugController.setActive(false); } @@ -551,6 +554,21 @@ void drawButtons(RenderDevice* rd) } void Demo::onGraphics(RenderDevice* rd) { + Vector2 mousepos = Vector2(0,0); + G3D::uint8 num = 0; + rd->window()->getRelativeMouseState(mousepos, num); + bool mouseOnScreen = true; + if(mousepos.x < 5 || mousepos.y < 5 || mousepos.x > rd->getViewport().width()-5 || mousepos.y > rd->getViewport().height()-5) + { + mouseOnScreen = false; + rd->window()->setInputCaptureCount(0); + } + else + { + mouseOnScreen = true; + rd->window()->setInputCaptureCount(1); + } + LightingParameters lighting(G3D::toSeconds(11, 00, 00, AM)); app->renderDevice->setProjectionAndCameraMatrix(app->debugCamera); @@ -683,10 +701,42 @@ void Demo::onGraphics(RenderDevice* rd) { glDisable( GL_TEXTURE_2D ); + + + + if(showMouse && mouseOnScreen) + { + glEnable( GL_TEXTURE_2D ); + glEnable(GL_BLEND);// you enable blending function + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + + glBindTexture( GL_TEXTURE_2D, cursorid); + + + glBegin( GL_QUADS ); + glTexCoord2d(0.0,0.0); + glVertex2f(mousepos.x-40, mousepos.y-40); + glTexCoord2d( 1.0,0.0 ); + glVertex2f(mousepos.x+40, mousepos.y-40); + glTexCoord2d(1.0,1.0 ); + glVertex2f(mousepos.x+40, mousepos.y+40 ); + glTexCoord2d( 0.0,1.0 ); + glVertex2f( mousepos.x-40, mousepos.y+40 ); + glEnd(); + + glDisable( GL_TEXTURE_2D ); + } + rd->afterPrimitive(); rd->popState(); + + + + + drawButtons(rd); app->renderDevice->pop2D(); @@ -701,12 +751,14 @@ void App::main() { go = Texture::fromFile(GetFileInPath("/content/images/Run.png")); go_ovr = Texture::fromFile(GetFileInPath("/content/images/Run_ovr.png")); go_dn = Texture::fromFile(GetFileInPath("/content/images/Run_dn.png")); + cursor = Texture::fromFile(GetFileInPath("/content/cursor.png")); go_id = go->getOpenGLID(); go_dn_id = go_dn->getOpenGLID(); go_ovr_id = go_ovr->getOpenGLID(); fntdominant = GFont::fromFile(GetFileInPath("/content/font/dominant.fnt")); fntlighttrek = GFont::fromFile(GetFileInPath("/content/font/lighttrek.fnt")); sky = Sky::create(NULL, ExePath() + "/content/sky/"); + cursorid = cursor->openGLID(); applet->run(); } @@ -752,6 +804,8 @@ int main(int argc, char** argv) { //Using the damned SDL window now SDLWindow* wnd = new SDLWindow(settings.window); + //wnd->setInputCaptureCount(200); + wnd->setMouseVisible(false); App app = App(settings, wnd); HWND hwnd = wnd->win32HWND();