Scroll.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. #include "Scroll.h"
  2. #include "Bild.h"
  3. #include "MausEreignis.h"
  4. using namespace Framework;
  5. // Inhalt der VScrollBar Klasse aus Scroll.h
  6. // Konstruktor
  7. ScrollBar::ScrollBar()
  8. : ReferenceCounter(),
  9. data(new ScrollData()),
  10. knopfdruck(0),
  11. farbe(0xFF808080),
  12. bgFarbe(0xFF000000),
  13. bg(0),
  14. klickScroll(10),
  15. mx(-1),
  16. my(-1),
  17. mp(0),
  18. rend(0)
  19. {}
  20. // Destruktor
  21. ScrollBar::~ScrollBar()
  22. {
  23. delete data;
  24. }
  25. // nicht constant
  26. void ScrollBar::setFarbe(int fc)
  27. {
  28. farbe = fc;
  29. rend = 1;
  30. }
  31. void ScrollBar::setBgFarbe(int fc, bool bgF)
  32. {
  33. bgFarbe = fc;
  34. bg = bgF;
  35. rend = 1;
  36. }
  37. void ScrollBar::update(int maxGr, int anzeigeGr)
  38. {
  39. if (data->max != maxGr || data->anzeige != anzeigeGr)
  40. {
  41. data->max = maxGr, data->anzeige = anzeigeGr;
  42. rend = 1;
  43. }
  44. if (data->scrollPos > data->max - data->anzeige
  45. && data->max - data->anzeige >= 0)
  46. {
  47. data->scrollPos = data->max - data->anzeige;
  48. rend = 1;
  49. }
  50. if (data->scrollPos < 0)
  51. {
  52. data->scrollPos = 0;
  53. rend = 1;
  54. }
  55. }
  56. void ScrollBar::setKlickScroll(int ks)
  57. {
  58. klickScroll = ks;
  59. rend = 1;
  60. }
  61. void ScrollBar::scroll(int height)
  62. {
  63. data->scrollPos = height;
  64. if (data->scrollPos > data->max - data->anzeige)
  65. data->scrollPos = data->max - data->anzeige;
  66. if (data->scrollPos < 0) data->scrollPos = 0;
  67. rend = 1;
  68. }
  69. bool ScrollBar::getRend()
  70. {
  71. if (knopfdruck == 1)
  72. {
  73. int tmp = data->scrollPos;
  74. data->scrollPos -= klickScroll;
  75. if (data->scrollPos > data->max - data->anzeige)
  76. data->scrollPos = data->max - data->anzeige;
  77. if (data->scrollPos < 0) data->scrollPos = 0;
  78. if (tmp != data->scrollPos) rend = 1;
  79. }
  80. if (knopfdruck == 2)
  81. {
  82. int tmp = data->scrollPos;
  83. data->scrollPos += klickScroll;
  84. if (data->scrollPos > data->max - data->anzeige)
  85. data->scrollPos = data->max - data->anzeige;
  86. if (data->scrollPos < 0) data->scrollPos = 0;
  87. if (tmp != data->scrollPos) rend = 1;
  88. }
  89. bool ret = rend;
  90. rend = 0;
  91. return ret;
  92. }
  93. // const
  94. ScrollData* ScrollBar::getScrollData() const
  95. {
  96. return data;
  97. }
  98. int ScrollBar::getKlickScroll() const
  99. {
  100. return klickScroll;
  101. }
  102. int ScrollBar::getFarbe() const
  103. {
  104. return farbe;
  105. }
  106. int ScrollBar::getBgFarbe() const
  107. {
  108. return bg ? bgFarbe : 0;
  109. }
  110. int ScrollBar::getScroll() const
  111. {
  112. return data->scrollPos;
  113. }
  114. // Inhalt der VScrollBar Klasse
  115. VScrollBar::VScrollBar()
  116. : ScrollBar()
  117. {}
  118. // Destruktor
  119. VScrollBar::~VScrollBar() {}
  120. bool VScrollBar::doMausMessage(int x, int y, int br, int hi, MausEreignis& me)
  121. {
  122. if (me.id == ME_Leaves)
  123. {
  124. mp = 0;
  125. mx = -1;
  126. my = -1;
  127. }
  128. bool ret = me.mx >= x && me.mx <= x + br && me.my >= y && me.my <= y + hi;
  129. knopfdruck = 0;
  130. if (me.verarbeitet)
  131. {
  132. mx = -1, my = -1;
  133. mp = 0;
  134. return ret;
  135. }
  136. if (me.id == ME_UScroll)
  137. {
  138. data->scrollPos -= klickScroll;
  139. if (data->scrollPos < 0) data->scrollPos = 0;
  140. rend = 1;
  141. return ret;
  142. }
  143. if (me.id == ME_DScroll)
  144. {
  145. data->scrollPos += klickScroll;
  146. if (data->scrollPos > data->max - data->anzeige)
  147. data->scrollPos = data->max - data->anzeige;
  148. if (data->scrollPos < 0) data->scrollPos = 0;
  149. rend = 1;
  150. return ret;
  151. }
  152. if (ret)
  153. mx = me.mx - x, my = me.my - y;
  154. else
  155. mx = -1, my = -1;
  156. if (me.id == ME_PLinks) mp = 1;
  157. if (me.id == ME_RLinks) mp = 0;
  158. if (mp)
  159. {
  160. if (mx >= 0 && my >= 0)
  161. {
  162. if (my < br)
  163. {
  164. knopfdruck = 1;
  165. data->scrollPos -= klickScroll;
  166. }
  167. else if (my > hi - br)
  168. {
  169. knopfdruck = 2;
  170. data->scrollPos += klickScroll;
  171. }
  172. else
  173. data->scrollPos
  174. = (int)((data->max / (hi - 2.0 * br)) * (my - br))
  175. - data->anzeige / 2;
  176. if (data->scrollPos > data->max - data->anzeige)
  177. data->scrollPos = data->max - data->anzeige;
  178. if (data->scrollPos < 0) data->scrollPos = 0;
  179. rend = 1;
  180. }
  181. }
  182. return ret;
  183. }
  184. void VScrollBar::render(int x, int y, int br, int hi, Bild& zRObj) const
  185. {
  186. if (bg) zRObj.alphaRegion(x, y, br, hi, bgFarbe);
  187. --br;
  188. --hi;
  189. zRObj.drawLinieH(x, y, br + 1, farbe);
  190. zRObj.drawLinieH(x, y + hi, br + 1, farbe);
  191. zRObj.drawLinieV(x, y + 1, hi - 1, farbe);
  192. zRObj.drawLinieV(x + br, y + 1, hi - 1, farbe);
  193. zRObj.drawLinieH(x + 1, y + br, br - 1, farbe);
  194. zRObj.drawLinieH(x + 1, y + hi - br, br - 1, farbe);
  195. ++br;
  196. ++hi;
  197. int st = (int)(data->scrollPos / (data->max / (hi - br * 2.0)));
  198. int end = (int)((hi - 2.0 * br) / ((double)data->max / data->anzeige));
  199. if (data->scrollPos > data->max - data->anzeige)
  200. data->scrollPos = data->max - data->anzeige;
  201. if (data->scrollPos < 0)
  202. {
  203. data->scrollPos = 0;
  204. end = hi - br * 2;
  205. }
  206. zRObj.fillRegion(x + 1, y + br + st, br - 1, end, farbe);
  207. }
  208. // Inhalt der HScrollBar Klasse aus Scroll.h
  209. // Konstruktor
  210. HScrollBar::HScrollBar()
  211. : ScrollBar()
  212. {}
  213. // Destruktor
  214. HScrollBar::~HScrollBar() {}
  215. // nicht constant
  216. bool HScrollBar::doMausMessage(int x, int y, int br, int hi, MausEreignis& me)
  217. {
  218. if (me.id == ME_Leaves)
  219. {
  220. mp = 0;
  221. mx = -1;
  222. my = -1;
  223. }
  224. bool ret = me.mx >= x && me.mx <= x + br && me.my >= y && me.my <= y + hi;
  225. knopfdruck = 0;
  226. if (me.verarbeitet)
  227. {
  228. mx = -1, my = -1;
  229. mp = 0;
  230. return ret;
  231. }
  232. if (me.id == ME_LScroll)
  233. {
  234. data->scrollPos -= klickScroll;
  235. if (data->scrollPos < 0) data->scrollPos = 0;
  236. rend = 1;
  237. return ret;
  238. }
  239. if (me.id == ME_RScroll)
  240. {
  241. data->scrollPos += klickScroll;
  242. if (data->scrollPos > data->max - data->anzeige)
  243. data->scrollPos = data->max - data->anzeige;
  244. if (data->scrollPos < 0) data->scrollPos = 0;
  245. rend = 1;
  246. return ret;
  247. }
  248. if (ret)
  249. mx = me.mx - x, my = me.my - y;
  250. else
  251. mx = -1, my = -1;
  252. if (me.id == ME_PLinks) mp = 1;
  253. if (me.id == ME_RLinks) mp = 0;
  254. if (mp)
  255. {
  256. if (mx >= 0 && my >= 0)
  257. {
  258. if (mx < hi)
  259. {
  260. knopfdruck = 1;
  261. data->scrollPos -= klickScroll;
  262. }
  263. else if (mx > br - hi)
  264. {
  265. knopfdruck = 2;
  266. data->scrollPos += klickScroll;
  267. }
  268. else
  269. data->scrollPos
  270. = (int)((data->max / (br - 2.0 * hi)) * (mx - hi))
  271. - data->anzeige / 2;
  272. if (data->scrollPos > data->max - data->anzeige)
  273. data->scrollPos = data->max - data->anzeige;
  274. if (data->scrollPos < 0) data->scrollPos = 0;
  275. rend = 1;
  276. }
  277. }
  278. return ret;
  279. }
  280. void HScrollBar::render(int x, int y, int br, int hi, Bild& zRObj) const
  281. {
  282. if (bg) zRObj.alphaRegion(x, y, br, hi, bgFarbe);
  283. --br;
  284. --hi;
  285. zRObj.drawLinieV(x, y, hi + 1, farbe);
  286. zRObj.drawLinieV(x + br, y, hi + 1, farbe);
  287. zRObj.drawLinieH(x + 1, y, br - 1, farbe);
  288. zRObj.drawLinieH(x + 1, y + hi, br - 1, farbe);
  289. zRObj.drawLinieV(x + hi, y + 1, hi - 1, farbe);
  290. zRObj.drawLinieV(x + br - hi, y + 1, hi - 1, farbe);
  291. ++br;
  292. ++hi;
  293. int st = (int)(data->scrollPos / (data->max / (br - hi * 2.0)));
  294. int end = (int)((br - 2.0 * hi) / ((double)data->max / data->anzeige));
  295. if (data->scrollPos > data->max - data->anzeige)
  296. data->scrollPos = data->max - data->anzeige;
  297. if (data->scrollPos < 0)
  298. {
  299. data->scrollPos = 0;
  300. end = br - hi * 2;
  301. }
  302. zRObj.fillRegion(x + hi + st, y + 1, end, hi - 1, farbe);
  303. }