1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
=begin header
layout.rb - a part of testgtk.c rewritten in Ruby/GTK2
Copyright (C) 2002-2005 Ruby-GNOME2 Project Team
$Id: layout.rb,v 1.6 2005/07/17 16:55:27 mutoh Exp $
Rewritten by Minoru Inachi <inachi@earth.interq.or.jp>
Original Copyright:
GTK - The GIMP Toolkit
Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
=end
require 'sample'
class LayoutSample < SampleWindow
def initialize
super("Gtk::Layout")
set_default_size(200, 200)
scrolledwindow = Gtk::ScrolledWindow.new
add(scrolledwindow)
@layout = Gtk::Layout.new(nil, nil)
scrolledwindow.add(@layout)
# We set step sizes here since GtkLayout does not set
# them itself.
@layout.hadjustment.step_increment = 10.0
@layout.vadjustment.step_increment = 10.0
@layout.set_events(Gdk::Event::EXPOSURE_MASK)
@layout.signal_connect("expose_event") do | w, event |
layout_expose_handler(event)
end
@layout.set_size(1600, 128000)
for i in 0..15 do
for j in 0..15 do
buf = "Button #{i}, #{j}"
if ((i + j) % 2) != 0 then
button = Gtk::Button.new(buf)
else
button = Gtk::Label.new(buf)
end
@layout.put(button, j*100, i*100)
button.show
end
end
for i in 16..1279 do
buf = "Button #{i}, 0"
if (i % 2) != 0 then
button = Gtk::Button.new(buf)
else
button = Gtk::Label.new(buf)
end
@layout.put(button, 0, i * 100)
end
end
private
def layout_expose_handler(event)
imin = (event.area.x) / 10
imax = (event.area.x + event.area.width + 9) / 10
jmin = (event.area.y) / 10
jmax = (event.area.y + event.area.height + 9) / 10
for i in imin..imax-1 do
for j in jmin..jmax-1 do
if ((i+j) % 2) != 0 then
@layout.bin_window.draw_rectangle(
@layout.style.black_gc,
true,
10 * i, 10 * j,
1 + i % 10, 1 + j % 10)
end
end
end
false
end
end
|