dcmemory.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: dcmemory.h
  3. // Purpose: interface of wxMemoryDC
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxMemoryDC
  9. A memory device context provides a means to draw graphics onto a bitmap.
  10. When drawing in to a mono-bitmap, using @c wxWHITE, @c wxWHITE_PEN and
  11. @c wxWHITE_BRUSH will draw the background colour (i.e. 0) whereas all other
  12. colours will draw the foreground colour (i.e. 1).
  13. A bitmap must be selected into the new memory DC before it may be used for
  14. anything. Typical usage is as follows:
  15. @code
  16. // Create a memory DC
  17. wxMemoryDC temp_dc;
  18. temp_dc.SelectObject(test_bitmap);
  19. // We can now draw into the memory DC...
  20. // Copy from this DC to another DC.
  21. old_dc.Blit(250, 50, BITMAP_WIDTH, BITMAP_HEIGHT, temp_dc, 0, 0);
  22. @endcode
  23. Note that the memory DC must be deleted (or the bitmap selected out of it)
  24. before a bitmap can be reselected into another memory DC.
  25. And, before performing any other operations on the bitmap data, the bitmap
  26. must be selected out of the memory DC:
  27. @code
  28. temp_dc.SelectObject(wxNullBitmap);
  29. @endcode
  30. This happens automatically when wxMemoryDC object goes out of scope.
  31. @library{wxcore}
  32. @category{dc}
  33. @see wxBitmap, wxDC
  34. */
  35. class wxMemoryDC : public wxDC
  36. {
  37. public:
  38. /**
  39. Constructs a new memory device context.
  40. Use the wxDC::IsOk() member to test whether the constructor was
  41. successful in creating a usable device context. Don't forget to select
  42. a bitmap into the DC before drawing on it.
  43. */
  44. wxMemoryDC();
  45. /**
  46. Constructs a new memory device context having the same characteristics
  47. as the given existing device context.
  48. This constructor creates a memory device context @e compatible with @a
  49. dc in wxMSW, the argument is ignored in the other ports. If @a dc is
  50. @NULL, a device context compatible with the screen is created, just as
  51. with the default constructor.
  52. */
  53. wxMemoryDC(wxDC *dc);
  54. /**
  55. Constructs a new memory device context and calls SelectObject() with
  56. the given bitmap.
  57. Use the wxDC::IsOk() member to test whether the constructor was
  58. successful in creating a usable device context.
  59. */
  60. wxMemoryDC(wxBitmap& bitmap);
  61. /**
  62. Works exactly like SelectObjectAsSource() but this is the function you
  63. should use when you select a bitmap because you want to modify it, e.g.
  64. drawing on this DC.
  65. Using SelectObjectAsSource() when modifying the bitmap may incur some
  66. problems related to wxBitmap being a reference counted object (see
  67. @ref overview_refcount).
  68. Before using the updated bitmap data, make sure to select it out of
  69. context first either by selecting ::wxNullBitmap into the device
  70. context or destroying the device context entirely.
  71. If the bitmap is already selected in this device context, nothing is
  72. done. If it is selected in another context, the function asserts and
  73. drawing on the bitmap won't work correctly.
  74. @see wxDC::DrawBitmap()
  75. */
  76. void SelectObject(wxBitmap& bitmap);
  77. /**
  78. Selects the given bitmap into the device context, to use as the memory
  79. bitmap. Selecting the bitmap into a memory DC allows you to draw into
  80. the DC (and therefore the bitmap) and also to use wxDC::Blit() to copy
  81. the bitmap to a window. For this purpose, you may find wxDC::DrawIcon()
  82. easier to use instead.
  83. If the argument is ::wxNullBitmap (or some other uninitialised wxBitmap)
  84. the current bitmap is selected out of the device context, and the
  85. original bitmap restored, allowing the current bitmap to be destroyed
  86. safely.
  87. */
  88. void SelectObjectAsSource(const wxBitmap& bitmap);
  89. };