Scroll.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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 height )
  61. {
  62. data->scrollPos = height;
  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. // Destruktor
  136. VScrollBar::~VScrollBar()
  137. {}
  138. bool VScrollBar::doMausMessage( int x, int y, int br, int hi, MausEreignis &me )
  139. {
  140. bool ret = me.mx >= x && me.mx <= x + br && me.my >= y && me.my <= y + hi;
  141. knopfdruck = 0;
  142. if( me.verarbeitet )
  143. {
  144. mx = -1, my = -1;
  145. mp = 0;
  146. return ret;
  147. }
  148. if( me.id == ME_UScroll )
  149. {
  150. data->scrollPos -= klickScroll;
  151. if( data->scrollPos < 0 )
  152. data->scrollPos = 0;
  153. rend = 1;
  154. return ret;
  155. }
  156. if( me.id == ME_DScroll )
  157. {
  158. data->scrollPos += klickScroll;
  159. if( data->scrollPos > data->max - data->anzeige )
  160. data->scrollPos = data->max - data->anzeige;
  161. if( data->scrollPos < 0 )
  162. data->scrollPos = 0;
  163. rend = 1;
  164. return ret;
  165. }
  166. if( ret )
  167. mx = me.mx - x, my = me.my - y;
  168. else
  169. mx = -1, my = -1;
  170. if( me.id == ME_PLinks )
  171. mp = 1;
  172. if( me.id == ME_RLinks )
  173. mp = 0;
  174. if( mp )
  175. {
  176. if( mx >= 0 && my >= 0 )
  177. {
  178. if( my < br )
  179. {
  180. knopfdruck = 1;
  181. data->scrollPos -= klickScroll;
  182. }
  183. else if( my > hi - br )
  184. {
  185. knopfdruck = 2;
  186. data->scrollPos += klickScroll;
  187. }
  188. else
  189. data->scrollPos = (int)( ( data->max / ( hi - 2.0 * br ) ) * ( my - br ) ) - data->anzeige / 2;
  190. if( data->scrollPos > data->max - data->anzeige )
  191. data->scrollPos = data->max - data->anzeige;
  192. if( data->scrollPos < 0 )
  193. data->scrollPos = 0;
  194. rend = 1;
  195. }
  196. }
  197. return ret;
  198. }
  199. void VScrollBar::render( int x, int y, int br, int hi, Bild &zRObj ) const
  200. {
  201. if( bg )
  202. zRObj.alphaRegion( x, y, br, hi, bgFarbe );
  203. --br;
  204. --hi;
  205. zRObj.drawLinieH( x, y, br + 1, farbe );
  206. zRObj.drawLinieH( x, y + hi, br + 1, farbe );
  207. zRObj.drawLinieV( x, y + 1, hi - 1, farbe );
  208. zRObj.drawLinieV( x + br, y + 1, hi - 1, farbe );
  209. zRObj.drawLinieH( x + 1, y + br, br - 1, farbe );
  210. zRObj.drawLinieH( x + 1, y + hi - br, br - 1, farbe );
  211. ++br;
  212. ++hi;
  213. int st = (int)( data->scrollPos / ( data->max / ( hi - br * 2.0 ) ) );
  214. int end = (int)( ( hi - 2.0 * br ) / ( (double)data->max / data->anzeige ) );
  215. if( data->scrollPos > data->max - data->anzeige )
  216. data->scrollPos = data->max - data->anzeige;
  217. if( data->scrollPos < 0 )
  218. {
  219. data->scrollPos = 0;
  220. end = hi - br * 2;
  221. }
  222. zRObj.fillRegion( x + 1, y + br + st, br - 1, end, farbe );
  223. }
  224. // Inhalt der HScrollBar Klasse aus Scroll.h
  225. // Konstruktor
  226. HScrollBar::HScrollBar()
  227. : ScrollBar()
  228. {}
  229. // Destruktor
  230. HScrollBar::~HScrollBar()
  231. {}
  232. // nicht constant
  233. bool HScrollBar::doMausMessage( int x, int y, int br, int hi, MausEreignis &me )
  234. {
  235. bool ret = me.mx >= x && me.mx <= x + br && me.my >= y && me.my <= y + hi;
  236. knopfdruck = 0;
  237. if( me.verarbeitet )
  238. {
  239. mx = -1, my = -1;
  240. mp = 0;
  241. return ret;
  242. }
  243. if( me.id == ME_LScroll )
  244. {
  245. data->scrollPos -= klickScroll;
  246. if( data->scrollPos < 0 )
  247. data->scrollPos = 0;
  248. rend = 1;
  249. return ret;
  250. }
  251. if( me.id == ME_RScroll )
  252. {
  253. data->scrollPos += klickScroll;
  254. if( data->scrollPos > data->max - data->anzeige )
  255. data->scrollPos = data->max - data->anzeige;
  256. if( data->scrollPos < 0 )
  257. data->scrollPos = 0;
  258. rend = 1;
  259. return ret;
  260. }
  261. if( ret )
  262. mx = me.mx - x, my = me.my - y;
  263. else
  264. mx = -1, my = -1;
  265. if( me.id == ME_PLinks )
  266. mp = 1;
  267. if( me.id == ME_RLinks )
  268. mp = 0;
  269. if( mp )
  270. {
  271. if( mx >= 0 && my >= 0 )
  272. {
  273. if( mx < hi )
  274. {
  275. knopfdruck = 1;
  276. data->scrollPos -= klickScroll;
  277. }
  278. else if( mx > br - hi )
  279. {
  280. knopfdruck = 2;
  281. data->scrollPos += klickScroll;
  282. }
  283. else
  284. data->scrollPos = (int)( ( data->max / ( br - 2.0 * hi ) ) * ( mx - hi ) ) - data->anzeige / 2;
  285. if( data->scrollPos > data->max - data->anzeige )
  286. data->scrollPos = data->max - data->anzeige;
  287. if( data->scrollPos < 0 )
  288. data->scrollPos = 0;
  289. rend = 1;
  290. }
  291. }
  292. return ret;
  293. }
  294. void HScrollBar::render( int x, int y, int br, int hi, Bild &zRObj ) const
  295. {
  296. if( bg )
  297. zRObj.alphaRegion( x, y, br, hi, bgFarbe );
  298. --br;
  299. --hi;
  300. zRObj.drawLinieV( x, y, hi + 1, farbe );
  301. zRObj.drawLinieV( x + br, y, hi + 1, farbe );
  302. zRObj.drawLinieH( x + 1, y, br - 1, farbe );
  303. zRObj.drawLinieH( x + 1, y + hi, br - 1, farbe );
  304. zRObj.drawLinieV( x + hi, y + 1, hi - 1, farbe );
  305. zRObj.drawLinieV( x + br - hi, y + 1, hi - 1, farbe );
  306. ++br;
  307. ++hi;
  308. int st = (int)( data->scrollPos / ( data->max / ( br - hi * 2.0 ) ) );
  309. int end = (int)( ( br - 2.0 * hi ) / ( (double)data->max / data->anzeige ) );
  310. if( data->scrollPos > data->max - data->anzeige )
  311. data->scrollPos = data->max - data->anzeige;
  312. if( data->scrollPos < 0 )
  313. {
  314. data->scrollPos = 0;
  315. end = br - hi * 2;
  316. }
  317. zRObj.fillRegion( x + hi + st, y + 1, end, hi - 1, farbe );
  318. }