home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / source / theatrix / scenery.cpp < prev    next >
C/C++ Source or Header  |  1995-04-18  |  3KB  |  147 lines

  1. #include <string.h>
  2. #include "standard.h"
  3. #include "scenery.h"
  4. #include "ascii.h"
  5. #include "theatrix.h"
  6.  
  7.  
  8. CUELIST(SceneryDirector)
  9.     KEYSTROKE(ESC,   on_escape)
  10.     KEYSTROKE(ENTER, on_enter)
  11.     KEYSTROKE(SPACE, on_space)
  12. ENDCUELIST
  13.  
  14. SceneryDirector::SceneryDirector(char *scfile, short int trans)
  15. {
  16.     scenery = scfile;
  17.     mousecursors = 0;
  18.     transition = trans;
  19. }
  20.  
  21. void SceneryDirector::display()
  22. {
  23.     if (scenery != 0)    {
  24.         static int inited = 0;
  25.         if (!inited || transition == ClearEveryTime)    {
  26.             init_video();
  27.             inited = 1;
  28.         }
  29.         if (transition && transition != ClearEveryTime)    {
  30.             fg_setcolor(0);
  31.             fg_fadeout(transition);
  32.         }
  33.         if (!show_pcx(scenery))    {
  34.             char smsg[100] = "Cannot load scenery: ";
  35.             strcat(smsg, scenery);
  36.             Theatrix::fatal(smsg);
  37.         }
  38.         fill_background_buffer(active_page());
  39.         if (transition && transition != ClearEveryTime)
  40.             fg_fadein(transition);
  41.         swap_video_pages();
  42.         synch_video_pages();
  43.     }
  44. }
  45.  
  46. const Type_info& SceneryDirector::get_next_director()
  47. {
  48.     if (next_director_set())
  49.         return VideoDirector::get_next_director();
  50.     return typeid(NextDirector);
  51. }
  52.  
  53. inline int inside(int x, int y, int x1, int y1, int x2, int y2)
  54. {
  55.     return (x >= x1 && x <= x2 && y >= y1 && y <= y2);
  56. }
  57.  
  58. void SceneryDirector::refresh_display()
  59. {
  60.     int mv = mouseinuse;
  61.     if (mv)
  62.         mouse_invisible();
  63.     swap_video_pages();
  64.     synch_video_pages();
  65.     if (mv)
  66.         mouse_visible();
  67. }
  68.  
  69. void SceneryDirector::display_original_scenery()
  70. {
  71.     restore_page();
  72.     refresh_display();
  73. }
  74.  
  75. void SceneryDirector::show_mousecursor(char *cursor)
  76. {
  77.     static int mousevisible = 1;
  78.     if (cursor)    {
  79.         mouse_cursorshape(cursor);
  80.         if (!mousevisible)    {
  81.             fg_mousevis(1);
  82.             mousevisible = 1;
  83.         }
  84.     }
  85.     else if (mousevisible)    {
  86.         fg_mousevis(0);
  87.         mousevisible = 0;
  88.     }
  89. }
  90.  
  91. void SceneryDirector::mousemoved(int x, int y, int)
  92. {
  93.     if (mouseinuse)    {
  94.         Mice *mc = mousecursors;
  95.         static char *oldcursorshape = 0;
  96.         while (mc->x1 != -1)    {
  97.             if (inside(x,y,mc->x1,mc->y1,mc->x2,mc->y2))    {
  98.                 // --- mouse is inside a cursor region
  99.                 char *cursor = mc->cursor;
  100.                 if (cursor != oldcursorshape)    {
  101.                     show_mousecursor(cursor);
  102.                     oldcursorshape = cursor;
  103.                 }
  104.                 break;
  105.             }
  106.             mc++;
  107.         }
  108.         if (mc->x1 == -1)    {
  109.             // ---- outside of any defined cursor region
  110.             oldcursorshape = DEFAULT;
  111.             show_mousecursor(DEFAULT);
  112.         }
  113.     }
  114. }
  115.  
  116. void SceneryDirector::mouseclicked(int x, int y)
  117. {
  118.     if (mouseinuse)    {
  119.         Mice *mc = mousecursors;
  120.         while (mc->x1 != -1)    {
  121.             if (inside(x,y,mc->x1,mc->y1,mc->x2,mc->y2))    {
  122.                 if (mc->func)    {
  123.                     // --- button press to be dispatched
  124.                     void (Hand::*cf)(int,int);
  125.                     Hand *h = (Hand*)this;
  126.                     cf=(void(Hand::*)(int,int))(mc->func);
  127.                     (h->*cf)(x,y);
  128.                 }
  129.                 break;
  130.             }
  131.             mc++;
  132.         }
  133.     }
  134. }
  135.  
  136. void SceneryDirector::initialize()
  137. {
  138.     VideoDirector::initialize();
  139.     mousecursors = GetMouseCursors();
  140.     if (mousecursors)    {
  141.         request_mousemove_cue((callback)&SceneryDirector::mousemoved);
  142.         request_mouseclick_cue(LEFTMOUSEBUTTON, 
  143.             (callback)&SceneryDirector::mouseclicked);
  144.     }
  145. }
  146.  
  147.