ToolTip.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #include "ToolTip.h"
  2. #include "TextFeld.h"
  3. #include "Text.h"
  4. #include "AlphaFeld.h"
  5. #include "Bild.h"
  6. #include "MausEreignis.h"
  7. #include "Schrift.h"
  8. #include "Bildschirm.h"
  9. using namespace Framework;
  10. // Inhalt der ToolTip Klasse aus ToolTip.h
  11. // Konstruktor
  12. ToolTip::ToolTip( Bildschirm *zScreen )
  13. : TextFeld(),
  14. size( 0, 0 ),
  15. animationSpeed( 250 ),
  16. warten( 1 ),
  17. wartenCount( 0 ),
  18. tval( 0 ),
  19. mausIn( 0 ),
  20. alpha( 0 ),
  21. sichtbar( 0 ),
  22. zeichnen( 0 ),
  23. bildschirm( zScreen )
  24. {
  25. bildschirm->addToolTip( ( ToolTip* )this->getThis() );
  26. }
  27. // Destruktor
  28. ToolTip::~ToolTip()
  29. {}
  30. // nicht constant
  31. void ToolTip::setSize( int breite, int height )
  32. {
  33. size.x = breite;
  34. size.y = height;
  35. rend = 1;
  36. }
  37. void ToolTip::setSize( Punkt &gr )
  38. {
  39. size = gr;
  40. rend = 1;
  41. }
  42. void ToolTip::setWarten( double warten )
  43. {
  44. this->warten = warten;
  45. }
  46. void ToolTip::setAnimationSpeed( double speed )
  47. {
  48. animationSpeed = speed;
  49. }
  50. void ToolTip::setMausIn( bool mausIn )
  51. {
  52. if( this->mausIn != mausIn )
  53. rend = 1;
  54. this->mausIn = mausIn;
  55. if( !mausIn )
  56. sichtbar = 0;
  57. }
  58. void ToolTip::wartenReset()
  59. {
  60. wartenCount = 0;
  61. }
  62. void ToolTip::setZeichnen()
  63. {
  64. zeichnen = 1;
  65. }
  66. bool ToolTip::tick( double tickVal )
  67. {
  68. this->tval += tickVal * animationSpeed;
  69. int val = ( int )this->tval;
  70. if( val < 1 )
  71. {
  72. bool ret = rend;
  73. rend = 0;
  74. return ret;
  75. }
  76. this->tval -= val;
  77. if( !sichtbar )
  78. {
  79. if( alpha )
  80. {
  81. if( alpha - val < 0 )
  82. alpha = 0;
  83. else
  84. alpha = (unsigned char)( alpha - val );
  85. rend = 1;
  86. }
  87. if( mausIn )
  88. {
  89. wartenCount += tickVal;
  90. if( wartenCount >= warten )
  91. {
  92. sichtbar = 1;
  93. wartenCount = 0;
  94. alpha = 0xFF;
  95. TextFeld::setSize( 0, 0 );
  96. }
  97. }
  98. else
  99. wartenCount = 0;
  100. }
  101. else
  102. {
  103. if( getBreite() != size.x )
  104. {
  105. TextFeld::setSize( getBreite() + val, getSchriftSize() + getRahmenBreite() * 2 );
  106. if( getBreite() > size.x )
  107. TextFeld::setSize( size.x, getHeight() );
  108. rend = 1;
  109. }
  110. else if( getHeight() != size.y )
  111. {
  112. TextFeld::setSize( getBreite(), getHeight() + val );
  113. if( getHeight() > size.y )
  114. TextFeld::setSize( getBreite(), size.y );
  115. rend = 1;
  116. }
  117. }
  118. return TextFeld::tick( tickVal );
  119. }
  120. void ToolTip::doMausEreignis( MausEreignis &me )
  121. {
  122. if( mausIn )
  123. pos.x = me.mx, pos.y = me.my + 15;
  124. sichtbar = 0;
  125. if( alpha )
  126. rend = 1;
  127. }
  128. void ToolTip::render( Bild &zRObj )
  129. {
  130. if( alpha && zeichnen )
  131. {
  132. zSchrift()->lock();
  133. zSchrift()->setSchriftSize( getSchriftSize() );
  134. size = Punkt( zSchrift()->getTextBreite( zText() ) + getRahmenBreite() * 2, zSchrift()->getTextHeight( zText() ) + getRahmenBreite() * 2 );
  135. zSchrift()->unlock();
  136. zRObj.setAlpha( alpha );
  137. setPosition( pos );
  138. if( getX() + getBreite() > zRObj.getBreite() )
  139. setPosition( getX() - ( getX() + getBreite() - zRObj.getBreite() ), getY() );
  140. if( getY() + getHeight() > zRObj.getHeight() )
  141. setPosition( getX(), getY() - ( getY() + getHeight() - zRObj.getHeight() ) );
  142. TextFeld::render( zRObj );
  143. zRObj.releaseAlpha();
  144. zeichnen = 0;
  145. }
  146. }
  147. // constant
  148. Bildschirm *ToolTip::zBildschirm() const
  149. {
  150. return bildschirm;
  151. }
  152. // Reference Counting
  153. TextFeld *ToolTip::getThis()
  154. {
  155. ++ref;
  156. return this;
  157. }
  158. TextFeld *ToolTip::release()
  159. {
  160. --ref;
  161. if( !ref )
  162. {
  163. delete this;
  164. return 0;
  165. }
  166. if( ref == 1 )
  167. {
  168. if( !bildschirm->removeToolTip( this ) )
  169. delete this;
  170. }
  171. return 0;
  172. }