Scroll.cpp 8.2 KB

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