diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2015-09-21 08:30:08 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2015-09-21 08:30:09 +0200 |
| commit | f662d49464e2b8326522aad67761ffdcb8a5e5f6 (patch) | |
| tree | f767f75977721299da029518ec938bfa0366597b /src | |
| parent | db3a636d9c4de1e4ee1d4e79e6dfeae738daac8d (diff) | |
* BmpPicture.cs:
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/BmpPicture.cs | 10 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 24 | ||||
| -rw-r--r-- | src/GraphicObjects/Group.cs | 2 | ||||
| -rwxr-xr-x | src/GraphicObjects/HorizontalStack.cs | 4 | ||||
| -rwxr-xr-x | src/GraphicObjects/Label.cs | 4 | ||||
| -rw-r--r-- | src/GraphicObjects/ListBox.cs | 20 | ||||
| -rw-r--r-- | src/GraphicObjects/TemplatedContainer.cs | 5 | ||||
| -rw-r--r-- | src/GraphicObjects/Window.cs | 140 | ||||
| -rwxr-xr-x | src/OpenTKGameWindow.cs | 26 | ||||
| -rw-r--r-- | src/Picture.cs | 1 |
10 files changed, 150 insertions, 86 deletions
diff --git a/src/BmpPicture.cs b/src/BmpPicture.cs index 2f6d11d6..0fd92da0 100644 --- a/src/BmpPicture.cs +++ b/src/BmpPicture.cs @@ -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) diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index a78273ec..807ad95b 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -62,6 +62,7 @@ namespace go Size _minimumSize;
Picture _backgroundImage;
+ string _backgroundImagePath;
string _template;
#endregion
@@ -289,6 +290,24 @@ namespace go false :
true; } }
[XmlAttributeAttribute()][DefaultValue(null)]
+ public virtual string BackgroundImagePath {
+ get { return _backgroundImagePath; }
+ set {
+ _backgroundImagePath = value;
+ if (string.IsNullOrEmpty(_backgroundImagePath))
+ return;
+
+ if (_backgroundImagePath.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture))
+ _backgroundImage = new SvgPicture ();
+ else
+ _backgroundImage = new BmpPicture ();
+
+ _backgroundImage.LoadImage (_backgroundImagePath);
+ //_backgroundImage.Scale = false;
+ registerForGraphicUpdate ();
+ }
+ }
+ [XmlAttributeAttribute()]
public virtual Picture BackgroundImage {
get { return _backgroundImage; }
set {
@@ -692,8 +711,9 @@ namespace go }
internal virtual void checkHoverWidget(MouseMoveEventArgs e)
{
- if (TopContainer.hoverWidget != this) {
- TopContainer.hoverWidget = this;
+ IGOLibHost glh = TopContainer;
+ if (glh.hoverWidget != this) {
+ glh.hoverWidget = this;
onMouseEnter (this, e);
}
diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 763cc091..179c4116 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -157,6 +157,8 @@ namespace go protected override void onDraw (Context gr)
{
Rectangle rBack = new Rectangle (Slot.Size);
+ if (BackgroundImage != null)
+ BackgroundImage.Paint (gr, rBack, BackImgSub);
gr.Color = Background;
CairoHelpers.CairoRectangle(gr,rBack,CornerRadius);
gr.Fill ();
diff --git a/src/GraphicObjects/HorizontalStack.cs b/src/GraphicObjects/HorizontalStack.cs index bdfc136e..6a192f9a 100755 --- a/src/GraphicObjects/HorizontalStack.cs +++ b/src/GraphicObjects/HorizontalStack.cs @@ -18,10 +18,6 @@ namespace go public override Orientation Orientation
{
get { return Orientation.Horizontal; }
- //set { }
}
-
-
-
}
}
diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index 68de029e..94c13790 100755 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -527,9 +527,9 @@ namespace go {
base.onMouseMove (sender, e);
- if ((sender as OpenTKGameWindow).activeWidget != this)
+ IGOLibHost glh = TopContainer;
+ if (glh.activeWidget != this)
return;
-
if (!Selectable)
return;
diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index 4222bc50..9b5ea73f 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -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 } } diff --git a/src/GraphicObjects/TemplatedContainer.cs b/src/GraphicObjects/TemplatedContainer.cs index 56217419..dcea97d7 100644 --- a/src/GraphicObjects/TemplatedContainer.cs +++ b/src/GraphicObjects/TemplatedContainer.cs @@ -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 (); } diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs index cbe1cc9b..f9e3a54b 100644 --- a/src/GraphicObjects/Window.cs +++ b/src/GraphicObjects/Window.cs @@ -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 (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; + 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; + 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; - } - } + 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; diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index ff1ffeed..ebe3735e 100755 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -25,7 +25,7 @@ namespace go // DisplayDevice.Default,
// 3,0,OpenTK.Graphics.GraphicsContextFlags.Default)
public OpenTKGameWindow(int _width, int _height, string _title="golib")
- : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8),
+ : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 1),
_title,GameWindowFlags.Default,DisplayDevice.GetDisplay(DisplayIndex.Second),
3,2,OpenTK.Graphics.GraphicsContextFlags.Debug|OpenTK.Graphics.GraphicsContextFlags.ForwardCompatible)
// public OpenTKGameWindow(int _width, int _height, string _title="golib")
@@ -153,7 +153,7 @@ namespace go byte[] bmp;
int texID;
- QuadVAO uiQuad;
+ public QuadVAO uiQuad, uiQuad2;
go.GLBackend.Shader shader;
Matrix4 projectionMatrix,
modelviewMatrix;
@@ -166,6 +166,7 @@ namespace go if (uiQuad != null)
uiQuad.Dispose ();
uiQuad = new QuadVAO (0, 0, ClientRectangle.Width, ClientRectangle.Height, 0, 1, 1, -1);
+ uiQuad2 = new QuadVAO (0, 0, ClientRectangle.Width, ClientRectangle.Height, 0, 0, 1, 1);
projectionMatrix = Matrix4.CreateOrthographicOffCenter
(0, ClientRectangle.Width, ClientRectangle.Height, 0, 0, 1);
modelviewMatrix = Matrix4.Identity;
@@ -217,6 +218,23 @@ namespace go shader.Disable ();
GL.Viewport (viewport [0], viewport [1], viewport [2], viewport [3]);
}
+ public void RenderCustomTextureOnUIQuad(int _customTex)
+ {
+ GL.GetInteger (GetPName.Viewport, viewport);
+ GL.Viewport (0, 0, ClientRectangle.Width, ClientRectangle.Height);
+ shader.Enable ();
+ shader.ProjectionMatrix = projectionMatrix;
+ shader.ModelViewMatrix = modelviewMatrix;
+ shader.Color = new Vector4(1f,1f,1f,1f);
+ GL.ActiveTexture (TextureUnit.Texture0);
+ GL.BindTexture (TextureTarget.Texture2D, _customTex);
+ GL.Disable (EnableCap.DepthTest);
+ uiQuad2.Render (PrimitiveType.TriangleStrip);
+ GL.Enable (EnableCap.DepthTest);
+ GL.BindTexture(TextureTarget.Texture2D, 0);
+ shader.Disable ();
+ GL.Viewport (viewport [0], viewport [1], viewport [2], viewport [3]);
+ }
#endregion
@@ -310,10 +328,6 @@ namespace go // Debug.WriteLine("UPDATE: {0} ticks \t, {1} ms",
// updateTime.ElapsedTicks,
// updateTime.ElapsedMilliseconds);
- //update Mouse cursor
- if (_hoverWidget is Window) {
-
- }
}
#endregion
diff --git a/src/Picture.cs b/src/Picture.cs index 411f3eb4..954878af 100644 --- a/src/Picture.cs +++ b/src/Picture.cs @@ -29,6 +29,7 @@ namespace go public string Path; public Size Dimensions; public bool KeepProportions = false; + public bool Scale = true; public Picture () { |