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

  1. //-------------------------------------------------------------
  2. //
  3. // Class:    CLabel
  4. //
  5. // Author:    John M Phillips
  6. //
  7. // Started:    06/05/00
  8. //
  9. // Base:    CActor
  10. //
  11. // Derived:    None
  12. //
  13. //-------------------------------------------------------------
  14.  
  15. #include "game.h"
  16.  
  17. //-------------------------------------------------------------
  18.  
  19. gsCFont *CLabel::m_font = 0;
  20.  
  21. //-------------------------------------------------------------
  22.  
  23. CLabel::CLabel()
  24. {
  25.     m_text[0] = 0;
  26.     m_time = 0.f;
  27. }
  28.  
  29. //-------------------------------------------------------------
  30.  
  31. CLabel::~CLabel()
  32. {
  33. //    CActor::~CActor();
  34. }
  35.  
  36. //-------------------------------------------------------------
  37.  
  38. bool CLabel::activate()
  39. {
  40.     if (!isActive())
  41.         m_timer.start();
  42.  
  43.     return CActor::activate();
  44. }
  45.  
  46. //-------------------------------------------------------------
  47.  
  48. void CLabel::onLeavingScreen()
  49. {
  50.     kill();
  51. }
  52.  
  53. //-------------------------------------------------------------
  54.  
  55. void __cdecl CLabel::setText(const char *format,...)
  56. {
  57.     va_list arglist;
  58.  
  59.     va_start(arglist,format);
  60.     vsprintf(m_text,format,arglist);
  61.     va_end(arglist);
  62.  
  63.     if (m_font)
  64.         m_offset = m_font->getStringSize(m_text) / gsCPoint(-2,-2);
  65.     else
  66.         m_offset = gsCPoint(0,0);
  67. }
  68.  
  69. //-------------------------------------------------------------
  70.  
  71. void CLabel::setTime(float seconds)
  72. {
  73.     m_time = seconds;
  74. }
  75.  
  76. //-------------------------------------------------------------
  77.  
  78. void CLabel::setFont(gsCFont *font)
  79. {
  80.     m_font = font;
  81. }
  82.  
  83. //-------------------------------------------------------------
  84.  
  85. bool CLabel::update(Controls *controls)
  86. {
  87.     if (m_timer.getTime() >= m_time) {
  88.         kill();
  89.         return true;
  90.         }
  91.  
  92.     m_position += m_velocity;
  93.  
  94.     return true;
  95. }
  96.  
  97. //-------------------------------------------------------------
  98.  
  99. bool CLabel::draw()
  100. {
  101.     if (m_font) {
  102.         m_font->setTextCursor(gsCPoint(m_position) + m_offset + m_scene->getMap()->getPosition());
  103.         m_font->printString(m_text);
  104.         }
  105.  
  106.     return true;
  107. }
  108.  
  109. //-------------------------------------------------------------
  110.  
  111.