main.cpp 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. is::Rectangle* windowselection = NULL;
  8. Window window = None;
  9. xengine->init( ":0" );
  10. xengine->grabCursor( is::Cross );
  11. while ( running ) {
  12. xengine->tick();
  13. if ( xengine->mouseDown( 3 ) ) {
  14. printf( "X: 0\n" );
  15. printf( "Y: 0\n" );
  16. printf( "W: 0\n" );
  17. printf( "H: 0\n" );
  18. printf( "User right-clicked. Canceled selection.\n" );
  19. state = -1;
  20. running = false;
  21. }
  22. switch ( state ) {
  23. default: {
  24. break;
  25. }
  26. case 0: {
  27. if ( window != xengine->m_hoverXWindow ) {
  28. if ( windowselection ) {
  29. xengine->removeRect( windowselection );
  30. }
  31. is::WindowRectangle t = xengine->m_hoverWindow;
  32. windowselection = new is::Rectangle( t.m_x,
  33. t.m_y,
  34. t.m_width,
  35. t.m_height,
  36. 10, 0 );
  37. xengine->addRect( windowselection );
  38. window = xengine->m_hoverXWindow;
  39. }
  40. if ( xengine->mouseDown( 1 ) ) {
  41. if ( windowselection ) {
  42. xengine->removeRect( windowselection );
  43. }
  44. state++;
  45. }
  46. break;
  47. }
  48. case 1: {
  49. selection = new is::Rectangle( xengine->m_mousex, xengine->m_mousey, 0, 0, 10, 0 );
  50. selection->setPos( xengine->m_mousex, xengine->m_mousey );
  51. xengine->addRect( selection );
  52. state++;
  53. break;
  54. }
  55. case 2: {
  56. if ( !xengine->mouseDown( 1 ) ) {
  57. state++;
  58. break;
  59. }
  60. selection->setDim( xengine->m_mousex - selection->m_x, xengine->m_mousey - selection->m_y );
  61. // x and y offsets can indicate if the selection is inside-out, which lets us know which kind of cursor we need.
  62. int x = selection->m_xoffset;
  63. int y = selection->m_yoffset;
  64. if ( x == 0 && y == 0) {
  65. xengine->setCursor( is::LowerRightCorner );
  66. } else if ( x && y == 0 ) {
  67. xengine->setCursor( is::LowerLeftCorner );
  68. } else if ( x == 0 && y ) {
  69. xengine->setCursor( is::UpperRightCorner );
  70. } else {
  71. xengine->setCursor( is::UpperLeftCorner );
  72. }
  73. break;
  74. }
  75. case 3: {
  76. int x = selection->m_x+selection->m_xoffset;
  77. int y = selection->m_y+selection->m_yoffset;
  78. int w = selection->m_width;
  79. int h = selection->m_height;
  80. xengine->removeRect( selection );
  81. running = false;
  82. if ( w || h || xengine->m_hoverXWindow == None ) {
  83. printf( "X: %i\n", x );
  84. printf( "Y: %i\n", y );
  85. printf( "W: %i\n", w + 1 );
  86. printf( "H: %i\n", h + 1 );
  87. break;
  88. }
  89. is::WindowRectangle t = xengine->m_hoverWindow;
  90. x = t.m_x;
  91. y = t.m_y;
  92. w = t.m_width + t.m_border;
  93. h = t.m_height + t.m_border;
  94. printf( "X: %i\n", x );
  95. printf( "Y: %i\n", y );
  96. printf( "W: %i\n", w );
  97. printf( "H: %i\n", h );
  98. break;
  99. }
  100. }
  101. // No need to max out CPU--
  102. usleep( 1000 );
  103. }
  104. delete xengine;
  105. return 0;
  106. }