rubygoo 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +8 -0
- data/Manifest.txt +9 -0
- data/README.txt +84 -25
- data/Rakefile +36 -2
- data/TODO +5 -4
- data/lib/rubygoo/adapters/gosu_app_adapter.rb +216 -220
- data/lib/rubygoo/adapters/gosu_render_adapter.rb +45 -17
- data/lib/rubygoo/adapters/rubygame_render_adapter.rb +14 -7
- data/lib/rubygoo/app.rb +82 -24
- data/lib/rubygoo/button.rb +29 -10
- data/lib/rubygoo/check_box.rb +21 -11
- data/lib/rubygoo/container.rb +53 -33
- data/lib/rubygoo/dialog.rb +4 -9
- data/lib/rubygoo/label.rb +14 -9
- data/lib/rubygoo/radio_button.rb +29 -0
- data/lib/rubygoo/radio_group.rb +40 -0
- data/lib/rubygoo/tab_group.rb +67 -0
- data/lib/rubygoo/text_field.rb +49 -31
- data/lib/rubygoo/widget.rb +53 -7
- data/lib/rubygoo.rb +4 -0
- data/samples/create_gui.rb +67 -0
- data/samples/gosu_app.rb +8 -61
- data/samples/icon.png +0 -0
- data/samples/rubygame_app.rb +5 -56
- data/test/app_spec.rb +24 -0
- data/test/test_rubygoo.rb +1 -0
- data/test/test_setup.rb +4 -0
- data/test/widget_spec.rb +19 -0
- data/themes/default/config.yml +2 -0
- metadata +25 -5
@@ -203,8 +203,8 @@ K_DOWN = KbDown
|
|
203
203
|
K_RIGHT = KbRight
|
204
204
|
K_LEFT = KbLeft
|
205
205
|
K_INSERT = enum += 1
|
206
|
-
K_HOME =
|
207
|
-
K_END =
|
206
|
+
K_HOME = KbHome
|
207
|
+
K_END = KbEnd
|
208
208
|
K_PAGEUP = enum += 1
|
209
209
|
K_PAGEDOWN = enum += 1
|
210
210
|
|
@@ -269,224 +269,217 @@ K_MOD_META = enum += 1
|
|
269
269
|
|
270
270
|
|
271
271
|
# key/mouse event mappings
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
STR2MOUSE[3] = MOUSE_RIGHT
|
285
|
-
end # module Mouse
|
272
|
+
# Hash to translate mouse button sym to string
|
273
|
+
MOUSE2STR = {
|
274
|
+
MOUSE_LEFT => "left",
|
275
|
+
MOUSE_MIDDLE => "middle",
|
276
|
+
MOUSE_RIGHT => "right"
|
277
|
+
}
|
278
|
+
# And to translate the other way...
|
279
|
+
STR2MOUSE = MOUSE2STR.invert()
|
280
|
+
# And allow numbers too (1 = left, so on)...
|
281
|
+
STR2MOUSE[1] = MOUSE_LEFT
|
282
|
+
STR2MOUSE[2] = MOUSE_MIDDLE
|
283
|
+
STR2MOUSE[3] = MOUSE_RIGHT
|
286
284
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
}
|
285
|
+
# All the keys which have ASCII print values
|
286
|
+
# It is 87 lines from here to the closing }, if you want to skip it...
|
287
|
+
KEY2ASCII = {
|
288
|
+
K_BACKSPACE => "\b",
|
289
|
+
K_TAB => "\t",
|
290
|
+
K_RETURN => "\n", #SDL docs: "\r". Win vs *nix? What about Mac?
|
291
|
+
K_ESCAPE => "^[",
|
292
|
+
K_SPACE => " ",
|
293
|
+
K_EXCLAIM => "!",
|
294
|
+
K_QUOTEDBL => "\"",
|
295
|
+
K_HASH => "#",
|
296
|
+
K_DOLLAR => "$",
|
297
|
+
K_AMPERSAND => "&",
|
298
|
+
K_QUOTE => "\'",
|
299
|
+
K_LEFTPAREN => "(",
|
300
|
+
K_RIGHTPAREN => ")",
|
301
|
+
K_ASTERISK => "*",
|
302
|
+
K_PLUS => "+",
|
303
|
+
K_COMMA => ",",
|
304
|
+
K_MINUS => "-",
|
305
|
+
K_PERIOD => ".",
|
306
|
+
K_SLASH => "/",
|
307
|
+
K_0 => "0",
|
308
|
+
K_1 => "1",
|
309
|
+
K_2 => "2",
|
310
|
+
K_3 => "3",
|
311
|
+
K_4 => "4",
|
312
|
+
K_5 => "5",
|
313
|
+
K_6 => "6",
|
314
|
+
K_7 => "7",
|
315
|
+
K_8 => "8",
|
316
|
+
K_9 => "9",
|
317
|
+
K_COLON => ":",
|
318
|
+
K_SEMICOLON => ";",
|
319
|
+
K_LESS => "<",
|
320
|
+
K_EQUALS => "=",
|
321
|
+
K_GREATER => ">",
|
322
|
+
K_QUESTION => "?",
|
323
|
+
K_AT => "@",
|
324
|
+
K_LEFTBRACKET => "[",
|
325
|
+
K_BACKSLASH => "\\",
|
326
|
+
K_RIGHTBRACKET => "]",
|
327
|
+
K_CARET => "^",
|
328
|
+
K_UNDERSCORE => "_",
|
329
|
+
K_BACKQUOTE => "`",
|
330
|
+
K_A => "a",
|
331
|
+
K_B => "b",
|
332
|
+
K_C => "c",
|
333
|
+
K_D => "d",
|
334
|
+
K_E => "e",
|
335
|
+
K_F => "f",
|
336
|
+
K_G => "g",
|
337
|
+
K_H => "h",
|
338
|
+
K_I => "i",
|
339
|
+
K_J => "j",
|
340
|
+
K_K => "k",
|
341
|
+
K_L => "l",
|
342
|
+
K_M => "m",
|
343
|
+
K_N => "n",
|
344
|
+
K_O => "o",
|
345
|
+
K_P => "p",
|
346
|
+
K_Q => "q",
|
347
|
+
K_R => "r",
|
348
|
+
K_S => "s",
|
349
|
+
K_T => "t",
|
350
|
+
K_U => "u",
|
351
|
+
K_V => "v",
|
352
|
+
K_W => "w",
|
353
|
+
K_X => "x",
|
354
|
+
K_Y => "y",
|
355
|
+
K_Z => "z",
|
356
|
+
K_KP0 => "0",
|
357
|
+
K_KP1 => "1",
|
358
|
+
K_KP2 => "2",
|
359
|
+
K_KP3 => "3",
|
360
|
+
K_KP4 => "4",
|
361
|
+
K_KP5 => "5",
|
362
|
+
K_KP6 => "6",
|
363
|
+
K_KP7 => "7",
|
364
|
+
K_KP8 => "8",
|
365
|
+
K_KP9 => "9",
|
366
|
+
K_KP_PERIOD => ".",
|
367
|
+
K_KP_DIVIDE => "/",
|
368
|
+
K_KP_MULTIPLY => "*",
|
369
|
+
K_KP_MINUS => "-",
|
370
|
+
K_KP_PLUS => "+",
|
371
|
+
K_KP_ENTER => "\n", #again, SDL docs say "\r"
|
372
|
+
K_KP_EQUALS => "=",
|
373
|
+
}
|
377
374
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
375
|
+
# And to translate the other way...
|
376
|
+
ASCII2KEY = KEY2ASCII.invert()
|
377
|
+
# accept uppercase letters too, return same as lowercase version:
|
378
|
+
("a".."z").each{ |letter| ASCII2KEY[letter.upcase] = ASCII2KEY[letter] }
|
382
379
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
380
|
+
# All the keys that are affected by the Shift key, in lower case
|
381
|
+
# 49 lines from here to the end of the hash
|
382
|
+
KEY2LOWER = {
|
383
|
+
K_QUOTE => "\'",
|
384
|
+
K_COMMA => ",",
|
385
|
+
K_MINUS => "-",
|
386
|
+
K_PERIOD => ".",
|
387
|
+
K_SLASH => "/",
|
388
|
+
K_0 => "0",
|
389
|
+
K_1 => "1",
|
390
|
+
K_2 => "2",
|
391
|
+
K_3 => "3",
|
392
|
+
K_4 => "4",
|
393
|
+
K_5 => "5",
|
394
|
+
K_6 => "6",
|
395
|
+
K_7 => "7",
|
396
|
+
K_8 => "8",
|
397
|
+
K_9 => "9",
|
398
|
+
K_SEMICOLON => ";",
|
399
|
+
K_EQUALS => "=",
|
400
|
+
K_LEFTBRACKET => "[",
|
401
|
+
K_BACKSLASH => "\\",
|
402
|
+
K_RIGHTBRACKET => "]",
|
403
|
+
K_BACKQUOTE => "`",
|
404
|
+
K_A => "a",
|
405
|
+
K_B => "b",
|
406
|
+
K_C => "c",
|
407
|
+
K_D => "d",
|
408
|
+
K_E => "e",
|
409
|
+
K_F => "f",
|
410
|
+
K_G => "g",
|
411
|
+
K_H => "h",
|
412
|
+
K_I => "i",
|
413
|
+
K_J => "j",
|
414
|
+
K_K => "k",
|
415
|
+
K_L => "l",
|
416
|
+
K_M => "m",
|
417
|
+
K_N => "n",
|
418
|
+
K_O => "o",
|
419
|
+
K_P => "p",
|
420
|
+
K_Q => "q",
|
421
|
+
K_R => "r",
|
422
|
+
K_S => "s",
|
423
|
+
K_T => "t",
|
424
|
+
K_U => "u",
|
425
|
+
K_V => "v",
|
426
|
+
K_W => "w",
|
427
|
+
K_X => "x",
|
428
|
+
K_Y => "y",
|
429
|
+
K_Z => "z",
|
430
|
+
}
|
434
431
|
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
end #module Key
|
487
|
-
|
488
|
-
include Mouse
|
489
|
-
include Key
|
432
|
+
# All the keys that are affected by the Shift key, in UPPER case
|
433
|
+
# 49 lines from here to the end of the hash
|
434
|
+
KEY2UPPER = {
|
435
|
+
K_QUOTE => "\"",
|
436
|
+
K_COMMA => "<",
|
437
|
+
K_MINUS => "_",
|
438
|
+
K_PERIOD => ">",
|
439
|
+
K_SLASH => "?",
|
440
|
+
K_0 => ")",
|
441
|
+
K_1 => "!",
|
442
|
+
K_2 => "@",
|
443
|
+
K_3 => "#",
|
444
|
+
K_4 => "$",
|
445
|
+
K_5 => "%",
|
446
|
+
K_6 => "^",
|
447
|
+
K_7 => "&",
|
448
|
+
K_8 => "*",
|
449
|
+
K_9 => "(",
|
450
|
+
K_SEMICOLON => ":",
|
451
|
+
K_EQUALS => "+",
|
452
|
+
K_LEFTBRACKET => "{",
|
453
|
+
K_BACKSLASH => "|",
|
454
|
+
K_RIGHTBRACKET => "}",
|
455
|
+
K_BACKQUOTE => "~",
|
456
|
+
K_A => "A",
|
457
|
+
K_B => "B",
|
458
|
+
K_C => "C",
|
459
|
+
K_D => "D",
|
460
|
+
K_E => "E",
|
461
|
+
K_F => "F",
|
462
|
+
K_G => "G",
|
463
|
+
K_H => "H",
|
464
|
+
K_I => "I",
|
465
|
+
K_J => "J",
|
466
|
+
K_K => "K",
|
467
|
+
K_L => "L",
|
468
|
+
K_M => "M",
|
469
|
+
K_N => "N",
|
470
|
+
K_O => "O",
|
471
|
+
K_P => "P",
|
472
|
+
K_Q => "Q",
|
473
|
+
K_R => "R",
|
474
|
+
K_S => "S",
|
475
|
+
K_T => "T",
|
476
|
+
K_U => "U",
|
477
|
+
K_V => "V",
|
478
|
+
K_W => "W",
|
479
|
+
K_X => "X",
|
480
|
+
K_Y => "Y",
|
481
|
+
K_Z => "Z",
|
482
|
+
}
|
490
483
|
|
491
484
|
class GosuAppAdapter
|
492
485
|
|
@@ -528,13 +521,16 @@ class GosuAppAdapter
|
|
528
521
|
mods << K_RALT if @main_window.button_down? KbRightAlt
|
529
522
|
mods << K_LCTRL if @main_window.button_down? KbLeftControl
|
530
523
|
mods << K_RCTRL if @main_window.button_down? KbRightControl
|
531
|
-
|
532
|
-
|
524
|
+
left_shift = @main_window.button_down? KbLeftShift
|
525
|
+
right_shift = @main_window.button_down? KbRightShift
|
526
|
+
mods << K_LSHIFT if left_shift
|
527
|
+
mods << K_RSHIFT if right_shift
|
528
|
+
|
533
529
|
button_string = @main_window.button_id_to_char(id)
|
530
|
+
button_string ||= "?"
|
534
531
|
|
532
|
+
button_string.upcase! if left_shift or right_shift
|
535
533
|
|
536
|
-
# TODO add caps
|
537
|
-
button_string ||= "?"
|
538
534
|
@app.on_event GooEvent.new(:key_pressed, {
|
539
535
|
:key => id, :mods => mods, :string => button_string})
|
540
536
|
end
|
@@ -1,15 +1,23 @@
|
|
1
1
|
module Rubygoo
|
2
|
+
class DelayedText
|
3
|
+
def initialize(font, text)
|
4
|
+
@font, @text = font, text
|
5
|
+
end
|
6
|
+
def draw(x, y, z, r, g, b); @font.draw(@text, x, y, z); end;
|
7
|
+
def width()
|
8
|
+
@width ||= @font.text_width(@text).ceil
|
9
|
+
end
|
10
|
+
def height()
|
11
|
+
@height ||= @font.height
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
2
15
|
class GosuRenderAdapter
|
3
16
|
|
4
17
|
def initialize(window)
|
5
18
|
@window = window
|
6
19
|
end
|
7
20
|
|
8
|
-
def draw_box_filled(x1,y1,x2,y2,color)
|
9
|
-
c = convert_color(color)
|
10
|
-
@window.draw_quad x1, y1, c, x2, y1, c, x1, y2, c, x2, y2, c
|
11
|
-
end
|
12
|
-
|
13
21
|
def draw_box(x1,y1,x2,y2,color)
|
14
22
|
c = convert_color(color)
|
15
23
|
@window.draw_line x1, y1, c, x2, y1, c
|
@@ -18,16 +26,35 @@ module Rubygoo
|
|
18
26
|
@window.draw_line x1, y2, c, x1, y1, c
|
19
27
|
end
|
20
28
|
|
21
|
-
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
29
|
+
CIRCLE_STEP = 10
|
30
|
+
def draw_circle(cx,cy,r,color)
|
31
|
+
c_color = convert_color(color)
|
32
|
+
|
33
|
+
0.step(360, CIRCLE_STEP) { |a1|
|
34
|
+
a2 = a1 + CIRCLE_STEP
|
35
|
+
@window.draw_line cx + offset_x(a1, r), cy + offset_y(a1, r), c_color, cx + offset_x(a2, r), cy + offset_y(a2, r), c_color, 0
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def draw_circle_filled(cx,cy,r,color)
|
40
|
+
c_color = convert_color(color)
|
41
|
+
|
42
|
+
0.step(360, CIRCLE_STEP) { |a1|
|
43
|
+
a2 = a1 + CIRCLE_STEP
|
44
|
+
@window.draw_triangle cx + offset_x(a1, r), cy + offset_y(a1, r), c_color, cx + offset_x(a2, r), cy + offset_y(a2, r), c_color, cx, cy, c_color, 0
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def fill_screen(color)
|
49
|
+
c = convert_color(color)
|
50
|
+
@window.draw_quad 0, 0, c, @window.width, 0, c, 0, @window.height, c, @window.width, @window.height, c
|
51
|
+
end
|
52
|
+
|
53
|
+
def fill(x1,y1,x2,y2,color)
|
54
|
+
c = convert_color(color)
|
55
|
+
@window.draw_quad x1, y1, c, x2, y1, c, x1, y2, c, x2, y2, c
|
28
56
|
end
|
29
57
|
|
30
|
-
# make static for now for migration ease of rendering fonts
|
31
58
|
def convert_color(goo_color)
|
32
59
|
Gosu::Color.new goo_color.a,goo_color.r,goo_color.g,goo_color.b
|
33
60
|
end
|
@@ -39,9 +66,9 @@ module Rubygoo
|
|
39
66
|
def draw_image(img, x, y, color=nil)
|
40
67
|
# z is unused here
|
41
68
|
if color
|
42
|
-
img.draw x, y,
|
69
|
+
img.draw x, y, 0,1,1,convert_color(color)
|
43
70
|
else
|
44
|
-
img.draw x, y,
|
71
|
+
img.draw x, y, 0
|
45
72
|
end
|
46
73
|
end
|
47
74
|
|
@@ -59,9 +86,10 @@ module Rubygoo
|
|
59
86
|
font = @font_cache[font_file][font_size] ||= Font.new(@window, font_file, font_size)
|
60
87
|
|
61
88
|
# TODO how do you set the color here?
|
62
|
-
text_image = Image.from_text(@window, text, font_file, font_size, 2, font.text_width(text).ceil
|
89
|
+
# text_image = Image.from_text(@window, text, font_file, font_size, 2, font.text_width(text).ceil, :left)
|
90
|
+
DelayedText.new font, text
|
91
|
+
# text_image = font.draw(text, 0, 0, 1)
|
63
92
|
end
|
64
93
|
|
65
|
-
|
66
94
|
end
|
67
95
|
end
|
@@ -10,13 +10,20 @@ module Rubygoo
|
|
10
10
|
@screen.draw_box [x1,y1], [x2,y2], convert_color(color)
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
def draw_circle(cx,cy,radius,color)
|
14
|
+
@screen.draw_circle_a [cx,cy],radius,convert_color(color)
|
15
|
+
end
|
16
|
+
|
17
|
+
def draw_circle_filled(cx,cy,radius,color)
|
18
|
+
@screen.draw_circle_s [cx,cy],radius,convert_color(color)
|
19
|
+
end
|
20
|
+
|
21
|
+
def fill_screen(color)
|
22
|
+
@screen.draw_box_s [0,0], [@screen.width,@screen.height], convert_color(color)
|
23
|
+
end
|
24
|
+
|
25
|
+
def fill(x1,y1,x2,y2,color)
|
26
|
+
@screen.draw_box_s [x1,y1], [x2,y2], convert_color(color)
|
20
27
|
end
|
21
28
|
|
22
29
|
def convert_color(goo_color)
|