Created
September 3, 2015 15:55
-
-
Save franc/29d6eaca3f87b3f9d915 to your computer and use it in GitHub Desktop.
elixir attempt at getting WX to draw a line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule AudioRenderer.Window do | |
@moduledoc """ | |
A window to draw our audio renderer within. | |
""" | |
@title 'Audio Renderer' | |
require Record | |
Record.defrecordp :wx, Record.extract(:wx, from_lib: "wx/include/wx.hrl") | |
Record.defrecordp :wxClose, Record.extract(:wxClose, from_lib: "wx/include/wx.hrl") | |
Record.defrecordp :wxCommand, Record.extract(:wxCommand, from_lib: "wx/include/wx.hrl") | |
Record.defrecordp :wxKey, Record.extract(:wxKey, from_lib: "wx/include/wx.hrl") | |
Record.defrecordp :wxPaint, Record.extract(:wxPaint, from_lib: "wx/include/wx.hrl") | |
def start(data) do | |
do_init(data) | |
end | |
def init(data) do | |
:wx.batch(fn() -> do_init(data) end) | |
end | |
def do_init(data) do | |
wx = :wx.new | |
frame = :wxFrame.new(wx, -1, @title, size: {500, 500}) | |
panel = :wxPanel.new(frame, []) | |
main_sizer = :wxBoxSizer.new(:wx_const.wx_vertical) | |
sizer = :wxStaticBoxSizer.new(:wx_const.wx_vertical, panel) | |
win = :wxPanel.new(panel, [style: :wx_const.wx_full_repaint_on_resize]) | |
:wxPanel.connect(win, :paint, [:callback]) | |
:wxPanel.connect(win, :size) | |
:wxSizer.add(sizer, win, [flag: :wx_const.wx_expand, proportion: 1]) | |
:wxSizer.add(main_sizer, sizer, [flag: :wx_const.wx_expand, proportion: 1]) | |
:wxPanel.setSizer(panel, main_sizer) | |
:wxFrame.show(frame) | |
receive do | |
:ok -> :ok | |
after 1000 -> | |
dc = :wxPaintDC.new(win) | |
canvas = :wxGraphicsContext.create(dc) | |
pen = :wxPen.new({255, 255, 255, 255}) | |
:wxGraphicsContext.setPen(canvas, pen) | |
:wxGraphicsContext.drawLines(canvas, [{100, 150}, {200, 200}]) | |
:timer.sleep(100) | |
end | |
receive do | |
:ok -> :ok | |
end | |
:ok | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment