public ColorGradient() { var colorGradient = UserInterface.GetElement("ColorGradient"); if (colorGradient != null) { throw new Exception("Only one color picker can currently exist at once. This is a limitation I intend to remove soon."); } this.Program = Shaders.GradientShader; this.Program.Use(); this.Program["hue"].SetValue(new Vector3(h, 0, 0)); this.Program["sel"].SetValue(new Vector2(selx, sely)); this.gradientQuad = Geometry.CreateQuad(this.Program, Vector2.Zero, new Vector2(150, 150)); this.RelativeTo = Corner.TopLeft; this.Position = new Point(30, 50); this.Size = new Point(150, 150); this.Name = "ColorGradient"; // set up the events for the mouse to move the indicator around this.OnMouseDown = new OnMouse((sender, eventArgs) => { mouseDown = (eventArgs.Button == MouseButton.Left); UpdateMousePosition(eventArgs.Location.X, eventArgs.Location.Y); }); this.OnMouseUp = new OnMouse((sender, eventArgs) => mouseDown = (eventArgs.Button == MouseButton.Left ? false : mouseDown)); this.OnMouseLeave = new OnMouse((sender, eventArgs) => mouseDown = false); this.OnMouseMove = new OnMouse((sender, eventArgs) => UpdateMousePosition(eventArgs.Location.X, eventArgs.Location.Y)); UpdateColor(); }
public ColorGradient() { if (UserInterface.GetElement(nameof(ColorGradient)) != null) { throw new Exception("Only one color picker can currently exist at once. This is a limitation I intend to remove soon."); } this.Program = Shaders.GradientShader; this.Program.Use(); this.Program["hue"].SetValue(new Vector3(this.h, 0.0f, 0.0f)); this.Program["sel"].SetValue(new Vector2(this.selx, this.sely)); this.gradientQuad = Geometry.CreateQuad(this.Program, Vector2.Zero, new Vector2(150f, 150f)); this.RelativeTo = Corner.TopLeft; this.Position = new Point(30, 50); this.Size = new Point(150, 150); this.Name = nameof(ColorGradient); this.OnMouseDown = (OnMouse)((sender, eventArgs) => { this.mouseDown = eventArgs.Button == MouseButton.Left; this.UpdateMousePosition(eventArgs.Location.X, eventArgs.Location.Y); }); this.OnMouseUp = (OnMouse)((sender, eventArgs) => this.mouseDown = eventArgs.Button != MouseButton.Left && this.mouseDown); this.OnMouseLeave = (OnMouse)((sender, eventArgs) => this.mouseDown = false); this.OnMouseMove = (OnMouse)((sender, eventArgs) => this.UpdateMousePosition(eventArgs.Location.X, eventArgs.Location.Y)); this.UpdateColor(); }
private void UpdateMousePosition(int x, int y) { if (!this.mouseDown) { return; } float num = (float)(UserInterface.Height - y - this.CorrectedPosition.Y) / (float)this.Size.Y; this.Program.Use(); this.Program["hue"].SetValue((float)(UserInterface.Height - y - this.CorrectedPosition.Y)); UIElement element = UserInterface.GetElement("ColorGradient"); if (element == null) { return; } ((ColorGradient)element).Hue = num; }
private void UpdateMousePosition(int x, int y) { if (!mouseDown) { return; } // calculate the selected hue based on the mouse position float hue = ((UserInterface.Height - y) - CorrectedPosition.Y) / (float)Size.Y; Program.Use(); Program["hue"].SetValue((float)((UserInterface.Height - y) - CorrectedPosition.Y)); // asks the user interface for the applicable color gradient // this will need to be modified if multiple color gradients are on the screen at once // which I can't imagine happening currently, but who knows var colorGradient = UserInterface.GetElement("ColorGradient"); if (colorGradient != null) { ((ColorGradient)colorGradient).Hue = hue; } }