Some work on mouse input to tri

This commit is contained in:
Stephen Seo 2020-07-21 20:44:10 +09:00
parent 1434948db9
commit 204aeb8a9a
3 changed files with 38 additions and 10 deletions

View file

@ -27,15 +27,8 @@ int main(int argc, char **argv) {
ImGui::SFML::ProcessEvent(event);
if(event.type == sf::Event::Closed) {
window.close();
} else if(event.type == sf::Event::KeyPressed) {
if(event.key.code == sf::Keyboard::H) {
state.flags.set(0);
}
} else if(event.type == sf::Event::KeyReleased) {
if(event.key.code == sf::Keyboard::H) {
state.flags.reset(0);
}
}
state.handle_event(&event);
// update
ImGui::SFML::Update(window, state.dt);

View file

@ -5,10 +5,38 @@
Tri::State::State() :
width(800),
height(600),
dt(sf::microseconds(16666))
{}
dt(sf::microseconds(16666)),
currentTri_state(CurrentState::NONE)
{
currentTri.setPointCount(3);
currentTri.setFillColor(sf::Color::White);
}
void Tri::State::handle_event(sf::Event *event) {
if(event->type == sf::Event::KeyPressed) {
if(event->key.code == sf::Keyboard::H) {
flags.set(0);
}
} else if(event->type == sf::Event::KeyReleased) {
if(event->key.code == sf::Keyboard::H) {
flags.reset(0);
}
} else if(event->type == sf::Event::MouseButtonPressed) {
switch(currentTri_state) {
case CurrentState::NONE:
break;
case CurrentState::FIRST:
break;
case CurrentState::SECOND:
break;
case CurrentState::THIRD:
break;
}
}
}
void Tri::State::update() {
// Seems misleading, but imgui handles setting up the window during update
Tri::draw_help(this);
}

View file

@ -2,8 +2,10 @@
#define TRIANGLES_STATE_HPP
#include <bitset>
#include <vector>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
namespace Tri {
struct State {
@ -16,6 +18,11 @@ namespace Tri {
const unsigned int height;
const sf::Time dt;
std::vector<sf::ConvexShape> tris;
sf::ConvexShape currentTri;
enum CurrentState { NONE, FIRST, SECOND, THIRD } currentTri_state;
void handle_event(sf::Event *event);
void update();
void draw();
};