Drawing.cpp 26 KB

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