Progress.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. #include "Progress.h"
  2. #include "AlphaField.h"
  3. #include "Image.h"
  4. #include "Border.h"
  5. #include "Font.h"
  6. #include "Scroll.h"
  7. #include "Text.h"
  8. using namespace Framework;
  9. // Contents of the FBalken class from Progress.h
  10. // Constructor
  11. FBalken::FBalken()
  12. : DrawableBackground(),
  13. maxAk(0),
  14. ak(0),
  15. fBorder(0),
  16. fBuffer(0),
  17. fBgF(0xFF000000),
  18. fBgImage(0),
  19. textRd(0),
  20. schriftFarbe(0),
  21. schriftSize(0)
  22. {
  23. style = 0;
  24. }
  25. // Destructor
  26. FBalken::~FBalken()
  27. {
  28. if (fBorder) fBorder->release();
  29. if (fBuffer) fBuffer->release();
  30. if (fBgImage) fBgImage->release();
  31. if (textRd) textRd->release();
  32. }
  33. // non-constant
  34. void FBalken::setAktionAnzahl(__int64 ak) // sets the number of actions
  35. {
  36. maxAk = ak;
  37. rend = 1;
  38. }
  39. void FBalken::aktionPlus(__int64 aktionen) // multiple actions are finished
  40. {
  41. ak += aktionen;
  42. if (ak > maxAk) ak = maxAk;
  43. rend = 1;
  44. }
  45. void FBalken::reset() // resets the completed actions
  46. {
  47. ak = 0;
  48. rend = 1;
  49. }
  50. void FBalken::setFBorderZ(
  51. Border* ram) // sets a pointer to the completion border
  52. {
  53. if (fBorder) fBorder->release();
  54. fBorder = ram;
  55. rend = 1;
  56. }
  57. void FBalken::setFRFarbe(int f) // sets the completion border color
  58. {
  59. if (!fBorder) fBorder = new LBorder();
  60. fBorder->setFarbe(f);
  61. rend = 1;
  62. }
  63. void FBalken::setFRBreite(int br) // sets the completion border width
  64. {
  65. if (!fBorder) fBorder = new LBorder();
  66. fBorder->setRamenBreite(br);
  67. rend = 1;
  68. }
  69. void FBalken::setFAlphaFeldZ(
  70. AlphaFeld* af) // sets a pointer to the completion AlphaFeld
  71. {
  72. if (fBuffer) fBuffer->release();
  73. fBuffer = af;
  74. rend = 1;
  75. }
  76. void FBalken::setFAFFarbe(int f) // sets the completion AlphaFeld color
  77. {
  78. if (!fBuffer) fBuffer = new AlphaFeld();
  79. fBuffer->setFarbe(f);
  80. rend = 1;
  81. }
  82. void FBalken::setFAFStrength(
  83. int st) // sets the strength of the completion AlphaFeld
  84. {
  85. if (!fBuffer) fBuffer = new AlphaFeld();
  86. fBuffer->setStrength(st);
  87. rend = 1;
  88. }
  89. void FBalken::setFBgFarbe(int f) // sets the completion background color
  90. {
  91. fBgF = f;
  92. rend = 1;
  93. }
  94. void FBalken::setFBgImageZ(Image* b) // sets the completion background image
  95. {
  96. if (fBgImage) fBgImage->release();
  97. fBgImage = b;
  98. rend = 1;
  99. }
  100. void FBalken::setFBgImage(Image* b) // copies into the completion background image
  101. {
  102. if (!fBgImage) fBgImage = new Image();
  103. fBgImage->neuImage(b->getBreite(), b->getHeight(), 0);
  104. fBgImage->drawImage(0, 0, b->getBreite(), b->getHeight(), *b);
  105. b->release();
  106. rend = 1;
  107. }
  108. void FBalken::setTextRendererZ(TextRenderer* textRd)
  109. {
  110. if (this->textRd) this->textRd->release();
  111. this->textRd = textRd;
  112. }
  113. void FBalken::setFontZ(Font* s) // sets the font
  114. {
  115. if (!textRd)
  116. textRd = new TextRenderer(s);
  117. else
  118. textRd->setFontZ(s);
  119. rend = 1;
  120. }
  121. void FBalken::setSFarbe(int f) // sets the font color
  122. {
  123. schriftFarbe = f;
  124. rend = 1;
  125. }
  126. void FBalken::setSSize(unsigned char gr) // sets the font size
  127. {
  128. schriftSize = gr;
  129. rend = 1;
  130. }
  131. void FBalken::render(Image& zRObj) // renders into zRObj
  132. {
  133. if (!hatStyle(Style::Sichtbar)) return;
  134. lockDrawable();
  135. removeStyle(Style::VScroll | Style::HScroll);
  136. DrawableBackground::render(zRObj);
  137. if (!zRObj.setDrawOptions(pos, gr))
  138. {
  139. unlockDrawable();
  140. return;
  141. }
  142. int xx = 0;
  143. int yy = 0;
  144. int b = gr.x;
  145. int h = gr.y;
  146. if (hatStyle(Style::L_R))
  147. b = (int)((gr.x / 100.0) * getProzent());
  148. else if (hatStyle(Style::R_L))
  149. {
  150. b = (int)((gr.x / 100.0) * getProzent());
  151. xx -= b;
  152. }
  153. else if (hatStyle(Style::O_U))
  154. h = (int)((gr.y / 100.0) * getProzent());
  155. else if (hatStyle(Style::U_O))
  156. {
  157. h = (int)((gr.y / 100.0) * getProzent());
  158. yy -= h;
  159. }
  160. if (maxAk == 0) b = 0, h = 0;
  161. if (!zRObj.setDrawOptions(xx, yy, b, h))
  162. {
  163. zRObj.releaseDrawOptions();
  164. unlockDrawable();
  165. return;
  166. }
  167. int rbr = 0;
  168. if (hatStyle(Style::FRahmen) && fBorder)
  169. {
  170. fBorder->setSize(b, h);
  171. fBorder->render(zRObj);
  172. rbr = fBorder->getRBreite();
  173. }
  174. if (hatStyle(Style::FFarbe))
  175. {
  176. if (hatStyle(Style::FAlpha))
  177. zRObj.alphaRegion(rbr, rbr, b - rbr * 2, h - rbr * 2, fBgF);
  178. else
  179. zRObj.fillRegion(rbr, rbr, b - rbr * 2, h - rbr * 2, fBgF);
  180. }
  181. if (hatStyle(Style::FImage) && fBgImage)
  182. {
  183. if (hatStyle(Style::FAlpha))
  184. zRObj.alphaImageSkall(
  185. rbr, rbr, gr.x - rbr * 2, gr.y - rbr * 2, *fBgImage);
  186. else
  187. zRObj.alphaImageSkall(
  188. rbr, rbr, gr.x - rbr * 2, gr.y - rbr * 2, *fBgImage);
  189. }
  190. if (hatStyle(Style::FBuffered) && fBuffer)
  191. {
  192. fBuffer->setSize(b - rbr * 2, h - rbr * 2);
  193. fBuffer->render(zRObj);
  194. }
  195. zRObj.releaseDrawOptions();
  196. if (hatStyle(Style::Aktionen) && textRd)
  197. {
  198. textRd->setSchriftSize(schriftSize);
  199. Text txt = Text("") + ak + "/" + maxAk;
  200. if (hatStyle(Style::Prozent))
  201. txt += Text(" (") + (int)(getProzent() + 0.5) + "%)";
  202. zRObj.alphaRegion(
  203. rbr + (gr.x - rbr * 2) / 2 - textRd->getTextBreite(txt) / 2,
  204. rbr + (gr.y - rbr * 2) / 2 - textRd->getTextHeight(txt) / 2,
  205. textRd->getTextBreite(txt),
  206. textRd->getTextHeight(txt),
  207. 0x70000000);
  208. textRd->renderText(
  209. rbr + (gr.x - rbr * 2) / 2 - textRd->getTextBreite(txt) / 2,
  210. rbr + (gr.y - rbr * 2) / 2 - textRd->getTextHeight(txt) / 2,
  211. txt,
  212. zRObj,
  213. schriftFarbe);
  214. }
  215. else if (hatStyle(Style::Prozent) && textRd)
  216. {
  217. textRd->setSchriftSize(schriftSize);
  218. Text txt;
  219. txt.append((int)(getProzent() + 0.5));
  220. txt.append("%");
  221. zRObj.alphaRegion(
  222. rbr + (gr.x - rbr * 2) / 2 - textRd->getTextBreite(txt) / 2,
  223. rbr + (gr.y - rbr * 2) / 2 - textRd->getTextHeight(txt) / 2,
  224. textRd->getTextBreite(txt),
  225. textRd->getTextHeight(txt),
  226. 0x70000000);
  227. textRd->renderText(
  228. rbr + (gr.x - rbr * 2) / 2 - textRd->getTextBreite(txt) / 2,
  229. rbr + (gr.y - rbr * 2) / 2 - textRd->getTextHeight(txt) / 2,
  230. txt,
  231. zRObj,
  232. schriftFarbe);
  233. }
  234. zRObj.releaseDrawOptions();
  235. unlockDrawable();
  236. }
  237. // constant
  238. __int64 FBalken::getAktionAnzahl() const // returns the number of actions
  239. {
  240. return maxAk;
  241. }
  242. double FBalken::getProzent() const // returns the current percentage
  243. {
  244. if (!maxAk) return 0;
  245. return (double)ak / ((double)maxAk / 100.0);
  246. }
  247. __int64 FBalken::getAktion() const // returns the completed actions
  248. {
  249. return ak;
  250. }
  251. Border* FBalken::getFBorder() const // returns the completion border
  252. {
  253. if (fBorder) return dynamic_cast<Border*>(fBorder->getThis());
  254. return 0;
  255. }
  256. Border* FBalken::zFBorder() const
  257. {
  258. return fBorder;
  259. }
  260. AlphaFeld* FBalken::getFAlphaFeld() const // returns the completion AlphaFeld
  261. {
  262. if (fBuffer) return dynamic_cast<AlphaFeld*>(fBuffer->getThis());
  263. return 0;
  264. }
  265. AlphaFeld* FBalken::zFAlphaFeld() const
  266. {
  267. return fBuffer;
  268. }
  269. int FBalken::getFBgFarbe() const // returns the completion background color
  270. {
  271. return fBgF;
  272. }
  273. Image* FBalken::getFBgImage() const // returns the completion background image
  274. {
  275. if (fBgImage) return dynamic_cast<Image*>(fBgImage->getThis());
  276. return 0;
  277. }
  278. Image* FBalken::zFBgImage() const
  279. {
  280. return fBgImage;
  281. }
  282. Font* FBalken::getFont() const // returns the font
  283. {
  284. if (textRd) return textRd->getFont();
  285. return 0;
  286. }
  287. Font* FBalken::zFont() const
  288. {
  289. return textRd ? textRd->zFont() : 0;
  290. }
  291. int FBalken::getSFarbe() const // returns the font color
  292. {
  293. return schriftFarbe;
  294. }