Drawing.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  1. #include "Drawing.h"
  2. #include "AlphaField.h"
  3. #include "Image.h"
  4. #include "Screen.h"
  5. #include "Globals.h"
  6. #include "MouseEvent.h"
  7. #include "Border.h"
  8. #include "Font.h"
  9. #include "Scroll.h"
  10. #include "KeyboardEvent.h"
  11. #include "Text.h"
  12. #include "TextField.h"
  13. #include "ToolTip.h"
  14. #include "UIInitialization.h"
  15. #ifdef WIN32
  16. # include <Windows.h>
  17. #endif
  18. using namespace Framework;
  19. // Contents of the Drawable class from Drawing.h
  20. // Constructor
  21. Drawable::Drawable()
  22. : ReferenceCounter(),
  23. pos(0, 0),
  24. gr(0, 0),
  25. makParam(0),
  26. takParam(0),
  27. mak(0),
  28. tak(0),
  29. nmakParam(0),
  30. ntakParam(0),
  31. nMak(0),
  32. nTak(0),
  33. mausIn(0),
  34. toolTip(0),
  35. style(0),
  36. rend(0),
  37. onNeedToolTip(0),
  38. toolTipRequested(0)
  39. {}
  40. // Destructor
  41. Drawable::~Drawable()
  42. {
  43. if (toolTip) toolTip->release();
  44. }
  45. void Drawable::doMausEreignis(MausEreignis& me, bool userRet)
  46. {
  47. me.verarbeitet = userRet;
  48. }
  49. // non-constant
  50. void Drawable::setRender()
  51. {
  52. rend = 1;
  53. }
  54. void Drawable::setToolTipText(
  55. const char* txt, Bildschirm* zScreen, Schrift* zSchrift)
  56. {
  57. if (!txt)
  58. toolTip = (ToolTip*)toolTip->release();
  59. else
  60. {
  61. if (!toolTip)
  62. {
  63. toolTip = new ToolTip(zScreen);
  64. toolTip->addStyle(DrawableBackground::Style::Hintergrund
  65. | DrawableBackground::Style::HAlpha
  66. | DrawableBackground::Style::Rahmen
  67. | DrawableBackground::Style::Sichtbar);
  68. toolTip->setHintergrundFarbe(0xA0000000);
  69. toolTip->setRahmenFarbe(0xFFFFFFFF);
  70. toolTip->setRahmenBreite(1);
  71. if (mausIn && toolTip) toolTip->setMausIn(1);
  72. }
  73. UIInit init = defaultUI(zSchrift, zScreen);
  74. TextFeld* t = init.createTextFeld(init.initParam);
  75. t->setText(txt);
  76. t->setSize(t->zTextRenderer()->getTextBreite(txt),
  77. t->zTextRenderer()->getTextHeight(txt));
  78. toolTip->addMember(t);
  79. }
  80. toolTipRequested = 0;
  81. }
  82. // sets a function that creates a tooltip on first use
  83. // if one does not exist yet
  84. // initToolTip: the function
  85. void Drawable::setNeedToolTipEvent(
  86. std::function<bool(Drawable*, Punkt localPos)> onNeedToolTip)
  87. {
  88. this->onNeedToolTip = onNeedToolTip;
  89. }
  90. // sets the tooltip
  91. // tt: the tooltip
  92. void Drawable::setToolTipZ(ToolTip* tt)
  93. {
  94. if (toolTip) toolTip->release();
  95. toolTip = tt;
  96. if (mausIn && toolTip) toolTip->setMausIn(1);
  97. toolTipRequested = 0;
  98. }
  99. void Drawable::lockDrawable()
  100. {
  101. cs.lock();
  102. }
  103. void Drawable::unlockDrawable()
  104. {
  105. cs.unlock();
  106. }
  107. void Drawable::setMausEreignisParameter(
  108. void* p) // sets the mouse event parameter
  109. {
  110. makParam = p;
  111. }
  112. void Drawable::setTastaturEreignisParameter(
  113. void* p) // sets the keyboard event parameter
  114. {
  115. takParam = p;
  116. }
  117. void Drawable::setMausEreignis(MausAktion ak) // sets the mouse event
  118. {
  119. mak = ak;
  120. }
  121. void Framework::Drawable::addMausEreignis(MausAktion ak)
  122. {
  123. if (!mak)
  124. {
  125. mak = ak;
  126. }
  127. else
  128. {
  129. MausAktion old = mak;
  130. mak = [old, ak](void* p, void* o, MausEreignis me) {
  131. return old(p, o, me) && ak(p, o, me);
  132. };
  133. }
  134. }
  135. void Drawable::setTastaturEreignis(
  136. TastaturAktion ak) // sets the keyboard event
  137. {
  138. tak = ak;
  139. }
  140. void Framework::Drawable::addTastaturEreignis(TastaturAktion ak)
  141. {
  142. if (!tak)
  143. {
  144. tak = ak;
  145. }
  146. else
  147. {
  148. TastaturAktion old = tak;
  149. tak = [old, ak](void* p, void* o, TastaturEreignis te) {
  150. return old(p, o, te) && ak(p, o, te);
  151. };
  152. }
  153. }
  154. void Drawable::setNMausEreignisParameter(
  155. void* p) // sets the mouse event parameter
  156. {
  157. nmakParam = p;
  158. }
  159. void Drawable::setNTastaturEreignisParameter(
  160. void* p) // sets the keyboard event parameter
  161. {
  162. ntakParam = p;
  163. }
  164. void Drawable::setNMausEreignis(MausAktion ak) // sets the mouse event
  165. {
  166. nMak = ak;
  167. }
  168. void Drawable::setNTastaturEreignis(
  169. TastaturAktion ak) // sets the keyboard event
  170. {
  171. nTak = ak;
  172. }
  173. void Drawable::doPublicMausEreignis(MausEreignis& me) // calls Mak
  174. {
  175. bool lock = hatStyle(Style::MELockDrawable);
  176. if (lock) lockDrawable();
  177. bool inside = istPunktInnen(me.mx, me.my);
  178. if (!me.insideParent || me.verarbeitet || !inside)
  179. {
  180. if (mausIn)
  181. {
  182. mausIn = 0;
  183. if (toolTip) toolTip->setMausIn(0);
  184. MausEreignis me2;
  185. me2.id = ME_Leaves;
  186. me2.mx = me.mx - pos.x;
  187. me2.my = me.my - pos.y;
  188. me2.verarbeitet = 0;
  189. me2.insideParent = me.insideParent;
  190. bool userRet = mak && mak(makParam, this, me2);
  191. doMausEreignis(me2, userRet);
  192. }
  193. }
  194. if (!inside && me.id == ME_PLinks) removeStyle(Style::Fokus);
  195. if ((me.verarbeitet && hatStyleNicht(Style::MEIgnoreVerarbeitet))
  196. || (!inside && hatStyleNicht(Style::MEIgnoreInside))
  197. || (hatStyleNicht(Style::Sichtbar)
  198. && hatStyleNicht(Style::MEIgnoreSichtbar)))
  199. {
  200. if (lock) unlockDrawable();
  201. return;
  202. }
  203. if (inside && me.id == ME_PLinks) addStyle(Style::Fokus);
  204. if (me.insideParent && !mausIn && me.id != ME_Leaves && inside
  205. && !me.verarbeitet && hatStyle(Style::Sichtbar))
  206. {
  207. mausIn = 1;
  208. if (toolTip)
  209. toolTip->setMausIn(1);
  210. else if (onNeedToolTip && !toolTipRequested)
  211. {
  212. toolTipRequested
  213. = onNeedToolTip(this, Punkt(me.mx - pos.x, me.my - pos.y));
  214. }
  215. MausEreignis me2;
  216. me2.id = ME_Betritt;
  217. me2.mx = me.mx - pos.x;
  218. me2.my = me.my - pos.y;
  219. me2.verarbeitet = 0;
  220. me2.insideParent = 1;
  221. bool userRet = mak && mak(makParam, this, me2);
  222. doMausEreignis(me2, userRet);
  223. }
  224. else if (me.insideParent && mausIn && me.id != ME_Leaves && inside
  225. && !me.verarbeitet && hatStyle(Style::Sichtbar) && !toolTip
  226. && onNeedToolTip && !toolTipRequested)
  227. {
  228. toolTipRequested
  229. = onNeedToolTip(this, Punkt(me.mx - pos.x, me.my - pos.y));
  230. }
  231. Punkt old = Punkt(me.mx, me.my);
  232. me.mx -= pos.x, me.my -= pos.y;
  233. if (me.insideParent || hatStyle(Style::MEIgnoreParentInside))
  234. {
  235. bool userRet = hatStyle(Style::Erlaubt)
  236. && (me.verarbeitet || !me.insideParent
  237. || (inside && mak && mak(makParam, this, me)));
  238. bool vera = me.verarbeitet;
  239. doMausEreignis(me, userRet);
  240. if (nMak && me.verarbeitet && !vera && hatStyle(Style::Erlaubt)
  241. && me.insideParent && inside)
  242. me.verarbeitet = nMak(nmakParam, this, me);
  243. }
  244. me.mx = old.x, me.my = old.y;
  245. if (lock) unlockDrawable();
  246. }
  247. void Drawable::doTastaturEreignis(TastaturEreignis& te) // calls Tak
  248. {
  249. if (te.verarbeitet) return;
  250. if (tak) te.verarbeitet |= tak(takParam, this, te);
  251. if (nTak && te.verarbeitet) te.verarbeitet = nTak(ntakParam, this, te);
  252. }
  253. void Drawable::setPosition(const Punkt& pos) // sets the position
  254. {
  255. lockDrawable();
  256. if (this->pos != pos) rend = 1;
  257. this->pos = pos;
  258. unlockDrawable();
  259. }
  260. void Drawable::setX(int xPos)
  261. {
  262. lockDrawable();
  263. if (pos.x != xPos)
  264. {
  265. rend = 1;
  266. pos.x = xPos;
  267. }
  268. unlockDrawable();
  269. }
  270. void Drawable::setY(int yPos)
  271. {
  272. lockDrawable();
  273. if (pos.y != yPos)
  274. {
  275. rend = 1;
  276. pos.y = yPos;
  277. }
  278. unlockDrawable();
  279. }
  280. void Drawable::setSize(const Punkt& gr) // sets the size
  281. {
  282. lockDrawable();
  283. if (this->gr != gr) rend = 1;
  284. this->gr = gr;
  285. unlockDrawable();
  286. }
  287. void Drawable::setPosition(int x, int y) // sets the position
  288. {
  289. setPosition(Punkt(x, y));
  290. }
  291. void Drawable::setSize(int x, int y) // sets the size
  292. {
  293. setSize(Punkt(x, y));
  294. }
  295. void Drawable::setWidth(int width)
  296. {
  297. lockDrawable();
  298. if (this->gr.x != width) rend = 1;
  299. gr.x = width;
  300. unlockDrawable();
  301. }
  302. void Drawable::setHeight(int height)
  303. {
  304. lockDrawable();
  305. if (this->gr.y != height) rend = 1;
  306. gr.y = height;
  307. unlockDrawable();
  308. }
  309. bool Drawable::tick(double tickval)
  310. {
  311. bool r = rend;
  312. rend = 0;
  313. return r;
  314. }
  315. void Drawable::setStyle(__int64 style) // sets the style of the text field
  316. {
  317. if (this->style != style)
  318. {
  319. this->style = style;
  320. rend = 1;
  321. }
  322. }
  323. void Drawable::setStyle(__int64 style, bool add_remove)
  324. {
  325. if (add_remove && (this->style | style) != this->style)
  326. {
  327. this->style |= style;
  328. rend = 1;
  329. }
  330. else if (!add_remove && (this->style & ~style) != this->style)
  331. {
  332. if (toolTip && (style | Style::Sichtbar) == style)
  333. toolTip->setMausIn(0);
  334. this->style &= ~style;
  335. rend = 1;
  336. }
  337. }
  338. void Drawable::addStyle(__int64 style)
  339. {
  340. if ((this->style | style) != this->style)
  341. {
  342. this->style |= style;
  343. rend = 1;
  344. }
  345. }
  346. void Drawable::removeStyle(__int64 style)
  347. {
  348. if ((this->style & ~style) != this->style)
  349. {
  350. if (toolTip && (style | Style::Sichtbar) == style)
  351. toolTip->setMausIn(0);
  352. this->style &= ~style;
  353. rend = 1;
  354. }
  355. }
  356. void Drawable::render(Bild& zRObj)
  357. {
  358. if (toolTip && (style | Style::Sichtbar) == style) toolTip->setZeichnen();
  359. }
  360. // constant
  361. bool Drawable::hatMausEreignis() const // checks if Mak is set
  362. {
  363. return mak != 0;
  364. }
  365. bool Drawable::hatTastaturEreignis() const // checks if Tak is set
  366. {
  367. return tak != 0;
  368. }
  369. const Punkt& Drawable::getPosition() const // returns the position
  370. {
  371. return pos;
  372. }
  373. const Punkt& Drawable::getSize() const // returns the size
  374. {
  375. return gr;
  376. }
  377. int Drawable::getBreite() const // returns the width
  378. {
  379. return gr.x;
  380. }
  381. int Drawable::getHeight() const // returns the height
  382. {
  383. return gr.y;
  384. }
  385. // Returns the width of the interior area of the drawing in pixels
  386. int Drawable::getInnenBreite() const
  387. {
  388. return gr.x;
  389. }
  390. // Returns the height of the interior area of the drawing in pixels
  391. int Drawable::getInnenHeight() const
  392. {
  393. return gr.y;
  394. }
  395. int Drawable::getX() const // returns X
  396. {
  397. return pos.x;
  398. }
  399. int Drawable::getY() const // returns Y
  400. {
  401. return pos.y;
  402. }
  403. // Checks if a point is inside this object
  404. // p: the point
  405. // return: 1 if the point is inside, 0 otherwise
  406. bool Drawable::istPunktInnen(Punkt p) const
  407. {
  408. return istPunktInnen(p.x, p.y);
  409. }
  410. // Checks if a point is inside this object
  411. // x: the x coordinate of the point
  412. // y: the y coordinate of the point
  413. // return: 1 if the point is inside, 0 otherwise
  414. bool Drawable::istPunktInnen(int x, int y) const
  415. {
  416. return x >= pos.x && x <= pos.x + gr.x && y >= pos.y && y <= pos.y + gr.y;
  417. }
  418. ToolTip* Drawable::getToolTip() const // returns the ToolTip text
  419. {
  420. return dynamic_cast<ToolTip*>(toolTip->getThis());
  421. }
  422. ToolTip* Drawable::zToolTip() const
  423. {
  424. return toolTip;
  425. }
  426. bool Drawable::hatStyle(__int64 style) const // checks if style is present
  427. {
  428. return (this->style | style) == this->style;
  429. }
  430. bool Drawable::hatStyleNicht(
  431. __int64 style) const // checks if style is not present
  432. {
  433. return (this->style | style) != this->style;
  434. }
  435. __int64 Framework::Drawable::getStyles() const
  436. {
  437. return style;
  438. }
  439. Drawable* Drawable::dublizieren() const // Creates a copy of the drawing
  440. {
  441. Drawable* obj = new Drawable();
  442. obj->setPosition(pos);
  443. obj->setSize(gr);
  444. obj->setMausEreignisParameter(makParam);
  445. obj->setTastaturEreignisParameter(takParam);
  446. obj->setMausEreignis(mak);
  447. obj->setTastaturEreignis(tak);
  448. if (toolTip) obj->setToolTipZ((ToolTip*)toolTip->dublizieren());
  449. return obj;
  450. }
  451. // Contents of the DrawableBackground class from Drawing.h
  452. // Constructor
  453. DrawableBackground::DrawableBackground()
  454. : Drawable()
  455. {
  456. hintergrundFarbe = 0xFF000000;
  457. rahmen = 0;
  458. hintergrundBild = 0;
  459. hintergrundFeld = 0;
  460. horizontalScrollBar = 0;
  461. vertikalScrollBar = 0;
  462. innenPosition.x = 0;
  463. innenPosition.y = 0;
  464. innenSize.x = 0;
  465. innenSize.y = 0;
  466. }
  467. // Destructor
  468. DrawableBackground::~DrawableBackground()
  469. {
  470. if (rahmen) rahmen->release();
  471. if (hintergrundBild) hintergrundBild->release();
  472. if (hintergrundFeld) hintergrundFeld->release();
  473. if (horizontalScrollBar) horizontalScrollBar->release();
  474. if (vertikalScrollBar) vertikalScrollBar->release();
  475. }
  476. void DrawableBackground::doMausEreignis(MausEreignis& me, bool userRet)
  477. {
  478. if (userRet)
  479. {
  480. int rbr = 0;
  481. if (hatStyle(Style::Rahmen) && rahmen) rbr = rahmen->getRBreite();
  482. bool vs = hatStyle(Style::VScroll) && vertikalScrollBar;
  483. bool hs = hatStyle(Style::HScroll) && horizontalScrollBar;
  484. if (vs)
  485. {
  486. if (hs)
  487. horizontalScrollBar->doMausMessage(
  488. rbr, gr.y - rbr - 15, gr.x - rbr * 2 - 15, 15, me);
  489. vertikalScrollBar->doMausMessage(
  490. gr.x - rbr - 15, rbr, 15, gr.y - rbr * 2, me);
  491. }
  492. else if (hs)
  493. horizontalScrollBar->doMausMessage(
  494. rbr, gr.y - rbr - 15, gr.x - rbr * 2, 15, me);
  495. }
  496. me.verarbeitet = userRet;
  497. }
  498. void DrawableBackground::setHintergrundBild(
  499. Bild* bild) // sets the background image
  500. {
  501. if (!hintergrundBild) hintergrundBild = new Bild();
  502. hintergrundBild->neuBild(bild->getBreite(), bild->getHeight(), 0);
  503. int* buff1 = hintergrundBild->getBuffer();
  504. int* buff2 = bild->getBuffer();
  505. for (int i = 0; i < bild->getBreite() * bild->getHeight(); ++i)
  506. buff1[i] = buff2[i];
  507. bild->release();
  508. rend = 1;
  509. }
  510. void DrawableBackground::setHintergrundBildZ(
  511. Bild* bild) // sets a pointer to the background image
  512. {
  513. if (hintergrundBild != bild)
  514. {
  515. if (hintergrundBild) hintergrundBild->release();
  516. hintergrundBild = bild;
  517. rend = 1;
  518. }
  519. }
  520. void DrawableBackground::setHintergrundFarbe(
  521. int fc) // sets the background color
  522. {
  523. if (hintergrundFarbe != fc)
  524. {
  525. hintergrundFarbe = fc;
  526. rend = 1;
  527. }
  528. }
  529. void DrawableBackground::setAlphaFeldZ(
  530. AlphaFeld* buff) // sets a pointer to the background buffer
  531. {
  532. if (hintergrundFeld != buff)
  533. {
  534. if (hintergrundFeld) hintergrundFeld->release();
  535. hintergrundFeld = buff;
  536. rend = 1;
  537. }
  538. }
  539. void DrawableBackground::setAlphaFeldStrength(
  540. int st) // sets the strength of the background buffer
  541. {
  542. if (!hintergrundFeld)
  543. {
  544. hintergrundFeld = new AlphaFeld();
  545. rend = 1;
  546. }
  547. if (hintergrundFeld->getStrength() != st)
  548. {
  549. hintergrundFeld->setStrength(st);
  550. rend = 1;
  551. }
  552. }
  553. void DrawableBackground::setAlphaFeldFarbe(
  554. int fc) // sets the color of the background buffer
  555. {
  556. if (!hintergrundFeld)
  557. {
  558. hintergrundFeld = new AlphaFeld();
  559. rend = 1;
  560. }
  561. if (hintergrundFeld->getFarbe() != fc)
  562. {
  563. hintergrundFeld->setFarbe(fc);
  564. rend = 1;
  565. }
  566. }
  567. void DrawableBackground::setRahmenZ(
  568. Rahmen* ram) // sets a pointer to the border
  569. {
  570. if (rahmen != ram)
  571. {
  572. if (rahmen) rahmen->release();
  573. rahmen = ram;
  574. rend = 1;
  575. }
  576. }
  577. void DrawableBackground::setRahmenBreite(int br) // sets the border width
  578. {
  579. if (!rahmen)
  580. {
  581. rahmen = new LRahmen();
  582. rend = 1;
  583. }
  584. if (rahmen->getRBreite() != br)
  585. {
  586. rahmen->setRamenBreite(br);
  587. rend = 1;
  588. }
  589. }
  590. void DrawableBackground::setRahmenFarbe(int fc) // sets the border color
  591. {
  592. if (!rahmen)
  593. {
  594. rahmen = new LRahmen();
  595. rend = 1;
  596. }
  597. if (rahmen->getFarbe() != fc)
  598. {
  599. rahmen->setFarbe(fc);
  600. rend = 1;
  601. }
  602. }
  603. void DrawableBackground::setVertikalKlickScroll(
  604. int ks) // sets the vertical scroll speed
  605. {
  606. if (!vertikalScrollBar)
  607. {
  608. vertikalScrollBar = new VScrollBar();
  609. rend = 1;
  610. }
  611. if (vertikalScrollBar->getKlickScroll() != ks)
  612. {
  613. vertikalScrollBar->setKlickScroll(ks);
  614. rend = 1;
  615. }
  616. }
  617. void DrawableBackground::setVertikalScrollPos(
  618. int pos) // sets the vertical scroll position
  619. {
  620. if (!vertikalScrollBar)
  621. {
  622. vertikalScrollBar = new VScrollBar();
  623. rend = 1;
  624. }
  625. if (vertikalScrollBar && vertikalScrollBar->getScroll() != pos)
  626. {
  627. vertikalScrollBar->scroll(pos);
  628. rend = 1;
  629. }
  630. }
  631. void DrawableBackground::setVertikalScrollFarbe(
  632. int f, int bgF) // sets the scroll color
  633. {
  634. if (!vertikalScrollBar)
  635. {
  636. vertikalScrollBar = new VScrollBar();
  637. rend = 1;
  638. }
  639. if (vertikalScrollBar
  640. && (vertikalScrollBar->getFarbe() != f
  641. || vertikalScrollBar->getBgFarbe() != bgF))
  642. {
  643. vertikalScrollBar->setFarbe(f);
  644. vertikalScrollBar->setBgFarbe(bgF, bgF != 0);
  645. rend = 1;
  646. }
  647. }
  648. void DrawableBackground::setHorizontalKlickScroll(
  649. int ks) // sets the horizontal scroll speed
  650. {
  651. if (!horizontalScrollBar)
  652. {
  653. horizontalScrollBar = new HScrollBar();
  654. rend = 1;
  655. }
  656. if (horizontalScrollBar && horizontalScrollBar->getKlickScroll() != ks)
  657. {
  658. horizontalScrollBar->setKlickScroll(ks);
  659. rend = 1;
  660. }
  661. }
  662. void DrawableBackground::setHorizontalScrollPos(
  663. int pos) // sets the horizontal scroll position
  664. {
  665. if (!horizontalScrollBar)
  666. {
  667. horizontalScrollBar = new HScrollBar();
  668. rend = 1;
  669. }
  670. if (horizontalScrollBar && horizontalScrollBar->getScroll() != pos)
  671. {
  672. horizontalScrollBar->scroll(pos);
  673. rend = 1;
  674. }
  675. }
  676. void DrawableBackground::setHorizontalScrollFarbe(
  677. int f, int bgF) // sets the scroll color
  678. {
  679. if (!horizontalScrollBar)
  680. {
  681. horizontalScrollBar = new HScrollBar();
  682. rend = 1;
  683. }
  684. if (horizontalScrollBar
  685. && (horizontalScrollBar->getFarbe() != f
  686. || horizontalScrollBar->getBgFarbe() != bgF))
  687. {
  688. horizontalScrollBar->setFarbe(f);
  689. horizontalScrollBar->setBgFarbe(bgF, bgF != 0);
  690. rend = 1;
  691. }
  692. }
  693. bool DrawableBackground::tick(double tickVal)
  694. {
  695. if (vertikalScrollBar && hatStyle(Style::VScroll))
  696. rend |= vertikalScrollBar->getRend();
  697. if (horizontalScrollBar && hatStyle(Style::HScroll))
  698. rend |= horizontalScrollBar->getRend();
  699. return Drawable::tick(tickVal);
  700. }
  701. void DrawableBackground::render(Bild& rObj)
  702. {
  703. innenPosition.x = pos.x;
  704. innenPosition.y = pos.y;
  705. innenSize.x = gr.x;
  706. innenSize.y = gr.y;
  707. if (hatStyleNicht(Style::Sichtbar)) return;
  708. lockDrawable();
  709. if (!rObj.setDrawOptions(pos.x, pos.y, gr.x, gr.y))
  710. {
  711. unlockDrawable();
  712. return;
  713. }
  714. Drawable::render(rObj);
  715. int rbr = 0;
  716. if (hatStyle(Style::Rahmen) && rahmen)
  717. {
  718. rahmen->setSize(gr);
  719. rahmen->render(rObj);
  720. rbr = rahmen->getRBreite();
  721. }
  722. innenPosition.x += rbr;
  723. innenPosition.y += rbr;
  724. innenSize.x -= rbr * 2;
  725. innenSize.y -= rbr * 2;
  726. if (!rObj.setDrawOptions(rbr, rbr, gr.x - rbr * 2, gr.y - rbr * 2))
  727. {
  728. rObj.releaseDrawOptions();
  729. unlockDrawable();
  730. return;
  731. }
  732. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  733. bool hs = horizontalScrollBar && hatStyle(Style::HScroll);
  734. if (vs)
  735. {
  736. vertikalScrollBar->render(
  737. gr.x - rbr * 2 - 15, 0, 15, gr.y - rbr * 2, rObj);
  738. innenSize.x -= 15;
  739. if (hs)
  740. {
  741. horizontalScrollBar->render(
  742. 0, gr.y - rbr * 2 - 15, gr.x - rbr * 2 - 15, 15, rObj);
  743. innenSize.y -= 15;
  744. if (!rObj.setDrawOptions(
  745. 0, 0, gr.x - rbr * 2 - 15, gr.y - rbr * 2 - 15))
  746. {
  747. rObj.releaseDrawOptions();
  748. rObj.releaseDrawOptions();
  749. unlockDrawable();
  750. return;
  751. }
  752. horizontalScrollBar->update(
  753. horizontalScrollBar->getScrollData()->max, innenSize.x);
  754. }
  755. else
  756. {
  757. if (!rObj.setDrawOptions(0, 0, gr.x - rbr * 2 - 15, gr.y - rbr * 2))
  758. {
  759. rObj.releaseDrawOptions();
  760. rObj.releaseDrawOptions();
  761. unlockDrawable();
  762. return;
  763. }
  764. }
  765. vertikalScrollBar->update(
  766. vertikalScrollBar->getScrollData()->max, innenSize.y);
  767. }
  768. else if (hs)
  769. {
  770. horizontalScrollBar->render(
  771. rbr, gr.y - rbr * 2 - 15, gr.x - rbr * 2, 15, rObj);
  772. innenSize.y -= 15;
  773. if (!rObj.setDrawOptions(0, 0, gr.x - rbr * 2, gr.y - rbr * 2 - 15))
  774. {
  775. rObj.releaseDrawOptions();
  776. rObj.releaseDrawOptions();
  777. unlockDrawable();
  778. return;
  779. }
  780. }
  781. if (hatStyle(Style::Hintergrund))
  782. {
  783. if (hatStyle(Style::HAlpha))
  784. rObj.alphaRegion(
  785. 0, 0, gr.x - rbr * 2, gr.y - rbr * 2, hintergrundFarbe);
  786. else
  787. rObj.fillRegion(
  788. 0, 0, gr.x - rbr * 2, gr.y - rbr * 2, hintergrundFarbe);
  789. if (hatStyle(Style::HBild) && hintergrundBild)
  790. {
  791. if (hatStyle(Style::HBildScale))
  792. {
  793. if (hatStyle(Style::HAlpha))
  794. rObj.alphaBildSkall(
  795. 0, 0, gr.x - rbr * 2, gr.y - rbr * 2, *hintergrundBild);
  796. else
  797. rObj.drawBildSkall(
  798. 0, 0, gr.x - rbr * 2, gr.y - rbr * 2, *hintergrundBild);
  799. }
  800. else
  801. {
  802. int x = (gr.x - rbr * 2 - hintergrundBild->getSize().x) / 2;
  803. int y = (gr.y - rbr * 2 - hintergrundBild->getSize().y) / 2;
  804. if (hatStyle(Style::HAlpha))
  805. rObj.alphaBild(
  806. x, y, gr.x - rbr * 2, gr.y - rbr * 2, *hintergrundBild);
  807. else
  808. rObj.drawBild(
  809. x, y, gr.x - rbr * 2, gr.y - rbr * 2, *hintergrundBild);
  810. }
  811. }
  812. }
  813. if (hatStyle(Style::Buffered) && hintergrundFeld)
  814. {
  815. hintergrundFeld->setSize(gr.x - rbr * 2, gr.y - rbr * 2);
  816. hintergrundFeld->render(rObj);
  817. }
  818. if (vs || hs) rObj.releaseDrawOptions();
  819. rObj.releaseDrawOptions();
  820. rObj.releaseDrawOptions();
  821. unlockDrawable();
  822. }
  823. // Returns the width of the interior area of the drawing in pixels
  824. int DrawableBackground::getInnenBreite() const
  825. {
  826. return getBreite() - 2 * getRahmenBreite();
  827. }
  828. // Returns the height of the interior area of the drawing in pixels
  829. int DrawableBackground::getInnenHeight() const
  830. {
  831. return getHeight() - 2 * getRahmenBreite();
  832. }
  833. Bild* DrawableBackground::getHintergrundBild()
  834. const // returns the background image
  835. {
  836. if (!hintergrundBild) return 0;
  837. return dynamic_cast<Bild*>(hintergrundBild->getThis());
  838. }
  839. Bild* DrawableBackground::zHintergrundBild()
  840. const // returns the background image without increased reference counter
  841. {
  842. return hintergrundBild;
  843. }
  844. int DrawableBackground::getHintergrundFarbe()
  845. const // returns the background color
  846. {
  847. return hintergrundFarbe;
  848. }
  849. AlphaFeld*
  850. DrawableBackground::getAlphaFeld() const // returns the background buffer
  851. {
  852. if (!hintergrundFeld) return 0;
  853. return dynamic_cast<AlphaFeld*>(hintergrundFeld->getThis());
  854. }
  855. AlphaFeld* DrawableBackground::zAlphaFeld()
  856. const // returns the background buffer without increased reference counter
  857. {
  858. return hintergrundFeld;
  859. }
  860. int DrawableBackground::getAlphaFeldStrength()
  861. const // returns the strength of the background buffer
  862. {
  863. if (!hintergrundFeld) return 0;
  864. return hintergrundFeld->getStrength();
  865. }
  866. int DrawableBackground::getAlphaFeldFarbe()
  867. const // returns the color of the background buffer
  868. {
  869. return hintergrundFeld->getFarbe();
  870. }
  871. Rahmen* DrawableBackground::getRahmen() const // returns the border
  872. {
  873. if (!rahmen) return 0;
  874. return dynamic_cast<Rahmen*>(rahmen->getThis());
  875. }
  876. Rahmen* DrawableBackground::zRahmen()
  877. const // returns the border without increased reference counter
  878. {
  879. return rahmen;
  880. }
  881. int DrawableBackground::getRahmenBreite() const // returns the border width
  882. {
  883. if (!rahmen || hatStyleNicht(Style::Rahmen)) return 0;
  884. return rahmen->getRBreite();
  885. }
  886. int DrawableBackground::getRahmenFarbe() const // returns the border color
  887. {
  888. return rahmen->getFarbe();
  889. }
  890. int DrawableBackground::getVertikalKlickScroll() const
  891. {
  892. return vertikalScrollBar ? vertikalScrollBar->getKlickScroll() : 0;
  893. }
  894. int DrawableBackground::getVertikalScrollPos() const
  895. {
  896. return vertikalScrollBar ? vertikalScrollBar->getScroll() : 0;
  897. }
  898. int DrawableBackground::getVertikalScrollFarbe() const
  899. {
  900. return vertikalScrollBar ? vertikalScrollBar->getFarbe() : 0;
  901. }
  902. int DrawableBackground::getVertikalScrollHintergrund() const
  903. {
  904. return vertikalScrollBar ? vertikalScrollBar->getBgFarbe() : 0;
  905. }
  906. int DrawableBackground::getHorizontalKlickScroll() const
  907. {
  908. return horizontalScrollBar ? horizontalScrollBar->getKlickScroll() : 0;
  909. }
  910. int DrawableBackground::getHorizontalScrollPos() const
  911. {
  912. return horizontalScrollBar ? horizontalScrollBar->getScroll() : 0;
  913. }
  914. int DrawableBackground::getHorizontalScrollFarbe() const
  915. {
  916. return horizontalScrollBar ? horizontalScrollBar->getFarbe() : 0;
  917. }
  918. int DrawableBackground::getHorizontalScrollHintergrund() const
  919. {
  920. return horizontalScrollBar ? horizontalScrollBar->getBgFarbe() : 0;
  921. }
  922. Drawable*
  923. DrawableBackground::dublizieren() const // Creates a copy of the drawing
  924. {
  925. DrawableBackground* obj = new DrawableBackground();
  926. obj->setPosition(pos);
  927. obj->setSize(gr);
  928. obj->setMausEreignisParameter(makParam);
  929. obj->setTastaturEreignisParameter(takParam);
  930. obj->setMausEreignis(mak);
  931. obj->setTastaturEreignis(tak);
  932. if (toolTip) obj->setToolTipZ((ToolTip*)toolTip->dublizieren());
  933. obj->setStyle(style);
  934. obj->setHintergrundFarbe(hintergrundFarbe);
  935. if (hintergrundFeld)
  936. obj->setAlphaFeldZ((AlphaFeld*)hintergrundFeld->dublizieren());
  937. if (rahmen) obj->setRahmenZ((Rahmen*)rahmen->dublizieren());
  938. if (hintergrundBild)
  939. obj->setHintergrundBild(
  940. dynamic_cast<Bild*>(hintergrundBild->getThis()));
  941. if (vertikalScrollBar)
  942. {
  943. obj->setVertikalKlickScroll(vertikalScrollBar->getKlickScroll());
  944. obj->setVertikalScrollPos(vertikalScrollBar->getScroll());
  945. obj->setVertikalScrollFarbe(
  946. vertikalScrollBar->getFarbe(), vertikalScrollBar->getBgFarbe());
  947. }
  948. if (horizontalScrollBar)
  949. {
  950. obj->setHorizontalKlickScroll(horizontalScrollBar->getKlickScroll());
  951. obj->setHorizontalScrollPos(horizontalScrollBar->getScroll());
  952. obj->setHorizontalScrollFarbe(
  953. horizontalScrollBar->getFarbe(), horizontalScrollBar->getBgFarbe());
  954. }
  955. return obj;
  956. }