slopstates.cpp 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "slopstates.hpp"
  2. SlopState::~SlopState() {
  3. }
  4. void SlopState::onEnter( SlopMemory& memory ) {
  5. }
  6. void SlopState::onExit( SlopMemory& memory ) {
  7. }
  8. void SlopState::update( SlopMemory& memory, double dt ) {
  9. }
  10. void SlopState::draw( SlopMemory& memory, glm::mat4 matrix ) {
  11. }
  12. // Start
  13. void SlopStart::update( SlopMemory& memory, double dt ) {
  14. if ( mouse->getButton( 1 ) ) {
  15. memory.setState( (SlopState*)new SlopStartDrag( mouse->getMousePos() ) );
  16. }
  17. }
  18. SlopStartDrag::SlopStartDrag( glm::vec2 point ) {
  19. startPoint = point;
  20. }
  21. void SlopStartDrag::onEnter( SlopMemory& memory ) {
  22. memory.rectangle->setPoints(startPoint, startPoint);
  23. }
  24. void SlopStartDrag::update( SlopMemory& memory, double dt ) {
  25. memory.rectangle->setPoints(startPoint, mouse->getMousePos());
  26. char a = startPoint.y > mouse->getMousePos().y;
  27. char b = startPoint.x > mouse->getMousePos().x;
  28. char c = (a << 1) | b;
  29. switch ( c ) {
  30. case 0: mouse->setCursor( XC_lr_angle ); break;
  31. case 1: mouse->setCursor( XC_ll_angle ); break;
  32. case 2: mouse->setCursor( XC_ur_angle ); break;
  33. case 3: mouse->setCursor( XC_ul_angle ); break;
  34. }
  35. if ( !mouse->getButton( 1 ) ) {
  36. memory.setState( (SlopState*)new SlopEndDrag() );
  37. }
  38. }
  39. void SlopStartDrag::draw( SlopMemory& memory, glm::mat4 matrix ) {
  40. memory.rectangle->draw( matrix );
  41. }
  42. void SlopEndDrag::onEnter( SlopMemory& memory ) {
  43. memory.running = false;
  44. }