How to draw a line in a window using wxWidget with erlang?

I am trying to draw a string in a window with wxWidget in Erlang. I tried:

wx:new(),
Frame = wxFrame:new(wx:null(), ?wxID_ANY, "Hello"),
wxDC:drawLine(50,50),

I get an error message:

undefined function wxDC:drawLine/2

I read the documentation here, but I don't understand how to do this:

http://www.erlang.org/doc/man/wxDC.html#drawLine-3

+3
source share
2 answers

X Windows programming is not so simple, and I'm not quite sure how you expect to draw a line with parameters such as [50, 50], which is the best point, and the line needs 2 points, and wxDC: drawLine should know where to draw a line because you can have many frames.

You can create such a frame, yes (-1 is used instead of a macro, because I use the shell here):

Wx = wx:new().
Frame = wxFrame:new(wx:null(), -1, "Hello").

, , REdrawing. , , , .. REdraw , .

, , , ANY paint, , , , :

wxFrame:connect(Frame, paint, [{callback,
    fun(_Evt, _Obj) ->
        io:format("paint~n"),
        DrawContext = wxPaintDC:new(Frame),
        wxDC:drawLine(DrawContext, {50, 50}, {150,100}),
        wxPaintDC:destroy(DrawContext)
        end
    }]).

io: , , , - , io: , , .

. , , , X Windows, , , , .

, , , :

wxFrame:show(Frame).

.

+5

, , , , .

Erlang , , . "arity", , , "arity". /2 .

wxDC:drawLine , wxDC:drawLine/2 undefined. , , , wxDC:drawLine/3, ( - , - , ).

+2

Source: https://habr.com/ru/post/1620220/


All Articles