Zeichnung.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. #ifndef Zeichnung_H
  2. #define Zeichnung_H
  3. #include <functional>
  4. #include "Critical.h"
  5. #include "MausEreignis.h"
  6. #include "Punkt.h"
  7. #include "ReferenceCounter.h"
  8. #include "TastaturEreignis.h"
  9. namespace Framework
  10. {
  11. struct MausEreignis; //! MausEreignis.h
  12. struct TastaturEreignis; //! TastaturEreignis.h
  13. class Bild; //! Bild.h
  14. class Zeichnung; //! From this file
  15. class ToolTip; //! ToolTip.h
  16. class Bildschirm; //! Bildschirm.h
  17. class Rahmen; //! Rahmen.h
  18. class AlphaFeld; //! AlphaFeld.h
  19. class VScrollBar; //! Scroll.h
  20. class HScrollBar; //! Scroll.h
  21. class Schrift;
  22. //! A drawing element for the 2D GUI Framework
  23. class Zeichnung : public virtual ReferenceCounter
  24. {
  25. public:
  26. class Style
  27. {
  28. public:
  29. //! If this style is set, the drawing is displayed when rendered
  30. static const __int64 Sichtbar = 0x00001;
  31. //! If this style is set, the user can interact with the drawing
  32. static const __int64 Erlaubt = 0x00002;
  33. //! If this style is set, keyboard events are processed by the drawing
  34. static const __int64 Fokus = 0x00004;
  35. //! If this style is set, mouse events are processed even when
  36. //! the object is not visible
  37. static const __int64 MEIgnoreSichtbar = 0x0800000000000000;
  38. //! If this style is set, the thread locks the object while
  39. //! the mouse event is being processed
  40. static const __int64 MELockZeichnung = 0x1000000000000000;
  41. //! If this style is set, mouse events are processed even when
  42. //! they are outside the drawing
  43. static const __int64 MEIgnoreInside = 0x2000000000000000;
  44. //! If this style is set, mouse events are processed even when
  45. //! they have already been processed by another drawing
  46. static const __int64 MEIgnoreVerarbeitet = 0x4000000000000000;
  47. //! If this style is set, mouse events are processed even when
  48. //! they are outside the drawing to which this drawing belongs
  49. static const __int64 MEIgnoreParentInside = 0x8000000000000000;
  50. };
  51. protected:
  52. Punkt pos;
  53. Punkt gr;
  54. void* makParam;
  55. void* takParam;
  56. MausAktion mak;
  57. TastaturAktion tak;
  58. void* nmakParam;
  59. void* ntakParam;
  60. MausAktion nMak;
  61. TastaturAktion nTak;
  62. bool mausIn;
  63. Critical cs;
  64. ToolTip* toolTip;
  65. __int64 style;
  66. bool rend;
  67. std::function<bool(Zeichnung*, Punkt localPos)> onNeedToolTip;
  68. bool toolTipRequested;
  69. //! Processes a mouse event. Called automatically by the framework.
  70. //! \param me The mouse event \param userRet true if
  71. //! MausEreignis::verarbeitet should be set to true
  72. DLLEXPORT virtual void doMausEreignis(MausEreignis& me, bool userRet);
  73. public:
  74. //! Constructor
  75. DLLEXPORT Zeichnung();
  76. //! Destructor
  77. DLLEXPORT virtual ~Zeichnung();
  78. //! Specifies whether the drawing has changed since the last frame
  79. //! and needs to be redrawn
  80. DLLEXPORT void setRender();
  81. //! Sets the text that appears when the user hovers the mouse over
  82. //! the drawing for a longer time \param txt The text to display
  83. //! \param zScreen A pointer to the screen object without increased
  84. //! reference counter \param zSchrift A pointer to the font to use
  85. //! without increased reference counter
  86. DLLEXPORT void setToolTipText(
  87. const char* txt, Bildschirm* zScreen, Schrift* zSchrift);
  88. //! Sets a function called when a tooltip is needed and none has
  89. //! been set yet \param initToolTip The function
  90. DLLEXPORT void setNeedToolTipEvent(
  91. std::function<bool(Zeichnung*, Punkt localPos)> onNeedTooltip);
  92. //! Sets the tooltip
  93. //! \param tt The tooltip
  94. DLLEXPORT void setToolTipZ(ToolTip* tt);
  95. //! This is necessary if multiple threads use the drawing simultaneously.
  96. //! If lockZeichnung() is called by two threads, the last one waits
  97. //! until the first has called unlockZeichnung().
  98. DLLEXPORT void lockZeichnung();
  99. //! This is necessary if multiple threads use the drawing simultaneously.
  100. //! If lockZeichnung() is called by two threads, the last one waits
  101. //! until the first has called unlockZeichnung().
  102. DLLEXPORT void unlockZeichnung();
  103. //! Sets the parameter passed to the callback function on a mouse event
  104. //! \param p The parameter
  105. DLLEXPORT void setMausEreignisParameter(void* p);
  106. //! Setzt den Parameter, der bei einem Tastatur Ereignis an die
  107. //! Rückruffunktion übergeben wird \param p Der Parameter
  108. DLLEXPORT void setTastaturEreignisParameter(void* p);
  109. //! Setzt die Rückruffunktion, die bei einem Maus Ereignis aufgerufen
  110. //! werden soll. Wenn die Rückruffunktion 0 zurückgiebt, oder nicht
  111. //! gesetzt wurde, wird ein Maus Ereignis von der Zeichnung nicht weiter
  112. //! beachtet Es kann die Standartfunktion __ret1ME verwendet werden, die
  113. //! in MausEreignis.h and always returns 1 \param ak A pointer to
  114. //! the callback function
  115. DLLEXPORT void setMausEreignis(MausAktion ak);
  116. //! Adds a callback function to be called on a mouse event.
  117. //! If any callback returns 0, or none was set, the mouse event
  118. //! is not further processed by the drawing. The standard function
  119. //! __ret1ME can be used, which is defined in MausEreignis.h and always
  120. //! returns 1 \param ak A pointer to the callback function
  121. DLLEXPORT void addMausEreignis(MausAktion ak);
  122. //! Sets the callback function to be called on a keyboard event.
  123. //! If the callback returns 0, or was not set, the keyboard event
  124. //! is not further processed by the drawing. The standard function
  125. //! __ret1TE can be used, which is defined in TastaturEreignis.h and
  126. //! always returns 1. Other standard functions are _nurNummernTE and
  127. //! _nurHexTE also from TastaturEreignis.h \param ak A pointer to
  128. //! the callback function
  129. DLLEXPORT void setTastaturEreignis(TastaturAktion ak);
  130. //! Adds a callback function to be called on a keyboard event.
  131. //! If any callback returns 0, or none was set, the keyboard event
  132. //! is not further processed by the drawing. The standard function
  133. //! __ret1TE can be used, which is defined in TastaturEreignis.h and
  134. //! always returns 1. Other standard functions are _nurNummernTE and
  135. //! _nurHexTE also from TastaturEreignis.h \param ak A pointer to
  136. //! the callback function
  137. DLLEXPORT void addTastaturEreignis(TastaturAktion ak);
  138. //! Sets the parameter passed to the callback function on a mouse event
  139. //! that is called after the event was processed by the drawing
  140. //! \param p The parameter
  141. DLLEXPORT void setNMausEreignisParameter(void* p);
  142. //! Sets the parameter passed to the callback function on a keyboard
  143. //! event that is called after the event was processed by the drawing
  144. //! \param p The parameter
  145. DLLEXPORT void setNTastaturEreignisParameter(void* p);
  146. //! Sets the callback function to be called on a mouse event after
  147. //! the event has already been processed by the drawing. If the callback
  148. //! returns 1, or was not set, the mouse event will not be processed
  149. //! by any other drawing, such as ones behind this drawing. The standard
  150. //! function __ret1ME can be used, which is defined in MausEreignis.h
  151. //! and always returns 1 \param ak A pointer to the callback function
  152. DLLEXPORT void setNMausEreignis(MausAktion ak);
  153. //! Sets the callback function to be called on a keyboard event after
  154. //! the event has already been processed by the drawing. If the callback
  155. //! returns 1, or was not set, the keyboard event will not be processed
  156. //! by any other drawing. The standard function __ret1TE can be used,
  157. //! which is defined in TastaturEreignis.h and always returns 1. Other
  158. //! standard functions are _nurNummernTE and _nurHexTE also from
  159. //! TastaturEreignis.h \param ak A pointer to the callback function
  160. DLLEXPORT void setNTastaturEreignis(TastaturAktion ak);
  161. //! Processes a mouse event. Called automatically by the framework.
  162. //! \param me The event
  163. DLLEXPORT virtual void doPublicMausEreignis(MausEreignis& me);
  164. //! Processes a keyboard event. Called automatically by the framework
  165. //! \param te The event
  166. DLLEXPORT virtual void doTastaturEreignis(TastaturEreignis& te);
  167. //! Processes the time elapsed since the last call of this function
  168. //! \param tickVal The elapsed time in seconds
  169. DLLEXPORT virtual bool tick(double tickval);
  170. //! Sets the position of the drawing
  171. //! \param pos The position in pixels
  172. DLLEXPORT void setPosition(const Punkt& pos);
  173. //! Sets the X position of the drawing
  174. //! \param xPos The position in pixels
  175. DLLEXPORT void setX(int xPos);
  176. //! Sets the Y position of the drawing
  177. //! \param yPos The position in pixels
  178. DLLEXPORT void setY(int yPos);
  179. //! Sets the size of the drawing
  180. //! \param gr A point with x as width and y as height in pixels
  181. DLLEXPORT void setSize(const Punkt& gr);
  182. //! Sets the position of the drawing
  183. //! \param x The X position in pixels
  184. //! \param y The Y position in pixels
  185. DLLEXPORT void setPosition(int x, int y);
  186. //! Sets the size of the drawing
  187. //! \param br The width in pixels
  188. //! \param height The height in pixels
  189. DLLEXPORT void setSize(int br, int height);
  190. //! Set the width in pixel
  191. //! \param width the width
  192. DLLEXPORT void setWidth(int width);
  193. //! Set the height in pixel
  194. //! \param width the height
  195. DLLEXPORT void setHeight(int height);
  196. //! Sets the style of the drawing
  197. //! \param style The new style consisting of flags from the
  198. //! corresponding Style class
  199. DLLEXPORT void setStyle(__int64 style);
  200. //! Sets the style of the drawing
  201. //! \param style All style flags to be modified
  202. //! \param add_remove 1 if the style should be added. 0 if the style
  203. //! should be removed
  204. DLLEXPORT void setStyle(__int64 style, bool add_remove);
  205. //! Adds style flags
  206. //! \param style The style to add
  207. DLLEXPORT void addStyle(__int64 style);
  208. //! Removes style flags
  209. //! \param style The style to remove
  210. DLLEXPORT void removeStyle(__int64 style);
  211. //! Renders the drawing into a specific image
  212. //! \param zRObj The image to draw into
  213. DLLEXPORT virtual void render(Bild& zRObj);
  214. //! Returns whether a callback function for mouse events was set
  215. DLLEXPORT bool hatMausEreignis() const;
  216. //! Returns whether a callback function for keyboard events was set
  217. DLLEXPORT bool hatTastaturEreignis() const;
  218. //! Returns the position of the drawing in pixels
  219. DLLEXPORT const Punkt& getPosition() const;
  220. //! Returns the size of the drawing in pixels. x for width and y
  221. //! for height
  222. DLLEXPORT const Punkt& getSize() const;
  223. //! Returns the width of the drawing in pixels
  224. DLLEXPORT int getBreite() const;
  225. //! Returns the height of the drawing in pixels
  226. DLLEXPORT int getHeight() const;
  227. //! Returns the inner width of the drawing in pixels
  228. DLLEXPORT virtual int getInnenBreite() const;
  229. //! Returns the inner height of the drawing in pixels
  230. DLLEXPORT virtual int getInnenHeight() const;
  231. //! Returns the X position of the drawing in pixels
  232. DLLEXPORT int getX() const;
  233. //! Returns the Y position of the drawing in pixels
  234. DLLEXPORT int getY() const;
  235. //! Prüft, ob ein Punkt in diesem Objekt liegt
  236. //! \param p der Punkt
  237. //! \return 1, wenn der punkt innen ist, 0 sonst
  238. DLLEXPORT virtual bool istPunktInnen(Punkt p) const;
  239. //! Prüft, ob ein Punkt in diesem Objekt liegt
  240. //! \param x die x koordinate des punktes
  241. //! \param y die y koordinate des punktes
  242. //! \return 1, wenn der punkt innen ist, 0 sonst
  243. DLLEXPORT virtual bool istPunktInnen(int x, int y) const;
  244. //! Returns a pointer to the tooltip object, if it is used
  245. DLLEXPORT ToolTip* getToolTip() const;
  246. //! Returns a pointer to the tooltip object without increased
  247. //! reference counter, if it is used
  248. DLLEXPORT ToolTip* zToolTip() const;
  249. //! Returns whether specific styles are set
  250. //! \param style The styles to check
  251. //! \return 1 if all styles in style are set
  252. DLLEXPORT bool hatStyle(__int64 style) const;
  253. //! Returns whether specific styles are not set
  254. //! \param style The styles to check
  255. //! \return 1 if all styles in style are not set
  256. DLLEXPORT bool hatStyleNicht(__int64 style) const;
  257. //! returns all currently active styles
  258. DLLEXPORT __int64 getStyles() const;
  259. //! Copies the complete drawing so it can be modified without
  260. //! affecting the original
  261. DLLEXPORT virtual Zeichnung* dublizieren() const;
  262. };
  263. //! A drawing element for the 2D GUI Framework with background, border
  264. //! and scroll bars
  265. class ZeichnungHintergrund : public Zeichnung
  266. {
  267. public:
  268. class Style : public Zeichnung::Style
  269. {
  270. public:
  271. //! If this flag is set, the drawing gets a border
  272. static const __int64 Rahmen = 0x00010;
  273. //! If this flag is set, the drawing gets a background
  274. static const __int64 Hintergrund = 0x00020;
  275. //! If this flag is set, the background is transparent.
  276. //! Requires flag Hintergrund
  277. static const __int64 HAlpha = 0x00040;
  278. //! If this flag is set, an image is used as background.
  279. //! Requires flag Hintergrund
  280. static const __int64 HBild = 0x00080;
  281. //! If this flag is set, a color gradient appears as border
  282. static const __int64 Buffered = 0x00100;
  283. //! If this flag is set, a scrollbar appears at the right edge
  284. static const __int64 VScroll = 0x00200;
  285. //! If this flag is set, a scrollbar appears at the bottom edge
  286. static const __int64 HScroll = 0x00400;
  287. //! If this flag is set, the image is scaled
  288. static const __int64 HBildScale = 0x00800;
  289. };
  290. protected:
  291. int hintergrundFarbe;
  292. Rahmen* rahmen;
  293. Bild* hintergrundBild;
  294. AlphaFeld* hintergrundFeld;
  295. VScrollBar* vertikalScrollBar;
  296. HScrollBar* horizontalScrollBar;
  297. Punkt innenPosition;
  298. Punkt innenSize;
  299. protected:
  300. //! Processes mouse messages
  301. //! \param me The event triggered by the mouse input
  302. DLLEXPORT void doMausEreignis(MausEreignis& me, bool userRet) override;
  303. public:
  304. //! Constructor
  305. DLLEXPORT ZeichnungHintergrund();
  306. //! Destructor
  307. DLLEXPORT virtual ~ZeichnungHintergrund();
  308. //! Sets the background image (requires drawing flag:
  309. //! Style::Hintergrund, HBild) \param bild The image is copied and used
  310. //! as background image
  311. DLLEXPORT void setHintergrundBild(Bild* bild);
  312. //! Sets a pointer to the background image (requires drawing flag:
  313. //! Style::Hintergrund) \param bild The image is used without copying
  314. DLLEXPORT void setHintergrundBildZ(Bild* bild);
  315. //! Sets the background color (requires drawing flag:
  316. //! Style::Hintergrund) \param fc The background color in A8R8G8B8 format
  317. DLLEXPORT void setHintergrundFarbe(int fc);
  318. //! Sets a pointer to the AlphaFeld (requires drawing flag:
  319. //! Style::Buffered) \param buff The AlphaFeld to draw over the background
  320. DLLEXPORT void setAlphaFeldZ(AlphaFeld* buff);
  321. //! Setzt die Stärke des AlphaFeldes (benötigt Flag zum Zeichnen:
  322. //! Style::Buffered) \param st Die Stärke des AlphaFeldes, welches über
  323. //! dem Hintergrund gezeichnet werden soll
  324. DLLEXPORT void setAlphaFeldStrength(int st);
  325. //! Setzt die Farbe des AlphaFeldes (benötigt Flag zum Zeichnen:
  326. //! Style::Buffered) \param fc Die Farbe des AlphaFeldes, welches über
  327. //! dem Hintergrund gezeichnet werden soll
  328. DLLEXPORT void setAlphaFeldFarbe(int fc);
  329. //! Sets a pointer to the line border drawn around the text field
  330. //! (requires drawing flag: Style::Rahmen)
  331. //! \param ram The border
  332. DLLEXPORT void setRahmenZ(Rahmen* ram);
  333. //! Sets the width of the line border (requires drawing flag:
  334. //! Style::Rahmen) \param br The width in pixels
  335. DLLEXPORT void setRahmenBreite(int br);
  336. //! Sets the color of the line border (requires drawing flag:
  337. //! Style::Rahmen) \param fc The color in A8R8G8B8 format
  338. DLLEXPORT void setRahmenFarbe(int fc);
  339. //! Sets the scroll speed of the vertical scroll bar (requires drawing
  340. //! flag: Style::VScroll) \param ks The scroll speed in pixels per mouse click
  341. DLLEXPORT void setVertikalKlickScroll(int ks);
  342. //! Scrolls to a specific position on the vertical scroll bar
  343. //! (requires drawing flag: Style::VScroll) \param pos The scroll offset in pixels
  344. DLLEXPORT void setVertikalScrollPos(int pos);
  345. //! Sets the color of the vertical scroll bar (requires drawing flag:
  346. //! Style::VScroll) \param f The foreground color in A8R8G8B8 format
  347. //! \param bgF The background color in A8R8G8B8 format
  348. DLLEXPORT void setVertikalScrollFarbe(int f, int bgF);
  349. //! Sets the scroll speed of the horizontal scroll bar (requires drawing
  350. //! flag: Style::HScroll) \param ks The scroll speed in pixels per mouse click
  351. DLLEXPORT void setHorizontalKlickScroll(int ks);
  352. //! Scrolls to a specific position on the horizontal scroll bar
  353. //! (requires drawing flag: Style::HScroll) \param pos The scroll offset in pixels
  354. DLLEXPORT void setHorizontalScrollPos(int pos);
  355. //! Sets the color of the horizontal scroll bar (requires drawing flag:
  356. //! Style::HScroll) \param f The foreground color in A8R8G8B8 format
  357. //! \param bgF The background color in A8R8G8B8 format
  358. DLLEXPORT void setHorizontalScrollFarbe(int f, int bgF);
  359. //! Updates the drawing background
  360. //! \param tickVal The elapsed time in seconds since the last call
  361. //! of this function \return 1 if the image needs to be redrawn. 0 otherwise
  362. DLLEXPORT bool tick(double tickVal) override;
  363. //! Renders the background of a drawing to rObj
  364. DLLEXPORT void render(Bild& rObj) override;
  365. //! Returns the inner width of the drawing in pixels
  366. DLLEXPORT virtual int getInnenBreite() const override;
  367. //! Returns the inner height of the drawing in pixels
  368. DLLEXPORT virtual int getInnenHeight() const override;
  369. //! Returns the background image.
  370. //! \return 0 if no background image is used
  371. DLLEXPORT Bild* getHintergrundBild() const;
  372. //! Returns the background image without increased reference counter.
  373. //! \return 0 if no background image is used
  374. DLLEXPORT Bild* zHintergrundBild() const;
  375. //! Returns the background color in A8R8G8B8 format
  376. DLLEXPORT int getHintergrundFarbe() const;
  377. //! Returns the AlphaFeld drawn over the background.
  378. //! \return 0 if the AlphaFeld was not defined
  379. DLLEXPORT AlphaFeld* getAlphaFeld() const;
  380. //! Returns the AlphaFeld without increased reference counter drawn
  381. //! over the background. \return 0 if the AlphaFeld was not defined
  382. DLLEXPORT AlphaFeld* zAlphaFeld() const;
  383. //! Returns the strength of the AlphaFeld
  384. DLLEXPORT int getAlphaFeldStrength() const;
  385. //! Returns the color of the AlphaFeld in A8R8G8B8 format
  386. DLLEXPORT int getAlphaFeldFarbe() const;
  387. //! Returns the border
  388. //! \return 0 if no border was defined
  389. DLLEXPORT Rahmen* getRahmen() const;
  390. //! Returns the border without increased reference counter
  391. //! \return 0 if no border was defined
  392. DLLEXPORT Rahmen* zRahmen() const;
  393. //! Returns the width of the border in pixels
  394. DLLEXPORT int getRahmenBreite() const;
  395. //! Returns the color of the border in A8R8G8B8 format
  396. DLLEXPORT int getRahmenFarbe() const;
  397. //! Returns the scroll speed of the vertical scroll bar
  398. DLLEXPORT int getVertikalKlickScroll() const;
  399. //! Returns the scroll position of the vertical scroll bar
  400. DLLEXPORT int getVertikalScrollPos() const;
  401. //! Returns the color of the vertical scroll bar in A8R8G8B8 format
  402. DLLEXPORT int getVertikalScrollFarbe() const;
  403. //! Returns the background color of the vertical scroll bar in A8R8G8B8
  404. //! format
  405. DLLEXPORT int getVertikalScrollHintergrund() const;
  406. //! Returns the scroll speed of the horizontal scroll bar
  407. DLLEXPORT int getHorizontalKlickScroll() const;
  408. //! Returns the scroll position of the horizontal scroll bar
  409. DLLEXPORT int getHorizontalScrollPos() const;
  410. //! Returns the color of the horizontal scroll bar in A8R8G8B8 format
  411. DLLEXPORT int getHorizontalScrollFarbe() const;
  412. //! Returns the background color of the horizontal scroll bar in A8R8G8B8
  413. //! format
  414. DLLEXPORT int getHorizontalScrollHintergrund() const;
  415. //! Creates a copy of the drawing that can be modified without
  416. //! affecting the original
  417. DLLEXPORT virtual Zeichnung* dublizieren() const;
  418. };
  419. } // namespace Framework
  420. #endif