rubygoo 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 = enum += 1
207
- K_END = enum += 1
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
- module Mouse
273
- # Hash to translate mouse button sym to string
274
- MOUSE2STR = {
275
- MOUSE_LEFT => "left",
276
- MOUSE_MIDDLE => "middle",
277
- MOUSE_RIGHT => "right"
278
- }
279
- # And to translate the other way...
280
- STR2MOUSE = MOUSE2STR.invert()
281
- # And allow numbers too (1 = left, so on)...
282
- STR2MOUSE[1] = MOUSE_LEFT
283
- STR2MOUSE[2] = MOUSE_MIDDLE
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
- module Key
288
- # All the keys which have ASCII print values
289
- # It is 87 lines from here to the closing }, if you want to skip it...
290
- KEY2ASCII = {
291
- K_BACKSPACE => "\b",
292
- K_TAB => "\t",
293
- K_RETURN => "\n", #SDL docs: "\r". Win vs *nix? What about Mac?
294
- K_ESCAPE => "^[",
295
- K_SPACE => " ",
296
- K_EXCLAIM => "!",
297
- K_QUOTEDBL => "\"",
298
- K_HASH => "#",
299
- K_DOLLAR => "$",
300
- K_AMPERSAND => "&",
301
- K_QUOTE => "\'",
302
- K_LEFTPAREN => "(",
303
- K_RIGHTPAREN => ")",
304
- K_ASTERISK => "*",
305
- K_PLUS => "+",
306
- K_COMMA => ",",
307
- K_MINUS => "-",
308
- K_PERIOD => ".",
309
- K_SLASH => "/",
310
- K_0 => "0",
311
- K_1 => "1",
312
- K_2 => "2",
313
- K_3 => "3",
314
- K_4 => "4",
315
- K_5 => "5",
316
- K_6 => "6",
317
- K_7 => "7",
318
- K_8 => "8",
319
- K_9 => "9",
320
- K_COLON => ":",
321
- K_SEMICOLON => ";",
322
- K_LESS => "<",
323
- K_EQUALS => "=",
324
- K_GREATER => ">",
325
- K_QUESTION => "?",
326
- K_AT => "@",
327
- K_LEFTBRACKET => "[",
328
- K_BACKSLASH => "\\",
329
- K_RIGHTBRACKET => "]",
330
- K_CARET => "^",
331
- K_UNDERSCORE => "_",
332
- K_BACKQUOTE => "`",
333
- K_A => "a",
334
- K_B => "b",
335
- K_C => "c",
336
- K_D => "d",
337
- K_E => "e",
338
- K_F => "f",
339
- K_G => "g",
340
- K_H => "h",
341
- K_I => "i",
342
- K_J => "j",
343
- K_K => "k",
344
- K_L => "l",
345
- K_M => "m",
346
- K_N => "n",
347
- K_O => "o",
348
- K_P => "p",
349
- K_Q => "q",
350
- K_R => "r",
351
- K_S => "s",
352
- K_T => "t",
353
- K_U => "u",
354
- K_V => "v",
355
- K_W => "w",
356
- K_X => "x",
357
- K_Y => "y",
358
- K_Z => "z",
359
- K_KP0 => "0",
360
- K_KP1 => "1",
361
- K_KP2 => "2",
362
- K_KP3 => "3",
363
- K_KP4 => "4",
364
- K_KP5 => "5",
365
- K_KP6 => "6",
366
- K_KP7 => "7",
367
- K_KP8 => "8",
368
- K_KP9 => "9",
369
- K_KP_PERIOD => ".",
370
- K_KP_DIVIDE => "/",
371
- K_KP_MULTIPLY => "*",
372
- K_KP_MINUS => "-",
373
- K_KP_PLUS => "+",
374
- K_KP_ENTER => "\n", #again, SDL docs say "\r"
375
- K_KP_EQUALS => "=",
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
- # And to translate the other way...
379
- ASCII2KEY = KEY2ASCII.invert()
380
- # accept uppercase letters too, return same as lowercase version:
381
- ("a".."z").each{ |letter| ASCII2KEY[letter.upcase] = ASCII2KEY[letter] }
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
- # All the keys that are affected by the Shift key, in lower case
384
- # 49 lines from here to the end of the hash
385
- KEY2LOWER = {
386
- K_QUOTE => "\'",
387
- K_COMMA => ",",
388
- K_MINUS => "-",
389
- K_PERIOD => ".",
390
- K_SLASH => "/",
391
- K_0 => "0",
392
- K_1 => "1",
393
- K_2 => "2",
394
- K_3 => "3",
395
- K_4 => "4",
396
- K_5 => "5",
397
- K_6 => "6",
398
- K_7 => "7",
399
- K_8 => "8",
400
- K_9 => "9",
401
- K_SEMICOLON => ";",
402
- K_EQUALS => "=",
403
- K_LEFTBRACKET => "[",
404
- K_BACKSLASH => "\\",
405
- K_RIGHTBRACKET => "]",
406
- K_BACKQUOTE => "`",
407
- K_A => "a",
408
- K_B => "b",
409
- K_C => "c",
410
- K_D => "d",
411
- K_E => "e",
412
- K_F => "f",
413
- K_G => "g",
414
- K_H => "h",
415
- K_I => "i",
416
- K_J => "j",
417
- K_K => "k",
418
- K_L => "l",
419
- K_M => "m",
420
- K_N => "n",
421
- K_O => "o",
422
- K_P => "p",
423
- K_Q => "q",
424
- K_R => "r",
425
- K_S => "s",
426
- K_T => "t",
427
- K_U => "u",
428
- K_V => "v",
429
- K_W => "w",
430
- K_X => "x",
431
- K_Y => "y",
432
- K_Z => "z",
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
- # All the keys that are affected by the Shift key, in UPPER case
436
- # 49 lines from here to the end of the hash
437
- KEY2UPPER = {
438
- K_QUOTE => "\"",
439
- K_COMMA => "<",
440
- K_MINUS => "_",
441
- K_PERIOD => ">",
442
- K_SLASH => "?",
443
- K_0 => ")",
444
- K_1 => "!",
445
- K_2 => "@",
446
- K_3 => "#",
447
- K_4 => "$",
448
- K_5 => "%",
449
- K_6 => "^",
450
- K_7 => "&",
451
- K_8 => "*",
452
- K_9 => "(",
453
- K_SEMICOLON => ":",
454
- K_EQUALS => "+",
455
- K_LEFTBRACKET => "{",
456
- K_BACKSLASH => "|",
457
- K_RIGHTBRACKET => "}",
458
- K_BACKQUOTE => "~",
459
- K_A => "A",
460
- K_B => "B",
461
- K_C => "C",
462
- K_D => "D",
463
- K_E => "E",
464
- K_F => "F",
465
- K_G => "G",
466
- K_H => "H",
467
- K_I => "I",
468
- K_J => "J",
469
- K_K => "K",
470
- K_L => "L",
471
- K_M => "M",
472
- K_N => "N",
473
- K_O => "O",
474
- K_P => "P",
475
- K_Q => "Q",
476
- K_R => "R",
477
- K_S => "S",
478
- K_T => "T",
479
- K_U => "U",
480
- K_V => "V",
481
- K_W => "W",
482
- K_X => "X",
483
- K_Y => "Y",
484
- K_Z => "Z",
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
- mods << K_LSHIFT if @main_window.button_down? KbLeftShift
532
- mods << K_RSHIFT if @main_window.button_down? KbRightShift
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
- # fill in a rect with color or full screen if no color
22
- def fill(color,rect=nil)
23
- if rect.nil?
24
- draw_box_filled 0, 0, @window.width, @window.height, color
25
- else
26
- draw_box_filled rect[0], rect[1], rect[2]+rect[0], rect[3]+rect[1], color
27
- end
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, 1,1,1,convert_color(color)
69
+ img.draw x, y, 0,1,1,convert_color(color)
43
70
  else
44
- img.draw x, y, 1
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+text.length*2, :left)
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
- # fill in a rect with color or full screen if no color
14
- def fill(color,rect=nil)
15
- if rect.nil?
16
- @screen.fill convert_color(color)
17
- else
18
- @screen.fill convert_color(color), rect
19
- end
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)