static IntPtr draw_line(IntPtr Self, IntPtr Args) { GuardDisposed(Self); Ruby.Array.Expect(Args, 5); Ruby.Array.Expect(Args, 0, "Integer"); Ruby.Array.Expect(Args, 1, "Integer"); Ruby.Array.Expect(Args, 2, "Integer"); Ruby.Array.Expect(Args, 3, "Integer"); Ruby.Array.Expect(Args, 4, "Color"); int x1 = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 0)); int y1 = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 1)); int x2 = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 2)); int y2 = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 3)); AutoUnlock(Self); odl.Color c = Color.CreateColor(Ruby.Array.Get(Args, 4)); BitmapDictionary[Self].DrawLine(x1, y1, x2, y2, c); AutoLock(Self); return(Ruby.True); }
static IntPtr draw_text(IntPtr Self, IntPtr Args) { GuardDisposed(Self); Ruby.Array.Expect(Args, 5, 6); Ruby.Array.Expect(Args, 0, "Integer"); Ruby.Array.Expect(Args, 1, "Integer"); Ruby.Array.Expect(Args, 2, "Integer"); Ruby.Array.Expect(Args, 3, "Integer"); Ruby.Array.Expect(Args, 4, "String"); int x = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 0)); int y = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 1)); int w = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 2)); int h = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 3)); string text = Ruby.String.FromPtr(Ruby.Array.Get(Args, 4)); int align = 0; if (Ruby.Array.Length(Args) == 6) { if (Ruby.Is(Ruby.Array.Get(Args, 5), "Symbol")) { string sym = Ruby.Symbol.FromPtr(Ruby.Array.Get(Args, 5)); if (sym == ":left") { align = 0; } else if (sym == ":center" || sym == ":middle") { align = 1; } else if (sym == ":right") { align = 2; } else { Ruby.Raise(Ruby.ErrorType.ArgumentError, "invalid alignment argument"); } } else { Ruby.Array.Expect(Args, 5, "Integer"); align = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 5)); if (align < 0 || align > 2) { Ruby.Raise(Ruby.ErrorType.ArgumentError, "invalid alignment argument"); } } } AutoUnlock(Self); BitmapDictionary[Self].Font = Font.CreateFont(Ruby.GetIVar(Self, "@font")); odl.Color color = Color.CreateColor(Ruby.GetIVar(Ruby.GetIVar(Self, "@font"), "@color")); odl.DrawOptions options = 0; bool outline = false; if (align == 0) { options |= odl.DrawOptions.LeftAlign; } else if (align == 1) { options |= odl.DrawOptions.CenterAlign; } else if (align == 2) { options |= odl.DrawOptions.RightAlign; } if (Ruby.GetIVar(Ruby.GetIVar(Self, "@font"), "@outline") == Ruby.True) { outline = true; } if (outline) { odl.Color outline_color = Color.CreateColor(Ruby.GetIVar(Ruby.GetIVar(Self, "@font"), "@outline_color")); BitmapDictionary[Self].DrawText(text, new odl.Rect(x - 1, y - 1, w, h), outline_color, options); BitmapDictionary[Self].DrawText(text, new odl.Rect(x, y - 1, w, h), outline_color, options); BitmapDictionary[Self].DrawText(text, new odl.Rect(x + 1, y - 1, w, h), outline_color, options); BitmapDictionary[Self].DrawText(text, new odl.Rect(x - 1, y, w, h), outline_color, options); BitmapDictionary[Self].DrawText(text, new odl.Rect(x + 1, y, w, h), outline_color, options); BitmapDictionary[Self].DrawText(text, new odl.Rect(x - 1, y + 1, w, h), outline_color, options); BitmapDictionary[Self].DrawText(text, new odl.Rect(x, y + 1, w, h), outline_color, options); BitmapDictionary[Self].DrawText(text, new odl.Rect(x + 1, y + 1, w, h), outline_color, options); } BitmapDictionary[Self].DrawText(text, new odl.Rect(x, y, w, h), color, options); odl.SDL2.SDL.SDL_SetTextureBlendMode(BitmapDictionary[Self].Texture, odl.SDL2.SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND); AutoLock(Self); return(Ruby.True); }
static IntPtr fill_rect(IntPtr Self, IntPtr Args) { GuardDisposed(Self); Ruby.Array.Expect(Args, 2, 5); int x = 0, y = 0, w = 0, h = 0; odl.Color c = null; long len = Ruby.Array.Length(Args); if (len == 2) { Ruby.Array.Expect(Args, 0, "Rect"); Ruby.Array.Expect(Args, 1, "Color"); if (Ruby.IVarIs(Ruby.Array.Get(Args, 0), "@x", "Float")) { x = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@x")); } else { x = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@x")); } if (Ruby.IVarIs(Ruby.Array.Get(Args, 0), "@y", "Float")) { y = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@y")); } else { y = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@y")); } if (Ruby.IVarIs(Ruby.Array.Get(Args, 0), "@width", "Float")) { w = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@width")); } else { w = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@width")); } if (Ruby.IVarIs(Ruby.Array.Get(Args, 0), "@height", "Float")) { h = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@height")); } else { h = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@height")); } c = Color.CreateColor(Ruby.Array.Get(Args, 1)); } else if (len == 5) { Ruby.Array.Expect(Args, 0, "Integer"); Ruby.Array.Expect(Args, 1, "Integer"); Ruby.Array.Expect(Args, 2, "Integer"); Ruby.Array.Expect(Args, 3, "Integer"); Ruby.Array.Expect(Args, 4, "Color"); x = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 0)); y = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 1)); w = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 2)); h = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 3)); c = Color.CreateColor(Ruby.Array.Get(Args, 4)); } AutoUnlock(Self); BitmapDictionary[Self].FillRect(x, y, w, h, c); AutoLock(Self); return(Ruby.True); }
public static void LoadSettings(params string[] Filenames) { foreach (string Filename in Filenames) { if (File.Exists(Filename)) { StreamReader sr = new StreamReader(File.OpenRead(Filename)); string str = sr.ReadToEnd(); sr.Close(); Dictionary <string, object> data = null; try { data = ((JObject)JsonConvert.DeserializeObject(str)).ToObject <Dictionary <string, object> >(); } catch (Exception ex) { Program.Error($"An error occured while loading the config JSON. It is likely not a valid JSON format.\n\n{ex}"); } bool setfps = false; bool setvsync = false; foreach (string key in data.Keys) { object value = data[key]; switch (key) { case "frame_rate": EnsureType(typeof(long), value, key); FrameRate = Convert.ToInt32(value); if (FrameRate < 1) { Program.Error($"The framerate specified by the config JSON must be at least 1."); } setfps = true; break; case "vsync": EnsureType(typeof(bool), value, key); VSync = Convert.ToBoolean(value); setvsync = true; break; case "window_width": EnsureType(typeof(long), value, key); WindowWidth = Convert.ToInt32(value); if (WindowWidth < 1) { Program.Error($"The window width specified by the config JSON must be at least 1."); } break; case "window_height": EnsureType(typeof(long), value, key); WindowHeight = Convert.ToInt32(value); if (WindowHeight < 1) { Program.Error($"The window height specified by the config JSON must be at least 1."); } break; case "window_icon": EnsureType(typeof(string), value, key); WindowIcon = (string)value; break; case "window_title": EnsureType(typeof(string), value, key); WindowTitle = (string)value; break; case "window_resizable": EnsureType(typeof(bool), value, key); WindowResizable = Convert.ToBoolean(value); break; case "window_scale": EnsureTypes(value, key, typeof(double), typeof(long)); WindowScale = Convert.ToDouble(value); break; case "maintain_aspect_ratio": EnsureType(typeof(bool), value, key); MaintainAspectRatio = Convert.ToBoolean(value); break; case "script": EnsureType(typeof(string), value, key); Script = (string)value; break; case "background_color": EnsureType(typeof(JObject), value, key); BackgroundColor = ParseColor(((JObject)value).ToObject <Dictionary <string, object> >(), key); break; case "main_directory": EnsureType(typeof(string), value, key); MainDirectory = (string)value; break; default: Program.Error($"Unknown key in the config JSON: '{key}'"); break; } } if (setfps && setvsync && VSync) { Program.Error($"Cannot specify a frame rate and also have vsync enabled."); } break; } } }
public static IntPtr CreateColor(odl.Color Color) { return(Ruby.Funcall(Class, "new", Ruby.Integer.ToPtr(Color.Red), Ruby.Integer.ToPtr(Color.Green), Ruby.Integer.ToPtr(Color.Blue), Ruby.Integer.ToPtr(Color.Alpha))); }