Changeset 27c40ce in opengl-game for game-gui-sdl.cpp


Ignore:
Timestamp:
Sep 12, 2019, 3:29:50 AM (6 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
7bf5433
Parents:
39278a8
Message:

Update vulkangame to correctly display a window in Windows and add some commented-out code for a generic system for processing UI events

File:
1 edited

Legend:

Unmodified
Added
Removed
  • game-gui-sdl.cpp

    r39278a8 r27c40ce  
    11#include "game-gui-sdl.hpp"
    22
     3#include <map>
     4#include <queue>
     5
    36#include "consts.hpp"
     7
     8map<unsigned int, unsigned char> s_keyState;
     9map<unsigned int, bool> s_keyDown;
     10
     11using namespace std;
     12
     13/*
     14// Temporary to allow the program using this class to receive events other than keyboard events
     15// Remove once I add a better game-gui wrapper for doing that
     16queue<SDL_Event> events;
     17
     18queue<MouseEvent> mouseEvents;
     19*/
    420
    521string GameGui_SDL::s_errorMessage;
     
    5975}
    6076
     77/*
     78void GameGui_SDL::processEvents() {
     79   SDL_Event e;
     80
     81   s_keyState.clear();
     82   while (SDL_PollEvent(&e)) {
     83      if (e.type == SDL_KEYDOWN || e.type == SDL_KEYUP) {
     84         if (e.type == SDL_KEYDOWN && !e.key.repeat) {
     85            s_keyState[e.key.keysym.sym] = RTWO_KEY_EVENT_PRESSED;
     86         } else if (e.type == SDL_KEYUP) {
     87            s_keyState[e.key.keysym.sym] = RTWO_KEY_EVENT_RELEASED;
     88         } else {
     89            s_keyState.erase(e.key.keysym.sym);
     90         }
     91
     92         s_keyDown[e.key.keysym.sym] = e.type == SDL_KEYDOWN;
     93      } else if (e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP) {
     94         MouseEvent mouseEvent { 0, 0, e.button.x, e.button.y };
     95
     96         mouseEvents.push(mouseEvent);
     97      } else {
     98         events.push(e);
     99      }
     100   }
     101}
     102
     103int GameGui_SDL::pollMouseEvent(MouseEvent* event) {
     104   if (mouseEvents.empty()) {
     105      return 0;
     106   }
     107
     108   *event = mouseEvents.front();
     109   mouseEvents.pop();
     110
     111   return 1;
     112}
     113
     114unsigned char GameGui_SDL::getKeyEvent(unsigned int key) {
     115   if (s_keyDown.count(key)) {
     116      return s_keyState[key];
     117   } else {
     118      return RTWO_KEY_EVENT_NONE;
     119   }
     120}
     121
     122bool GameGui_SDL::isKeyPressed(unsigned int key) {
     123   if (s_keyDown.count(key)) {
     124      return s_keyDown[key];
     125   } else {
     126      return false;
     127   }
     128}
     129
     130int GameGui_SDL::pollEvent(SDL_Event* event) {
     131   if (events.empty()) {
     132      return 0;
     133   }
     134
     135   *event = events.front();
     136   events.pop();
     137
     138   return 1;
     139}
     140*/
     141
    61142#ifdef GAMEGUI_INCLUDE_VULKAN
    62143
Note: See TracChangeset for help on using the changeset viewer.