Scroll.cpp 8.1 KB

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