[erlang-questions] Device contexts using wx module

Dan Gudmundsson dangud@REDACTED
Thu Jun 10 10:46:32 CEST 2010


-module(dl).

-export([test/0]).

-include_lib("wx/include/wx.hrl").

test() ->
    Wx = wx:new(),
    Frame = wxFrame:new(Wx, -1, "Draw Lines", [{size, {280, 180}}]),

    OnPaint = fun(_Evt, _Obj) ->
		      Paint = wxPaintDC:new(Frame),
		      wxDC:drawLine(Paint, {50, 60}, {190,60}),
		      wxPaintDC:destroy(Paint)
	      end,
    wxFrame:connect(Frame, paint, [{callback, OnPaint}]),

    wxFrame:center(Frame),
    wxFrame:show(Frame).

/Dan



On Wed, Jun 9, 2010 at 10:15 PM, Doug Edmunds (gmail)
<dougedmunds@REDACTED> wrote:
> 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
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>


More information about the erlang-questions mailing list