Progress.cpp 7.8 KB

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