-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGUI.rb
102 lines (84 loc) · 1.94 KB
/
GUI.rb
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
# $Id$
#
# Shade: A science-fiction computer roleplaying game.
# Copyright (C) 2002 Greg McIntyre
#
# Shade is licensed under the GNU General Public License as published
# by the Free Software Foundation. For more information, please refer
# to gpl.txt.
require 'Display'
class Widget
attr_accessor :parent
attr_accessor :name
# Position
attr_accessor :x
attr_accessor :y
# Size
attr_accessor :width
attr_accessor :height
def draw
draw_contents
end
# Draw the contents of this window. This must be defined by all
# inheriting classes. When drawing, (0,0) represents the
# top-left-most drawable point inside the window, according to the
# padding values.
def draw_contents
end
end
class ContainerWidget < Widget
attr :children
def initialize
@children = []
end
def <<(child)
@children << child
end
# Draw all children widgets.
def draw_contents
for c in @children
c.draw
end
end
end
class Window < ContainerWidget
# Padding.
attr :pleft
attr :pright
attr :ptop
attr :pbottom
# Create a width by height window which will be drawn at
# (x,y). The title may or may not be displayed depending
# on the decoration. The default decoration does not
# display the title.
#
# p<direction> is the padding in that direction.
# Padding determines where the window contents is from the
# position given here. It should include the size of the
# decorations so that they are not drawn over.
def initialize(name, x, y, width, height, pleft=0, pright=0, ptop=0, pbottom=0)
@name = name
@x = x
@y = y
@width = width
@height = height
@pleft = pleft
@pright = pright
@ptop = ptop
@pbottom = pbottom
super()
end
# Decorate and draw the contents of a window.
def draw
# Clear.
Display::set_colour 0x000000
decorate
draw_contents
end
# Draw a plain rectangle around the border of the
# window. Disable this by redefining this method with a
# null op.
def decorate
Display::set_colour 0xFFFFFF
end
end