Some work on mouse input to tri
This commit is contained in:
parent
1434948db9
commit
204aeb8a9a
3 changed files with 38 additions and 10 deletions
|
@ -27,15 +27,8 @@ int main(int argc, char **argv) {
|
||||||
ImGui::SFML::ProcessEvent(event);
|
ImGui::SFML::ProcessEvent(event);
|
||||||
if(event.type == sf::Event::Closed) {
|
if(event.type == sf::Event::Closed) {
|
||||||
window.close();
|
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
|
// update
|
||||||
ImGui::SFML::Update(window, state.dt);
|
ImGui::SFML::Update(window, state.dt);
|
||||||
|
|
|
@ -5,10 +5,38 @@
|
||||||
Tri::State::State() :
|
Tri::State::State() :
|
||||||
width(800),
|
width(800),
|
||||||
height(600),
|
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() {
|
void Tri::State::update() {
|
||||||
|
// Seems misleading, but imgui handles setting up the window during update
|
||||||
Tri::draw_help(this);
|
Tri::draw_help(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
#define TRIANGLES_STATE_HPP
|
#define TRIANGLES_STATE_HPP
|
||||||
|
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <SFML/System.hpp>
|
#include <SFML/System.hpp>
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
namespace Tri {
|
namespace Tri {
|
||||||
struct State {
|
struct State {
|
||||||
|
@ -16,6 +18,11 @@ namespace Tri {
|
||||||
const unsigned int height;
|
const unsigned int height;
|
||||||
const sf::Time dt;
|
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 update();
|
||||||
void draw();
|
void draw();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue