Code: Select all
wxBrush brush(stipple);
wxAutoBufferedPaintDC dc(this);
dc.SetBrush(brush);
dc.SetPen(*wxTRANSPARENT_PEN);
dc.Clear();
dc.DrawRectangle(8, 8, 64, 64);
How can I change both pattern background and foreground?
Code: Select all
wxBrush brush(stipple);
wxAutoBufferedPaintDC dc(this);
dc.SetBrush(brush);
dc.SetPen(*wxTRANSPARENT_PEN);
dc.Clear();
dc.DrawRectangle(8, 8, 64, 64);
Code: Select all
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/bitmap.h"
#include "wx/frame.h"
#include "wx/dcbuffer.h"
#endif
#include "checker.xbm"
class Frame : public wxFrame
{
public:
Frame();
void InitBrush();
private:
void OnPaint(wxPaintEvent &event);
wxBrush brush;
wxDECLARE_EVENT_TABLE();
};
wxBEGIN_EVENT_TABLE(Frame, wxFrame)
EVT_PAINT(Frame::OnPaint)
wxEND_EVENT_TABLE()
Frame::Frame()
: wxFrame(nullptr, wxID_ANY, "Pattern")
{
InitBrush();
SetBackgroundStyle(wxBG_STYLE_PAINT);
}
void Frame::InitBrush()
{
wxBitmap stipple((char*)checker_bits, checker_width, checker_height);
stipple.SetMask(new wxMask(stipple));
this->brush.SetStipple(stipple);
this->brush.SetStyle(wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE);
}
void Frame::OnPaint(wxPaintEvent &event)
{
wxAutoBufferedPaintDC dc(this);
dc.SetBackground(*wxWHITE_BRUSH);
dc.Clear();
dc.SetBrush(this->brush);
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetTextBackground(wxColour(0xE6, 0x6A, 0x5C));
dc.SetTextForeground(wxColour(0xF1, 0xAE, 0xA6));
dc.DrawRectangle(8, 8, 64, 64);
}
class App : public wxApp
{
bool OnInit() override;
Frame *frame = nullptr;
};
wxIMPLEMENT_APP(App);
bool App::OnInit()
{
this->frame = new Frame();
this->frame->Show();
return true;
}
Code: Select all
wxBitmap stipple(checker_bits);
this->brush.SetStipple(stipple);
Code: Select all
dc.SetBrush(this->brush);
dc.SetPen(*wxTRANSPARENT_PEN);
dc.DrawRectangle(8, 8, 64, 64);