2 # StrokeFont library by eto 2003-0314
3 # $Id: codeviewer.rb,v 1.1 2003-11-10 08:11:46 eto Exp $
4 # Copyright (C) 2002-2003 Kouichirou Eto, All rights reserved.
5 # This is free software with ABSOLUTELY NO WARRANTY.
6 # You can redistribute it and/or modify it under the terms of the GNU GPL2.
11 class CodeViewer #======================================================================
12 WIDTH, HEIGHT = 256, 256
14 def initialize(cx=0, cy=0)
17 @x1, @y1 = @cx-@s*WIDTH/2, @cy-@s*HEIGHT/2
18 @x2, @y2 = @cx+@s*WIDTH/2, @cy+@s*HEIGHT/2
19 @px, @py = @cx, @cy #とりあえず中心が開始点
20 @pw, @ph, @pr = 30, 30, 10
28 colorHSV(0, 0, 100, 10) #まずは下敷きになる枠を書きます。
29 rect(@x1, @y1, @x2, @y2)
31 colorHSV(0, 0, 100, 50)
34 line(@x1, @y1+n*s, @x2, @y1+n*s)
35 line(@x1+n*s, @y1, @x1+n*s, @y2)
37 colorHSV(0, 100, 100, 100) # 次にポインターを書きます
39 line(@px-@pw/2, @py, @px+@pw/2, @py)
40 line(@px, @py-@ph/2, @px, @py+@ph/2)
46 if @dragging || @onkeydown
48 @px, @py = x, y #p [x, y]
49 @px = @x1 if @px < @x1
50 @py = @y1 if @py < @y1
51 @px = @x2-1 if @x2-1 < @px
52 @py = @y2-1 if @y2-1 < @py
59 x = ((@px - @x1)/@s).to_i
60 y = HEIGHT-1 - ((@py - @y1)/@s).to_i
66 printf("%02x %02x %04x\n", x, y, @code)
72 colorHSV(0, 100, 100, 100)
74 x, y = code_to_xy(code)
80 cy = HEIGHT - (code / WIDTH) #intになる?
85 def length(x, y) Math.sqrt(x*x + y*y) end
87 if length(@px-x, @py-y) < @pr
91 def onMouseUp(x, y) @dragging = false end
108 if $0 == __FILE__ #======================================================================
109 $LOAD_PATH << '../../src'
112 require 'chise/stroke'
117 window(-300,-300,300,300)
121 @csf1 = CSFFont.new() #普通の文字
122 @csf2 = CSFFont.new(CSF_KOUKOTSU_FILE) #甲骨文字
124 @kage = KageFont.new()
129 @changed = @cs.onMouse(mouseX, mouseY) #変化があったか?
131 @cs.show_list(@kage.cache_list)
144 char = Character.get(code)
146 @kage.init(code) if @changed
147 @kage.print(code) if @changed
152 char = Character.get(ucs)
154 j = char.japanese_jisx0208
157 csf = @key == 1 ? @csf1 : @csf2
158 csf.init(code) if @changed
159 csf.print(code) if @changed
163 def onMouseDown(x, y) @cs.onMouseDown(x, y)end
164 def onMouseUp(x, y) @cs.onMouseUp(x, y)end
172 #----------------------------------------------------------------------end.