Scroll.cpp 7.4 KB

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