]> O.S.I.I.S - jp/crow.git/commitdiff
* BmpPicture.cs:
authorjpbruyere <jp.bruyere@hotmail.com>
Mon, 21 Sep 2015 06:30:08 +0000 (08:30 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Mon, 21 Sep 2015 06:30:09 +0000 (08:30 +0200)
  allow unscalled picture

* GraphicObject.cs:
  background image path, problems with repaint of background

* Group.cs:
  background image

* HorizontalStack.cs:
  clean code

* Label.cs:
  debug

* TemplatedContainer.cs:
  fix dataSource==null to clear binding successfully

* Window.cs:
  resizable or not

* OpenTKGameWindow.cs:
  RenderCustomTextureOnUIQuad (usefull for cached content)

* Picture.cs:
  Scale boolean

* ListBox.cs:
  remove debug loading time

src/BmpPicture.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Group.cs
src/GraphicObjects/HorizontalStack.cs
src/GraphicObjects/Label.cs
src/GraphicObjects/ListBox.cs
src/GraphicObjects/TemplatedContainer.cs
src/GraphicObjects/Window.cs
src/OpenTKGameWindow.cs
src/Picture.cs

index 2f6d11d693604f48b6b4bbe78131d649f91e77c0..0fd92da042d80e07d5796c7bc4bbcd61bdd9e92b 100644 (file)
@@ -63,8 +63,14 @@ namespace go
 
                public override void Paint (Cairo.Context gr, Rectangle rect, string subPart = "")
                {
-                       float widthRatio = (float)rect.Width / Dimensions.Width;
-                       float heightRatio = (float)rect.Height / Dimensions.Height;
+                       float widthRatio = 1f;
+                       float heightRatio = 1f;
+
+                       if (Scale){
+                               widthRatio = (float)rect.Width / Dimensions.Width;
+                               heightRatio = (float)rect.Height / Dimensions.Height;
+                       }
+
                        float ratio = Math.Min (widthRatio, heightRatio);
 
 //                     if (KeepProportions)
index a78273ec995766621abdfc3530faadbbe00b72b8..807ad95b0574888aa38b7b23e7a317d46819b887 100644 (file)
@@ -62,6 +62,7 @@ namespace go
                Size _minimumSize;\r
 \r
                Picture _backgroundImage;\r
+               string _backgroundImagePath;\r
                string _template;\r
                #endregion\r
 \r
@@ -289,6 +290,24 @@ namespace go
                                false : \r
                                true; } }\r
                [XmlAttributeAttribute()][DefaultValue(null)]\r
+               public virtual string BackgroundImagePath {\r
+                       get { return _backgroundImagePath; }\r
+                       set { \r
+                               _backgroundImagePath = value;\r
+                               if (string.IsNullOrEmpty(_backgroundImagePath))                                 \r
+                                       return;\r
+\r
+                               if (_backgroundImagePath.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture)) \r
+                                       _backgroundImage = new SvgPicture ();\r
+                               else \r
+                                       _backgroundImage = new BmpPicture ();\r
+\r
+                               _backgroundImage.LoadImage (_backgroundImagePath);\r
+                               //_backgroundImage.Scale = false;\r
+                               registerForGraphicUpdate ();\r
+                       }\r
+               }\r
+               [XmlAttributeAttribute()]\r
                public virtual Picture BackgroundImage {\r
                        get { return _backgroundImage; }\r
                        set { \r
@@ -692,8 +711,9 @@ namespace go
                }\r
                internal virtual void checkHoverWidget(MouseMoveEventArgs e)\r
                {\r
-                       if (TopContainer.hoverWidget != this) {\r
-                               TopContainer.hoverWidget = this;\r
+                       IGOLibHost glh = TopContainer;\r
+                       if (glh.hoverWidget != this) {\r
+                               glh.hoverWidget = this;\r
                                onMouseEnter (this, e);\r
                        }\r
 \r
index 763cc091805c7bd2b741ff758e2c7c2f7c8db4c5..179c4116174005613d560e308a35a372edbdb592 100644 (file)
@@ -157,6 +157,8 @@ namespace go
                protected override void onDraw (Context gr)\r
                {\r
                        Rectangle rBack = new Rectangle (Slot.Size);\r
+                       if (BackgroundImage != null)                            \r
+                               BackgroundImage.Paint (gr, rBack, BackImgSub);\r
                        gr.Color = Background;\r
                        CairoHelpers.CairoRectangle(gr,rBack,CornerRadius);\r
                        gr.Fill ();\r
index bdfc136e548e82e439de3f7de2681f7ab415c8ce..6a192f9a71fc629fc427b91d01c23b3b8a433203 100755 (executable)
@@ -18,10 +18,6 @@ namespace go
         public override Orientation Orientation\r
         {\r
             get { return Orientation.Horizontal; }\r
-            //set {  }\r
         }\r
-\r
-\r
-\r
     }\r
 }\r
index 68de029ec70fdd01ce2a1214a481b5ea5d457315..94c13790a824ccff54fdbede3fa9a4aa30cbf470 100755 (executable)
@@ -527,9 +527,9 @@ namespace go
                {\r
                        base.onMouseMove (sender, e);\r
 \r
-                       if ((sender as OpenTKGameWindow).activeWidget != this)\r
+                       IGOLibHost glh = TopContainer;\r
+                       if (glh.activeWidget != this)\r
                                return;\r
-\r
                        if (!Selectable)\r
                                return;\r
                        \r
index 4222bc50972a94a3a2454f2da828ecb5e68eaf7b..9b5ea73f6e5b17fb532fbb191fe38474554230b1 100644 (file)
@@ -85,10 +85,10 @@ namespace go
                                if (data == null)
                                        return;
 
-                               #if DEBUG
-                               Stopwatch loadingTime = new Stopwatch ();
-                               loadingTime.Start ();
-                               #endif
+//                             #if DEBUG
+//                             Stopwatch loadingTime = new Stopwatch ();
+//                             loadingTime.Start ();
+//                             #endif
 
                                MemoryStream ms = new MemoryStream ();
                                using (Stream stream = Interface.GetStreamFromPath (ItemTemplate))                                      
@@ -105,12 +105,12 @@ namespace go
 
                                ms.Dispose ();
 
-                               #if DEBUG
-                               loadingTime.Stop ();
-                               Debug.WriteLine("Listbox Loading: {0} ticks \t, {1} ms",
-                                       loadingTime.ElapsedTicks,
-                                       loadingTime.ElapsedMilliseconds);
-                               #endif
+//                             #if DEBUG
+//                             loadingTime.Stop ();
+//                             Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms",
+//                                     loadingTime.ElapsedTicks,
+//                                     loadingTime.ElapsedMilliseconds, this.ToString());
+//                             #endif
                        }
                }
 
index 56217419e6695dc539fd144b063c131d6f3b62d6..dcea97d7976d80ecaf1a9b950186ec0c1c5f33b0 100644 (file)
@@ -35,8 +35,11 @@ namespace go
                #region GraphicObject overrides
                public override void ClearBinding ()
                {
-                       if (Content != null)
+                       if (Content != null) {
+                               //fix datasource = null to clear bindings, but it's illogic
+                               Content.DataSource = this.DataSource;
                                Content.ClearBinding ();
+                       }
 
                        base.ClearBinding ();
                }
index cbe1cc9b6ca874fc8b6d4024a12b056f7d75aea1..f9e3a54b428bce78f0a23353078710b0eb9630db 100644 (file)
@@ -24,6 +24,7 @@ namespace go
 
                string _title;
                string _icon;
+               bool _resizable;
                Container _contentContainer;
                Direction currentDirection = Direction.None;
 
@@ -64,7 +65,18 @@ namespace go
                                NotifyValueChanged ("Icon", _icon);
                        }
                } 
-                       
+               [XmlAttributeAttribute()][DefaultValue(true)]
+               public bool Resizable {
+                       get {
+                               return _resizable;
+                       }
+                       set {
+                               _resizable = value;
+                               NotifyValueChanged ("Resizable", _resizable);
+                       }
+               }
+
+
                public override void onMouseMove (object sender, MouseMoveEventArgs e)
                {
                        base.onMouseMove (sender, e);
@@ -72,60 +84,62 @@ namespace go
                        OpenTKGameWindow otkgw = TopContainer as OpenTKGameWindow;
 
                        if (otkgw.activeWidget == null) {
-                               Direction lastDir = currentDirection;
-
-                               if (Math.Abs (e.Position.Y - this.Slot.Y) < Interface.BorderThreshold) {
-                                       if (Math.Abs (e.Position.X - this.Slot.X) < Interface.BorderThreshold)
-                                               currentDirection = Direction.NW;
-                                       else if (Math.Abs (e.Position.X - this.Slot.Right) < Interface.BorderThreshold)
-                                               currentDirection = Direction.NE;
-                                       else
-                                               currentDirection = Direction.N;
-                               } else if (Math.Abs (e.Position.Y - this.Slot.Bottom) < Interface.BorderThreshold) {
-                                       if (Math.Abs (e.Position.X - this.Slot.X) < Interface.BorderThreshold)
-                                               currentDirection = Direction.SW;
+                               if (Resizable) {
+                                       Direction lastDir = currentDirection;
+
+                                       if (Math.Abs (e.Position.Y - this.Slot.Y) < Interface.BorderThreshold) {
+                                               if (Math.Abs (e.Position.X - this.Slot.X) < Interface.BorderThreshold)
+                                                       currentDirection = Direction.NW;
+                                               else if (Math.Abs (e.Position.X - this.Slot.Right) < Interface.BorderThreshold)
+                                                       currentDirection = Direction.NE;
+                                               else
+                                                       currentDirection = Direction.N;
+                                       } else if (Math.Abs (e.Position.Y - this.Slot.Bottom) < Interface.BorderThreshold) {
+                                               if (Math.Abs (e.Position.X - this.Slot.X) < Interface.BorderThreshold)
+                                                       currentDirection = Direction.SW;
+                                               else if (Math.Abs (e.Position.X - this.Slot.Right) < Interface.BorderThreshold)
+                                                       currentDirection = Direction.SE;
+                                               else
+                                                       currentDirection = Direction.S;
+                                       } else if (Math.Abs (e.Position.X - this.Slot.X) < Interface.BorderThreshold)
+                                               currentDirection = Direction.W;
                                        else if (Math.Abs (e.Position.X - this.Slot.Right) < Interface.BorderThreshold)
-                                               currentDirection = Direction.SE;
+                                               currentDirection = Direction.E;
                                        else
-                                               currentDirection = Direction.S;
-                               } else if (Math.Abs (e.Position.X - this.Slot.X) < Interface.BorderThreshold)
-                                       currentDirection = Direction.W;
-                               else if (Math.Abs (e.Position.X - this.Slot.Right) < Interface.BorderThreshold)
-                                       currentDirection = Direction.E;
-                               else
-                                       currentDirection = Direction.None;
-
-                               if (currentDirection != lastDir) {
-                                       switch (currentDirection) {
-                                       case Direction.None:
-                                               otkgw.Cursor = XCursor.Default;
-                                               break;
-                                       case Direction.N:
-                                               otkgw.Cursor = XCursor.V;
-                                               break;
-                                       case Direction.S:
-                                               otkgw.Cursor = XCursor.V;
-                                               break;
-                                       case Direction.E:
-                                               otkgw.Cursor = XCursor.H;
-                                               break;
-                                       case Direction.W:
-                                               otkgw.Cursor = XCursor.H;
-                                               break;
-                                       case Direction.NW:
-                                               otkgw.Cursor = XCursor.NW;
-                                               break;
-                                       case Direction.NE:
-                                               otkgw.Cursor = XCursor.NE;
-                                               break;
-                                       case Direction.SW:
-                                               otkgw.Cursor = XCursor.SW;
-                                               break;
-                                       case Direction.SE:
-                                               otkgw.Cursor = XCursor.SE;
-                                               break;
-                                       }
-                               }                               
+                                               currentDirection = Direction.None;
+
+                                       if (currentDirection != lastDir) {
+                                               switch (currentDirection) {
+                                               case Direction.None:
+                                                       otkgw.Cursor = XCursor.Default;
+                                                       break;
+                                               case Direction.N:
+                                                       otkgw.Cursor = XCursor.V;
+                                                       break;
+                                               case Direction.S:
+                                                       otkgw.Cursor = XCursor.V;
+                                                       break;
+                                               case Direction.E:
+                                                       otkgw.Cursor = XCursor.H;
+                                                       break;
+                                               case Direction.W:
+                                                       otkgw.Cursor = XCursor.H;
+                                                       break;
+                                               case Direction.NW:
+                                                       otkgw.Cursor = XCursor.NW;
+                                                       break;
+                                               case Direction.NE:
+                                                       otkgw.Cursor = XCursor.NE;
+                                                       break;
+                                               case Direction.SW:
+                                                       otkgw.Cursor = XCursor.SW;
+                                                       break;
+                                               case Direction.SE:
+                                                       otkgw.Cursor = XCursor.SE;
+                                                       break;
+                                               }
+                                       }                               
+                               }
                                return;
                        }
 
@@ -134,38 +148,46 @@ namespace go
                                
                        this.TopContainer.redrawClip.AddRectangle (this.ScreenCoordinates(this.Slot));
 
+                       int currentLeft = this.Left;
+                       int currentTop = this.Top;
+
+                       if (currentLeft == 0)
+                               currentLeft = this.Slot.Left;
+                       if (currentTop == 0)
+                               currentTop = this.Slot.Top;
+
                        switch (currentDirection) {
                        case Direction.None:
-                               this.Left += e.XDelta;
-                               this.Top += e.YDelta;
+                               this.Left = currentLeft + e.XDelta;                             
+                               this.Top = currentTop + e.YDelta;
                                break;
                        case Direction.N:
-                               this.Top += e.YDelta;
+                               this.Top = currentTop + e.YDelta;
                                this.Height -= e.YDelta;
                                break;
                        case Direction.S:
                                this.Height += e.YDelta;
                                break;
                        case Direction.W:
-                               this.Left += e.XDelta;
+                               this.Left = currentLeft + e.XDelta;
                                this.Width -= e.XDelta;
                                break;
                        case Direction.E:
                                this.Width += e.XDelta;
                                break;
                        case Direction.NW:
-                               this.Left += e.XDelta;
-                               this.Top += e.YDelta;
+                               this.Left = currentLeft + e.XDelta;
+                               this.Top = currentTop + e.YDelta;
                                this.Width -= e.XDelta;
                                this.Height -= e.YDelta;
                                break;
                        case Direction.NE:
                                this.Width += e.XDelta;
-                               this.Top += e.YDelta;
+                               this.Top = currentTop + e.YDelta;
                                this.Height -= e.YDelta;
                                break;
                        case Direction.SW:
-                               this.Left += e.XDelta;
+                               this.Left = currentLeft + e.XDelta;
                                this.Width -= e.XDelta;
                                this.Height += e.YDelta;
                                break;
index ff1ffeedc33132d50689e2fc47adfa577dc6865c..ebe3735e4aa590e87f6abd613ec32217c3047608 100755 (executable)
@@ -25,7 +25,7 @@ namespace go
 //                             DisplayDevice.Default,\r
 //                             3,0,OpenTK.Graphics.GraphicsContextFlags.Default)\r
                public OpenTKGameWindow(int _width, int _height, string _title="golib")\r
-                       : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8), \r
+                       : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 1), \r
                                _title,GameWindowFlags.Default,DisplayDevice.GetDisplay(DisplayIndex.Second),\r
                                3,2,OpenTK.Graphics.GraphicsContextFlags.Debug|OpenTK.Graphics.GraphicsContextFlags.ForwardCompatible)\r
 //             public OpenTKGameWindow(int _width, int _height, string _title="golib")\r
@@ -153,7 +153,7 @@ namespace go
                byte[] bmp;\r
                int texID;\r
 \r
-               QuadVAO uiQuad;\r
+               public QuadVAO uiQuad, uiQuad2;\r
                go.GLBackend.Shader shader;\r
                Matrix4 projectionMatrix, \r
                                modelviewMatrix;\r
@@ -166,6 +166,7 @@ namespace go
                        if (uiQuad != null)\r
                                uiQuad.Dispose ();\r
                        uiQuad = new QuadVAO (0, 0, ClientRectangle.Width, ClientRectangle.Height, 0, 1, 1, -1);\r
+                       uiQuad2 = new QuadVAO (0, 0, ClientRectangle.Width, ClientRectangle.Height, 0, 0, 1, 1);\r
                        projectionMatrix = Matrix4.CreateOrthographicOffCenter \r
                                (0, ClientRectangle.Width, ClientRectangle.Height, 0, 0, 1);\r
                        modelviewMatrix = Matrix4.Identity;\r
@@ -217,6 +218,23 @@ namespace go
                        shader.Disable ();\r
                        GL.Viewport (viewport [0], viewport [1], viewport [2], viewport [3]);\r
                }\r
+               public void RenderCustomTextureOnUIQuad(int _customTex)\r
+               {\r
+                       GL.GetInteger (GetPName.Viewport, viewport);\r
+                       GL.Viewport (0, 0, ClientRectangle.Width, ClientRectangle.Height);\r
+                       shader.Enable ();\r
+                       shader.ProjectionMatrix = projectionMatrix;\r
+                       shader.ModelViewMatrix = modelviewMatrix;\r
+                       shader.Color = new Vector4(1f,1f,1f,1f);\r
+                       GL.ActiveTexture (TextureUnit.Texture0);\r
+                       GL.BindTexture (TextureTarget.Texture2D, _customTex);\r
+                       GL.Disable (EnableCap.DepthTest);\r
+                       uiQuad2.Render (PrimitiveType.TriangleStrip);\r
+                       GL.Enable (EnableCap.DepthTest);\r
+                       GL.BindTexture(TextureTarget.Texture2D, 0);\r
+                       shader.Disable ();\r
+                       GL.Viewport (viewport [0], viewport [1], viewport [2], viewport [3]);                   \r
+               }\r
                        \r
                #endregion\r
 \r
@@ -310,10 +328,6 @@ namespace go
 //                     Debug.WriteLine("UPDATE: {0} ticks \t, {1} ms",\r
 //                             updateTime.ElapsedTicks,\r
 //                             updateTime.ElapsedMilliseconds);\r
-                       //update Mouse cursor\r
-                       if (_hoverWidget is Window) {\r
-                               \r
-                       }\r
                }                                               \r
                #endregion\r
                        \r
index 411f3eb4ad83bdba5012c7b197647ad99b712c7e..954878af89218dbf8e3eac03bc54d804c9946e0d 100644 (file)
@@ -29,6 +29,7 @@ namespace go
                public string Path;
                public Size Dimensions;
                public bool KeepProportions = false;
+               public bool Scale = true;
 
                public Picture ()
                {