private void OpenTkControl_OnRender(TimeSpan delta) { _elapsedTime += delta; var c = Color4.FromHsv(new Vector4((float)_elapsedTime.TotalSeconds * 0.1f % 1, 1f, 0.9999f, 1)); GL.ClearColor(c); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Enable(EnableCap.ScissorTest); var xPos = 50 + (ActualWidth - 250) * (0.5 + 0.5 * Math.Sin(_stopwatch.Elapsed.TotalSeconds)); GL.Scissor((int)xPos, 25, 50, 50); GL.ClearColor(Color4.Blue); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Disable(EnableCap.ScissorTest); GL.LoadIdentity(); GL.Begin(PrimitiveType.Triangles); GL.Color4(1.0f, 0.0f, 0.0f, 1.0f); GL.Vertex2(0.0f, 1.0f); GL.Color4(0.0f, 1.0f, 0.0f, 1.0f); GL.Vertex2(0.87f, -0.5f); GL.Color4(0.0f, 0.0f, 1.0f, 1.0f); GL.Vertex2(-0.87f, -0.5f); GL.End(); GL.Finish(); }
public static Color FromHsv(Vector4 vec) { return(Color4.FromHsv(vec)); }
public void Reload() { float mult = 0.12345f; if (!Directory.Exists(searchPath)) { Directory.CreateDirectory(searchPath); } using (Bitmap palette = new Bitmap(16, 8)) { for (int i = 0; i < 16 * 8; i++) { palette.SetPixel(i % 16, (i - i % 16) / 16, (Color)Color4.FromHsv(new OpenTK.Vector4(i * mult % 1, defS, defV, 1))); } palette.Save(Path.Combine(searchPath, "Random.png")); } using (Bitmap palette = new Bitmap(32, 8)) { for (int i = 0; i < 32 * 8; i++) { palette.SetPixel(i % 32, (i - i % 32) / 32, (Color)Color4.FromHsv(new OpenTK.Vector4(i * mult % 1, defS, defV, 1))); i++; palette.SetPixel(i % 32, (i - i % 32) / 32, (Color)Color4.FromHsv(new OpenTK.Vector4(((i - 1) * mult + 0.166f) % 1, defS, defV, 1))); } palette.Save(Path.Combine(searchPath, "Random Gradients.png")); } using (Bitmap palette = new Bitmap(32, 8)) { for (int i = 0; i < 32 * 8; i++) { palette.SetPixel(i % 32, (i - i % 32) / 32, (Color)Color4.FromHsv(new OpenTK.Vector4(i * mult % 1, defS, defV, 0.8f))); i++; palette.SetPixel(i % 32, (i - i % 32) / 32, (Color)Color4.FromHsv(new OpenTK.Vector4(((i - 1) * mult + 0.166f) % 1, defS, defV, 0.8f))); } palette.Save(Path.Combine(searchPath, "Random Alpha Gradients.png")); } using (Bitmap palette = new Bitmap(16, 8)) { for (int i = 0; i < 16 * 8; i++) { palette.SetPixel(i % 16, (i - i % 16) / 16, (Color)Color4.FromHsv(new OpenTK.Vector4(i * mult % 1, defS, defV, 0.8f))); } palette.Save(Path.Combine(searchPath, "Random with Alpha.png")); } var imagePaths = Directory.GetFiles(searchPath).Where(s => s.EndsWith(".png")).ToArray(); paletteList.Items.Clear(); foreach (var i in images) { i.Dispose(); } images.Clear(); Array.Sort(imagePaths, new Comparison <string>((s1, s2) => { if (s1.Contains("Random.png")) { return(-1); } if (s2.Contains("Random.png")) { return(1); } else { return(0); } })); foreach (var i in imagePaths) { try { using (var fs = new System.IO.FileStream(i, System.IO.FileMode.Open)) { Bitmap img = new Bitmap(fs); if (!(img.Width == 16 || img.Width == 32) || img.Width < 1) { continue; } images.Add(img); var item = new ListBoxItem() { Content = Path.GetFileNameWithoutExtension(i) }; if (img.Width == 32) { item.Foreground = Brushes.Blue; } paletteList.Items.Add(item); } } catch { } } ReadPFAConfig(); SelectImage(SelectedImage); }
private void slider_OnValueChanged(object sender, EventArgs e) => Value = Color4.FromHsv(new Vector4(hueSlider.Value % 1f, saturationSlider.Value, brightnessSlider.Value, alphaSlider.Value));
public ColourPicker() { AutoSizeAxes = Axes.Y; Width = 300; Children = new Drawable[] { new FillFlowContainer { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, Direction = FillDirection.Vertical, Spacing = new osuTK.Vector2(26), Children = new Drawable[] { switchModesButton = new BasicButton { RelativeSizeAxes = Axes.X, Height = 30, Action = SwitchModes, }, new Container { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, Children = new Drawable[] { hsvContainer = new FillFlowContainer <ColourPropertyDisplay> { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, Direction = FillDirection.Vertical, Spacing = new osuTK.Vector2(10), Children = new ColourPropertyDisplay[] { hueProp = new ColourPropertyDisplay("Hue", b => Color4.FromHsv(new osuTK.Vector4(b / 255f, 1, 1, 1))), satProp = new ColourPropertyDisplay("Saturation", b => Color4.FromHsv(new osuTK.Vector4(0.5f, b / 255f, 0.5f, 1))), valProp = new ColourPropertyDisplay("Value", b => Color4.FromHsv(new osuTK.Vector4(0, 1, b / 255f, 1))), } }, rgbContainer = new FillFlowContainer <ColourPropertyDisplay> { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, Direction = FillDirection.Vertical, Spacing = new osuTK.Vector2(10), Children = new ColourPropertyDisplay[] { redProp = new ColourPropertyDisplay("Red", b => new Color4(b / 255f, 0, 0, 1)), greenProp = new ColourPropertyDisplay("Green", b => new Color4(0, b / 255f, 0, 1)), blueProp = new ColourPropertyDisplay("Blue", b => new Color4(0, 0, b / 255f, 1)), } } } }, new FillFlowContainer <GridItem> { RelativeSizeAxes = Axes.X, Height = 30, Direction = FillDirection.Horizontal, Spacing = new osuTK.Vector2(6), Children = new GridItem[] { new GridItem(resultBox = new Box { RelativeSizeAxes = Axes.X, Height = 30 }), new GridItem(applyButton = new BasicButton { Text = "Apply", RelativeSizeAxes = Axes.Both, Action = () => OnCommit?.Invoke(GetColour()) }) } } } } }; hueProp.Bindable.BindValueChanged(HsvChanged, true); satProp.Bindable.BindValueChanged(HsvChanged, true); valProp.Bindable.BindValueChanged(HsvChanged, true); redProp.Bindable.BindValueChanged(RgbChanged, true); greenProp.Bindable.BindValueChanged(RgbChanged, true); blueProp.Bindable.BindValueChanged(RgbChanged, true); do { SwitchModes(); }while (rgbMode); }
private Color4 colourFor(TouchSource source) { return(Color4.FromHsv(new Vector4((float)source / TouchState.MAX_TOUCH_COUNT, 1f, 1f, 1f))); }
public static void Main() { Console.Title = "Instant Gameworks"; Console.WriteLine("Instant Gameworks (c) 2018"); Logging.LogEvent("Main thread startup"); // Set window settings DisplayDevice DefaultDisplay = DisplayDevice.Default; GameWindowRefreshRate = 0;//DefaultDisplay.RefreshRate; GameWindowSize = new OpenTK.Vector2(1920, 1080); GameWindowPosition = new OpenTK.Vector2(0, 0); GameWindowBorder = WindowBorder.Hidden; GameWindowState = WindowState.Fullscreen; // Create window Logging.LogEvent("Initializing GameworksWindow"); ThreadStart GameThread = new ThreadStart(CreateGameworksWindow); Thread RunGame = new Thread(GameThread); RunGame.Start(); // Wait for window to initialize SpinWait.SpinUntil(() => GameWindow != null && GameWindow.Exists); // // // // Game logic // // // Logging.LogEvent("Importing resources"); // Initialize camera StudioCamera Camera = new StudioCamera { MoveSensitivity = 0.01f }; GameWindow.Camera = Camera; // Establish lighting StudioCamera SunLook = new StudioCamera(); SunLook.Orientation = new Vector2(0, (float)-Math.PI / 2); // look down var Sun = GameWindow.AddDirectionalLight(); Sun.Name = "Sun"; Sun.RelativeDirection = SunLook.LookAt; Sun.Intensity = 128; Sun.Enabled = true; Sun.DiffuseColor = Color4.Black; // Import objects var Land = GameWindow.AddObject(@"Testing\dragon.igwo"); Land.DiffuseColor = Color4.DarkRed; Land.AmbientColor = new Color4(30, 0, 0, 0); Land.SpecularColor = Color4.White; Land.Scale = new Vector3(1.5f, 1.5f, 1.5f); var GuiHolder = GameWindow.AddGui(); GuiHolder.Color = new Color4(128, 128, 128, 255); GuiHolder.AbsoluteSize = new Vector2(32f / 1920f, 2f / 1080f); GuiHolder.AbsolutePosition = new Vector2(0.5f - 16f / 1920f, 0.5f - 1f / 1080f); var G2 = GameWindow.AddGui(); G2.Color = new Color4(128, 128, 128, 255); G2.AbsoluteSize = new Vector2(2f / 1920f, 32f / 1080f); G2.AbsolutePosition = new Vector2(0.5f - 1f / 1920f, 0.5f - 16f / 1080f); double _lastTime = 0; double _time = 0; float AdjustedSpeedForFramerate = 1f; void OnUpdateFrameTimer(object sender, FrameEventArgs e) { _lastTime = _time; _time += e.Time; } void ObjectUpdateFrame(object sender, FrameEventArgs e) { Sun.RelativeDirection = SunLook.LookAt; Land.Rotation += new Vector3(0, 0.005f * AdjustedSpeedForFramerate, 0); GuiHolder.Color = Color4.FromHsv(new Vector4(DateTime.Now.Millisecond / 1000f, 0.8f, 1f, 0.5f)); G2.Color = Color4.FromHsv(new Vector4(DateTime.Now.Millisecond / 1000f, 0.8f, 1f, 0.5f)); } // Camera implementation Dictionary <Key, bool> KeysDown = new Dictionary <Key, bool>() { [Key.W] = false, [Key.A] = false, [Key.S] = false, [Key.D] = false }; OpenTK.Vector2 LastMousePosition = new OpenTK.Vector2(0, 0); bool IsRightMouseDown = false; bool IsLeftMouseDown = false; bool IsSettingMousePosition = false; Vector2 CurrentMousePosition = new Vector2(0, 0); void CameraUpdateFrame(object sender, FrameEventArgs e) { if (IsRightMouseDown || IsLeftMouseDown) { IsSettingMousePosition = true; Mouse.SetPosition(LastMousePosition.X + GameWindow.X, LastMousePosition.Y + GameWindow.Y); } AdjustedSpeedForFramerate = 144f / (1f / ((float)_time - (float)_lastTime)); if (KeysDown[Key.W] == true) { Camera.Move(0, 0, -AdjustedSpeedForFramerate); } if (KeysDown[Key.A] == true) { Camera.Move(AdjustedSpeedForFramerate, 0, 0); } if (KeysDown[Key.S] == true) { Camera.Move(0, 0, AdjustedSpeedForFramerate); } if (KeysDown[Key.D] == true) { Camera.Move(-AdjustedSpeedForFramerate, 0, 0); } Vector2 mousePos = new Vector2(CurrentMousePosition.X + GameWindow.X, CurrentMousePosition.Y + GameWindow.Y); GuiHolder.AbsolutePosition = new Vector2((mousePos.X / 1920f) - (16 / 1920f), (mousePos.Y / 1080f) - (1 / 1080f)); G2.AbsolutePosition = new Vector2((mousePos.X / 1920f) - (1 / 1920f), (mousePos.Y / 1080f) - (16 / 1080f)); } void MouseDown(object sender, MouseButtonEventArgs e) { if (e.Button == MouseButton.Right) { if (!IsRightMouseDown) { IsRightMouseDown = true; LastMousePosition = new OpenTK.Vector2(e.X, e.Y); } } if (e.Button == MouseButton.Left) { if (!IsLeftMouseDown) { IsLeftMouseDown = true; LastMousePosition = new OpenTK.Vector2(e.X, e.Y); } } } void MouseUp(object sender, MouseButtonEventArgs e) { if (e.Button == MouseButton.Right) { IsRightMouseDown = false; } if (e.Button == MouseButton.Left) { IsLeftMouseDown = false; } } void MouseMove(object sender, MouseMoveEventArgs e) { if (GameWindow.Focused && IsRightMouseDown && !IsSettingMousePosition) { Camera.AddRotation(e.XDelta, e.YDelta); } if (GameWindow.Focused && IsLeftMouseDown && !IsSettingMousePosition) { SunLook.AddRotation(e.XDelta, e.YDelta); } IsSettingMousePosition = false; CurrentMousePosition = new Vector2(e.X, e.Y); } void KeyDown(object sender, KeyboardKeyEventArgs e) { switch (e.Key) { case Key.W: KeysDown[Key.W] = true; break; case Key.A: KeysDown[Key.A] = true; break; case Key.S: KeysDown[Key.S] = true; break; case Key.D: KeysDown[Key.D] = true; break; case Key.Escape: GameWindow.Exit(); break; } } void KeyUp(object sender, KeyboardKeyEventArgs e) { switch (e.Key) { case Key.W: KeysDown[Key.W] = false; break; case Key.A: KeysDown[Key.A] = false; break; case Key.S: KeysDown[Key.S] = false; break; case Key.D: KeysDown[Key.D] = false; break; } } void MouseWheel(object sender, MouseWheelEventArgs e) { Camera.Move(0, 0, -e.Delta / Camera.MoveSensitivity * 0.25f); } //assign OnUpdateFrame Logging.LogEvent("Adding update frame events"); GameWindow.UpdateFrame += OnUpdateFrameTimer; GameWindow.UpdateFrame += ObjectUpdateFrame; GameWindow.UpdateFrame += CameraUpdateFrame; //assign input events Logging.LogEvent("Adding input events"); GameWindow.MouseDown += MouseDown; GameWindow.MouseUp += MouseUp; GameWindow.MouseMove += MouseMove; GameWindow.KeyDown += KeyDown; GameWindow.KeyUp += KeyUp; GameWindow.MouseWheel += MouseWheel; //Exit RunGame.Join(); NativeMethods.ConsoleApp.ShowConsole(); Logging.LogEvent("Shutting down"); /*Logging.WriteToFile(); * Logging.DisplayLog().Join(); *///end of thread }