Scroll.cpp 8.0 KB

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