brush.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: brush.h
  3. // Purpose: interface of wxBrush
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. The possible brush styles.
  9. */
  10. enum wxBrushStyle
  11. {
  12. wxBRUSHSTYLE_INVALID = -1,
  13. wxBRUSHSTYLE_SOLID = wxSOLID,
  14. /**< Solid. */
  15. wxBRUSHSTYLE_TRANSPARENT = wxTRANSPARENT,
  16. /**< Transparent (no fill). */
  17. wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE = wxSTIPPLE_MASK_OPAQUE,
  18. /**< Uses a bitmap as a stipple; the mask is used for blitting monochrome
  19. using text foreground and background colors. */
  20. wxBRUSHSTYLE_STIPPLE_MASK = wxSTIPPLE_MASK,
  21. /**< Uses a bitmap as a stipple; mask is used for masking areas in the
  22. stipple bitmap. */
  23. wxBRUSHSTYLE_STIPPLE = wxSTIPPLE,
  24. /**< Uses a bitmap as a stipple. */
  25. wxBRUSHSTYLE_BDIAGONAL_HATCH,
  26. /**< Backward diagonal hatch. */
  27. wxBRUSHSTYLE_CROSSDIAG_HATCH,
  28. /**< Cross-diagonal hatch. */
  29. wxBRUSHSTYLE_FDIAGONAL_HATCH,
  30. /**< Forward diagonal hatch. */
  31. wxBRUSHSTYLE_CROSS_HATCH,
  32. /**< Cross hatch. */
  33. wxBRUSHSTYLE_HORIZONTAL_HATCH,
  34. /**< Horizontal hatch. */
  35. wxBRUSHSTYLE_VERTICAL_HATCH,
  36. /**< Vertical hatch. */
  37. wxBRUSHSTYLE_FIRST_HATCH,
  38. /**< First of the hatch styles (inclusive). */
  39. wxBRUSHSTYLE_LAST_HATCH
  40. /**< Last of the hatch styles (inclusive). */
  41. };
  42. /**
  43. @class wxBrush
  44. A brush is a drawing tool for filling in areas. It is used for painting
  45. the background of rectangles, ellipses, etc. It has a colour and a style.
  46. On a monochrome display, wxWidgets shows all brushes as white unless the
  47. colour is really black.
  48. Do not initialize objects on the stack before the program commences, since
  49. other required structures may not have been set up yet. Instead, define
  50. global pointers to objects and create them in wxApp::OnInit or when required.
  51. An application may wish to create brushes with different characteristics
  52. dynamically, and there is the consequent danger that a large number of
  53. duplicate brushes will be created. Therefore an application may wish to
  54. get a pointer to a brush by using the global list of brushes ::wxTheBrushList,
  55. and calling the member function wxBrushList::FindOrCreateBrush().
  56. This class uses reference counting and copy-on-write internally so that
  57. assignments between two instances of this class are very cheap.
  58. You can therefore use actual objects instead of pointers without efficiency problems.
  59. If an instance of this class is changed it will create its own data internally
  60. so that other instances, which previously shared the data using the reference
  61. counting, are not affected.
  62. @library{wxcore}
  63. @category{gdi}
  64. @stdobjects
  65. @li ::wxNullBrush
  66. @li ::wxBLACK_BRUSH
  67. @li ::wxBLUE_BRUSH
  68. @li ::wxCYAN_BRUSH
  69. @li ::wxGREEN_BRUSH
  70. @li ::wxYELLOW_BRUSH
  71. @li ::wxGREY_BRUSH
  72. @li ::wxLIGHT_GREY_BRUSH
  73. @li ::wxMEDIUM_GREY_BRUSH
  74. @li ::wxRED_BRUSH
  75. @li ::wxTRANSPARENT_BRUSH
  76. @li ::wxWHITE_BRUSH
  77. @see wxBrushList, wxDC, wxDC::SetBrush
  78. */
  79. class wxBrush : public wxGDIObject
  80. {
  81. public:
  82. /**
  83. Default constructor.
  84. The brush will be uninitialised, and wxBrush:IsOk() will return @false.
  85. */
  86. wxBrush();
  87. /**
  88. Constructs a brush from a colour object and @a style.
  89. @param colour
  90. Colour object.
  91. @param style
  92. One of the ::wxBrushStyle enumeration values.
  93. */
  94. wxBrush(const wxColour& colour, wxBrushStyle style = wxBRUSHSTYLE_SOLID);
  95. /**
  96. Constructs a stippled brush using a bitmap.
  97. The brush style will be set to @c wxBRUSHSTYLE_STIPPLE.
  98. */
  99. wxBrush(const wxBitmap& stippleBitmap);
  100. /**
  101. Copy constructor, uses @ref overview_refcount "reference counting".
  102. */
  103. wxBrush(const wxBrush& brush);
  104. /**
  105. Destructor.
  106. See @ref overview_refcount_destruct for more info.
  107. @remarks Although all remaining brushes are deleted when the application
  108. exits, the application should try to clean up all brushes itself.
  109. This is because wxWidgets cannot know if a pointer to the brush
  110. object is stored in an application data structure, and there is
  111. a risk of double deletion.
  112. */
  113. virtual ~wxBrush();
  114. /**
  115. Returns a reference to the brush colour.
  116. @see SetColour()
  117. */
  118. virtual wxColour GetColour() const;
  119. /**
  120. Gets a pointer to the stipple bitmap. If the brush does not have a @c wxBRUSHSTYLE_STIPPLE
  121. style, this bitmap may be non-@NULL but uninitialised (i.e. wxBitmap:IsOk() returns @false).
  122. @see SetStipple()
  123. */
  124. virtual wxBitmap* GetStipple() const;
  125. /**
  126. Returns the brush style, one of the ::wxBrushStyle values.
  127. @see SetStyle(), SetColour(), SetStipple()
  128. */
  129. virtual wxBrushStyle GetStyle() const;
  130. /**
  131. Returns @true if the style of the brush is any of hatched fills.
  132. @see GetStyle()
  133. */
  134. virtual bool IsHatch() const;
  135. /**
  136. Returns @true if the brush is initialised.
  137. Notice that an uninitialized brush object can't be queried for any
  138. brush properties and all calls to the accessor methods on it will
  139. result in an assert failure.
  140. */
  141. virtual bool IsOk() const;
  142. /**
  143. Returns @true if the brush is a valid non-transparent brush.
  144. This method returns @true if the brush object is initialized and has a
  145. non-transparent style. Notice that this should be used instead of
  146. simply testing whether GetStyle() returns a style different from
  147. wxBRUSHSTYLE_TRANSPARENT if the brush may be invalid as GetStyle()
  148. would assert in this case.
  149. @see IsTransparent()
  150. @since 2.9.2.
  151. */
  152. bool IsNonTransparent() const;
  153. /**
  154. Returns @true if the brush is transparent.
  155. A transparent brush is simply a brush with wxBRUSHSTYLE_TRANSPARENT
  156. style.
  157. Notice that this function works even for non-initialized brushes (for
  158. which it returns @false) unlike tests of the form <code>GetStyle() ==
  159. wxBRUSHSTYLE_TRANSPARENT</code> which would assert if the brush is
  160. invalid.
  161. @see IsNonTransparent()
  162. @since 2.9.2.
  163. */
  164. bool IsTransparent() const;
  165. //@{
  166. /**
  167. Sets the brush colour using red, green and blue values.
  168. @see GetColour()
  169. */
  170. virtual void SetColour(const wxColour& colour);
  171. virtual void SetColour(unsigned char red, unsigned char green, unsigned char blue);
  172. //@}
  173. /**
  174. Sets the stipple bitmap.
  175. @param bitmap
  176. The bitmap to use for stippling.
  177. @remarks The style will be set to @c wxBRUSHSTYLE_STIPPLE, unless the bitmap
  178. has a mask associated to it, in which case the style will be set
  179. to @c wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE.
  180. @see wxBitmap
  181. */
  182. virtual void SetStipple(const wxBitmap& bitmap);
  183. /**
  184. Sets the brush style.
  185. @param style
  186. One of the ::wxBrushStyle values.
  187. @see GetStyle()
  188. */
  189. virtual void SetStyle(wxBrushStyle style);
  190. /**
  191. Inequality operator.
  192. See @ref overview_refcount_equality for more info.
  193. */
  194. bool operator !=(const wxBrush& brush) const;
  195. /**
  196. Equality operator.
  197. See @ref overview_refcount_equality for more info.
  198. */
  199. bool operator ==(const wxBrush& brush) const;
  200. };
  201. /**
  202. An empty brush.
  203. wxBrush::IsOk() always returns @false for this object.
  204. */
  205. wxBrush wxNullBrush;
  206. /**
  207. Blue brush.
  208. Except for the color it has all standard attributes
  209. (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...).
  210. */
  211. wxBrush* wxBLUE_BRUSH;
  212. /**
  213. Green brush.
  214. Except for the color it has all standard attributes
  215. (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...).
  216. */
  217. wxBrush* wxGREEN_BRUSH;
  218. /**
  219. Yellow brush.
  220. Except for the color it has all standard attributes
  221. (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...).
  222. */
  223. wxBrush* wxYELLOW_BRUSH;
  224. /**
  225. White brush.
  226. Except for the color it has all standard attributes
  227. (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...).
  228. */
  229. wxBrush* wxWHITE_BRUSH;
  230. /**
  231. Black brush.
  232. Except for the color it has all standard attributes
  233. (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...).
  234. */
  235. wxBrush* wxBLACK_BRUSH;
  236. /**
  237. Grey brush.
  238. Except for the color it has all standard attributes
  239. (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...).
  240. */
  241. wxBrush* wxGREY_BRUSH;
  242. /**
  243. Medium grey brush.
  244. Except for the color it has all standard attributes
  245. (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...).
  246. */
  247. wxBrush* wxMEDIUM_GREY_BRUSH;
  248. /**
  249. Light grey brush.
  250. Except for the color it has all standard attributes
  251. (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...).
  252. */
  253. wxBrush* wxLIGHT_GREY_BRUSH;
  254. /**
  255. Transparent brush.
  256. Except for the color it has all standard attributes
  257. (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...).
  258. */
  259. wxBrush* wxTRANSPARENT_BRUSH;
  260. /**
  261. Cyan brush.
  262. Except for the color it has all standard attributes
  263. (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...).
  264. */
  265. wxBrush* wxCYAN_BRUSH;
  266. /**
  267. Red brush.
  268. Except for the color it has all standard attributes
  269. (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...).
  270. */
  271. wxBrush* wxRED_BRUSH;
  272. /**
  273. @class wxBrushList
  274. A brush list is a list containing all brushes which have been created.
  275. The application should not construct its own brush list: it should use the
  276. object pointer ::wxTheBrushList.
  277. @library{wxcore}
  278. @category{gdi}
  279. @see wxBrush
  280. */
  281. class wxBrushList
  282. {
  283. public:
  284. /**
  285. Finds a brush with the specified attributes and returns it, else creates a new
  286. brush, adds it to the brush list, and returns it.
  287. @param colour
  288. Colour object.
  289. @param style
  290. Brush style. See ::wxBrushStyle for a list of styles.
  291. */
  292. wxBrush* FindOrCreateBrush(const wxColour& colour,
  293. wxBrushStyle style = wxBRUSHSTYLE_SOLID);
  294. };
  295. /**
  296. The global wxBrushList instance.
  297. */
  298. wxBrushList* wxTheBrushList;