luikore-cici 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +53 -0
- data/lib/cici.rb +7 -0
- data/lib/cici/SciLexer.dll +0 -0
- data/lib/cici/canvas.rb +207 -0
- data/lib/cici/config.rb +44 -0
- data/lib/cici/countlines.rb +8 -0
- data/lib/cici/element_base.rb +12 -0
- data/lib/cici/ext.so +0 -0
- data/lib/cici/lexers/ruby +64 -0
- data/lib/cici/list.rb +22 -0
- data/lib/cici/misc.rb +33 -0
- data/lib/cici/scintilla.rb +45 -0
- data/lib/cici/support.rb +69 -0
- data/lib/cici/view.rb +130 -0
- metadata +70 -0
data/README.rdoc
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
= Cici
|
2
|
+
|
3
|
+
Mini Ruby text-based traditional GUI lib for Windows. (project just started)
|
4
|
+
|
5
|
+
No other prepared libraries needed, that is -- No Qt, Gtk, Mfc ...
|
6
|
+
|
7
|
+
Light and small with nice efficiency.
|
8
|
+
|
9
|
+
== Download
|
10
|
+
|
11
|
+
Cici is packed with this ruby1.9.1.zip
|
12
|
+
|
13
|
+
http://github.com/LuiKore/Cici/downloads
|
14
|
+
|
15
|
+
== Example
|
16
|
+
|
17
|
+
require 'cici'
|
18
|
+
include Cici::View
|
19
|
+
view [100, 30] do
|
20
|
+
button('hello').onclick = -> this { alert 'world' }
|
21
|
+
end
|
22
|
+
|
23
|
+
Find more in examples folder.
|
24
|
+
|
25
|
+
== Document
|
26
|
+
|
27
|
+
http://wiki.github.com/LuiKore/Cici
|
28
|
+
|
29
|
+
== License (MIT)
|
30
|
+
|
31
|
+
Copyright (c) 2009 Lui Kore
|
32
|
+
|
33
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
34
|
+
of this software and associated documentation files (the "Software"), to
|
35
|
+
deal in the Software without restriction, including without limitation the
|
36
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
37
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
38
|
+
furnished to do so, subject to the following conditions:
|
39
|
+
|
40
|
+
The above copyright notice and this permission notice shall be included in
|
41
|
+
all copies or substantial portions of the Software.
|
42
|
+
|
43
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
44
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
45
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
46
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
47
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
48
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
49
|
+
|
50
|
+
== My blog (中文)
|
51
|
+
|
52
|
+
http://night-stalker.javaeye.com
|
53
|
+
|
data/lib/cici.rb
ADDED
Binary file
|
data/lib/cici/canvas.rb
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
# Coding: utf-8
|
2
|
+
module Cici
|
3
|
+
class Canvas
|
4
|
+
# downing: the biggest bottom position of current elements
|
5
|
+
# padding: space between horizontal elements
|
6
|
+
attr_reader :padding, :downing, :turtlex, :turtley, :children
|
7
|
+
|
8
|
+
# note that data_wrap_objects don't call initializer
|
9
|
+
def marginx= n
|
10
|
+
@marginx = (n.to_i || @marginx)
|
11
|
+
end
|
12
|
+
|
13
|
+
def inspect
|
14
|
+
print 'Canvas: '
|
15
|
+
%w[@padding @downing @turtlex @turtley].map do |e|
|
16
|
+
"#{e}=#{self.instance_variable_get(e)}"
|
17
|
+
end.join ','
|
18
|
+
end
|
19
|
+
|
20
|
+
# ----------------------------------------------------------------
|
21
|
+
# fixed layout
|
22
|
+
module Fixed
|
23
|
+
private
|
24
|
+
def onresize
|
25
|
+
end
|
26
|
+
|
27
|
+
def onchildresize child
|
28
|
+
end
|
29
|
+
|
30
|
+
def onappend child, cx, cy
|
31
|
+
child.displace @turtlex, @turtley, cx, cy
|
32
|
+
child.instance_variable_set "@parent", self
|
33
|
+
@turtlex += cx + @padding
|
34
|
+
@downing = cy if @downing < cy
|
35
|
+
@children << child
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
public
|
40
|
+
def br space = 5
|
41
|
+
@turtlex = @marginx
|
42
|
+
@turtley += (@downing + space)
|
43
|
+
@downing = 0
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# ----------------------------------------------------------------
|
48
|
+
# flow layout
|
49
|
+
module Flow
|
50
|
+
private
|
51
|
+
def onresize
|
52
|
+
end
|
53
|
+
|
54
|
+
def onchildresize child
|
55
|
+
# when appending, this mark is set to false to avoid unecessary resize
|
56
|
+
return unless @do_onchildresize
|
57
|
+
|
58
|
+
@turtlex = @marginx
|
59
|
+
@turtley = 0
|
60
|
+
@downing = 0
|
61
|
+
to_append = @children.dup
|
62
|
+
@children = []
|
63
|
+
to_append.each do |c|
|
64
|
+
self.append c, *c.size
|
65
|
+
end
|
66
|
+
# self.invalidate_rect # FIXME doesn't work...
|
67
|
+
end
|
68
|
+
|
69
|
+
def onappend child, cx, cy
|
70
|
+
# set mark to avoid unecessary resize
|
71
|
+
@do_onchildresize = false
|
72
|
+
|
73
|
+
# do a line break if width exceeds flow_width
|
74
|
+
fw = @flow_width || self.size[0]
|
75
|
+
if (@turtlex > @marginx) and (fw < (@turtlex + cx + @padding))
|
76
|
+
@turtlex = @marginx
|
77
|
+
@turtley += (@downing + 5)
|
78
|
+
@downing = 0
|
79
|
+
end
|
80
|
+
|
81
|
+
child.displace @turtlex, @turtley, cx, cy
|
82
|
+
child.instance_variable_set "@parent", self
|
83
|
+
@turtlex += cx + @padding
|
84
|
+
@downing = cy if @downing < cy
|
85
|
+
@children << child
|
86
|
+
|
87
|
+
# set mark back
|
88
|
+
@do_onchildresize = true
|
89
|
+
end
|
90
|
+
|
91
|
+
public
|
92
|
+
def flow_width= fw
|
93
|
+
@flow_width = fw.to_i
|
94
|
+
self.onchildresize nil
|
95
|
+
fw
|
96
|
+
end
|
97
|
+
|
98
|
+
attr_reader :flow_width
|
99
|
+
end # module Flow
|
100
|
+
|
101
|
+
# ----------------------------------------------------------------
|
102
|
+
# zoom layout
|
103
|
+
module Zoom
|
104
|
+
# FIXME when removing child ?
|
105
|
+
private
|
106
|
+
def onresize
|
107
|
+
if @percents
|
108
|
+
@turtlex = @marginx
|
109
|
+
@turtley = 0
|
110
|
+
@downing = 0
|
111
|
+
to_append = @children.dup
|
112
|
+
stored_percents = @percents.dup
|
113
|
+
@children = []
|
114
|
+
szx, szy = self.size
|
115
|
+
to_append.each_with_index do |c, i|
|
116
|
+
px, py = stored_percents[i]
|
117
|
+
self.append c, px*szx, py*szy
|
118
|
+
end
|
119
|
+
else
|
120
|
+
@percents = []
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def onchildresize child
|
125
|
+
end
|
126
|
+
|
127
|
+
def onappend child, cx, cy
|
128
|
+
child.displace @turtlex, @turtley, cx, cy
|
129
|
+
child.instance_variable_set "@parent", self
|
130
|
+
@turtlex += cx + @padding
|
131
|
+
@downing = cy if @downing < cy
|
132
|
+
@children << child
|
133
|
+
@percents ||= []
|
134
|
+
szx, szy = self.size
|
135
|
+
@percents << [cx.to_f/szx, cy.to_f/szy]
|
136
|
+
self
|
137
|
+
end
|
138
|
+
|
139
|
+
public
|
140
|
+
def br space = 5
|
141
|
+
@turtlex = @marginx
|
142
|
+
@turtley += (@downing + space)
|
143
|
+
@downing = 0
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# ----------------------------------------------------------------
|
148
|
+
# tab layout (or say, navigate / tabbook layout)
|
149
|
+
module Tab
|
150
|
+
private
|
151
|
+
def check_index idx
|
152
|
+
raise "index #{idx} out of range" if @pages.empty? or (not ((0...(@pages.size)).include? idx))
|
153
|
+
end
|
154
|
+
|
155
|
+
def new_label txt
|
156
|
+
idx = @labels.children.size
|
157
|
+
label = Button.create @labels, txt, 0
|
158
|
+
label.onclick = proc{
|
159
|
+
self.tab_index = idx
|
160
|
+
}
|
161
|
+
end
|
162
|
+
|
163
|
+
# initialize some instance vars
|
164
|
+
def init
|
165
|
+
@tab_index = 0
|
166
|
+
@labels = Canvas.paint(self, 2000, 22, Flow) {}
|
167
|
+
@labels.displace 0, 0, 2000, 22
|
168
|
+
@labels.instance_variable_set "@padding", 1
|
169
|
+
@pages = []
|
170
|
+
@turtley = 22
|
171
|
+
end
|
172
|
+
|
173
|
+
def onresize
|
174
|
+
end
|
175
|
+
|
176
|
+
def onchildresize child
|
177
|
+
end
|
178
|
+
|
179
|
+
def onappend child, cx, cy
|
180
|
+
end
|
181
|
+
|
182
|
+
public
|
183
|
+
attr_reader :tab_index, :pages, :labels
|
184
|
+
def tab_index= idx
|
185
|
+
check_index idx
|
186
|
+
if idx != @tab_index
|
187
|
+
@pages[@tab_index].hide
|
188
|
+
@tab_index = idx
|
189
|
+
@pages[@tab_index].restore
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def []= txt, page
|
194
|
+
init() unless @tab_index
|
195
|
+
new_label txt
|
196
|
+
if @pages[@tab_index]
|
197
|
+
@pages[@tab_index].hide
|
198
|
+
end
|
199
|
+
@pages << page
|
200
|
+
page.parent = self
|
201
|
+
page.pos = [0, 22]
|
202
|
+
@tab_index = @pages.size - 1
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
end # class Canvas
|
207
|
+
end
|
data/lib/cici/config.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module Cici
|
3
|
+
Config = Object.new
|
4
|
+
|
5
|
+
ANSI_CHARSET = 0
|
6
|
+
DEFAULT_CHARSET = 1
|
7
|
+
SYMBOL_CHARSET = 2
|
8
|
+
SHIFTJIS_CHARSET = 128
|
9
|
+
HANGEUL_CHARSET = 129
|
10
|
+
HANGUL_CHARSET = 129
|
11
|
+
GB2312_CHARSET = 134
|
12
|
+
CHINESEBIG5_CHARSET = 136
|
13
|
+
|
14
|
+
KEYMAP = {'LEFT'=>37,'UP'=>38,'RIGHT'=>39,'DOWN'=>40,
|
15
|
+
'PAGE UP'=>33,'PAGE DOWN'=>34,'END'=>35,'HOME'=>36,
|
16
|
+
'`'=>192,'-'=>189,'='=>187,'BACKSPACE'=>8,
|
17
|
+
'['=>219,']'=>221,'\\'=>220,
|
18
|
+
';'=>186,'\''=>222,'ENTER'=>13,
|
19
|
+
','=>188,'.'=>190,'/'=>191,
|
20
|
+
'F1'=>112,'F2'=>113,'F3'=>114,'F4'=>115,'F5'=>116,'F6'=>117,'F7'=>118,'F8'=>119,'F9'=>120,'F10'=>121,
|
21
|
+
'PRINT SCREEN'=>44,'PAUSE'=>19,'INSERT'=>45,'DELETE'=>46
|
22
|
+
}
|
23
|
+
|
24
|
+
class << Config
|
25
|
+
@@config = {
|
26
|
+
:default_font => Font['宋体', 12, '', GB2312_CHARSET],
|
27
|
+
:external_font_paths => [],
|
28
|
+
}
|
29
|
+
|
30
|
+
def << hash
|
31
|
+
@@config.each_key do |k|
|
32
|
+
next unless hash[k]
|
33
|
+
@@config[k] = hash[k]
|
34
|
+
end
|
35
|
+
hash.each_key do |k|
|
36
|
+
puts "warning: config[#{k}] takes no effect" if !@@config[k]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def [] k
|
41
|
+
@@config[k]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/cici/ext.so
ADDED
Binary file
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# normal keywords
|
2
|
+
set_keywords 0, "DATA __END__ __FILE__ __LINE__ alias and begin break case class def defined? do else elsif end ensure false for if in module next nil not or raise redo rescue retry return self super then true undef unless until when while yield"
|
3
|
+
|
4
|
+
# indent keywords
|
5
|
+
set_keywords 1, "def class module if unless begin do elsif else case while for when"
|
6
|
+
|
7
|
+
# unindent keywords
|
8
|
+
set_keywords 2, "end rescue ensure when"
|
9
|
+
|
10
|
+
# line number
|
11
|
+
style_set_color 33, nil, 0XC0C0C0
|
12
|
+
|
13
|
+
#brace highlight
|
14
|
+
style_set_color 34, 0X00009F, 0XFFFF80
|
15
|
+
|
16
|
+
#brace incomplete highlight
|
17
|
+
style_set_color 35, 0XFF0000, 0X000000
|
18
|
+
|
19
|
+
#control chars
|
20
|
+
style_set_color 36, 0X000000, nil
|
21
|
+
|
22
|
+
#indent guides
|
23
|
+
style_set_color 37, 0XC0C0C0, 0XFFFFFF
|
24
|
+
|
25
|
+
# from scite
|
26
|
+
{
|
27
|
+
0=>0X808080,
|
28
|
+
2=>0X007f00,
|
29
|
+
3=>0X004000,
|
30
|
+
4=>0X7f7f00,
|
31
|
+
5=>0X7f0000,
|
32
|
+
6=>0X7f007f,
|
33
|
+
7=>0X7f007f,
|
34
|
+
8=>0Xff0000,
|
35
|
+
9=>0X7f7f00,
|
36
|
+
12=>0X000000,
|
37
|
+
13=>0X800080,
|
38
|
+
14=>0X30a0c0,
|
39
|
+
15=>0Xa000a0,
|
40
|
+
16=>0X8000b0,
|
41
|
+
17=>0Xb00080,
|
42
|
+
18=>0X00ffff,
|
43
|
+
19=>0X000060,
|
44
|
+
20=>0X000000,
|
45
|
+
21=>0X7f007f,
|
46
|
+
22=>0X7f007f,
|
47
|
+
23=>0X7f007f,
|
48
|
+
24=>0X7f007f,
|
49
|
+
26=>0X00ffff,
|
50
|
+
27=>0X000000,
|
51
|
+
28=>0X000000,
|
52
|
+
34=>0Xff0000,
|
53
|
+
35=>0X0000ff
|
54
|
+
}.each do |n, c|
|
55
|
+
style_set_color n, c, nil
|
56
|
+
end
|
57
|
+
|
58
|
+
@indent_pattern = /^\s*
|
59
|
+
(?:def|class|if|elsif|else|case|while|for)\b.*
|
60
|
+
|
|
61
|
+
.*(?:\bdo|\{)(?:\s*\|[^\|]*?\|)?
|
62
|
+
\s*$/x
|
63
|
+
|
64
|
+
@unindent_pattern = %r"^\s*(?:end|\})\s*$"
|
data/lib/cici/list.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Coding: utf-8
|
2
|
+
module Cici
|
3
|
+
module ListBase
|
4
|
+
def items= args
|
5
|
+
args.each do |e|
|
6
|
+
self.append e
|
7
|
+
end
|
8
|
+
@items = args
|
9
|
+
end
|
10
|
+
def items
|
11
|
+
@items
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class ListBox
|
16
|
+
include ListBase
|
17
|
+
end
|
18
|
+
|
19
|
+
class DropList
|
20
|
+
include ListBase
|
21
|
+
end
|
22
|
+
end
|
data/lib/cici/misc.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Coding: utf-8
|
2
|
+
module Cici
|
3
|
+
# the menu part
|
4
|
+
class Menu
|
5
|
+
def build hash
|
6
|
+
hash.each do |key, val| # key.toString called in C
|
7
|
+
sz = self.size
|
8
|
+
if val.is_a? Proc
|
9
|
+
self.insert sz, key, val
|
10
|
+
elsif val.is_a? Hash
|
11
|
+
self.insert_menu sz, key, Menu.popup(@parent).build(val)
|
12
|
+
elsif val.nil?
|
13
|
+
self.insert_line sz
|
14
|
+
else
|
15
|
+
raise 'Menu item processor should be a proc or hash or nil(separate line)'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
return self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Canvas
|
23
|
+
def menu hash
|
24
|
+
Menu.sys(self).build(hash).draw
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class ElementBase
|
29
|
+
def menu hash
|
30
|
+
self.menu = Menu.popup(@parent).build hash
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Cici
|
2
|
+
class Scintilla
|
3
|
+
def lexer= l
|
4
|
+
l.downcase!
|
5
|
+
self._lexer = l
|
6
|
+
eval File.read(File.dirname(__FILE__) + '\\lexers\\' + l)
|
7
|
+
l
|
8
|
+
end
|
9
|
+
alias lexer _lexer
|
10
|
+
|
11
|
+
# set all font to f
|
12
|
+
def font= f
|
13
|
+
33.times{ |i| style_set_font i, f }
|
14
|
+
@font = f
|
15
|
+
end
|
16
|
+
attr_reader :font
|
17
|
+
|
18
|
+
attr_accessor :onchar
|
19
|
+
|
20
|
+
# called when an indentation is needed
|
21
|
+
# lineno: current line number
|
22
|
+
def onindentneeded lineno
|
23
|
+
return nil unless (@indent_pattern and @unindent_pattern)
|
24
|
+
i = nil # indent
|
25
|
+
|
26
|
+
# fuck in prev line
|
27
|
+
prev = self[lineno - 1]
|
28
|
+
if (lineno > 1) and (prev =~ @unindent_pattern)
|
29
|
+
i = self.get_line_indent lineno - 2
|
30
|
+
prev_prev = self[lineno - 2]
|
31
|
+
unless prev_prev =~ @indent_pattern
|
32
|
+
i = i - self.indent
|
33
|
+
end
|
34
|
+
self.set_line_indent lineno - 1, i
|
35
|
+
end
|
36
|
+
|
37
|
+
# fuck out current line
|
38
|
+
i = self.get_line_indent lineno - 1
|
39
|
+
if prev =~ @indent_pattern
|
40
|
+
i += self.indent
|
41
|
+
end
|
42
|
+
self.set_line_indent lineno, i
|
43
|
+
end
|
44
|
+
end # class Scintilla
|
45
|
+
end
|
data/lib/cici/support.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Coding: utf-8
|
2
|
+
class Object
|
3
|
+
def toString
|
4
|
+
self.to_s.encode Encoding.default_external
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class String
|
9
|
+
def toString
|
10
|
+
self.encode Encoding.default_external
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# TODO not used yet
|
15
|
+
class Fixnum
|
16
|
+
def percent
|
17
|
+
@percent = true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Size = Object.new
|
22
|
+
def Size.[] x, y
|
23
|
+
[x, y]
|
24
|
+
end
|
25
|
+
Position = Size
|
26
|
+
|
27
|
+
RGB = Object.new
|
28
|
+
RGB.instance_variable_set "@mem", {}
|
29
|
+
def RGB.[] r, g = nil, b = nil
|
30
|
+
res = @mem[[r, g, b]]
|
31
|
+
if res
|
32
|
+
res
|
33
|
+
else
|
34
|
+
@mem[[r, g, b]] =
|
35
|
+
(g and b) ?
|
36
|
+
((b << 16) | (g << 8) | r) :
|
37
|
+
(((r & 0xff) << 16) | (r & 0xff00) | ((r & 0xff0000) >> 16))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
Font = Object.new
|
42
|
+
Font.instance_variable_set "@mem", {}
|
43
|
+
def Font.[] face, sz, style = '', charset = 0
|
44
|
+
if style.is_a? Fixnum
|
45
|
+
sz, style = style, sz
|
46
|
+
elsif not (sz.is_a? Fixnum)
|
47
|
+
raise 'the second or third param should be size'
|
48
|
+
end
|
49
|
+
res = @mem[[face, sz, style, charset]]
|
50
|
+
if res
|
51
|
+
res
|
52
|
+
else
|
53
|
+
@mem[[face, sz, style, charset]] =
|
54
|
+
Cici::FontClass.create face.toString,
|
55
|
+
sz, (style ? style.downcase : ''), charset
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
Stroke = Object.new
|
60
|
+
class << Stroke
|
61
|
+
Styles = { solid:0, dash:1, dot:2, dashdot:3, dashdotdot:4, insideframe:5 }
|
62
|
+
def [] color, opts = {}
|
63
|
+
# example --- solid: 5
|
64
|
+
raise 'option should be like :solid => 5' unless opts.first
|
65
|
+
style = Styles[opts.first[0]]
|
66
|
+
thick = opts.first[1]
|
67
|
+
Cici::StrokeClass.create style, thick.to_i, color.to_i
|
68
|
+
end
|
69
|
+
end
|
data/lib/cici/view.rb
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module Cici
|
3
|
+
module View
|
4
|
+
def choose_file filter = nil
|
5
|
+
arg = "All (*.*)\0*.*\0"
|
6
|
+
if filter.is_a? Hash
|
7
|
+
arg = filter.map do |(k, v)|
|
8
|
+
"#{k} (#{v})\0#{v}\0"
|
9
|
+
end.join
|
10
|
+
end
|
11
|
+
Cici.choose_file "#{arg}\0"
|
12
|
+
end
|
13
|
+
|
14
|
+
def save_file filter = nil
|
15
|
+
arg = "All (*.*)\0*.*\0"
|
16
|
+
if filter.is_a? Hash
|
17
|
+
arg = filter.map do |(k, v)|
|
18
|
+
"#{k} (#{v})\0#{v}\0"
|
19
|
+
end.join
|
20
|
+
end
|
21
|
+
Cici.save_file "#{arg}\0"
|
22
|
+
end
|
23
|
+
|
24
|
+
def popup_menu hash
|
25
|
+
Menu.popup(Canvas.current).build hash
|
26
|
+
end
|
27
|
+
|
28
|
+
def button txt, sz=nil, &block
|
29
|
+
b = Button.create nil, txt.toString, 0
|
30
|
+
b.onclick = block if block
|
31
|
+
b.size = sz if sz.is_a? Array
|
32
|
+
b
|
33
|
+
end
|
34
|
+
|
35
|
+
# BS_AUTOCHECKBOX
|
36
|
+
def checkbox &block
|
37
|
+
b = Button.create nil, '', 3
|
38
|
+
b.onclick = block if block
|
39
|
+
b
|
40
|
+
end
|
41
|
+
|
42
|
+
# BS_AUTORADIOBUTTON
|
43
|
+
=begin
|
44
|
+
def radio txt, sz=nil, &block
|
45
|
+
b = Button.create nil, txt.toString, 9
|
46
|
+
b.onclick = block if block
|
47
|
+
b.size = sz if sz.is_a? Array
|
48
|
+
b
|
49
|
+
end
|
50
|
+
=end
|
51
|
+
|
52
|
+
def text txt, font = nil
|
53
|
+
font = nil unless font.is_a? FontClass
|
54
|
+
Text.create nil, txt.toString, font
|
55
|
+
end
|
56
|
+
|
57
|
+
def image path, sz = nil
|
58
|
+
x, y = nil, nil
|
59
|
+
if sz.is_a? Array
|
60
|
+
x, y = *sz
|
61
|
+
end
|
62
|
+
Image.create nil, path, x, y
|
63
|
+
end
|
64
|
+
|
65
|
+
def edit sz = nil
|
66
|
+
sz = [200, 28] unless (sz.is_a? Array)
|
67
|
+
Edit.create nil, sz[0], sz[1], nil
|
68
|
+
end
|
69
|
+
|
70
|
+
def listbox sz
|
71
|
+
ListBox.create(nil, sz[0].to_i, sz[1].to_i)
|
72
|
+
end
|
73
|
+
|
74
|
+
def droplist sz = nil
|
75
|
+
sz = [200, 28] unless (sz.is_a? Array)
|
76
|
+
DropList.create(nil, sz[0].to_i, sz[1].to_i)
|
77
|
+
end
|
78
|
+
|
79
|
+
# new canvas
|
80
|
+
def paint sz, opts = {}, &block
|
81
|
+
mod = {
|
82
|
+
flow: Canvas::Flow,
|
83
|
+
zoom: Canvas::Zoom,
|
84
|
+
tab: Canvas::Tab
|
85
|
+
}[opts[:layout]]
|
86
|
+
mod ||= Canvas::Fixed # default
|
87
|
+
Canvas.paint nil, sz[0], sz[1], mod, &block
|
88
|
+
end
|
89
|
+
|
90
|
+
def scintilla sz
|
91
|
+
Scintilla.create nil, sz[0], sz[1]
|
92
|
+
end
|
93
|
+
|
94
|
+
# main
|
95
|
+
def view sz = nil, opts = {}, &block
|
96
|
+
Config[:external_font_paths].each do |p|
|
97
|
+
Cici.load_external_font p
|
98
|
+
end
|
99
|
+
raise 'Config[:default_font] should be a Font' unless Config[:default_font].is_a? Cici::FontClass
|
100
|
+
Cici.set_default_font Config[:default_font]
|
101
|
+
|
102
|
+
Cici.app (opts[:title] || 'Cici') do
|
103
|
+
paint sz, opts, &block
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def br space = 5
|
108
|
+
Canvas.current.br space
|
109
|
+
end
|
110
|
+
|
111
|
+
def keymap char, *mods, &block
|
112
|
+
modnum = 0
|
113
|
+
mods.each do |mod|
|
114
|
+
modnum |= 1 if mod == :shift
|
115
|
+
modnum |= 2 if mod == :ctrl
|
116
|
+
modnum |= 4 if mod == :alt
|
117
|
+
end
|
118
|
+
charnum = nil
|
119
|
+
if char.is_a? Fixnum
|
120
|
+
charnum = char.to_i
|
121
|
+
else
|
122
|
+
charnum = Cici::KEYMAP[char]
|
123
|
+
charnum ||= char.upcase.ord
|
124
|
+
end
|
125
|
+
raise 'char not valid' unless charnum
|
126
|
+
Cici.register_key charnum, modnum, block
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: luikore-cici
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- luikore
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-16 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: usurffx@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- lib
|
27
|
+
- lib/cici
|
28
|
+
- lib/cici/canvas.rb
|
29
|
+
- lib/cici/config.rb
|
30
|
+
- lib/cici/countlines.rb
|
31
|
+
- lib/cici/element_base.rb
|
32
|
+
- lib/cici/ext.so
|
33
|
+
- lib/cici/lexers
|
34
|
+
- lib/cici/lexers/ruby
|
35
|
+
- lib/cici/list.rb
|
36
|
+
- lib/cici/misc.rb
|
37
|
+
- lib/cici/SciLexer.dll
|
38
|
+
- lib/cici/scintilla.rb
|
39
|
+
- lib/cici/support.rb
|
40
|
+
- lib/cici/view.rb
|
41
|
+
- lib/cici.rb
|
42
|
+
has_rdoc: false
|
43
|
+
homepage: http://wiki.github.com/luikore/cici
|
44
|
+
licenses:
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.9.1
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.3.5
|
66
|
+
signing_key:
|
67
|
+
specification_version: 2
|
68
|
+
summary: Mini Ruby GUI for Windows
|
69
|
+
test_files: []
|
70
|
+
|