Example #1
0
        public void Draw(Float2 _Pos, Float2 _Size, string _String)
        {
            float stringwidth = StringWidth(_String);

            float charheight = _Size.Y;

            //Float2 Delta = new Float2(_Size / stringwidth, 0);
            Float2 Pos = _Pos;

            Graphics.defaultshader.SetParameter("DiffuseMap", spritefont);
            Graphics.defaultshader.Begin();
            foreach (char c in _String)
            {
                CharBounds chr = bounds[c];

                float charwidth = (CharWidth(c) / stringwidth) * _Size.X;

                Graphics.DrawRectangle(
                    _Pos,
                    _Pos + new Float2(charwidth, 0),
                    _Pos + new Float2(0, charheight),
                    _Pos + new Float2(charwidth, charheight),

                    chr.Pos,
                    chr.Pos + new Float2(chr.Size.X, 0),
                    chr.Pos + new Float2(0, chr.Size.Y),
                    chr.Pos + chr.Size, 0.5f);

                _Pos.X += charwidth;
            }
            Graphics.defaultshader.End();
        }
Example #2
0
 public Vertex(Float3 _Position, Float2 _UV, Float4 _Color)
 {
     Position = _Position;
     UV = _UV;
     R = G = B = A = 0;
     Color = _Color;
 }
Example #3
0
        /// <summary>
        /// draws a rectangle using the provided image to the active render target
        /// </summary>
        /// <param name="_A">Left upper Coordinate</param>
        /// <param name="_B">Right upper Coordinate</param>
        /// <param name="_C">Left lower Coordinate</param>
        /// <param name="_D">Right lower Coordinate</param>
        /// <param name="_Image"></param>
        public static void DrawRectangle(Float3 _A, Float3 _B, Float3 _C, Float3 _D, Float2 _UVA, Float2 _UVB, Float2 _UVC, Float2 _UVD)
        {
            device.RenderState.DepthBufferEnable = false;
            device.RenderState.CullMode = CullMode.None;

            VertexBuffer vbo = new VertexBuffer(Graphics.device, Marshal.SizeOf(typeof(Vertex)) * 4, BufferUsage.None);
            VertexPositionTexture[] vertices = new VertexPositionTexture[]
            {
                new VertexPositionTexture(new Vector3(_A.X,_A.Y,_A.Z), new Vector2(_UVA.X,_UVA.Y)),
                new VertexPositionTexture(new Vector3(_B.X,_B.Y,_B.Z), new Vector2(_UVB.X,_UVB.Y)),
                new VertexPositionTexture(new Vector3(_C.X,_C.Y,_C.Z), new Vector2(_UVC.X,_UVC.Y)),
                new VertexPositionTexture(new Vector3(_D.X,_D.Y,_D.Z), new Vector2(_UVD.X,_UVD.Y))
            };
            vbo.SetData(vertices);
            device.VertexDeclaration = new VertexDeclaration(device, VertexPositionTexture.VertexElements);
            device.DrawUserPrimitives(PrimitiveType.TriangleStrip, vertices, 0, 2);
        }
Example #4
0
 public static Float2 Normalize(Float2 _A)
 {
     return _A / _A.Length();
 }
Example #5
0
 /// <summary>
 /// draws a rectangle using the provided image to the active render target
 /// </summary>
 /// <param name="_A">Left upper Coordinate</param>
 /// <param name="_B">Right upper Coordinate</param>
 /// <param name="_C">Left lower Coordinate</param>
 /// <param name="_D">Right lower Coordinate</param>
 /// <param name="_Image"></param>
 public static void DrawRectangle(Float2 _A, Float2 _B, Float2 _C, Float2 _D, Float2 _UVA, Float2 _UVB, Float2 _UVC, Float2 _UVD, float _Depth)
 {
     DrawRectangle(
         new Float3(_A.X, _A.Y, _Depth),
         new Float3(_B.X, _B.Y, _Depth),
         new Float3(_C.X, _C.Y, _Depth),
         new Float3(_D.X, _D.Y, _Depth),
         _UVA,
         _UVB,
         _UVC,
         _UVD);
 }
Example #6
0
 public static Float3x3 Translate(Float2 _Translation)
 {
     return new Float3x3(1, 0, 0, 0, 1, 0, _Translation.X, _Translation.Y, 1);
 }
 public UITouchEvent(Float2 _Position, bool _Pressed, bool _Released)
 {
     position = _Position;
     pressed = _Pressed;
     released = _Released;
 }
        public void OnDraw()
        {
            Graphics.SetBlendMode(Graphics.BlendMode.Alpha);
            Graphics.defaultshader.SetParameter("View", GetTransformation());
            Graphics.defaultshader.SetParameter("DiffuseMap", ClientResources.GenericBrowserElementBackground);
            Graphics.defaultshader.Begin();
            Graphics.DrawRectangle(
                new Float2(0, 0),
                new Float2(1, 0),
                new Float2(0, 1),
                new Float2(1, 1),
                0.5f);
            Graphics.defaultshader.End();

            Float2 Fontoffset = new Float2(0.05f, 0.05f);
            /*
            Graphics.defaultshader.Begin();
            Graphics.DrawRectangle(
                new Float2(-1, -1),
                new Float2(1, -1),
                new Float2(-1, 1),
                new Float2(1, 1),
                0.5f);
            Graphics.defaultshader.End();
            */
            //ClientResources.handwrittenfont.DrawMakeFit(new Float2(0, 0) + Fontoffset, new Float2(1, 1) - Fontoffset * 2, Name, true);
            ClientResources.handwrittenfont.Draw(new Float2(0, 0) + Fontoffset, new Float2(1, 1) - Fontoffset * 2, Name);
            ClientResources.handwrittenfont.Draw(new Float2(90, 0) + Fontoffset, new Float2(1, 1) - Fontoffset * 2, "Fields:" + networkclass.Fields.Count);
        }
Example #9
0
 public static float Length(Float2 _A)
 {
     return _A.Length();
 }
Example #10
0
 public Vertex(Float3 _Position, Float2 _UV)
 {
     Position = _Position;
     UV = _UV;
     R = G = B = A = 255;
 }
Example #11
0
        /// <summary>
        /// draws a rectangle using the provided image to the active render target
        /// </summary>
        /// <param name="_A">Left upper Coordinate</param>
        /// <param name="_B">Right upper Coordinate</param>
        /// <param name="_C">Left lower Coordinate</param>
        /// <param name="_D">Right lower Coordinate</param>
        /// <param name="_Image"></param>
        public static void DrawRectangle(Float3 _A, Float3 _B, Float3 _C, Float3 _D, Float2 _UVA, Float2 _UVB, Float2 _UVC, Float2 _UVD)
        {
            device.RenderState.DepthBufferEnable = false;
            device.RenderState.CullMode = CullMode.None;

            VertexBuffer vbo = new VertexBuffer(Graphics.device, Marshal.SizeOf(typeof(Vertex)) * 4, BufferUsage.None);
            Vertex[] vertices = new Vertex[]
            {
                new Vertex(_A, _UVA),
                new Vertex(_B, _UVB),
                new Vertex(_C, _UVC),
                new Vertex(_D, _UVD)
            };
            vbo.SetData(vertices);
            device.VertexDeclaration = new VertexDeclaration(device, Vertex.VertexElements);
            device.DrawUserPrimitives(PrimitiveType.TriangleStrip, vertices, 0, 2);
        }
Example #12
0
        public static void DrawLine(Float2 _A, Float2 _B, Float4 _ColorA, Float4 _ColorB, float _Thickness)
        {
            device.RenderState.DepthBufferEnable = false;

            VertexBuffer vbo = new VertexBuffer(Graphics.device, Marshal.SizeOf(typeof(Vertex)) * 2, BufferUsage.None);
            VertexPositionColor[] vertices = new VertexPositionColor[]
            {
                new VertexPositionColor(new Vector3(_A.X,_A.Y,0),new Color(new Vector4(_ColorA.X,_ColorA.Y,_ColorA.Z,_ColorA.W))),
                new VertexPositionColor(new Vector3(_B.X,_B.Y,0),new Color(new Vector4(_ColorB.X,_ColorB.Y,_ColorB.Z,_ColorB.W)))
            };
            vbo.SetData(vertices);
            device.VertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements);
            device.DrawUserPrimitives(PrimitiveType.LineStrip, vertices, 0, 1);
        }
Example #13
0
        public void DrawMakeFit(Float2 _Pos, Float2 _Size, string _String, bool _VCenter)
        {
            float stringwidth = StringWidth(_String);

            Float2 b = new Float2(stringwidth, bounds['B'].Size.Y * ((float)spritefont.Size.Y / (float)spritefont.Size.X));
            b *= _Size.Y / b.Y;
            if (b.X > _Size.X) b *= _Size.X / b.X;

            //if (_VCenter) _Pos.Y += (_Size.Y - b.Y) / 2;

            Draw(_Pos, b, _String);
        }
Example #14
0
 public void Draw(Float2 _Pos, float _Width, string _String)
 {
     float stringwidth = StringWidth(_String);
     float charheight = (bounds['B'].Size.Y / stringwidth) * ((float)spritefont.Size.Y / (float)spritefont.Size.X) * _Width;
     Draw(_Pos, new Float2(_Width, charheight), _String);
 }
Example #15
0
 public Float3(Float2 _XY, float _Z)
 {
     X = _XY.X; Y = _XY.Y; Z = _Z;
 }
Example #16
0
 //Methods
 public static float Dot(Float2 _A, Float2 _B)
 {
     return _A.X * _B.X + _A.Y * _B.Y;
 }
Example #17
0
 public static void SetScissorRect(Float2 _From, Float2 _To)
 {
     SetScissorRect(
         new Int2((int)(_From.X * device.Viewport.Width), (int)(_From.Y * device.Viewport.Height)),
         new Int2((int)(_To.X * device.Viewport.Width), (int)(_To.Y * device.Viewport.Height)));
 }
Example #18
0
        public void Tick()
        {
            System.Drawing.Point mouse = PointToClient(MousePosition);
            Float2 cursorpos = new Float2(
                (float)mouse.X / (float)ClientRectangle.Width,
                (float)mouse.Y / (float)ClientRectangle.Height);

            cursorpos = cursorpos * 2 - new Float2(1, 1);
            cursorpos.Y = -cursorpos.Y;
            bool press = MouseButtons == System.Windows.Forms.MouseButtons.Left;
            if (press && !lastpress) presstime = Environment.TickCount;
            if ((press && lastpos != cursorpos) || lastpress != press)
                Root.HandleControllerInput(new UITouchEvent(cursorpos, press != lastpress && press == true, press != lastpress && press == false));
            if (press) ScreenSaverStartTimer = Environment.TickCount + 60000;

            if (!press && lastpress && ScreenSaverEnabled && Environment.TickCount - presstime < 250)
                ScreenSaverStopTimer = Environment.TickCount + 10000;
            if (press)
            {
                ScreenSaverDropletPos = cursorpos;
                ScreenSaverCustomDroplet = true;
            }
            lastpress = press;

            Root.Update();
            //optionally apply screensaver
            if (ScreenSaverEnabled)
                Graphics.SetRenderTarget(ScreenSaverTarget);

            //rotate scene
            SceneRotation += 0.005f;
            foreach (UIFloor f in Floors)
            {
                f.Rotation = (float)Math.Cos(SceneRotation) * ((float)Math.PI / 8.0f);
            }

            Root.Draw();

            if (Environment.TickCount > ScreenSaverStartTimer && ScreenSaverStartTimer != 0) { ScreenSaverEnabled = true; ScreenSaverStartTimer = 0; ScreenSaverStopTimer = 0; frame1 = true; }
            if (ScreenSaverEnabled)
            {
                if (Environment.TickCount > ScreenSaverStopTimer && ScreenSaverStopTimer != 0) { ScreenSaverEnabled = false; ScreenSaverStopTimer = 0; }
                Graphics.SetRenderTarget(null);
                TextureGPU screenbuffer = ScreenSaverTarget.Resolve();
                Graphics.SetBlendMode(Graphics.BlendMode.None);
                Graphics.SetRenderTarget(ScreenSaverWobbleTarget);
                ScreenSaverShader.SetParameter("RenderSize", new Float2(TargetResolution.X, TargetResolution.Y));
                ScreenSaverShader.SetTechnique("Wobbler");
                ScreenSaverShader.Begin();
                Graphics.DrawRectangle(
                    new Float2(-1, 1),
                    new Float2(1, 1),
                    new Float2(-1, -1),
                    new Float2(1, -1), 0.5f);
                ScreenSaverShader.End();
                if (frame1) Graphics.Clear(new Float4(0, 0, 0, 0));
                if (ScreenSaverStopTimer == 0 && ScreenSaverDroplet.Get() != null)
                {
                    if (ScreenSaverCustomDroplet)
                    {
                        Graphics.SetBlendMode(Graphics.BlendMode.Alpha);
                        Graphics.defaultshader.SetParameter("View", new Float3x3(0.1f, 0, 0, 0, 0.1f, 0, ScreenSaverDropletPos.X, ScreenSaverDropletPos.Y, 1));
                        Graphics.defaultshader.SetParameter("DiffuseMap", (TextureGPU)ScreenSaverDroplet.Get());
                        Graphics.defaultshader.Begin();
                        Graphics.DrawRectangle(
                            new Float2(-1, 1),
                            new Float2(1, 1),
                            new Float2(-1, -1),
                            new Float2(1, -1), 0.5f);
                        Graphics.defaultshader.End();
                        Graphics.SetBlendMode(Graphics.BlendMode.None);
                        ScreenSaverCustomDroplet = false;
                    }
                    if (Environment.TickCount > ScreenSaverDropTimeout)
                    {
                        ScreenSaverDropTimeout = Environment.TickCount + random.Next(2000);
                        Graphics.SetBlendMode(Graphics.BlendMode.Add);
                        Graphics.defaultshader.SetParameter("View", new Float3x3(0.05f, 0, 0, 0, 0.05f, 0, (float)random.NextDouble() * 2 - 1, (float)random.NextDouble() * 2 - 1, 1));
                        Graphics.defaultshader.SetParameter("DiffuseMap", (TextureGPU)ScreenSaverDroplet.Get());
                        Graphics.defaultshader.Begin();
                        Graphics.DrawRectangle(
                            new Float2(-1, 1),
                            new Float2(1, 1),
                            new Float2(-1, -1),
                            new Float2(1, -1), 0.5f);
                        Graphics.defaultshader.End();
                        Graphics.SetBlendMode(Graphics.BlendMode.None);
                    }
                }
                Graphics.SetRenderTarget(null);
                ScreenSaverBuffer = ScreenSaverWobbleTarget.Resolve();
                ScreenSaverShader.SetParameter("WobblerMap", ScreenSaverBuffer);
                ScreenSaverShader.SetParameter("DiffuseMap", screenbuffer);
                ScreenSaverShader.SetTechnique("Main");
                ScreenSaverShader.Begin();
                Graphics.DrawRectangle(
                    new Float2(-1, 1),
                    new Float2(1, 1),
                    new Float2(-1, -1),
                    new Float2(1, -1), 0.5f);
                ScreenSaverShader.End();
                Graphics.SetBlendMode(Graphics.BlendMode.Alpha);
            }
            Synergy.Graphics.Present(p_WorkingArea.Handle);
            ResourceManager.Update();
            frame1 = false;
        }
Example #19
0
        public static void Present(IntPtr _WindowHandle, Float2 _SourceRectFrom, Float2 _SourceRectTo, Int2 _TargetRectFrom, Int2 _TargetRectTo)
        {
            float w = device.PresentationParameters.BackBufferWidth;
            float h = device.PresentationParameters.BackBufferHeight;
            _SourceRectTo.X *= w;
            _SourceRectTo.Y *= h;
            _SourceRectFrom.X *= w;
            _SourceRectFrom.Y *= h;

            _SourceRectTo -= _SourceRectFrom;
            _TargetRectTo -= _TargetRectFrom;
            device.Present(
                new Rectangle((int)_SourceRectFrom.X, (int)_SourceRectFrom.Y, (int)_SourceRectTo.X, (int)_SourceRectTo.Y),
                new Rectangle(_TargetRectFrom.X, _TargetRectFrom.Y, _TargetRectTo.X, _TargetRectTo.Y),

                _WindowHandle);
        }
        public void OnDraw()
        {
            Graphics.SetBlendMode(Graphics.BlendMode.Alpha);
            Graphics.defaultshader.SetParameter("View", GetTransformation());
            Graphics.defaultshader.SetParameter("DiffuseMap", ClientResources.GenericBrowserHeaderBackground);
            Graphics.defaultshader.Begin();
            Graphics.DrawRectangle(
                new Float2(0, 0),
                new Float2(1, 0),
                new Float2(0, 1),
                new Float2(1, 1),
                0.3f);
            Graphics.defaultshader.End();

            Float2 Fontoffset = new Float2(0.05f, 0.05f);
            ClientResources.handwrittenfont.Draw(new Float2(0, 0) + Fontoffset, new Float2(1, 1) - Fontoffset * 2, node.NodeID.ToString());
        }
Example #21
0
 public Vertex(Float3 _Position, Float2 _UV)
 {
     Position = _Position;
     UV = _UV;
 }
Example #22
0
 public void SetParameter(string _FieldName, Float2 _Float2)
 {
     shader.Parameters[_FieldName].SetValue(new Vector2(_Float2.X, _Float2.Y));
 }
Example #23
0
 public static Float3x3 Scale(Float2 _Scale)
 {
     return new Float3x3(_Scale.X, 0, 0, 0, _Scale.Y, 0, 0, 0, 1);
 }