File: sdlskk.rb

package info (click to toggle)
ruby-sdl 2.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,344 kB
  • ctags: 4,200
  • sloc: cpp: 7,598; ansic: 4,475; ruby: 2,258; sh: 102; makefile: 97
file content (70 lines) | stat: -rw-r--r-- 1,543 bytes parent folder | download | duplicates (4)
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
#
# SDLSKK from Ruby/SDL
#
# This sample needs three files.
#   jisyo       : SKK's dictionary
#   rule_table  : SDLSKK's
#   nihongo.ttf : True Type Font file that has Japanese characters
#
# Usage:
#   ruby sdlskk.rb [-m]
#   
#     -m  Use minibuffer
#
require 'sdl'

use_minibuffer = (ARGV[0]=='-m')
  
SDL.init( SDL::INIT_VIDEO )
SDL::TTF.init
SDL::Event.enableUNICODE

font = SDL::TTF.open( 'nihongo.ttf', 14 )

dict = SDL::SKK::Dictionary.new
dict.load( 'jisyo', false )
table = SDL::SKK::RomKanaRuleTable.new( 'rule_table' )
bind = SDL::SKK::Keybind.new
bind.set_default_key

context = SDL::SKK::Context.new( dict, table, bind, use_minibuffer )

screen = SDL::Screen.open( 640, 480, 16, SDL::SWSURFACE )
SDL::WM.set_caption( $0, $0 )

BLACK = screen.format.map_rgb( 0, 0, 0 )
loop do

  while event = SDL::Event.poll do
    case event
    when SDL::Event::Quit
      exit
    when SDL::Event::KeyDown
      if event.sym == SDL::Key::ESCAPE then
	exit
      end
      if event.sym == SDL::Key::F1
	dict.save("test_user_dict")
      end
      
      context.input( event )      
    end
  end

  text_surface = context.render_str( font, 255, 0, 255 )

  screen.fill_rect( 0, 0, 640, 480, BLACK )
  SDL::Surface.blit( text_surface, 0, 0, 0, 0, screen, 0, 0 )

  if use_minibuffer then
    minibuffer_surface = context.render_minibuffer_str( font, 255, 0, 255 )
    if minibuffer_surface then
      SDL::Surface.blit( minibuffer_surface, 0, 0, 0, 0, screen, 0, 40 )
    end
  end
  
  screen.update_rect( 0, 0, 0, 0 )

  sleep 0.05
  
end