home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / XenonSource.exe / gamesystem / source / gs_menuitem.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-09  |  4.6 KB  |  208 lines

  1. //-------------------------------------------------------------
  2. //
  3. // Class:    gsCMenuItem
  4. //
  5. // Author:    John M Phillips
  6. //
  7. // Started:    12/03/00
  8. //
  9. // Base:    gsCObject
  10. //
  11. // Derived:    gsCMenuOption
  12. //            gsCMenuSlider
  13. //            gsCMenuSeperator
  14. //
  15. //-------------------------------------------------------------
  16.  
  17. #include "gamesystem.h"
  18.  
  19. //-------------------------------------------------------------
  20.  
  21. gsCMenuItem::gsCMenuItem(const char *name)
  22. {
  23.     m_name = name;
  24.     m_value = 0;
  25. }
  26.  
  27. //-------------------------------------------------------------
  28.  
  29. gsCMenuItem::~gsCMenuItem()
  30. {
  31. }
  32.  
  33. //-------------------------------------------------------------
  34.  
  35. bool gsCMenuItem::setValue(int value)
  36. {
  37.     return false;
  38. }
  39.  
  40. //-------------------------------------------------------------
  41.  
  42. int gsCMenuItem::getValue()
  43. {
  44.     return m_value;
  45. }
  46.  
  47. //-------------------------------------------------------------
  48.  
  49. const char *gsCMenuItem::getName()
  50. {
  51.     return m_name;
  52. }
  53.  
  54. //-------------------------------------------------------------
  55.  
  56. void gsCMenuItem::draw(gsCScreen *screen,gsCFont *font,int y,bool highlight)
  57. {
  58.     if (m_name) {
  59.         if (highlight) {
  60.             gsCPoint size = font->getStringSize(m_name);
  61.             screen->drawSolidRect(gsCRect((screen->getSize().getX() - size.getX()) / 2 - 1,
  62.                                           y - 1,
  63.                                           (screen->getSize().getX() + size.getX()) / 2 + 1,
  64.                                           y + size.getY() + 1),
  65.                                           gsCColour(128,128,128));
  66.             }
  67.  
  68.         font->setTextCursor(gsCPoint(0,y));
  69.         font->justifyString(m_name);
  70.         }
  71. }
  72.  
  73. //-------------------------------------------------------------
  74.  
  75. gsCMenuOptionList::gsCMenuOptionList(const char *name)
  76.     : gsCMenuItem(name)
  77. {
  78. }
  79.  
  80. //-------------------------------------------------------------
  81.  
  82. gsCMenuOptionList::~gsCMenuOptionList()
  83. {
  84. }
  85.  
  86. //-------------------------------------------------------------
  87.  
  88. bool gsCMenuOptionList::setValue(int value)
  89. {
  90.     if (value < 0 ||
  91.         value >= m_options.getSize())
  92.         return false;
  93.  
  94.     m_value = value;
  95.     return true;
  96. }
  97.  
  98. //-------------------------------------------------------------
  99.  
  100. void gsCMenuOptionList::addOption(const char *option)
  101. {
  102.     m_options.addItem(option);
  103. }
  104.  
  105. //-------------------------------------------------------------
  106.  
  107. void gsCMenuOptionList::draw(gsCScreen *screen,gsCFont *font,int y,bool highlight)
  108. {
  109.     static char buffer[100];
  110.  
  111.     strcpy(buffer,m_name);
  112.             
  113.     if (m_options.getSize() > 0) {
  114.         strcat(buffer," : ");
  115.         strcat(buffer,m_options[m_value]);
  116.         }
  117.  
  118.     if (highlight) {
  119.         gsCPoint size = font->getStringSize(buffer);
  120.         screen->drawSolidRect(gsCRect((screen->getSize().getX() - size.getX()) / 2 - 1,
  121.                                        y - 1,
  122.                                        (screen->getSize().getX() + size.getX()) / 2 + 1,
  123.                                        y + size.getY() + 1),
  124.                                        gsCColour(128,128,128));
  125.         }
  126.  
  127.     font->setTextCursor(gsCPoint(0,y));
  128.     font->justifyString(buffer);
  129. }
  130.  
  131. //-------------------------------------------------------------
  132.  
  133. gsCMenuSlider::gsCMenuSlider(const char *name,int size,int min,int max)
  134.     : gsCMenuItem(name)
  135. {
  136.     m_size = size;
  137.     m_min = min;
  138.     m_max = max;
  139. }
  140.  
  141. //-------------------------------------------------------------
  142.  
  143. gsCMenuSlider::~gsCMenuSlider()
  144. {
  145. }
  146.  
  147. //-------------------------------------------------------------
  148.  
  149. bool gsCMenuSlider::setValue(int value)
  150. {
  151.     if (value < m_min ||
  152.         value > m_max)
  153.         return false;
  154.  
  155.     m_value = value;
  156.     return true;
  157. }
  158.  
  159. //-------------------------------------------------------------
  160.  
  161. void gsCMenuSlider::draw(gsCScreen *screen,gsCFont *font,int y,bool highlight)
  162. {
  163.     static char buffer[100];
  164.     static char slider[2] = { 126,0 };
  165.     static char control[2] = { 127,0 };
  166.  
  167.     strcpy(buffer,m_name);
  168.             
  169.     strcat(buffer," : ");
  170.     for (int i = m_min; i <= m_max; i++) {
  171.         if (m_value == i)
  172.             strcat(buffer,control);
  173.         else
  174.             strcat(buffer,slider);
  175.         }
  176.     strcat(buffer," ");
  177.     char val[10];
  178.     sprintf(val,"%02i",m_value);
  179.     strcat(buffer,val);
  180.  
  181.     if (highlight) {
  182.         gsCPoint size = font->getStringSize(buffer);
  183.         screen->drawSolidRect(gsCRect((screen->getSize().getX() - size.getX()) / 2 - 1,
  184.                                        y - 1,
  185.                                        (screen->getSize().getX() + size.getX()) / 2 + 1,
  186.                                        y + size.getY() + 1),
  187.                                        gsCColour(128,128,128));
  188.         }
  189.  
  190.     font->setTextCursor(gsCPoint(0,y));
  191.     font->justifyString(buffer);
  192. }
  193.  
  194. //-------------------------------------------------------------
  195.  
  196. gsCMenuSeperator::gsCMenuSeperator(const char *name)
  197.     : gsCMenuItem(name)
  198. {
  199. }
  200.  
  201. //-------------------------------------------------------------
  202.  
  203. gsCMenuSeperator::~gsCMenuSeperator()
  204. {
  205. }
  206.  
  207. //-------------------------------------------------------------
  208.