Device contexts using wx module

Doug Edmunds (gmail) dougedmunds@REDACTED
Wed Jun 9 22:15:18 CEST 2010


I am trying to figure out how to use device contexts
using the wx module.  I found this C++ code which draws
a line in a window. I can't figure out how to do
this in Erlang.  Anyone?

Source code at:
http://zetcode.com/tutorials/wxwidgetstutorial/gdi/
Image at:
http://zetcode.com/tutorials/wxwidgetstutorial/images/line.jpg

--------
line.h

#include <wx/wx.h>

class Line : public wxFrame
{
public:
     Line(const wxString& title);

     void OnPaint(wxPaintEvent& event);

};

---------
line.cpp

#include "line.h"


Line::Line(const wxString& title)
        : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(280, 
180))
{
   this->Connect(wxEVT_PAINT, wxPaintEventHandler(Line::OnPaint));
   this->Centre();
}

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

   wxCoord x1 = 50, y1 = 60;
   wxCoord x2 = 190, y2 = 60;

   dc.DrawLine(x1, y1, x2, y2);
}

---------
main.h

#include <wx/wx.h>

class MyApp : public wxApp
{
   public:
     virtual bool OnInit();
};

---------
main.cpp

#include "main.h"
#include "line.h"

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{

     Line *line = new Line(wxT("Line"));
     line->Show(true);

     return true;
}


Thanks.

-dae


More information about the erlang-questions mailing list