41、wxWidgets绘画之基础

#include <wx/wx.h>

class Simple:public wxFrame
{
public:
    Simple(const wxString& title);
protected:
    void OnPaint(wxPaintEvent& event);

};


Simple::Simple(const wxString& title)
    :wxFrame(NULL,-1,title,wxPoint(-1,-1),wxSize(680,580))
{
    Bind(wxEVT_PAINT,wxPaintEventHandler(Simple::OnPaint),this);
    Centre();
}

void Simple::OnPaint(wxPaintEvent& event)
{
    wxPaintDC dc(this);

    // 点
    dc.SetPen(*wxBLACK);
    dc.DrawPoint(50, 50);
    wxCoord x=0,y=0;
    for (int i = 0; i<1000; i++) {
      x = rand() % GetSize().x + 1;
      y = rand() % GetSize().y + 1;
      dc.DrawPoint(x, y);
  }

    // 线
    dc.SetPen(*wxBLUE_PEN);
    dc.DrawLine(wxPoint(15, 15), wxPoint(75, 75));
    dc.SetPen(*wxRED);
    dc.DrawLine(60,100,190,100);//画线


    // 矩形、圆角矩形
    dc.SetPen(*wxBLUE);
    dc.DrawRectangle(wxPoint(80, 35), wxSize(50, 45));
    dc.SetPen(*wxBLUE);
    dc.DrawRoundedRectangle(wxPoint(150,35),wxSize(50,50),10);

    // 多边形
    const wxPoint points[] = {
        wxPoint(120, 120),
        wxPoint(120, 260),
        wxPoint(200, 260)
    };
    dc.SetPen(*wxYELLOW);
    dc.SetBrush(*wxLIGHT_GREY);
    dc.DrawPolygon(3, points);

    // 圆
    dc.SetPen(wxColour(59, 128, 59));
    dc.SetBrush(wxColour(59, 128, 59));
    dc.DrawCircle(wxPoint(280, 100), 80);

    //渐变
    dc.GradientFillLinear(wxRect(wxPoint(180,100),wxSize(100,100)),*wxWHITE,*wxBLUE,wxRIGHT);
    // 文字
    dc.DrawText(wxT("测试文字"), wxPoint(200, 160));

    dc.SetFont(wxFont(10
                      ,wxFONTFAMILY_SWISS
                      ,wxFONTSTYLE_NORMAL
                      ,wxFONTWEIGHT_BOLD
                      ,false
                      ,wxT("Arial")
                      )
               );
    dc.SetTextForeground(*wxBLUE);
    dc.DrawText(wxT("中国加油"),50,120);

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值