# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
-require "stroke"
+require "chise/stroke"
module StrokeFont
class CodeViewer
WIDTH, HEIGHT = 256, 256
SCALE = 2
+
def initialize(cx=0, cy=0)
@cx, @cy = cx, cy
@s = SCALE
calc_code
end
attr_reader :code
+
def draw
colorHSV(0, 0, 100, 10) #まずは下敷きになる枠を書きます。
rect(@x1, @y1, @x2, @y2)
line(@px-@pw/2, @py, @px+@pw/2, @py)
line(@px, @py-@ph/2, @px, @py+@ph/2)
end
+
def onMouse(x, y)
if @onkeydown
x, y = @px, @py
return false
end
end
+
def calc_code()
x = ((@px - @x1)/@s).to_i
y = HEIGHT-1 - ((@py - @y1)/@s).to_i
return false
end
end
+
def show_list(list)
colorHSV(0, 100, 100, 100)
list.each {|code|
rect(x, y, x+2, y-2)
}
end
+
def code_to_xy(code)
cx = code % WIDTH
cy = HEIGHT - (code / WIDTH) #intになる?
y = cy * SCALE + @y1
return x, y
end
+
def length(x, y) Math.sqrt(x*x + y*y) end
+
def onMouseDown(x, y)
if length(@px-x, @py-y) < @pr
@dragging = true
end
end
+
def onMouseUp(x, y) @dragging = false end
+
def onKeyDown(key)
@onkeydown = true
case key