main.cpp 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <unistd.h>
  2. #include "x.hpp"
  3. int main( int argc, char** argv ) {
  4. int state = 0;
  5. bool running = true;
  6. is::Rectangle* selection;
  7. xengine->init( ":0" );
  8. xengine->grabCursor( is::Cross );
  9. while ( running ) {
  10. xengine->tick();
  11. switch ( state ) {
  12. case 0: {
  13. if ( xengine->mouseDown( 1 ) ) {
  14. state++;
  15. }
  16. break;
  17. }
  18. case 1: {
  19. // Check to make sure we actually have a cursor position before creating the selection rectangle.
  20. if ( xengine->m_mousex == -1 ) {
  21. break;
  22. }
  23. selection = new is::Rectangle( xengine->m_mousex, xengine->m_mousey, 1, 1, 10, 0 );
  24. selection->setPos( xengine->m_mousex, xengine->m_mousey );
  25. xengine->addRect( selection );
  26. state++;
  27. break;
  28. }
  29. case 2: {
  30. if ( !xengine->mouseDown( 1 ) ) {
  31. state++;
  32. break;
  33. }
  34. selection->setDim( xengine->m_mousex - selection->m_x, xengine->m_mousey - selection->m_y );
  35. // x and y offsets can indicate if the selection is inside-out, which lets us know which kind of cursor we need.
  36. int x = selection->m_xoffset;
  37. int y = selection->m_yoffset;
  38. if ( x == 0 && y == 0) {
  39. xengine->setCursor( is::LowerRightCorner );
  40. } else if ( x && y == 0 ) {
  41. xengine->setCursor( is::LowerLeftCorner );
  42. } else if ( x == 0 && y ) {
  43. xengine->setCursor( is::UpperRightCorner );
  44. } else {
  45. xengine->setCursor( is::UpperLeftCorner );
  46. }
  47. break;
  48. }
  49. case 3: {
  50. printf( "X: %i\n", selection->m_x+selection->m_xoffset );
  51. printf( "Y: %i\n", selection->m_y+selection->m_yoffset );
  52. printf( "W: %i\n", selection->m_width + 1 );
  53. printf( "H: %i\n", selection->m_height + 1 );
  54. xengine->removeRect( selection );
  55. running = false;
  56. break;
  57. }
  58. }
  59. // No need to max out CPU--
  60. usleep( 1000 );
  61. }
  62. delete xengine;
  63. return 0;
  64. }