protected internal override void OnMouseUp(Input.Mouse.MouseEventArgs e) { base.OnMouseUp(e); if (pressedctl != null) { Control2D c2d = (pressedctl as Control2D); if (c2d == null) { return; } MouseEventArgs args = new MouseEventArgs(e.Buttons, (int)(e.X - c2d.Position.X), (int)(e.Y - c2d.Position.Y)); pressedctl.OnMouseUp(args); pressedctl = null; return; } Control2D ctl = HitTest(e.X, e.Y); if (ctl != null) { MouseEventArgs args = new MouseEventArgs(e.Buttons, (int)(e.X - ctl.Position.X), (int)(e.Y - ctl.Position.Y)); ctl.OnMouseUp(args); return; } if (e.Buttons == Input.Mouse.MouseButton.Primary) { mvarMoving = false; } }
private static void _OnMotion(int x, int y) { Window w = null; if (mvarLastFullscreenWindow != null) { w = mvarLastFullscreenWindow; } else { int handle = Internal.FreeGLUT.Methods.glutGetWindow(); w = handleWindows[handle]; } MouseEventArgs args = new MouseEventArgs(MouseButton.None, x, y); if (w._motionCtl != null) { w._motionCtl.OnMouseMove(args); } else { Control2D ctl = w.HitTest(x, y); if (ctl != null) { args = new MouseEventArgs(MouseButton.None, (int)(x - ctl.Position.X), (int)(y - ctl.Position.Y)); ctl.OnMouseMove(args); } else { w.OnMouseMove(args); } } }
private Control2D HitTest(int x, int y) { x += mvarOffsetX; y += mvarOffsetY; // x += (int)this.Position.X; // y += 42; // y -= 20; /* * if (Parent is Window && (Parent as Window).FullScreen) * { * y -= System.Windows.Forms.SystemInformation.CaptionHeight; * y -= 5; * } */ foreach (Control ctl in this.Controls) { if (!ctl.Visible) { continue; } if (ctl is Control2D) { Control2D c2d = (ctl as Control2D); if (x >= c2d.Position.X && y >= c2d.Position.Y && x <= c2d.Position.X + c2d.Size.Width && y <= c2d.Position.Y + c2d.Size.Height) { return(c2d); } } } return(null); }
private void RenderControl(RenderEventArgs e, Control ctl) { if (ctl is Control2D) { Control2D c2d = (ctl as Control2D); Internal.OpenGL.Methods.glMatrixMode(MatrixMode.ModelView); Internal.OpenGL.Methods.glTranslated(c2d.Position.X, c2d.Position.Y, 0); Internal.OpenGL.Methods.glTranslated(5, 1, 0); } BeforeRenderEventArgs bre = new BeforeRenderEventArgs(e.Canvas); ctl.OnBeforeRender(bre); if (bre.Cancel) { return; } ctl.OnRender(e); ctl.OnAfterRender(e); if (ctl is Control2D) { Control2D c2d = (ctl as Control2D); Internal.OpenGL.Methods.glMatrixMode(MatrixMode.ModelView); Internal.OpenGL.Methods.glTranslated(-c2d.Position.X, -c2d.Position.Y, 0); Internal.OpenGL.Methods.glTranslated(-5, -1, 0); } }
protected internal override void OnMouseMove(Input.Mouse.MouseEventArgs e) { base.OnMouseMove(e); if (mvarMoving) { base.Position = new PositionVector2((e.X - dx), (e.Y - dy)); base.Parent.Refresh(); } else { Control2D ctl = HitTest(e.X, e.Y); if (ctl != null) { MouseEventArgs args = new MouseEventArgs(e.Buttons, (int)(e.X - ctl.Position.X + mvarOffsetX), (int)(e.Y - ctl.Position.Y + mvarOffsetY)); // args = new MouseEventArgs(e.Buttons, (int)(e.X), (int)(e.Y)); ctl.OnMouseMove(args); } } }
public Control2D HitTest(double x, double y) { for (int i = mvarControls.Count - 1; i >= 0; i--) { Control ctl = mvarControls[i]; if (!ctl.Visible) { continue; } if (ctl is Control2D) { Control2D c2d = (ctl as Control2D); if (x >= c2d.Position.X && y >= c2d.Position.Y && x <= c2d.Position.X + c2d.Size.Width && y <= c2d.Position.Y + c2d.Size.Height) { return(c2d); } } } return(null); }
protected internal override void OnMouseDown(Input.Mouse.MouseEventArgs e) { base.OnMouseDown(e); Control2D ctl = HitTest(e.X, e.Y); if (ctl != null) { MouseEventArgs args = new MouseEventArgs(e.Buttons, (int)(e.X - ctl.Position.X), (int)(e.Y - ctl.Position.Y)); ctl.OnMouseDown(args); pressedctl = ctl; return; } if (e.Buttons == Input.Mouse.MouseButton.Primary && e.Y <= 20) { mvarMoving = true; cx = base.Position.X; cy = base.Position.Y; dx = e.X; dy = e.Y; } }
private static void _OnMouse(int button, int state, int x, int y) { Window w = null; if (mvarLastFullscreenWindow != null) { w = mvarLastFullscreenWindow; } else { int handle = Internal.FreeGLUT.Methods.glutGetWindow(); w = handleWindows[handle]; } MouseButton buttons = MouseButton.None; switch (button) { case 0: { buttons = MouseButton.Primary; break; } case 1: { buttons = MouseButton.Wheel; break; } case 2: { buttons = MouseButton.Secondary; break; } case 3: { // Wheel up if (state == 0) { state = 2; } else if (state == 1) { return; } break; } case 4: { // Wheel down if (state == 0) { state = 2; } else if (state == 1) { return; } break; } case 7: { buttons = MouseButton.XButton1; break; } case 8: { buttons = MouseButton.XButton2; break; } } MouseEventArgs args = new MouseEventArgs(buttons, x, y); /* * if (w.FullScreen) * { * y += 25; * x -= 5; * } */ switch (state) { case 0: { Control2D c2d = w.HitTest(x, y); if (c2d != null) { args = new MouseEventArgs(buttons, (int)(x - c2d.Position.X), (int)(y - c2d.Position.Y)); w._motionCtl = c2d; if (mvarFocusedControl != c2d) { if (mvarFocusedControl != null) { mvarFocusedControl.HasFocus = false; mvarFocusedControl.OnLostFocus(EventArgs.Empty); } mvarFocusedControl = c2d; c2d.HasFocus = true; c2d.OnGotFocus(EventArgs.Empty); } c2d.OnMouseDown(args); return; } else if (mvarFocusedControl != null) { mvarFocusedControl.HasFocus = false; mvarFocusedControl.OnLostFocus(EventArgs.Empty); mvarFocusedControl = null; } w.OnMouseDown(args); break; } case 1: { Control2D c2d = (w._motionCtl as Control2D); if (c2d != null) { args = new MouseEventArgs(buttons, (int)(x - c2d.Position.X), (int)(y - c2d.Position.Y)); w._motionCtl.OnMouseUp(args); w._motionCtl = null; return; } w.OnMouseUp(args); break; } case 2: { Control2D c2d = w.HitTest(x, y); if (c2d != null) { args = new MouseEventArgs(buttons, (int)(x - 4 - c2d.Position.X), (int)(y + 12 - c2d.Position.Y)); c2d.OnMouseWheel(args); return; } w.OnMouseWheel(args); break; } } }
private static void _OnRender() { Window w = null; if (mvarLastFullscreenWindow != null) { w = mvarLastFullscreenWindow; } else { int handle = Internal.FreeGLUT.Methods.glutGetWindow(); w = handleWindows[handle]; } BeforeRenderEventArgs bre = new BeforeRenderEventArgs(w.Canvas); RenderEventArgs re = new RenderEventArgs(w.Canvas); Internal.OpenGL.Methods.glMatrixMode(MatrixMode.Projection); Internal.OpenGL.Methods.glLoadIdentity(); Internal.OpenGL.Methods.glViewport(0, 0, w.Width, w.Height); Internal.OpenGL.Methods.glOrtho(0, w.Width, w.Height, 0, -1, 1); Internal.OpenGL.Methods.glMatrixMode(MatrixMode.ModelView); Internal.OpenGL.Methods.glLoadIdentity(); Internal.OpenGL.Methods.glClearColor(w.BackgroundColor.Red, w.BackgroundColor.Green, w.BackgroundColor.Blue, w.BackgroundColor.Alpha); Internal.OpenGL.Methods.glClear(Internal.OpenGL.Constants.GL_COLOR_BUFFER_BIT | Internal.OpenGL.Constants.GL_DEPTH_BUFFER_BIT); w.OnBeforeRender(bre); if (bre.Cancel) { return; } bool depthtest = Internal.OpenGL.Methods.glIsEnabled(Internal.OpenGL.Constants.GLCapabilities.DepthTesting); bool lighting = Internal.OpenGL.Methods.glIsEnabled(Internal.OpenGL.Constants.GLCapabilities.Lighting); double ofsx = 1.0, ofsy = 11.0; if (w.FullScreen) { ofsx = 0; ofsy = -10; } foreach (Control ctl in w.Controls) { if (ctl.Visible) { if (ctl is Control2D) { // set up for 2D rendering Caltron.Internal.OpenGL.Methods.glViewport(0, 0, w.Width, w.Height); Control2D c2d = (ctl as Control2D); Internal.OpenGL.Methods.glMatrixMode(MatrixMode.ModelView); Internal.OpenGL.Methods.glLoadIdentity(); Internal.OpenGL.Methods.glTranslated((c2d.Position.X + ofsx), (c2d.Position.Y + ofsy), 0); if (depthtest) { Internal.OpenGL.Methods.glDisable(Internal.OpenGL.Constants.GLCapabilities.DepthTesting); } if (lighting) { Internal.OpenGL.Methods.glDisable(Internal.OpenGL.Constants.GLCapabilities.Lighting); } } ctl.OnBeforeRender(bre); if (!bre.Cancel) { ctl.OnRender(re); ctl.OnAfterRender(re); } if (ctl is Control2D) { Control2D c2d = (ctl as Control2D); Internal.OpenGL.Methods.glMatrixMode(MatrixMode.ModelView); Internal.OpenGL.Methods.glTranslated(-(c2d.Position.X + ofsx), -(c2d.Position.Y + ofsy), 0); if (depthtest) { Internal.OpenGL.Methods.glEnable(Internal.OpenGL.Constants.GLCapabilities.DepthTesting); } if (lighting) { Internal.OpenGL.Methods.glEnable(Internal.OpenGL.Constants.GLCapabilities.Lighting); } } } } w.OnAfterRender(re); Internal.FreeGLUT.Methods.glutSwapBuffers(); }