wxruby-ruby19 1.9.8-x86-darwin-9 → 1.9.10-x86-darwin-9
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +53 -0
- data/README +297 -0
- data/lib/wx.rb +2 -2
- data/lib/wx/accessors.rb +7 -1
- data/lib/wx/classes/app.rb +10 -4
- data/lib/wx/classes/bitmap.rb +29 -1
- data/lib/wx/classes/clipboard.rb +19 -3
- data/lib/wx/classes/colour.rb +6 -4
- data/lib/wx/classes/data_object.rb +14 -0
- data/lib/wx/classes/data_object_simple.rb +6 -0
- data/lib/wx/classes/dataformat.rb +23 -0
- data/lib/wx/classes/evthandler.rb +79 -4
- data/lib/wx/classes/genericdirctrl.rb +36 -0
- data/lib/wx/classes/grid.rb +8 -0
- data/lib/wx/classes/hboxsizer.rb +6 -0
- data/lib/wx/classes/icon.rb +12 -1
- data/lib/wx/classes/image.rb +13 -1
- data/lib/wx/classes/listctrl.rb +12 -0
- data/lib/wx/classes/point.rb +8 -0
- data/lib/wx/classes/rect.rb +10 -1
- data/lib/wx/classes/richtextctrl.rb +63 -0
- data/lib/wx/classes/size.rb +9 -0
- data/lib/wx/classes/sizer.rb +18 -3
- data/lib/wx/classes/standardpaths.rb +9 -0
- data/lib/wx/classes/texturlevent.rb +14 -2
- data/lib/wx/classes/toolbar.rb +4 -6
- data/lib/wx/classes/vboxsizer.rb +6 -0
- data/lib/wx/classes/window.rb +7 -0
- data/lib/wx/classes/xmlresource.rb +17 -0
- data/lib/wx/helpers.rb +16 -1
- data/lib/wx/keyword_ctors.rb +3 -2
- data/lib/wx/keyword_defs.rb +56 -5
- data/lib/wx/version.rb +1 -1
- data/lib/wxruby2.bundle +0 -0
- data/samples/SAMPLES-LICENSE.TXT +18 -0
- data/samples/aui/aui.rb +1356 -0
- data/samples/bigdemo/About.rbw +39 -0
- data/samples/bigdemo/ColorPanel.rbw +23 -0
- data/samples/bigdemo/GridSimple.rbw +78 -0
- data/samples/bigdemo/MDIDemo.rbw +57 -0
- data/samples/bigdemo/PopupMenu.rbw +149 -0
- data/samples/bigdemo/ShapedWindow.rbw +131 -0
- data/samples/bigdemo/Sizers.rbw +543 -0
- data/samples/bigdemo/bigdemo.rb +823 -0
- data/samples/bigdemo/demoTemplate.rbw +33 -0
- data/samples/bigdemo/helpfile.htb +0 -0
- data/samples/bigdemo/icons/Test 015.jpg +0 -0
- data/samples/bigdemo/icons/Test 015.png +0 -0
- data/samples/bigdemo/icons/choice.bmp +0 -0
- data/samples/bigdemo/icons/choice.xpm +27 -0
- data/samples/bigdemo/icons/combo.bmp +0 -0
- data/samples/bigdemo/icons/combo.xpm +27 -0
- data/samples/bigdemo/icons/copy.xpm +25 -0
- data/samples/bigdemo/icons/cut.xpm +24 -0
- data/samples/bigdemo/icons/gauge.bmp +0 -0
- data/samples/bigdemo/icons/gauge.xpm +27 -0
- data/samples/bigdemo/icons/help.xpm +25 -0
- data/samples/bigdemo/icons/list.bmp +0 -0
- data/samples/bigdemo/icons/list.xpm +27 -0
- data/samples/bigdemo/icons/mondrian.ico +0 -0
- data/samples/bigdemo/icons/mondrian.xpm +44 -0
- data/samples/bigdemo/icons/new.xpm +24 -0
- data/samples/bigdemo/icons/ogl.ico +0 -0
- data/samples/bigdemo/icons/ogl.xpm +45 -0
- data/samples/bigdemo/icons/open.xpm +26 -0
- data/samples/bigdemo/icons/paste.bmp +0 -0
- data/samples/bigdemo/icons/paste.xpm +38 -0
- data/samples/bigdemo/icons/pointy.png +0 -0
- data/samples/bigdemo/icons/preview.xpm +26 -0
- data/samples/bigdemo/icons/print.xpm +26 -0
- data/samples/bigdemo/icons/radio.bmp +0 -0
- data/samples/bigdemo/icons/radio.xpm +27 -0
- data/samples/bigdemo/icons/robert.xpm +415 -0
- data/samples/bigdemo/icons/ruby.png +0 -0
- data/samples/bigdemo/icons/sashtest.ico +0 -0
- data/samples/bigdemo/icons/save.xpm +25 -0
- data/samples/bigdemo/icons/smiles.bmp +0 -0
- data/samples/bigdemo/icons/smiles.xpm +39 -0
- data/samples/bigdemo/icons/smiley.ico +0 -0
- data/samples/bigdemo/icons/smiley.xpm +42 -0
- data/samples/bigdemo/icons/stattext.xpm +24 -0
- data/samples/bigdemo/icons/test2.bmp +0 -0
- data/samples/bigdemo/icons/test2.png +0 -0
- data/samples/bigdemo/icons/test2.xpm +79 -0
- data/samples/bigdemo/icons/text.bmp +0 -0
- data/samples/bigdemo/icons/text.xpm +27 -0
- data/samples/bigdemo/icons/tog1.bmp +0 -0
- data/samples/bigdemo/icons/tog1.xpm +38 -0
- data/samples/bigdemo/icons/tog2.bmp +0 -0
- data/samples/bigdemo/icons/tog2.xpm +38 -0
- data/samples/bigdemo/icons/wxwin.ico +0 -0
- data/samples/bigdemo/icons/wxwin16x16.png +0 -0
- data/samples/bigdemo/icons/wxwin16x16.xpm +25 -0
- data/samples/bigdemo/icons/wxwin32x32.png +0 -0
- data/samples/bigdemo/icons/wxwin48x48.png +0 -0
- data/samples/bigdemo/run.rb +90 -0
- data/samples/bigdemo/tips.txt +7 -0
- data/samples/bigdemo/utils.rb +12 -0
- data/samples/bigdemo/wxArtProvider.rbw +281 -0
- data/samples/bigdemo/wxBitmapButton.rbw +65 -0
- data/samples/bigdemo/wxButton.rbw +64 -0
- data/samples/bigdemo/wxCalendarCtrl.rbw +60 -0
- data/samples/bigdemo/wxCheckBox.rbw +50 -0
- data/samples/bigdemo/wxCheckListBox.rbw +65 -0
- data/samples/bigdemo/wxChoice.rbw +47 -0
- data/samples/bigdemo/wxChoicebook.rbw +78 -0
- data/samples/bigdemo/wxColourDialog.rbw +31 -0
- data/samples/bigdemo/wxComboBox.rbw +77 -0
- data/samples/bigdemo/wxCursor.rbw +136 -0
- data/samples/bigdemo/wxDialog.rbw +74 -0
- data/samples/bigdemo/wxDirDialog.rbw +29 -0
- data/samples/bigdemo/wxDragImage.rbw +70 -0
- data/samples/bigdemo/wxFileDialog.rbw +37 -0
- data/samples/bigdemo/wxFileDialog_Save.rbw +35 -0
- data/samples/bigdemo/wxFindReplaceDialog.rbw +82 -0
- data/samples/bigdemo/wxFontDialog.rbw +173 -0
- data/samples/bigdemo/wxFrame.rbw +53 -0
- data/samples/bigdemo/wxGauge.rbw +71 -0
- data/samples/bigdemo/wxGenericDirCtrl.rbw +74 -0
- data/samples/bigdemo/wxGrid.rbw +66 -0
- data/samples/bigdemo/wxHtmlHelpController.rbw +52 -0
- data/samples/bigdemo/wxListBox.rbw +140 -0
- data/samples/bigdemo/wxListCtrl_virtual.rbw +112 -0
- data/samples/bigdemo/wxMDIWindows.rbw +50 -0
- data/samples/bigdemo/wxMenu.rbw +236 -0
- data/samples/bigdemo/wxMessageDialog.rbw +27 -0
- data/samples/bigdemo/wxMiniFrame.rbw +70 -0
- data/samples/bigdemo/wxMultipleChoiceDialog.rbw +32 -0
- data/samples/bigdemo/wxNotebook.rbw +136 -0
- data/samples/bigdemo/wxProgressDialog.rbw +43 -0
- data/samples/bigdemo/wxRadioBox.rbw +72 -0
- data/samples/bigdemo/wxRadioButton.rbw +125 -0
- data/samples/bigdemo/wxSashWindow.rbw +141 -0
- data/samples/bigdemo/wxScrolledMessageDialog.rbw +57 -0
- data/samples/bigdemo/wxScrolledWindow.rbw +199 -0
- data/samples/bigdemo/wxSingleChoiceDialog.rbw +33 -0
- data/samples/bigdemo/wxSlider.rbw +42 -0
- data/samples/bigdemo/wxSpinButton.rbw +50 -0
- data/samples/bigdemo/wxSpinCtrl.rbw +51 -0
- data/samples/bigdemo/wxSplitterWindow.rbw +63 -0
- data/samples/bigdemo/wxStaticBitmap.rbw +51 -0
- data/samples/bigdemo/wxStaticText.rbw +55 -0
- data/samples/bigdemo/wxStatusBar.rbw +126 -0
- data/samples/bigdemo/wxTextCtrl.rbw +149 -0
- data/samples/bigdemo/wxTextEntryDialog.rbw +31 -0
- data/samples/bigdemo/wxToggleButton.rbw +49 -0
- data/samples/bigdemo/wxToolBar.rbw +131 -0
- data/samples/bigdemo/wxTreeCtrl.rbw +191 -0
- data/samples/calendar/calendar.rb +256 -0
- data/samples/caret/caret.rb +282 -0
- data/samples/caret/mondrian.xpm +44 -0
- data/samples/controls/controls.rb +1136 -0
- data/samples/controls/get_item_sample.rb +87 -0
- data/samples/controls/icons/choice.xpm +27 -0
- data/samples/controls/icons/combo.xpm +27 -0
- data/samples/controls/icons/gauge.xpm +27 -0
- data/samples/controls/icons/list.xpm +27 -0
- data/samples/controls/icons/radio.xpm +27 -0
- data/samples/controls/icons/stattext.xpm +24 -0
- data/samples/controls/icons/text.xpm +27 -0
- data/samples/controls/mondrian.ico +0 -0
- data/samples/controls/mondrian.xpm +44 -0
- data/samples/controls/test2.bmp +0 -0
- data/samples/dialogs/dialogs.rb +797 -0
- data/samples/dialogs/tips.txt +18 -0
- data/samples/dragdrop/dragdrop.rb +177 -0
- data/samples/drawing/graphics_drawing.rb +235 -0
- data/samples/drawing/images.rb +37 -0
- data/samples/drawing/paperclip.png +0 -0
- data/samples/etc/activation.rb +102 -0
- data/samples/etc/choice.rb +67 -0
- data/samples/etc/miniframe.rb +79 -0
- data/samples/etc/sash.rb +130 -0
- data/samples/etc/scrollwin.rb +110 -0
- data/samples/etc/system_settings.rb +252 -0
- data/samples/etc/threaded.rb +72 -0
- data/samples/etc/toolbar_sizer_additem.rb +55 -0
- data/samples/etc/wizard.rb +74 -0
- data/samples/event/event.rb +182 -0
- data/samples/event/update_ui_event.rb +70 -0
- data/samples/grid/grid.rb +198 -0
- data/samples/grid/gridtablebase.rb +148 -0
- data/samples/html/html.rb +262 -0
- data/samples/listbook/listbook.rb +174 -0
- data/samples/listbook/listbook.xrc +370 -0
- data/samples/mdi/mdi.rb +85 -0
- data/samples/media/mediactrl.rb +167 -0
- data/samples/minimal/minimal.rb +77 -0
- data/samples/minimal/mondrian.ico +0 -0
- data/samples/minimal/mondrian.png +0 -0
- data/samples/minimal/nothing.rb +16 -0
- data/samples/opengl/cube.rb +117 -0
- data/samples/printing/mondrian.ico +0 -0
- data/samples/printing/mondrian.xpm +44 -0
- data/samples/printing/printing.rb +487 -0
- data/samples/sockets/SocketPackets.rb +27 -0
- data/samples/sockets/res/message-new.png +0 -0
- data/samples/sockets/res/user.png +0 -0
- data/samples/sockets/wxClient.rb +395 -0
- data/samples/sockets/wxServer.rb +422 -0
- data/samples/sockets/wxSocketGUI.rb +97 -0
- data/samples/text/format-text-bold.png +0 -0
- data/samples/text/format-text-italic.png +0 -0
- data/samples/text/format-text-underline.png +0 -0
- data/samples/text/mondrian.ico +0 -0
- data/samples/text/mondrian.xpm +44 -0
- data/samples/text/rich_textctrl.rb +98 -0
- data/samples/text/scintilla.rb +169 -0
- data/samples/text/textctrl.rb +111 -0
- data/samples/text/unicode.rb +242 -0
- data/samples/text/utf8.txt +15 -0
- data/samples/treectrl/icon1.xpm +79 -0
- data/samples/treectrl/icon2.xpm +53 -0
- data/samples/treectrl/icon3.xpm +79 -0
- data/samples/treectrl/icon4.xpm +43 -0
- data/samples/treectrl/icon5.xpm +79 -0
- data/samples/treectrl/treectrl.rb +1166 -0
- data/samples/xrc/samples.xrc +46 -0
- data/samples/xrc/xrc_sample.rb +76 -0
- metadata +17 -3
@@ -0,0 +1,167 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
|
3
|
+
# Freely reusable code: see SAMPLES-LICENSE.TXT for details
|
4
|
+
begin
|
5
|
+
require 'rubygems'
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
require 'wx'
|
9
|
+
|
10
|
+
# This sample demonstrates the use of Wx::MediaCtrl, which can be used
|
11
|
+
# to playback sounds or movies using a platform-native player.
|
12
|
+
class MediaPanel < Wx::Panel
|
13
|
+
def initialize(parent)
|
14
|
+
super(parent, :style => Wx::TAB_TRAVERSAL|Wx::CLIP_CHILDREN)
|
15
|
+
|
16
|
+
# The actual media player control
|
17
|
+
@mc = Wx::MediaCtrl.new(self)
|
18
|
+
|
19
|
+
evt_media_loaded @mc,:on_media_loaded
|
20
|
+
|
21
|
+
# Some buttons to control playback
|
22
|
+
@btn_load = Wx::Button.new(self, :label => "Load File")
|
23
|
+
evt_button @btn_load,:on_load_file
|
24
|
+
|
25
|
+
@btn_play = Wx::Button.new(self, :label => "Play")
|
26
|
+
evt_button @btn_play, :on_play
|
27
|
+
@btn_play.disable
|
28
|
+
|
29
|
+
@btn_pause = Wx::Button.new(self, :label => "Pause")
|
30
|
+
evt_button @btn_pause, :on_pause
|
31
|
+
@btn_pause.disable
|
32
|
+
|
33
|
+
@btn_stop = Wx::Button.new(self, :label => "Stop")
|
34
|
+
evt_button @btn_stop,:on_stop
|
35
|
+
@btn_stop.disable
|
36
|
+
|
37
|
+
@slider = Wx::Slider.new(self, :min_value => 0, :max_value => 1)
|
38
|
+
@slider.min_size = [150, -1]
|
39
|
+
evt_slider @slider, :on_seek
|
40
|
+
|
41
|
+
@st_size = Wx::StaticText.new(self, :label => "", :size => [100, -1])
|
42
|
+
@st_len = Wx::StaticText.new(self, :label => "", :size => [100, -1])
|
43
|
+
@st_pos = Wx::StaticText.new(self, :label => "", :size => [100, -1])
|
44
|
+
|
45
|
+
# layout the panel
|
46
|
+
sizer = Wx::BoxSizer.new(Wx::VERTICAL)
|
47
|
+
|
48
|
+
sizer.add(@mc, 1, Wx::EXPAND|Wx::ALL, 5)
|
49
|
+
sizer.add(@slider, 0, Wx::EXPAND|Wx::ALL, 5)
|
50
|
+
|
51
|
+
# For the playback text
|
52
|
+
secs_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
|
53
|
+
secs_sizer.add(@st_pos, 0, Wx::ALL, 2)
|
54
|
+
secs_sizer.add(@st_len, 0, Wx::ALL, 2)
|
55
|
+
secs_sizer.add(@st_size, 0, Wx::ALL, 2)
|
56
|
+
sizer.add(secs_sizer, 0, Wx::ALIGN_RIGHT|Wx::ALL, 0)
|
57
|
+
|
58
|
+
btn_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
|
59
|
+
btn_sizer.add(@btn_load, 1, Wx::ALL, 2)
|
60
|
+
btn_sizer.add(@btn_play, 1, Wx::ALL, 2)
|
61
|
+
btn_sizer.add(@btn_pause, 1, Wx::ALL, 2)
|
62
|
+
btn_sizer.add(@btn_stop, 1, Wx::ALL, 2)
|
63
|
+
sizer.add(btn_sizer, 0, Wx::ALL, 5)
|
64
|
+
|
65
|
+
self.sizer = sizer
|
66
|
+
|
67
|
+
@timer = Wx::Timer.new(self,101)
|
68
|
+
evt_timer(101,:on_timer)
|
69
|
+
@timer.start(100)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Update the position indicator in seconds
|
73
|
+
def on_timer(evt)
|
74
|
+
offset = @mc.tell
|
75
|
+
# Will be -1 if nothing is loaded
|
76
|
+
if offset >= 0
|
77
|
+
@slider.value = offset
|
78
|
+
offset_secs = offset / 1000
|
79
|
+
@st_pos.label = "%i:%02d" % [ offset_secs / 60, offset_secs % 60 ]
|
80
|
+
else
|
81
|
+
@st_pos.label = ""
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Actually load a file into the mediactrl
|
86
|
+
def do_load_file(path)
|
87
|
+
@btn_play.disable
|
88
|
+
unless @mc.load(path)
|
89
|
+
Wx::message_box("Unable to load file", "ERROR",
|
90
|
+
Wx::ICON_ERROR|Wx::OK)
|
91
|
+
else
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
MEDIA_FILE_WILDCARD = "MP3 Files (*.mp3)|*.mp3|Avi Files (*.avi)|*.avi"
|
97
|
+
# Load a media file from disk
|
98
|
+
def on_load_file(evt)
|
99
|
+
dlg = Wx::FileDialog.new( self,
|
100
|
+
:message => "Choose a media file",
|
101
|
+
:wildcard => MEDIA_FILE_WILDCARD,
|
102
|
+
:style => Wx::OPEN)
|
103
|
+
if dlg.show_modal == Wx::ID_OK
|
104
|
+
do_load_file(dlg.path)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Move the media to a position in the file, using the slider
|
109
|
+
def on_seek(evt)
|
110
|
+
offset = @slider.value
|
111
|
+
@mc.seek(offset)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Set up the initial size for the move
|
115
|
+
def on_media_loaded(evt)
|
116
|
+
# Readjust to the original size of the video
|
117
|
+
@mc.set_initial_size
|
118
|
+
|
119
|
+
# Enable the control buttons
|
120
|
+
@btn_play.enable
|
121
|
+
@btn_pause.enable
|
122
|
+
@btn_stop.enable
|
123
|
+
|
124
|
+
# Update the length and position text indicators with the media's
|
125
|
+
# time length, shown as minutes and seconds
|
126
|
+
len_secs = @mc.length / 1000
|
127
|
+
@st_len.label = "%i:%02d" % [ len_secs / 60, len_secs % 60 ]
|
128
|
+
|
129
|
+
# Set the seek slider
|
130
|
+
@slider.set_range(0, @mc.length)
|
131
|
+
|
132
|
+
# Refresh the layout
|
133
|
+
sizer.layout
|
134
|
+
end
|
135
|
+
|
136
|
+
# Stop the playback
|
137
|
+
def on_stop(evt)
|
138
|
+
@mc.stop
|
139
|
+
end
|
140
|
+
|
141
|
+
# Pause the playback
|
142
|
+
def on_pause(evt)
|
143
|
+
@mc.pause
|
144
|
+
end
|
145
|
+
|
146
|
+
# Start the playback
|
147
|
+
def on_play(evt)
|
148
|
+
if not @mc.play
|
149
|
+
Wx::MessageBox("unable to play media","ERROR",Wx::ICON_ERROR|Wx::OK)
|
150
|
+
else
|
151
|
+
@mc.set_initial_size
|
152
|
+
sizer.layout
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
class MediaFrame<Wx::Frame
|
158
|
+
def initialize()
|
159
|
+
super(nil,:title=>"MediaCtrl test",:size=>[700,700])
|
160
|
+
win = MediaPanel.new(self)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
# Actually run the app
|
165
|
+
Wx::App.run do
|
166
|
+
MediaFrame.new.show
|
167
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
|
3
|
+
# Freely reusable code: see SAMPLES-LICENSE.TXT for details
|
4
|
+
begin
|
5
|
+
require 'rubygems'
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
require 'wx'
|
9
|
+
|
10
|
+
# This sample shows a fairly minimal Wx::App using a Frame, with a
|
11
|
+
# MenuBar and StatusBar but no controls. For the absolute minimum app,
|
12
|
+
# see nothing.rb
|
13
|
+
|
14
|
+
# A Wx::Frame is a self-contained, top-level Window that can contain
|
15
|
+
# controls, menubars, and statusbars
|
16
|
+
class MinimalFrame < Wx::Frame
|
17
|
+
def initialize(title)
|
18
|
+
# The main application frame has no parent (nil)
|
19
|
+
super(nil, :title => title, :size => [ 400, 300 ])
|
20
|
+
|
21
|
+
# Give the frame an icon. PNG is a good choice of format for
|
22
|
+
# cross-platform images. Note that OS X doesn't have "Frame" icons.
|
23
|
+
icon_file = File.join( File.dirname(__FILE__), "mondrian.png")
|
24
|
+
self.icon = Wx::Icon.new(icon_file)
|
25
|
+
|
26
|
+
menu_bar = Wx::MenuBar.new
|
27
|
+
# The "file" menu
|
28
|
+
menu_file = Wx::Menu.new
|
29
|
+
# Using Wx::ID_EXIT standard id means the menu item will be given
|
30
|
+
# the right label for the platform and language, and placed in the
|
31
|
+
# correct platform-specific menu - eg on OS X, in the Application's menu
|
32
|
+
menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
|
33
|
+
menu_bar.append(menu_file, "&File")
|
34
|
+
|
35
|
+
# The "help" menu
|
36
|
+
menu_help = Wx::Menu.new
|
37
|
+
menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
|
38
|
+
menu_bar.append(menu_help, "&Help")
|
39
|
+
|
40
|
+
# Assign the menubar to this frame
|
41
|
+
self.menu_bar = menu_bar
|
42
|
+
|
43
|
+
# Create a status bar at the bottom of the frame
|
44
|
+
create_status_bar(2)
|
45
|
+
self.status_text = "Welcome to wxRuby!"
|
46
|
+
|
47
|
+
# Set it up to handle menu events using the relevant methods.
|
48
|
+
evt_menu Wx::ID_EXIT, :on_quit
|
49
|
+
evt_menu Wx::ID_ABOUT, :on_about
|
50
|
+
end
|
51
|
+
|
52
|
+
# End the application; it should finish automatically when the last
|
53
|
+
# window is closed.
|
54
|
+
def on_quit
|
55
|
+
close()
|
56
|
+
end
|
57
|
+
|
58
|
+
# show an 'About' dialog - WxRuby's about_box function will show a
|
59
|
+
# platform-native 'About' dialog, but you could also use an ordinary
|
60
|
+
# Wx::MessageDialog here.
|
61
|
+
def on_about
|
62
|
+
Wx::about_box(:name => self.title,
|
63
|
+
:version => Wx::WXRUBY_VERSION,
|
64
|
+
:description => "This is the minimal sample",
|
65
|
+
:developers => ['The wxRuby Development Team'] )
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Wx::App is the container class for any wxruby app. To start an
|
70
|
+
# application, either define a subclass of Wx::App, create an instance,
|
71
|
+
# and call its main_loop method, OR, simply call the Wx::App.run class
|
72
|
+
# method, as shown here.
|
73
|
+
Wx::App.run do
|
74
|
+
self.app_name = 'Minimal'
|
75
|
+
frame = MinimalFrame.new("Minimal wxRuby App")
|
76
|
+
frame.show
|
77
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
|
3
|
+
# Freely reusable code: see SAMPLES-LICENSE.TXT for details
|
4
|
+
begin
|
5
|
+
require 'rubygems'
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
require 'wx'
|
9
|
+
|
10
|
+
|
11
|
+
# This is the minimum code to start a WxRuby app - create a Frame, and
|
12
|
+
# show it.
|
13
|
+
Wx::App.run do
|
14
|
+
frame = Wx::Frame.new(nil, :title => "Minimal wxRuby App")
|
15
|
+
frame.show
|
16
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
|
3
|
+
# Freely reusable code: see SAMPLES-LICENSE.TXT for details
|
4
|
+
begin
|
5
|
+
require 'rubygems'
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
require 'wx'
|
9
|
+
require 'gl'
|
10
|
+
require 'glu'
|
11
|
+
|
12
|
+
include Gl
|
13
|
+
include Glu
|
14
|
+
|
15
|
+
class CubeFrame < Wx::Frame
|
16
|
+
def initialize(title)
|
17
|
+
super(nil, :title => title, :size => [ 400, 300 ])
|
18
|
+
attrib = [Wx::GL_RGBA, Wx::GL_DOUBLEBUFFER, Wx::GL_DEPTH_SIZE, 24]
|
19
|
+
@canvas = Wx::GLCanvas.new(self, -1, [-1, -1], [-1, -1],
|
20
|
+
Wx::FULL_REPAINT_ON_RESIZE, 'GLCanvas', attrib)
|
21
|
+
@canvas.evt_paint { @canvas.paint { render } }
|
22
|
+
@canvas.evt_key_down {|evt| on_key_down(evt.get_key_code) }
|
23
|
+
@rotate = [0.0, 0.0, 0.0]
|
24
|
+
end
|
25
|
+
|
26
|
+
def on_key_down(key)
|
27
|
+
case key
|
28
|
+
when Wx::K_UP
|
29
|
+
@rotate[0] -= 3.0
|
30
|
+
when Wx::K_DOWN
|
31
|
+
@rotate[0] += 3.0
|
32
|
+
when Wx::K_LEFT
|
33
|
+
@rotate[2] -= 3.0
|
34
|
+
when Wx::K_RIGHT
|
35
|
+
@rotate[2] += 3.0
|
36
|
+
end
|
37
|
+
render
|
38
|
+
end
|
39
|
+
|
40
|
+
def render
|
41
|
+
@canvas.set_current
|
42
|
+
sz = @canvas.get_size
|
43
|
+
w = sz.get_width
|
44
|
+
h = sz.get_height
|
45
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
46
|
+
glEnable(GL_DEPTH_TEST)
|
47
|
+
glViewport(0, 0, w, h)
|
48
|
+
glMatrixMode(GL_PROJECTION)
|
49
|
+
glLoadIdentity()
|
50
|
+
gluPerspective(30.0, w.to_f/h.to_f, 0.1, 1000.0)
|
51
|
+
glMatrixMode(GL_MODELVIEW)
|
52
|
+
glLoadIdentity()
|
53
|
+
gluLookAt(0.0, -10.0, 0.0,
|
54
|
+
0.0, 0.0, 0.0,
|
55
|
+
0.0, 0.0, 1.0)
|
56
|
+
glRotate(@rotate[0], 1.0, 0.0, 0.0)
|
57
|
+
glRotate(@rotate[1], 0.0, 1.0, 0.0)
|
58
|
+
glRotate(@rotate[2], 0.0, 0.0, 1.0)
|
59
|
+
glBegin(GL_TRIANGLES)
|
60
|
+
#left
|
61
|
+
glColor3d(1.0, 1.0, 1.0)
|
62
|
+
glVertex3d(-1.0, 1.0, 1.0)
|
63
|
+
glVertex3d(-1.0, 1.0,-1.0)
|
64
|
+
glVertex3d(-1.0,-1.0, 1.0)
|
65
|
+
glVertex3d(-1.0,-1.0, 1.0)
|
66
|
+
glVertex3d(-1.0, 1.0,-1.0)
|
67
|
+
glVertex3d(-1.0,-1.0,-1.0)
|
68
|
+
#right
|
69
|
+
glColor3d(0.0, 1.0, 1.0)
|
70
|
+
glVertex3d( 1.0,-1.0, 1.0)
|
71
|
+
glVertex3d( 1.0,-1.0,-1.0)
|
72
|
+
glVertex3d( 1.0, 1.0, 1.0)
|
73
|
+
glVertex3d( 1.0, 1.0, 1.0)
|
74
|
+
glVertex3d( 1.0,-1.0,-1.0)
|
75
|
+
glVertex3d( 1.0, 1.0,-1.0)
|
76
|
+
#up
|
77
|
+
glColor3d(0.0, 0.0, 1.0)
|
78
|
+
glVertex3d(-1.0, 1.0, 1.0)
|
79
|
+
glVertex3d(-1.0,-1.0, 1.0)
|
80
|
+
glVertex3d( 1.0, 1.0, 1.0)
|
81
|
+
glVertex3d( 1.0, 1.0, 1.0)
|
82
|
+
glVertex3d(-1.0,-1.0, 1.0)
|
83
|
+
glVertex3d( 1.0,-1.0, 1.0)
|
84
|
+
#down
|
85
|
+
glColor3d(1.0, 0.0, 0.0)
|
86
|
+
glVertex3d(-1.0,-1.0,-1.0)
|
87
|
+
glVertex3d(-1.0, 1.0,-1.0)
|
88
|
+
glVertex3d( 1.0,-1.0,-1.0)
|
89
|
+
glVertex3d( 1.0,-1.0,-1.0)
|
90
|
+
glVertex3d(-1.0, 1.0,-1.0)
|
91
|
+
glVertex3d( 1.0, 1.0,-1.0)
|
92
|
+
#front
|
93
|
+
glColor3d(1.0, 1.0, 0.0)
|
94
|
+
glVertex3d(-1.0,-1.0, 1.0)
|
95
|
+
glVertex3d(-1.0,-1.0,-1.0)
|
96
|
+
glVertex3d( 1.0,-1.0, 1.0)
|
97
|
+
glVertex3d( 1.0,-1.0, 1.0)
|
98
|
+
glVertex3d(-1.0,-1.0,-1.0)
|
99
|
+
glVertex3d( 1.0,-1.0,-1.0)
|
100
|
+
#back
|
101
|
+
glColor3d(0.0, 1.0, 0.0)
|
102
|
+
glVertex3d( 1.0, 1.0, 1.0)
|
103
|
+
glVertex3d( 1.0, 1.0,-1.0)
|
104
|
+
glVertex3d(-1.0, 1.0, 1.0)
|
105
|
+
glVertex3d(-1.0, 1.0, 1.0)
|
106
|
+
glVertex3d( 1.0, 1.0,-1.0)
|
107
|
+
glVertex3d(-1.0, 1.0,-1.0)
|
108
|
+
glEnd()
|
109
|
+
@canvas.swap_buffers
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
Wx::App.run do
|
114
|
+
self.app_name = 'GLCanvas Cube'
|
115
|
+
frame = CubeFrame.new("OpenGL Canvas wxRuby App")
|
116
|
+
frame.show
|
117
|
+
end
|
Binary file
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/* XPM */
|
2
|
+
static char *mondrian_xpm[] = {
|
3
|
+
/* columns rows colors chars-per-pixel */
|
4
|
+
"32 32 6 1",
|
5
|
+
" c Black",
|
6
|
+
". c Blue",
|
7
|
+
"X c #00bf00",
|
8
|
+
"o c Red",
|
9
|
+
"O c Yellow",
|
10
|
+
"+ c Gray100",
|
11
|
+
/* pixels */
|
12
|
+
" ",
|
13
|
+
" oooooo +++++++++++++++++++++++ ",
|
14
|
+
" oooooo +++++++++++++++++++++++ ",
|
15
|
+
" oooooo +++++++++++++++++++++++ ",
|
16
|
+
" oooooo +++++++++++++++++++++++ ",
|
17
|
+
" oooooo +++++++++++++++++++++++ ",
|
18
|
+
" oooooo +++++++++++++++++++++++ ",
|
19
|
+
" oooooo +++++++++++++++++++++++ ",
|
20
|
+
" ",
|
21
|
+
" ++++++ ++++++++++++++++++ .... ",
|
22
|
+
" ++++++ ++++++++++++++++++ .... ",
|
23
|
+
" ++++++ ++++++++++++++++++ .... ",
|
24
|
+
" ++++++ ++++++++++++++++++ .... ",
|
25
|
+
" ++++++ ++++++++++++++++++ .... ",
|
26
|
+
" ++++++ ++++++++++++++++++ ",
|
27
|
+
" ++++++ ++++++++++++++++++ ++++ ",
|
28
|
+
" ++++++ ++++++++++++++++++ ++++ ",
|
29
|
+
" ++++++ ++++++++++++++++++ ++++ ",
|
30
|
+
" ++++++ ++++++++++++++++++ ++++ ",
|
31
|
+
" ++++++ ++++++++++++++++++ ++++ ",
|
32
|
+
" ++++++ ++++++++++++++++++ ++++ ",
|
33
|
+
" ++++++ ++++++++++++++++++ ++++ ",
|
34
|
+
" ++++++ ++++++++++++++++++ ++++ ",
|
35
|
+
" ++++++ ++++++++++++++++++ ++++ ",
|
36
|
+
" ++++++ ++++ ",
|
37
|
+
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
38
|
+
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
39
|
+
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
40
|
+
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
41
|
+
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
42
|
+
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
43
|
+
" "
|
44
|
+
};
|
@@ -0,0 +1,487 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
|
3
|
+
# Freely reusable code: see SAMPLES-LICENSE.TXT for details
|
4
|
+
begin
|
5
|
+
require 'rubygems'
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
require 'wx'
|
9
|
+
|
10
|
+
WXPRINT_QUIT = Wx::ID_EXIT
|
11
|
+
WXPRINT_PRINT = Wx::ID_PRINT
|
12
|
+
WXPRINT_PAGE_SETUP = Wx::ID_PRINT_SETUP
|
13
|
+
WXPRINT_PREVIEW = Wx::ID_PREVIEW
|
14
|
+
|
15
|
+
WXPRINT_PRINT_PS = 105
|
16
|
+
WXPRINT_PAGE_SETUP_PS = 107
|
17
|
+
WXPRINT_PREVIEW_PS = 108
|
18
|
+
|
19
|
+
WXPRINT_ABOUT = Wx::ID_ABOUT
|
20
|
+
|
21
|
+
WXPRINT_ANGLEUP = 110
|
22
|
+
WXPRINT_ANGLEDOWN = 111
|
23
|
+
|
24
|
+
class MyFrame < Wx::Frame
|
25
|
+
|
26
|
+
attr_accessor :canvas
|
27
|
+
|
28
|
+
def initialize(parent,title,pos,size)
|
29
|
+
super(parent,-1,title,pos,size)
|
30
|
+
@canvas = nil
|
31
|
+
@bitmap = Wx::Bitmap.new
|
32
|
+
@angle = 30
|
33
|
+
|
34
|
+
# map events
|
35
|
+
evt_menu(WXPRINT_QUIT) {|e| on_exit(e)}
|
36
|
+
evt_menu(WXPRINT_PRINT) {|e| on_print(e)}
|
37
|
+
evt_menu(WXPRINT_PREVIEW) {|e| on_print_preview(e)}
|
38
|
+
evt_menu(WXPRINT_PAGE_SETUP) {|e| on_page_setup(e)}
|
39
|
+
evt_menu(WXPRINT_ABOUT) {|e| on_print_about(e)}
|
40
|
+
evt_menu(WXPRINT_ANGLEUP) {|e| on_angle_up(e)}
|
41
|
+
evt_menu(WXPRINT_ANGLEDOWN) {|e| on_angle_down(e)}
|
42
|
+
end
|
43
|
+
|
44
|
+
def draw(dc)
|
45
|
+
dc.set_background(Wx::WHITE_BRUSH)
|
46
|
+
dc.clear()
|
47
|
+
dc.set_font(Wx::get_app.test_font)
|
48
|
+
|
49
|
+
dc.set_background_mode(Wx::TRANSPARENT)
|
50
|
+
|
51
|
+
dc.set_brush(Wx::CYAN_BRUSH)
|
52
|
+
dc.set_pen(Wx::RED_PEN)
|
53
|
+
|
54
|
+
dc.draw_rounded_rectangle(0, 20, 200, 80, 20)
|
55
|
+
|
56
|
+
dc.draw_text( "Rectangle 200 by 80", 40, 40)
|
57
|
+
|
58
|
+
dc.set_pen( Wx::Pen.new(Wx::BLACK,0,Wx::DOT_DASH) )
|
59
|
+
dc.draw_ellipse(50, 140, 100, 50)
|
60
|
+
dc.set_pen(Wx::RED_PEN)
|
61
|
+
|
62
|
+
dc.draw_text( "Test message: this is in 10 point text", 10, 180)
|
63
|
+
|
64
|
+
test = "Hebrew שלום -- Japanese (日本語)"
|
65
|
+
dc.draw_text( test, 10, 200 )
|
66
|
+
|
67
|
+
points = []
|
68
|
+
points << Wx::Point.new(0,0)
|
69
|
+
points << Wx::Point.new(20,0)
|
70
|
+
points << Wx::Point.new(20,20)
|
71
|
+
points << Wx::Point.new(10,20)
|
72
|
+
points << Wx::Point.new(10,-20)
|
73
|
+
|
74
|
+
dc.draw_polygon( points, 20, 250, Wx::ODDEVEN_RULE )
|
75
|
+
dc.draw_polygon( points, 50, 250, Wx::WINDING_RULE )
|
76
|
+
|
77
|
+
dc.draw_elliptic_arc( 80, 250, 60, 30, 0.0, 270.0 )
|
78
|
+
|
79
|
+
points[0].x = 150
|
80
|
+
points[0].y = 250
|
81
|
+
points[1].x = 180
|
82
|
+
points[1].y = 250
|
83
|
+
points[2].x = 180
|
84
|
+
points[2].y = 220
|
85
|
+
points[3].x = 200
|
86
|
+
points[3].y = 220
|
87
|
+
points.pop
|
88
|
+
dc.draw_spline( points )
|
89
|
+
|
90
|
+
dc.draw_arc( 20,10, 10,10, 25,40 )
|
91
|
+
|
92
|
+
str = ""
|
93
|
+
i = 0
|
94
|
+
str = "---- Text at angle #{i} ----"
|
95
|
+
dc.draw_rotated_text( str, 100, 300, i )
|
96
|
+
|
97
|
+
i = @angle;
|
98
|
+
str = "---- Text at angle #{i} ----"
|
99
|
+
dc.draw_rotated_text( str, 100, 300, i )
|
100
|
+
|
101
|
+
dc.set_pen(Wx::BLACK_PEN)
|
102
|
+
dc.draw_line(0, 0, 200, 200)
|
103
|
+
dc.draw_line(200, 0, 0, 200)
|
104
|
+
|
105
|
+
# Load icon
|
106
|
+
if Wx::PLATFORM == "WXMSW"
|
107
|
+
icon_file = File.join(File.dirname(__FILE__), 'mondrian.ico')
|
108
|
+
my_icon = Wx::Icon.new(icon_file, Wx::BITMAP_TYPE_ICO)
|
109
|
+
else
|
110
|
+
icon_file = File.join(File.dirname(__FILE__), 'mondrian.xpm')
|
111
|
+
my_icon = Wx::Icon.new(icon_file, Wx::BITMAP_TYPE_XPM)
|
112
|
+
end
|
113
|
+
|
114
|
+
dc.draw_icon( my_icon, 100, 100)
|
115
|
+
|
116
|
+
if @bitmap.is_ok
|
117
|
+
dc.draw_bitmap( @bitmap, 10, 10 )
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def on_angle_up(event)
|
122
|
+
@angle += 5
|
123
|
+
canvas.refresh
|
124
|
+
end
|
125
|
+
|
126
|
+
def on_angle_down(event)
|
127
|
+
@angle -= 5
|
128
|
+
canvas.refresh
|
129
|
+
end
|
130
|
+
|
131
|
+
def on_size(event)
|
132
|
+
super(event)
|
133
|
+
end
|
134
|
+
|
135
|
+
def on_print(event)
|
136
|
+
print_dialog_data = Wx::PrintDialogData.new(Wx::get_app.print_data)
|
137
|
+
|
138
|
+
printer = Wx::Printer.new(print_dialog_data)
|
139
|
+
printout = MyPrintout.new("My printout")
|
140
|
+
if (!printer.print(self, printout, true))
|
141
|
+
if (Wx::Printer.get_last_error == Wx::PRINTER_ERROR)
|
142
|
+
Wx::message_box("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", Wx::OK)
|
143
|
+
else
|
144
|
+
Wx::message_box("You canceled printing", "Printing", Wx::OK)
|
145
|
+
end
|
146
|
+
else
|
147
|
+
Wx::get_app.print_data = printer.get_print_dialog_data.get_print_data
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def on_print_preview(event)
|
152
|
+
# Pass two printout objects: for preview, and possible printing.
|
153
|
+
print_dialog_data = Wx::PrintDialogData.new(Wx::get_app.print_data)
|
154
|
+
preview = Wx::PrintPreview.new(MyPrintout.new, MyPrintout.new, print_dialog_data)
|
155
|
+
if not preview.is_ok
|
156
|
+
#delete preview;
|
157
|
+
Wx::message_box("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", Wx::OK)
|
158
|
+
return
|
159
|
+
end
|
160
|
+
|
161
|
+
prev_frame = Wx::PreviewFrame.new(preview, self, "Demo Print Preview", Wx::Point.new(100, 100), Wx::Size.new(600, 650))
|
162
|
+
prev_frame.centre(Wx::BOTH)
|
163
|
+
prev_frame.init
|
164
|
+
prev_frame.show
|
165
|
+
end
|
166
|
+
|
167
|
+
def on_page_setup(event)
|
168
|
+
Wx::get_app.page_setup_data = Wx::PageSetupDialogData.new(Wx::get_app.print_data)
|
169
|
+
page_setup_dialog = Wx::PageSetupDialog.new(self, Wx::get_app.page_setup_data)
|
170
|
+
page_setup_dialog.show_modal
|
171
|
+
|
172
|
+
Wx::get_app.print_data = page_setup_dialog.get_page_setup_data.get_print_data
|
173
|
+
Wx::get_app.page_setup_data = Wx::PageSetupDialogData.new(Wx::get_app.print_data)
|
174
|
+
end
|
175
|
+
|
176
|
+
def on_exit(event)
|
177
|
+
close(true)
|
178
|
+
end
|
179
|
+
|
180
|
+
def on_print_about(event)
|
181
|
+
Wx::message_box("wxWidgets printing demo\nAuthor: Julian Smart\nAdapted to wxRuby by Sean Long",
|
182
|
+
"About wxRuby printing demo", Wx::OK|Wx::CENTRE)
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
class MyCanvas < Wx::ScrolledWindow
|
188
|
+
#attr_accessor :frame
|
189
|
+
|
190
|
+
def initialize(parent,pos,size,style = Wx::RETAINED)
|
191
|
+
super(parent,-1,pos,size,style)
|
192
|
+
@frame = parent
|
193
|
+
set_background_colour(Wx::WHITE)
|
194
|
+
evt_mouse_events() {|e| on_event(e)}
|
195
|
+
end
|
196
|
+
|
197
|
+
def on_draw(dc)
|
198
|
+
@frame.draw(dc)
|
199
|
+
end
|
200
|
+
|
201
|
+
def on_event(event)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
class MyPrintout < Wx::Printout
|
206
|
+
def initialize(title = "My printout")
|
207
|
+
super(title)
|
208
|
+
end
|
209
|
+
|
210
|
+
def on_print_page(page)
|
211
|
+
dc = get_dc
|
212
|
+
if dc
|
213
|
+
if page == 1
|
214
|
+
draw_page_one(dc)
|
215
|
+
elsif (page == 2)
|
216
|
+
draw_page_two(dc)
|
217
|
+
end
|
218
|
+
dc.set_device_origin(0, 0)
|
219
|
+
dc.set_user_scale(1.0, 1.0)
|
220
|
+
|
221
|
+
buf = "PAGE #{page}"
|
222
|
+
dc.draw_text(buf, 10, 10)
|
223
|
+
|
224
|
+
return true
|
225
|
+
else
|
226
|
+
return false
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
def on_begin_document(start_page,end_page)
|
231
|
+
go_ahead = super(start_page, end_page)
|
232
|
+
if (!go_ahead)
|
233
|
+
return false
|
234
|
+
end
|
235
|
+
return true
|
236
|
+
end
|
237
|
+
|
238
|
+
def has_page(page)
|
239
|
+
return (page == 1 || page == 2)
|
240
|
+
end
|
241
|
+
|
242
|
+
def get_page_info
|
243
|
+
min_page = 1
|
244
|
+
max_page = 2
|
245
|
+
sel_page_from = 1
|
246
|
+
sel_page_to = 2
|
247
|
+
[min_page,max_page,sel_page_from,sel_page_to]
|
248
|
+
end
|
249
|
+
|
250
|
+
def draw_page_one(dc)
|
251
|
+
# You might use THIS code if you were scaling
|
252
|
+
# graphics of known size to fit on the page.
|
253
|
+
|
254
|
+
# We know the graphic is 200x200. If we didn't know this,
|
255
|
+
# we'd need to calculate it.
|
256
|
+
max_x = 200
|
257
|
+
max_y = 200
|
258
|
+
|
259
|
+
# Let's have at least 50 device units margin
|
260
|
+
margin_x = 50
|
261
|
+
margin_y = 50
|
262
|
+
|
263
|
+
# Add the margin to the graphic size
|
264
|
+
max_x += (2*margin_x)
|
265
|
+
max_y += (2*margin_y)
|
266
|
+
|
267
|
+
# Get the size of the DC in pixels
|
268
|
+
size = dc.get_size
|
269
|
+
w = size.get_width
|
270
|
+
h = size.get_height
|
271
|
+
|
272
|
+
# Calculate a suitable scaling factor
|
273
|
+
scale_x=(w/max_x)
|
274
|
+
scale_y=(h/max_y)
|
275
|
+
|
276
|
+
# Use x or y scaling factor, whichever fits on the DC
|
277
|
+
#actualScale = Wx::min(scaleX,scaleY)
|
278
|
+
if scale_x < scale_y
|
279
|
+
actual_scale = scale_x
|
280
|
+
else
|
281
|
+
actual_scale = scale_y
|
282
|
+
end
|
283
|
+
|
284
|
+
# Calculate the position on the DC for centring the graphic
|
285
|
+
pos_x = ((w - (200*actual_scale))/2.0)
|
286
|
+
pos_y = ((h - (200*actual_scale))/2.0)
|
287
|
+
|
288
|
+
# Set the scale and origin
|
289
|
+
dc.set_user_scale(actual_scale, actual_scale)
|
290
|
+
dc.set_device_origin( pos_x.to_i, pos_y.to_i )
|
291
|
+
|
292
|
+
Wx::get_app.frame.draw(dc)
|
293
|
+
end
|
294
|
+
|
295
|
+
def draw_page_two(dc)
|
296
|
+
# You might use THIS code to set the printer DC to ROUGHLY reflect
|
297
|
+
# the screen text size. This page also draws lines of actual length
|
298
|
+
# 5cm on the page.
|
299
|
+
|
300
|
+
# Get the logical pixels per inch of screen and printer
|
301
|
+
ppi_screen_x, ppi_screen_y = get_ppi_screen
|
302
|
+
ppi_printer_x, ppi_printer_y = get_ppi_printer
|
303
|
+
|
304
|
+
# This scales the DC so that the printout roughly represents the
|
305
|
+
# the screen scaling. The text point size _should_ be the right size
|
306
|
+
# but in fact is too small for some reason. This is a detail that will
|
307
|
+
# need to be addressed at some point but can be fudged for the
|
308
|
+
# moment.
|
309
|
+
scale = ( ppi_printer_x.to_f / ppi_screen_x.to_f )
|
310
|
+
|
311
|
+
# Now we have to check in case our real page size is reduced
|
312
|
+
# (e.g. because we're drawing to a print preview memory DC)
|
313
|
+
page_width, page_height = get_page_size_pixels
|
314
|
+
size = dc.get_size
|
315
|
+
w = size.get_width
|
316
|
+
h = size.get_height
|
317
|
+
|
318
|
+
# If printer pageWidth == current DC width, then this doesn't
|
319
|
+
# change. But w might be the preview bitmap width, so scale down.
|
320
|
+
overall_scale = scale * (w/page_width)
|
321
|
+
dc.set_user_scale(overall_scale, overall_scale)
|
322
|
+
|
323
|
+
# Calculate conversion factor for converting millimetres into
|
324
|
+
# logical units.
|
325
|
+
# There are approx. 25.4 mm to the inch. There are ppi
|
326
|
+
# device units to the inch. Therefore 1 mm corresponds to
|
327
|
+
# ppi/25.4 device units. We also divide by the
|
328
|
+
# screen-to-printer scaling factor, because we need to
|
329
|
+
# unscale to pass logical units to DrawLine.
|
330
|
+
|
331
|
+
# Draw 50 mm by 50 mm L shape
|
332
|
+
log_units_factor = (ppi_printer_x/(scale*25.4))
|
333
|
+
log_units = (50*log_units_factor)
|
334
|
+
dc.set_pen(Wx::BLACK_PEN)
|
335
|
+
dc.draw_line(50, 250, (50.0 + log_units).to_i, 250)
|
336
|
+
dc.draw_line(50, 250, 50, (250.0 + log_units).to_i)
|
337
|
+
|
338
|
+
dc.set_background_mode(Wx::TRANSPARENT)
|
339
|
+
dc.set_brush(Wx::TRANSPARENT_BRUSH)
|
340
|
+
|
341
|
+
# GetTextExtent demo:
|
342
|
+
words = ["This ", "is ", "GetTextExtent ", "testing ", "string. ", "Enjoy ", "it!"]
|
343
|
+
w, h = 0,0
|
344
|
+
x = 200
|
345
|
+
y= 250
|
346
|
+
fnt = Wx::Font.new(15, Wx::SWISS, Wx::NORMAL, Wx::NORMAL)
|
347
|
+
|
348
|
+
dc.set_font(fnt)
|
349
|
+
|
350
|
+
words.each do |word|
|
351
|
+
w,h = dc.get_text_extent(word)
|
352
|
+
dc.draw_rectangle(x, y, w.to_i, h.to_i)
|
353
|
+
w,h = dc.get_text_extent(word)
|
354
|
+
dc.draw_text(word, x, y)
|
355
|
+
x += w
|
356
|
+
end
|
357
|
+
|
358
|
+
dc.set_font(Wx::get_app.test_font)
|
359
|
+
|
360
|
+
dc.draw_text("Some test text", 200, 300 )
|
361
|
+
|
362
|
+
left_margin = 20
|
363
|
+
right_margin = 20
|
364
|
+
top_margin = 20
|
365
|
+
bottom_margin = 20
|
366
|
+
|
367
|
+
page_width_mm, page_height_mm = get_page_size_mm
|
368
|
+
|
369
|
+
left_margin_logical = (log_units_factor*left_margin).to_i
|
370
|
+
top_margin_logical = (log_units_factor*top_margin).to_i
|
371
|
+
bottom_margin_logical = (log_units_factor*(page_height_mm - bottom_margin)).to_i
|
372
|
+
right_margin_logical = (log_units_factor*(page_width_mm - right_margin)).to_i
|
373
|
+
|
374
|
+
dc.set_pen(Wx::RED_PEN)
|
375
|
+
dc.draw_line( left_margin_logical, top_margin_logical,
|
376
|
+
right_margin_logical, top_margin_logical)
|
377
|
+
dc.draw_line( left_margin_logical, bottom_margin_logical,
|
378
|
+
right_margin_logical, bottom_margin_logical)
|
379
|
+
|
380
|
+
write_page_header(self, dc, "A header", log_units_factor)
|
381
|
+
end
|
382
|
+
|
383
|
+
# Writes a header on a page. Margin units are in millimetres.
|
384
|
+
def write_page_header(printout, dc, text, mm_to_logical)
|
385
|
+
page_width_mm, page_height_mm = printout.get_page_size_mm
|
386
|
+
|
387
|
+
left_margin = 10
|
388
|
+
top_margin = 10
|
389
|
+
right_margin = 10
|
390
|
+
|
391
|
+
left_margin_logical = (mm_to_logical*left_margin).to_i
|
392
|
+
top_margin_logical = (mm_to_logical*top_margin).to_i
|
393
|
+
right_margin_logical = (mm_to_logical*(page_width_mm - right_margin)).to_i
|
394
|
+
|
395
|
+
x_extent, y_extent= dc.get_text_extent(text)
|
396
|
+
x_pos = (((((page_width_mm - left_margin - right_margin)/2.0)+left_margin)*mm_to_logical) - (x_extent/2.0))
|
397
|
+
dc.draw_text(text, x_pos.to_i, top_margin_logical)
|
398
|
+
|
399
|
+
dc.set_pen(Wx::BLACK_PEN)
|
400
|
+
dc.draw_line( left_margin_logical, (top_margin_logical + y_extent).to_i,
|
401
|
+
right_margin_logical, (top_margin_logical + y_extent).to_i )
|
402
|
+
|
403
|
+
return true
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
class MyApp < Wx::App
|
408
|
+
attr_accessor :frame,:test_font,:print_data,:page_setup_data
|
409
|
+
|
410
|
+
def on_init
|
411
|
+
@test_font = Wx::Font.new(10, Wx::SWISS, Wx::NORMAL, Wx::NORMAL)
|
412
|
+
|
413
|
+
# Create the main frame window
|
414
|
+
@frame = MyFrame.new(nil, "wxRuby Printing Demo", Wx::Point.new(0, 0), Wx::Size.new(400, 400))
|
415
|
+
|
416
|
+
# Give it a status line
|
417
|
+
@frame.create_status_bar(2)
|
418
|
+
|
419
|
+
|
420
|
+
# Load icon and bitmap
|
421
|
+
if Wx::PLATFORM == "WXMSW"
|
422
|
+
icon_file = File.join(File.dirname(__FILE__), 'mondrian.ico')
|
423
|
+
@frame.set_icon( Wx::Icon.new(icon_file, Wx::BITMAP_TYPE_ICO) )
|
424
|
+
else
|
425
|
+
icon_file = File.join(File.dirname(__FILE__), 'mondrian.xpm')
|
426
|
+
@frame.set_icon( Wx::Icon.new(icon_file, Wx::BITMAP_TYPE_XPM) )
|
427
|
+
end
|
428
|
+
|
429
|
+
# Make a menubar
|
430
|
+
file_menu = Wx::Menu.new
|
431
|
+
|
432
|
+
file_menu.append(WXPRINT_PRINT, "&Print...","Print")
|
433
|
+
file_menu.append(WXPRINT_PAGE_SETUP, "Page Set&up...","Page setup")
|
434
|
+
file_menu.append(WXPRINT_PREVIEW, "Print Pre&view","Preview")
|
435
|
+
|
436
|
+
=begin
|
437
|
+
# Accelerators
|
438
|
+
wxAcceleratorEntry entries[1];
|
439
|
+
entries[0].Set(wxACCEL_CTRL, (int) 'V', WXPRINT_PREVIEW);
|
440
|
+
wxAcceleratorTable accel(1, entries);
|
441
|
+
frame->SetAcceleratorTable(accel);
|
442
|
+
=end
|
443
|
+
|
444
|
+
file_menu.append_separator()
|
445
|
+
file_menu.append(WXPRINT_ANGLEUP, "Angle up\tAlt-U","Raise rotated text angle")
|
446
|
+
file_menu.append(WXPRINT_ANGLEDOWN, "Angle down\tAlt-D","Lower rotated text angle")
|
447
|
+
file_menu.append_separator()
|
448
|
+
file_menu.append(WXPRINT_QUIT, "E&xit","Exit program")
|
449
|
+
|
450
|
+
help_menu = Wx::Menu.new
|
451
|
+
help_menu.append(WXPRINT_ABOUT, "&About","About this demo")
|
452
|
+
|
453
|
+
menu_bar = Wx::MenuBar.new
|
454
|
+
|
455
|
+
menu_bar.append(file_menu, "&File")
|
456
|
+
menu_bar.append(help_menu, "&Help")
|
457
|
+
|
458
|
+
# Associate the menu bar with the frame
|
459
|
+
@frame.set_menu_bar(menu_bar)
|
460
|
+
|
461
|
+
canvas = MyCanvas.new(@frame, Wx::Point.new(0, 0), Wx::Size.new(100, 100), Wx::RETAINED|Wx::HSCROLL|Wx::VSCROLL)
|
462
|
+
|
463
|
+
# Give it scrollbars: the virtual canvas is 20 * 50 = 1000 pixels in each direction
|
464
|
+
canvas.set_scrollbars(20, 20, 50, 50)
|
465
|
+
|
466
|
+
@frame.canvas = canvas
|
467
|
+
|
468
|
+
@frame.centre(Wx::BOTH)
|
469
|
+
@frame.show()
|
470
|
+
|
471
|
+
@frame.set_status_text("Printing demo")
|
472
|
+
|
473
|
+
set_top_window(@frame)
|
474
|
+
|
475
|
+
@print_data = Wx::PrintData.new
|
476
|
+
@page_setup_data = Wx::PageSetupDialogData.new
|
477
|
+
|
478
|
+
return true
|
479
|
+
end
|
480
|
+
|
481
|
+
def on_exit
|
482
|
+
return true
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|
486
|
+
|
487
|
+
MyApp.new.main_loop()
|