Fortschritt.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. #include "Fortschritt.h"
  2. #include "Rahmen.h"
  3. #include "AlphaFeld.h"
  4. #include "Bild.h"
  5. #include "Schrift.h"
  6. #include "Scroll.h"
  7. #include "Text.h"
  8. using namespace Framework;
  9. // Inhalt der FBalken Klasse aus Fortschritt.h
  10. // Konstruktor
  11. FBalken::FBalken()
  12. : ZeichnungHintergrund(),
  13. maxAk( 0 ),
  14. ak( 0 ),
  15. fRahmen( 0 ),
  16. fBuffer( 0 ),
  17. fBgF( 0xFF000000 ),
  18. fBgBild( 0 ),
  19. schrift( 0 ),
  20. schriftFarbe( 0 ),
  21. schriftSize( 0 ),
  22. ref( 1 )
  23. {
  24. style = 0;
  25. }
  26. // Destructor
  27. FBalken::~FBalken()
  28. {
  29. if( fRahmen )
  30. fRahmen->release();
  31. if( fBuffer )
  32. fBuffer->release();
  33. if( fBgBild )
  34. fBgBild->release();
  35. if( schrift )
  36. schrift->release();
  37. }
  38. // nicht constant
  39. void FBalken::setAktionAnzahl( __int64 ak ) // setzt die anzahl der Aktionen
  40. {
  41. maxAk = ak;
  42. rend = 1;
  43. }
  44. void FBalken::aktionPlus( __int64 aktionen ) // mehrere Aktionen sind fertig
  45. {
  46. ak += aktionen;
  47. if( ak > maxAk )
  48. ak = maxAk;
  49. rend = 1;
  50. }
  51. void FBalken::reset() // setzt die fertigen Aktionen zurück
  52. {
  53. ak = 0;
  54. rend = 1;
  55. }
  56. void FBalken::setFRahmenZ( Rahmen *ram ) // setzt einen Zeiger zum Fertig Rahmen
  57. {
  58. if( fRahmen )
  59. fRahmen->release();
  60. fRahmen = ram;
  61. rend = 1;
  62. }
  63. void FBalken::setFRFarbe( int f ) // setzt die Fertig Rahmen Farbe
  64. {
  65. if( !fRahmen )
  66. fRahmen = new LRahmen();
  67. fRahmen->setFarbe( f );
  68. rend = 1;
  69. }
  70. void FBalken::setFRBreite( int br ) // setzt die Fertig Rahmen Breite
  71. {
  72. if( !fRahmen )
  73. fRahmen = new LRahmen();
  74. fRahmen->setRamenBreite( br );
  75. rend = 1;
  76. }
  77. void FBalken::setFAlphaFeldZ( AlphaFeld *af ) // setzt einen Zeiger zum Fertig Alpha Feld
  78. {
  79. if( fBuffer )
  80. fBuffer->release();
  81. fBuffer = af;
  82. rend = 1;
  83. }
  84. void FBalken::setFAFFarbe( int f ) // setzt die Fertig Alpha Feld Farbe
  85. {
  86. if( !fBuffer )
  87. fBuffer = new AlphaFeld();
  88. fBuffer->setFarbe( f );
  89. rend = 1;
  90. }
  91. void FBalken::setFAFStrength( int st ) // setzt die Stärke des Fertig Alpha Feldes
  92. {
  93. if( !fBuffer )
  94. fBuffer = new AlphaFeld();
  95. fBuffer->setStrength( st );
  96. rend = 1;
  97. }
  98. void FBalken::setFBgFarbe( int f ) // setzt einen Zeiger zur Fertig Hintergrund Farbe
  99. {
  100. fBgF = f;
  101. rend = 1;
  102. }
  103. void FBalken::setFBgBildZ( Bild *b ) // setzt das Fertig Hintergrund Bild
  104. {
  105. if( fBgBild )
  106. fBgBild->release();
  107. fBgBild = b;
  108. rend = 1;
  109. }
  110. void FBalken::setFBgBild( Bild *b ) // kopiert in das Fertig Hintergrund Bild
  111. {
  112. if( !fBgBild )
  113. fBgBild = new Bild();
  114. fBgBild->neuBild( b->getBreite(), b->getHeight(), 0 );
  115. fBgBild->drawBild( 0, 0, b->getBreite(), b->getHeight(), *b );
  116. b->release();
  117. rend = 1;
  118. }
  119. void FBalken::setSchriftZ( Schrift *s ) // setzt die Schrift
  120. {
  121. if( schrift )
  122. schrift->release();
  123. schrift = s;
  124. rend = 1;
  125. }
  126. void FBalken::setSFarbe( int f ) // setzt die Schrift Farbe
  127. {
  128. schriftFarbe = f;
  129. rend = 1;
  130. }
  131. void FBalken::setSSize( unsigned char gr ) // setzt die Schrift größe
  132. {
  133. schriftSize = gr;
  134. rend = 1;
  135. }
  136. void FBalken::render( Bild &zRObj ) // zeichnet nach zRObj
  137. {
  138. if( !hatStyle( Style::Sichtbar ) )
  139. return;
  140. lockZeichnung();
  141. removeStyle( Style::VScroll | Style::HScroll );
  142. ZeichnungHintergrund::render( zRObj );
  143. if( !zRObj.setDrawOptions( pos, gr ) )
  144. {
  145. unlockZeichnung();
  146. return;
  147. }
  148. int xx = 0;
  149. int yy = 0;
  150. int b = gr.x;
  151. int h = gr.y;
  152. if( hatStyle( Style::L_R ) )
  153. b = (int)( ( gr.x / 100.0 ) * getProzent() );
  154. else if( hatStyle( Style::R_L ) )
  155. {
  156. b = (int)( ( gr.x / 100.0 ) * getProzent() );
  157. xx -= b;
  158. }
  159. else if( hatStyle( Style::O_U ) )
  160. h = (int)( ( gr.y / 100.0 ) * getProzent() );
  161. else if( hatStyle( Style::U_O ) )
  162. {
  163. h = (int)( ( gr.y / 100.0 ) * getProzent() );
  164. yy -= h;
  165. }
  166. if( maxAk == 0 )
  167. b = 0, h = 0;
  168. if( !zRObj.setDrawOptions( xx, yy, b, h ) )
  169. {
  170. zRObj.releaseDrawOptions();
  171. unlockZeichnung();
  172. return;
  173. }
  174. int rbr = 0;
  175. if( hatStyle( Style::FRahmen ) && fRahmen )
  176. {
  177. fRahmen->setSize( b, h );
  178. fRahmen->render( zRObj );
  179. rbr = fRahmen->getRBreite();
  180. }
  181. if( hatStyle( Style::FFarbe ) )
  182. {
  183. if( hatStyle( Style::FAlpha ) )
  184. zRObj.alphaRegion( rbr, rbr, b - rbr * 2, h - rbr * 2, fBgF );
  185. else
  186. zRObj.fillRegion( rbr, rbr, b - rbr * 2, h - rbr * 2, fBgF );
  187. }
  188. if( hatStyle( Style::FBild ) && fBgBild )
  189. {
  190. if( hatStyle( Style::FAlpha ) )
  191. zRObj.alphaBildSkall( rbr, rbr, gr.x - rbr * 2, gr.y - rbr * 2, *fBgBild );
  192. else
  193. zRObj.alphaBildSkall( rbr, rbr, gr.x - rbr * 2, gr.y - rbr * 2, *fBgBild );
  194. }
  195. if( hatStyle( Style::FBuffered ) && fBuffer )
  196. {
  197. fBuffer->setSize( b - rbr * 2, h - rbr * 2 );
  198. fBuffer->render( zRObj );
  199. }
  200. zRObj.releaseDrawOptions();
  201. if( hatStyle( Style::Prozent ) && schrift )
  202. {
  203. schrift->setSchriftSize( schriftSize );
  204. Text txt;
  205. txt.append( (int)getProzent() );
  206. txt.append( "%" );
  207. schrift->setDrawPosition( rbr + ( gr.x - rbr * 2 ) / 2 - schrift->getTextBreite( &txt ) / 2, rbr + ( gr.y - rbr * 2 ) / 2 - schrift->getTextHeight( &txt ) / 2 );
  208. schrift->renderText( &txt, zRObj, schriftFarbe );
  209. }
  210. zRObj.releaseDrawOptions();
  211. unlockZeichnung();
  212. }
  213. // constant
  214. __int64 FBalken::getAktionAnzahl() const // gibt die Anzahl der Aktionen zurück
  215. {
  216. return maxAk;
  217. }
  218. double FBalken::getProzent() const // gibt die momentane Prozentzahl zurück
  219. {
  220. if( !maxAk )
  221. return 0;
  222. return (double)ak / ( (double)maxAk / 100.0 );
  223. }
  224. __int64 FBalken::getAktion() const // gibt die fertigen Aktionen zurück
  225. {
  226. return ak;
  227. }
  228. Rahmen *FBalken::getFRahmen() const // gibt den Fertig Rahmen zurück
  229. {
  230. if( fRahmen )
  231. return fRahmen->getThis();
  232. return 0;
  233. }
  234. Rahmen *FBalken::zFRahmen() const
  235. {
  236. return fRahmen;
  237. }
  238. AlphaFeld *FBalken::getFAlphaFeld() const // gibt das Fertig Alpha Feld zurück
  239. {
  240. if( fBuffer )
  241. return fBuffer->getThis();
  242. return 0;
  243. }
  244. AlphaFeld *FBalken::zFAlphaFeld() const
  245. {
  246. return fBuffer;
  247. }
  248. int FBalken::getFBgFarbe() const // gibt die Fertig Hintergrund Farbe zurück
  249. {
  250. return fBgF;
  251. }
  252. Bild *FBalken::getFBgBild() const // gibt das Fertig Hintergrund Bild zurück
  253. {
  254. if( fBgBild )
  255. return fBgBild->getThis();
  256. return 0;
  257. }
  258. Bild *FBalken::zFBgBild() const
  259. {
  260. return fBgBild;
  261. }
  262. Schrift *FBalken::getSchrift() const // gibt die Schrift zurück
  263. {
  264. if( schrift )
  265. return schrift->getThis();
  266. return 0;
  267. }
  268. Schrift *FBalken::zSchrift() const
  269. {
  270. return schrift;
  271. }
  272. int FBalken::getSFarbe() const // gibt die Schrift Farbe zurück
  273. {
  274. return schriftFarbe;
  275. }
  276. // Reference Counting
  277. FBalken *FBalken::getThis()
  278. {
  279. ++ref;
  280. return this;
  281. }
  282. FBalken *FBalken::release()
  283. {
  284. --ref;
  285. if( ref == 0 )
  286. delete this;
  287. return 0;
  288. }