From: unknown Date: Thu, 18 Mar 2010 16:18:25 +0000 (+0900) Subject: kb X-Git-Url: http://git.osdn.jp/view?a=commitdiff_plain;h=ee118c1cb2979154a0c1ed80bf1c13e7fe4e8970;p=psychlops%2Fsilverlight.git kb --- diff --git a/dev3/psychlops/core/device/hid.cs b/dev3/psychlops/core/device/hid.cs index 0dce2b3..a8bdc53 100644 --- a/dev3/psychlops/core/device/hid.cs +++ b/dev3/psychlops/core/device/hid.cs @@ -28,25 +28,6 @@ namespace Psychlops } } - public class Keyboard - { - static public HID.Button - esc, spc, rtn, - left, right, up, down, - comma, period, - q,w,e,r,t,y,u,i,o,p, - a,s,d,f,g,h,j,k,l, - z,x,c,v,b,n,m, - one, two, three, four, five, six, seven, eight, nine, zero, - pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8, pad9; - static private System.Collections.Generic.Dictionary map; - static public void Canvas_KeyUp(object sender, KeyEventArgs e) - { - } - static public void Canvas_KeyDown(object sender, KeyEventArgs e) - { - } - } public static class Mouse { @@ -85,4 +66,77 @@ namespace Psychlops } } + + public static class Keyboard + { + public class IKey + { + //internal static HID.Button[] states; + //int p; + internal HID.Button state; + public void down() { state.down(); } + public void up() { state.up(); } + public bool pushed() { return state.pushed(); } + public bool released() { return state.released(); } + public bool pressed() { return state.pressed(); } + } + static public IKey + alt, shift, ctrl, + esc, spc, rtn, + left, right, up, down, + tab, + comma, period, + q, w, e, r, t, y, u, i, o, p, + a, s, d, f, g, h, j, k, l, + z, x, c, v, b, n, m, + one, two, three, four, five, six, seven, eight, nine, zero, + pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8, pad9; + static private System.Collections.Generic.Dictionary map; + static public void Canvas_KeyUp(object sender, KeyEventArgs e) + { + Main.drawable.msg("hoge", 0,0,Color.green); + if (map.ContainsKey(e.Key)) map[e.Key].up(); + } + static public void Canvas_KeyDown(object sender, KeyEventArgs e) + { + if (map.ContainsKey(e.Key)) map[e.Key].down(); + } + + + static Keyboard() + { + /* + esc = new Key(0); spc = new Key(1); rtn = new Key(2); + left = new Key(3); right = new Key(4); up = new Key(5); down = new Key(6); + comma = new Key(7); period = new Key(8); + 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); + 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); + 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); + 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); + 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); + */ + alt = new IKey(); shift = new IKey(); ctrl = new IKey(); + esc = new IKey(); spc = new IKey(); rtn = new IKey(); + left = new IKey(); right = new IKey(); up = new IKey(); down = new IKey(); + comma = new IKey(); period = new IKey(); + 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(); + 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(); + z = new IKey(); x = new IKey(); c = new IKey(); v = new IKey(); b = new IKey(); n = new IKey(); m = new IKey(); + 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(); + 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(); + + map = new System.Collections.Generic.Dictionary(); + map.Add(Key.Alt, alt); map.Add(Key.Shift, shift); map.Add(Key.Ctrl, ctrl); + map.Add(Key.Escape, esc); map.Add(Key.Space, spc); map.Add(Key.Enter, rtn); + map.Add(Key.Left, left); map.Add(Key.Right, right); map.Add(Key.Up, up); map.Add(Key.Down, down); + map.Add(Key.Tab, tab); + map.Add(Key.PageDown, comma); map.Add(Key.PageUp, period); + 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); + 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); + 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); + 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); + 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); + } + } + } \ No newline at end of file diff --git a/dev3/psychlops/core/graphic/canvas.cs b/dev3/psychlops/core/graphic/canvas.cs index 9098329..9653142 100644 --- a/dev3/psychlops/core/graphic/canvas.cs +++ b/dev3/psychlops/core/graphic/canvas.cs @@ -52,6 +52,8 @@ namespace Psychlops api_canvas.MouseLeftButtonDown += Mouse.Canvas_LDown; api_canvas.MouseLeftButtonUp += Mouse.Canvas_LUp; api_canvas.MouseWheel += Mouse.Canvas_MouseWheel; + panel.KeyDown += Keyboard.Canvas_KeyDown; + panel.KeyUp += Keyboard.Canvas_KeyUp; Mouse._prime = api_canvas; Main.drawable = this; default_buffer = buffer; @@ -94,9 +96,25 @@ namespace Psychlops static System.Windows.Media.SolidColorBrush api_fill; static System.Windows.Media.SolidColorBrush api_stroke; static System.Windows.Media.TranslateTransform api_translation; + protected static System.Collections.Generic.Dictionary FONT_WEIGHT_BRIDGE; + protected static System.Collections.Generic.Dictionary FONT_STYLE_BRIDGE; + protected static System.Collections.Generic.Dictionary LETTERS_H_ALIGN_BRIDGE; static Canvas() { - api_line = new System.Windows.Shapes.Line(); + FONT_WEIGHT_BRIDGE = new System.Collections.Generic.Dictionary(); + FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.normal, System.Windows.FontWeights.Normal); + FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.bold, System.Windows.FontWeights.Bold); + FONT_STYLE_BRIDGE = new System.Collections.Generic.Dictionary(); + FONT_STYLE_BRIDGE.Add(Font.Style.normal, System.Windows.FontStyles.Normal); + FONT_STYLE_BRIDGE.Add(Font.Style.italic, System.Windows.FontStyles.Italic); + FONT_STYLE_BRIDGE.Add(Font.Style.oblique, System.Windows.FontStyles.Italic); + LETTERS_H_ALIGN_BRIDGE = new System.Collections.Generic.Dictionary(); + LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.TEXT_ALIGN_LEFT, TextAlignment.Left); + LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.TEXT_ALIGN_CENTER, TextAlignment.Center); + LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.TEXT_ALIGN_RIGHT, TextAlignment.Right); + LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.NOT_SPECIFIED, TextAlignment.Left); + + api_line = new System.Windows.Shapes.Line(); api_curve = new System.Windows.Shapes.Path(); api_rect = new System.Windows.Shapes.Rectangle(); api_ellipse = new System.Windows.Shapes.Ellipse(); @@ -177,19 +195,26 @@ namespace Psychlops //var zapi_shape = new System.Windows.Documents.Glyphs(); var zapi_shape = new System.Windows.Controls.TextBlock(); var zapi_fill = new System.Windows.Media.SolidColorBrush(); - zapi_shape.MaxWidth = width; - zapi_shape.MaxHeight = height; + zapi_shape.Width = width; + zapi_shape.Height = height; zapi_shape.Text = drawee.str; //zapi_shape.FontFamily = ; zapi_shape.FontSize = drawee.font.size; - zapi_shape.FontStyle = drawee.font.style==Font.Style.normal_style ? System.Windows.FontStyles.Normal : System.Windows.FontStyles.Italic; - zapi_shape.FontWeight = drawee.font.weight>400 ? System.Windows.FontWeights.Bold : System.Windows.FontWeights.Normal; - zapi_shape.TextAlignment = drawee.align==Letters.HorizontalAlign.TEXT_ALIGN_LEFT ? TextAlignment.Left : TextAlignment.Center; + zapi_shape.FontStyle = FONT_STYLE_BRIDGE[drawee.font.style]; + zapi_shape.FontWeight = FONT_WEIGHT_BRIDGE[drawee.font.weight]; + zapi_shape.TextAlignment = LETTERS_H_ALIGN_BRIDGE[drawee.align]; zapi_fill.Color = col; zapi_shape.Foreground = zapi_fill; api_canvas.Children.Add(zapi_shape); - System.Windows.Controls.Canvas.SetLeft(zapi_shape, drawee.datum.x); - System.Windows.Controls.Canvas.SetTop(zapi_shape, drawee.datum.y); + double left = 0; + switch(drawee.align) + { + case Letters.HorizontalAlign.TEXT_ALIGN_LEFT: break; + case Letters.HorizontalAlign.TEXT_ALIGN_CENTER: left = zapi_shape.Width/2; break; + case Letters.HorizontalAlign.TEXT_ALIGN_RIGHT: left = zapi_shape.Width; break; + } + System.Windows.Controls.Canvas.SetLeft(zapi_shape, drawee.datum.x - left); + System.Windows.Controls.Canvas.SetTop(zapi_shape, drawee.datum.y - drawee.font.size); } public void image(Image drawee) { @@ -202,6 +227,17 @@ namespace Psychlops } + public void msg(string str, double x, double y) { msg(str, x, y, Color.white); } + public void msg(string str, double x, double y, Color col) + { + var let = new Letters(str); + let.locate(x, y); + this.letters(let, col); + } + public void var(Type val, double x, double y) { msg(val.ToString(), x, y, Color.white); } + public void var(Type val, double x, double y, Color col) { msg(val.ToString(), x, y, col); } + + public int frame; public void flip() { diff --git a/dev3/psychlops/core/graphic/font.cs b/dev3/psychlops/core/graphic/font.cs index 3c03840..4984b3a 100644 --- a/dev3/psychlops/core/graphic/font.cs +++ b/dev3/psychlops/core/graphic/font.cs @@ -15,8 +15,8 @@ namespace Psychlops { public static Font default_font; - public enum Style { normal_style, italic, oblique }; - public enum Weight { normal_weight=400, bold=700 }; + public enum Style { normal, italic, oblique }; + public enum Weight { normal=400, bold=700 }; public double size; public int weight; public Style style; @@ -28,9 +28,9 @@ namespace Psychlops } public Font() { - size = 24; - weight = (int)Weight.normal_weight; - style = Style.normal_style; + size = 18; + weight = (int)Weight.normal; + style = Style.normal; family = new string[1]; } public Font(double size_, int weight_, Style style_, string family_) diff --git a/dev3/psychlops/core/graphic/module.cs b/dev3/psychlops/core/graphic/module.cs index 2ecc730..67bf68f 100644 --- a/dev3/psychlops/core/graphic/module.cs +++ b/dev3/psychlops/core/graphic/module.cs @@ -129,6 +129,7 @@ namespace Psychlops void polygon(Polygon drawee, Color col); void letters(Letters drawee, Color col); void image(Image drawee); + void msg(string s, double x, double y, Color c); } diff --git a/test3/MainPage.xaml.cs b/test3/MainPage.xaml.cs index 082ec87..89df586 100644 --- a/test3/MainPage.xaml.cs +++ b/test3/MainPage.xaml.cs @@ -14,6 +14,9 @@ namespace PsychlopsSilverlight3test Canvas.default_buffer_frame = main_buffer; Canvas.default_api_canvas = LayoutRoot; Canvas.default_panel = this; + this.IsTabStop = true; + this.IsEnabled = true; + this.MouseEnter += getFocusMouseEnter; System.Windows.Application.Current.Host.Settings.MaxFrameRate = 60; System.Windows.Application.Current.Host.Settings.EnableFrameRateCounter = true; System.Windows.Application.Current.Host.Settings.EnableCacheVisualization = true; @@ -26,6 +29,10 @@ namespace PsychlopsSilverlight3test main = new PsychlopsMain(); main.initialize(); } + protected void getFocusMouseEnter(object sender, System.Windows.Input.MouseEventArgs e) + { + this.Focus(); + } int background; private void backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs args) { diff --git a/test3/PsychlopsMain.cs b/test3/PsychlopsMain.cs index 1a00e41..64db8ce 100644 --- a/test3/PsychlopsMain.cs +++ b/test3/PsychlopsMain.cs @@ -17,7 +17,7 @@ namespace PsychlopsSilverlight3test cnvs = new Canvas(500, 500); img = new Image(isize * 2, isize * 2); fixation = new Rectangle(10, 10); - var poly = new Letters("glkhglk"); + var poly = new Letters("日本語"); shape = poly; cnvs.clear(Color.gray); } @@ -38,6 +38,7 @@ namespace PsychlopsSilverlight3test shape.centering(Mouse.position); shape.draw(Color.red); + if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100); cnvs.flip(); }