}\r
}\r
\r
- public class Keyboard\r
- {\r
- static public HID.Button\r
- esc, spc, rtn,\r
- left, right, up, down,\r
- comma, period,\r
- q,w,e,r,t,y,u,i,o,p,\r
- a,s,d,f,g,h,j,k,l,\r
- z,x,c,v,b,n,m,\r
- one, two, three, four, five, six, seven, eight, nine, zero,\r
- pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8, pad9;\r
- static private System.Collections.Generic.Dictionary<System.Windows.Input.Key, HID.Button> map;\r
- static public void Canvas_KeyUp(object sender, KeyEventArgs e)\r
- {\r
- }\r
- static public void Canvas_KeyDown(object sender, KeyEventArgs e)\r
- {\r
- }\r
- }\r
\r
public static class Mouse\r
{\r
}\r
}\r
\r
+\r
+ public static class Keyboard\r
+ {\r
+ public class IKey\r
+ {\r
+ //internal static HID.Button[] states;\r
+ //int p;\r
+ internal HID.Button state;\r
+ public void down() { state.down(); }\r
+ public void up() { state.up(); }\r
+ public bool pushed() { return state.pushed(); }\r
+ public bool released() { return state.released(); }\r
+ public bool pressed() { return state.pressed(); }\r
+ }\r
+ static public IKey\r
+ alt, shift, ctrl,\r
+ esc, spc, rtn,\r
+ left, right, up, down,\r
+ tab,\r
+ comma, period,\r
+ q, w, e, r, t, y, u, i, o, p,\r
+ a, s, d, f, g, h, j, k, l,\r
+ z, x, c, v, b, n, m,\r
+ one, two, three, four, five, six, seven, eight, nine, zero,\r
+ pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8, pad9;\r
+ static private System.Collections.Generic.Dictionary<System.Windows.Input.Key, IKey> map;\r
+ static public void Canvas_KeyUp(object sender, KeyEventArgs e)\r
+ {\r
+ Main.drawable.msg("hoge", 0,0,Color.green);\r
+ if (map.ContainsKey(e.Key)) map[e.Key].up();\r
+ }\r
+ static public void Canvas_KeyDown(object sender, KeyEventArgs e)\r
+ {\r
+ if (map.ContainsKey(e.Key)) map[e.Key].down();\r
+ }\r
+\r
+\r
+ static Keyboard()\r
+ {\r
+ /*\r
+ esc = new Key(0); spc = new Key(1); rtn = new Key(2);\r
+ left = new Key(3); right = new Key(4); up = new Key(5); down = new Key(6);\r
+ comma = new Key(7); period = new Key(8);\r
+ q = new Key(32); w = new Key(33); e = new Key(34); r = new Key(35); t = new Key(36); y = new Key(37); u = new Key(38); i = new Key(39); o = new Key(40); p = new Key(41);\r
+ a = new Key(42); s = new Key(43); d = new Key(44); f = new Key(45); g = new Key(46); h = new Key(47); j = new Key(48); k = new Key(49); l = new Key(50);\r
+ z = new Key(51); x = new Key(52); c = new Key(53); v = new Key(54); b = new Key(55); n = new Key(56); m = new Key(57);\r
+ one = new Key(80); two = new Key(81); three = new Key(82); four = new Key(83); five = new Key(84); six = new Key(85); seven = new Key(86); eight = new Key(87); nine = new Key(88); zero = new Key(96);\r
+ pad0 = new Key(96); pad1 = new Key(97); pad2 = new Key(98); pad3 = new Key(99); pad4 = new Key(100); pad5 = new Key(101); pad6 = new Key(102); pad7 = new Key(103); pad8 = new Key(104); pad9 = new Key(105);\r
+ */\r
+ alt = new IKey(); shift = new IKey(); ctrl = new IKey();\r
+ esc = new IKey(); spc = new IKey(); rtn = new IKey();\r
+ left = new IKey(); right = new IKey(); up = new IKey(); down = new IKey();\r
+ comma = new IKey(); period = new IKey();\r
+ q = new IKey(); w = new IKey(); e = new IKey(); r = new IKey(); t = new IKey(); y = new IKey(); u = new IKey(); i = new IKey(); o = new IKey(); p = new IKey();\r
+ a = new IKey(); s = new IKey(); d = new IKey(); f = new IKey(); g = new IKey(); h = new IKey(); j = new IKey(); k = new IKey(); l = new IKey();\r
+ z = new IKey(); x = new IKey(); c = new IKey(); v = new IKey(); b = new IKey(); n = new IKey(); m = new IKey();\r
+ one = new IKey(); two = new IKey(); three = new IKey(); four = new IKey(); five = new IKey(); six = new IKey(); seven = new IKey(); eight = new IKey(); nine = new IKey(); zero = new IKey();\r
+ pad0 = new IKey(); pad1 = new IKey(); pad2 = new IKey(); pad3 = new IKey(); pad4 = new IKey(); pad5 = new IKey(); pad6 = new IKey(); pad7 = new IKey(); pad8 = new IKey(); pad9 = new IKey();\r
+\r
+ map = new System.Collections.Generic.Dictionary<System.Windows.Input.Key, IKey>();\r
+ map.Add(Key.Alt, alt); map.Add(Key.Shift, shift); map.Add(Key.Ctrl, ctrl);\r
+ map.Add(Key.Escape, esc); map.Add(Key.Space, spc); map.Add(Key.Enter, rtn);\r
+ map.Add(Key.Left, left); map.Add(Key.Right, right); map.Add(Key.Up, up); map.Add(Key.Down, down);\r
+ map.Add(Key.Tab, tab);\r
+ map.Add(Key.PageDown, comma); map.Add(Key.PageUp, period);\r
+ map.Add(Key.Q, q); map.Add(Key.W, w); map.Add(Key.E, e); map.Add(Key.R, r); map.Add(Key.T, t); map.Add(Key.Y, y); map.Add(Key.U, u); map.Add(Key.I, i); map.Add(Key.O, o); map.Add(Key.P, p);\r
+ map.Add(Key.A, a); map.Add(Key.S, s); map.Add(Key.D, d); map.Add(Key.F, f); map.Add(Key.G, g); map.Add(Key.H, h); map.Add(Key.J, j); map.Add(Key.K, k); map.Add(Key.L, l);\r
+ map.Add(Key.Z, z); map.Add(Key.X, x); map.Add(Key.C, c); map.Add(Key.V, v); map.Add(Key.B, b); map.Add(Key.N, n); map.Add(Key.M, m);\r
+ map.Add(Key.D1, one); map.Add(Key.D2, two); map.Add(Key.D3, three); map.Add(Key.D4, four); map.Add(Key.D5, five); map.Add(Key.D6, six); map.Add(Key.D7, seven); map.Add(Key.D8, eight); map.Add(Key.D9, nine); map.Add(Key.D0, zero);\r
+ map.Add(Key.NumPad0, pad0); map.Add(Key.NumPad1, pad1); map.Add(Key.NumPad2, pad2); map.Add(Key.NumPad3, pad3); map.Add(Key.NumPad4, pad4); map.Add(Key.NumPad5, pad5); map.Add(Key.NumPad6, pad6); map.Add(Key.NumPad7, pad7); map.Add(Key.NumPad8, pad8); map.Add(Key.NumPad9, pad9);\r
+ }\r
+ }\r
+\r
}
\ No newline at end of file
api_canvas.MouseLeftButtonDown += Mouse.Canvas_LDown;\r
api_canvas.MouseLeftButtonUp += Mouse.Canvas_LUp;\r
api_canvas.MouseWheel += Mouse.Canvas_MouseWheel;\r
+ panel.KeyDown += Keyboard.Canvas_KeyDown;\r
+ panel.KeyUp += Keyboard.Canvas_KeyUp;\r
Mouse._prime = api_canvas;\r
Main.drawable = this;\r
default_buffer = buffer;\r
static System.Windows.Media.SolidColorBrush api_fill;\r
static System.Windows.Media.SolidColorBrush api_stroke;\r
static System.Windows.Media.TranslateTransform api_translation;\r
+ protected static System.Collections.Generic.Dictionary<int, System.Windows.FontWeight> FONT_WEIGHT_BRIDGE;\r
+ protected static System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle> FONT_STYLE_BRIDGE;\r
+ protected static System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment> LETTERS_H_ALIGN_BRIDGE;\r
static Canvas()\r
{\r
- api_line = new System.Windows.Shapes.Line();\r
+ FONT_WEIGHT_BRIDGE = new System.Collections.Generic.Dictionary<int, System.Windows.FontWeight>();\r
+ FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.normal, System.Windows.FontWeights.Normal);\r
+ FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.bold, System.Windows.FontWeights.Bold);\r
+ FONT_STYLE_BRIDGE = new System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle>();\r
+ FONT_STYLE_BRIDGE.Add(Font.Style.normal, System.Windows.FontStyles.Normal);\r
+ FONT_STYLE_BRIDGE.Add(Font.Style.italic, System.Windows.FontStyles.Italic);\r
+ FONT_STYLE_BRIDGE.Add(Font.Style.oblique, System.Windows.FontStyles.Italic);\r
+ LETTERS_H_ALIGN_BRIDGE = new System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment>();\r
+ LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.TEXT_ALIGN_LEFT, TextAlignment.Left);\r
+ LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.TEXT_ALIGN_CENTER, TextAlignment.Center);\r
+ LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.TEXT_ALIGN_RIGHT, TextAlignment.Right);\r
+ LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.NOT_SPECIFIED, TextAlignment.Left);\r
+\r
+ api_line = new System.Windows.Shapes.Line();\r
api_curve = new System.Windows.Shapes.Path();\r
api_rect = new System.Windows.Shapes.Rectangle();\r
api_ellipse = new System.Windows.Shapes.Ellipse();\r
//var zapi_shape = new System.Windows.Documents.Glyphs();\r
var zapi_shape = new System.Windows.Controls.TextBlock();\r
var zapi_fill = new System.Windows.Media.SolidColorBrush();\r
- zapi_shape.MaxWidth = width;\r
- zapi_shape.MaxHeight = height;\r
+ zapi_shape.Width = width;\r
+ zapi_shape.Height = height;\r
zapi_shape.Text = drawee.str;\r
//zapi_shape.FontFamily = ;\r
zapi_shape.FontSize = drawee.font.size;\r
- zapi_shape.FontStyle = drawee.font.style==Font.Style.normal_style ? System.Windows.FontStyles.Normal : System.Windows.FontStyles.Italic;\r
- zapi_shape.FontWeight = drawee.font.weight>400 ? System.Windows.FontWeights.Bold : System.Windows.FontWeights.Normal;\r
- zapi_shape.TextAlignment = drawee.align==Letters.HorizontalAlign.TEXT_ALIGN_LEFT ? TextAlignment.Left : TextAlignment.Center;\r
+ zapi_shape.FontStyle = FONT_STYLE_BRIDGE[drawee.font.style];\r
+ zapi_shape.FontWeight = FONT_WEIGHT_BRIDGE[drawee.font.weight];\r
+ zapi_shape.TextAlignment = LETTERS_H_ALIGN_BRIDGE[drawee.align];\r
zapi_fill.Color = col;\r
zapi_shape.Foreground = zapi_fill;\r
api_canvas.Children.Add(zapi_shape);\r
- System.Windows.Controls.Canvas.SetLeft(zapi_shape, drawee.datum.x);\r
- System.Windows.Controls.Canvas.SetTop(zapi_shape, drawee.datum.y);\r
+ double left = 0;\r
+ switch(drawee.align)\r
+ {\r
+ case Letters.HorizontalAlign.TEXT_ALIGN_LEFT: break;\r
+ case Letters.HorizontalAlign.TEXT_ALIGN_CENTER: left = zapi_shape.Width/2; break;\r
+ case Letters.HorizontalAlign.TEXT_ALIGN_RIGHT: left = zapi_shape.Width; break;\r
+ }\r
+ System.Windows.Controls.Canvas.SetLeft(zapi_shape, drawee.datum.x - left);\r
+ System.Windows.Controls.Canvas.SetTop(zapi_shape, drawee.datum.y - drawee.font.size);\r
}\r
public void image(Image drawee)\r
{\r
}\r
\r
\r
+ public void msg(string str, double x, double y) { msg(str, x, y, Color.white); }\r
+ public void msg(string str, double x, double y, Color col)\r
+ {\r
+ var let = new Letters(str);\r
+ let.locate(x, y);\r
+ this.letters(let, col);\r
+ }\r
+ public void var<Type>(Type val, double x, double y) { msg(val.ToString(), x, y, Color.white); }\r
+ public void var<Type>(Type val, double x, double y, Color col) { msg(val.ToString(), x, y, col); }\r
+\r
+\r
public int frame;\r
public void flip()\r
{\r
{\r
public static Font default_font;\r
\r
- public enum Style { normal_style, italic, oblique };\r
- public enum Weight { normal_weight=400, bold=700 };\r
+ public enum Style { normal, italic, oblique };\r
+ public enum Weight { normal=400, bold=700 };\r
public double size;\r
public int weight;\r
public Style style;\r
}\r
public Font()\r
{\r
- size = 24;\r
- weight = (int)Weight.normal_weight;\r
- style = Style.normal_style;\r
+ size = 18;\r
+ weight = (int)Weight.normal;\r
+ style = Style.normal;\r
family = new string[1];\r
}\r
public Font(double size_, int weight_, Style style_, string family_)\r
void polygon(Polygon drawee, Color col);\r
void letters(Letters drawee, Color col);\r
void image(Image drawee);\r
+ void msg(string s, double x, double y, Color c);\r
}\r
\r
\r
Canvas.default_buffer_frame = main_buffer;\r
Canvas.default_api_canvas = LayoutRoot;\r
Canvas.default_panel = this;\r
+ this.IsTabStop = true;\r
+ this.IsEnabled = true;\r
+ this.MouseEnter += getFocusMouseEnter;\r
System.Windows.Application.Current.Host.Settings.MaxFrameRate = 60;\r
System.Windows.Application.Current.Host.Settings.EnableFrameRateCounter = true;\r
System.Windows.Application.Current.Host.Settings.EnableCacheVisualization = true;\r
main = new PsychlopsMain();\r
main.initialize();\r
}\r
+ protected void getFocusMouseEnter(object sender, System.Windows.Input.MouseEventArgs e)\r
+ {\r
+ this.Focus();\r
+ }\r
int background;\r
private void backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs args)\r
{\r
cnvs = new Canvas(500, 500);\r
img = new Image(isize * 2, isize * 2);\r
fixation = new Rectangle(10, 10);\r
- var poly = new Letters("glkhglk");\r
+ var poly = new Letters("日本語");\r
shape = poly;\r
cnvs.clear(Color.gray);\r
}\r
\r
shape.centering(Mouse.position);\r
shape.draw(Color.red);\r
+ if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100);\r
\r
cnvs.flip();\r
}\r