home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / demos / mouse / build / main.cpp next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  2.0 KB  |  92 lines

  1. #include <theatrix.h>
  2.  
  3. const int fg = 0;
  4. const int bg = 15;
  5.  
  6. class MouseDemo : public SceneryDirector  {
  7.   void display();
  8.   void hide();
  9.   void on_quit(int,int,int);
  10.   void on_click(int x,int y,int b);
  11.   void on_move(int x,int y,int b);
  12.   void on_centerclick(int, int);
  13.   DECLARE_CUELIST
  14.   DECLARE_MOUSECURSORS
  15. public:
  16.   MouseDemo()
  17.     { }
  18. };
  19.  
  20. CUELIST(MouseDemo)
  21.   MOUSECLICK(RIGHTMOUSEBUTTON,on_quit)
  22.   MOUSECLICK(LEFTMOUSEBUTTON,on_click)
  23.   MOUSEMOVE(on_move)
  24.   KEYSTROKE(ESC, on_quit)
  25. ENDCUELIST
  26.  
  27. CURSORLIST(MouseDemo)
  28.   MOUSE_CURSOR(  0,  0,105, 79,UPPERLEFTARROWCURSOR, 0)
  29.   MOUSE_CURSOR(106,  0,211, 79,UPARROWCURSOR, 0)
  30.   MOUSE_CURSOR(212,  0,319, 79,UPPERRIGHTARROWCURSOR, 0)
  31.   MOUSE_CURSOR(  0, 80,105,159,LEFTARROWCURSOR, 0)
  32.   MOUSE_CURSOR(106, 80,211,159,CENTERCURSOR, on_centerclick)
  33.   MOUSE_CURSOR(212, 80,319,159,RIGHTARROWCURSOR, 0)
  34.   MOUSE_CURSOR(  0,160,105,239,LOWERLEFTARROWCURSOR, 0)
  35.   MOUSE_CURSOR(106,160,211,239,DOWNARROWCURSOR, 0)
  36.   MOUSE_CURSOR(212,160,319,239,LOWERRIGHTARROWCURSOR, 0)
  37. ENDCURSORLIST
  38.  
  39. void MouseDemo::display()
  40. {
  41.   fg_setcolor(bg);
  42.   fg_fillpage();
  43.   fg_setcolor(fg);
  44.   mouse_visible();
  45. }
  46.  
  47. void MouseDemo::hide()
  48. {
  49.     mouse_invisible();
  50. }
  51. void MouseDemo::on_quit(int,int,int)
  52. {
  53.   stop_director();
  54. }
  55. void MouseDemo::on_click(int x,int y,int)
  56. {
  57.   fg_move(x,y);       // position graphics cursor
  58.   mouse_invisible();
  59.   fg_circle(5);       // draw a circle
  60.   mouse_visible();
  61. }
  62. void MouseDemo::on_move(int x,int y,int b)
  63. {
  64.   fg_move(x,y);
  65.   mouse_invisible();
  66.   fg_circle((b & LEFTMOUSEBUTTON) ? 5 : 1);
  67.   mouse_visible();
  68. }
  69. void MouseDemo::on_centerclick(int x, int y)
  70. {
  71.   mouse_invisible();
  72.   fg_box(x, x+10, y, y+10);
  73.   mouse_visible();
  74. }
  75.  
  76. class MouseApp : public Theatrix  {
  77. public:
  78.   MouseApp() : Theatrix("mouse demo")
  79.     { demo=new MouseDemo; }
  80.   ~MouseApp()
  81.     { delete demo; }
  82. private:
  83.   MouseDemo* demo;
  84. };
  85.  
  86. int main()
  87. {
  88.   MouseApp app;
  89.   app.go();
  90.   return 0;
  91. }
  92.