aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2015-03-30 12:48:56 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2015-03-30 12:48:56 +0200
commit30baf7a73449a5a0b5c6ea7f3952d4d614ec741f (patch)
tree65f8c22ad3d6c65fac0e657754b4870fcbfa29bc /src/GraphicObjects
parent4338402e29d2c448c24f4efe6a788adb84f81785 (diff)
- svg image support
- bug fixes
Diffstat (limited to 'src/GraphicObjects')
-rwxr-xr-xsrc/GraphicObjects/Button.cs4
-rw-r--r--src/GraphicObjects/Container.cs13
-rwxr-xr-xsrc/GraphicObjects/GraphicObject.cs26
-rw-r--r--src/GraphicObjects/Group.cs20
-rw-r--r--src/GraphicObjects/ILayoutable.cs3
-rwxr-xr-xsrc/GraphicObjects/Image.cs46
-rwxr-xr-xsrc/GraphicObjects/Label.cs2
-rw-r--r--src/GraphicObjects/ProgressBar.cs1
-rw-r--r--src/GraphicObjects/Window.cs12
9 files changed, 104 insertions, 23 deletions
diff --git a/src/GraphicObjects/Button.cs b/src/GraphicObjects/Button.cs
index 837b7012..c0c12565 100755
--- a/src/GraphicObjects/Button.cs
+++ b/src/GraphicObjects/Button.cs
@@ -13,7 +13,7 @@ using System.ComponentModel;
namespace go
{
- public class Button : Container, IXmlSerializable
+ public class Button : Container
{
#region CTOR
public Button() : base()
@@ -37,7 +37,7 @@ namespace go
set { base.Height = value; }
}
[XmlAttributeAttribute()][DefaultValue("Gray")]
- public virtual Color Background {
+ public override Color Background {
get { return base.Background; }
set { base.Background = value; }
}
diff --git a/src/GraphicObjects/Container.cs b/src/GraphicObjects/Container.cs
index 67d9e6ff..c1134ec5 100644
--- a/src/GraphicObjects/Container.cs
+++ b/src/GraphicObjects/Container.cs
@@ -2,6 +2,7 @@ using System;
using System.Xml.Serialization;
using System.Reflection;
using OpenTK.Input;
+using System.ComponentModel;
namespace go
{
@@ -35,6 +36,13 @@ namespace go
}
#region GraphicObject Overrides
+ //check if not causing problems
+ [XmlAttributeAttribute()][DefaultValue(true)]
+ public override bool Focusable
+ {
+ get { return base.Focusable; }
+ set { base.Focusable = value; }
+ }
[XmlIgnore]public override bool LayoutIsValid
{
get
@@ -56,6 +64,11 @@ namespace go
return child == null ? null : child.FindByName (nameToFind);
}
+ public override bool Contains (GraphicObject goToFind)
+ {
+ return child == goToFind ? true :
+ child == null ? false : child.Contains(goToFind);
+ }
public override void InvalidateLayout()
{
base.InvalidateLayout();
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index ec3b7fef..935729f2 100755
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -114,7 +114,9 @@ namespace go
return cb;
}
}
-
+ [XmlIgnore]public virtual OpenTKGameWindow TopContainer {
+ get { return Parent.TopContainer; }
+ }
public virtual void InvalidateLayout ()
{
bmp = null;
@@ -134,6 +136,10 @@ namespace go
{
return Slot;
}
+ public virtual Rectangle getBounds()
+ {
+ return Bounds;
+ }
#endregion
#region EVENT HANDLERS
@@ -279,8 +285,15 @@ namespace go
return;
_isVisible = value;
- if (Parent != null)
- Parent.InvalidateLayout ();
+
+ //add slot to clipping to redraw
+ OpenTKGameWindow.gobjsToRedraw.Add (this);
+
+ //ensure main win doesn't keep hidden childrens ref
+ if (this.Contains (OpenTKGameWindow.currentWindow.hoverWidget))
+ OpenTKGameWindow.currentWindow.hoverWidget = null;
+// if (Parent != null)
+// Parent.InvalidateLayout ();
//else
// registerForRedraw();
}
@@ -347,6 +360,9 @@ namespace go
public virtual GraphicObject FindByName(string nameToFind){
return nameToFind == _name ? this : null;
}
+ public virtual bool Contains(GraphicObject goToFind){
+ return false;
+ }
/// <summary>
@@ -429,7 +445,7 @@ namespace go
Slot.X = Parent.ClientRectangle.Width / 2 - Slot.Width / 2;
break;
}
- } else
+ } else// if (Parent.getBounds().Width>=0)
xIsValid = false;
}
@@ -451,7 +467,7 @@ namespace go
Slot.Y = Parent.ClientRectangle.Height / 2 - Slot.Height / 2;
break;
}
- } else
+ } else// if (Parent.getBounds().Height>=0)
yIsValid = false;
}
}
diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs
index ef101ed1..4e8e5492 100644
--- a/src/GraphicObjects/Group.cs
+++ b/src/GraphicObjects/Group.cs
@@ -114,6 +114,16 @@ namespace go
}
return null;
}
+ public override bool Contains (GraphicObject goToFind)
+ {
+ foreach (GraphicObject w in Children) {
+ if (w == goToFind)
+ return true;
+ if (w.Contains (goToFind))
+ return true;
+ }
+ return false;
+ }
public override void InvalidateLayout()
{
base.InvalidateLayout();
@@ -162,10 +172,16 @@ namespace go
if (c.LayoutIsValid)
continue;
- if (Width < 0 && c.Width != 0)
+ if (Width < 0 && c.Width != 0) {
+ if (!atLeastOneChildHasWNotDependingOnParent && !(this is GenericStack))
+ c.XIsValid = true;
atLeastOneChildHasWNotDependingOnParent = true;
- if (Height < 0 && c.Height != 0)
+ }
+ if (Height < 0 && c.Height != 0) {
+ if (!atLeastOneChildHasHNotDependingOnParent && !(this is GenericStack))
+ c.YIsValid = true;
atLeastOneChildHasHNotDependingOnParent = true;
+ }
c.UpdateLayout ();
}
diff --git a/src/GraphicObjects/ILayoutable.cs b/src/GraphicObjects/ILayoutable.cs
index 6560eb6c..579fe2b0 100644
--- a/src/GraphicObjects/ILayoutable.cs
+++ b/src/GraphicObjects/ILayoutable.cs
@@ -16,6 +16,9 @@ namespace go
Rectangle ClientRectangle { get; }
Rectangle getSlot();
+ Rectangle getBounds();
+
+ OpenTKGameWindow TopContainer { get; }
void InvalidateLayout ();
diff --git a/src/GraphicObjects/Image.cs b/src/GraphicObjects/Image.cs
index a71205b6..aa3ea56d 100755
--- a/src/GraphicObjects/Image.cs
+++ b/src/GraphicObjects/Image.cs
@@ -2,10 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
-
-//using OpenTK.Graphics.OpenGL;
using Cairo;
using System.IO;
+using System.Runtime.InteropServices;
namespace go
{
@@ -13,6 +12,7 @@ namespace go
{
byte[] image;
+ Rsvg.Handle hSVG;
Size imgSize;
string _imgPath;
@@ -58,19 +58,33 @@ namespace go
protected override Size measureRawSize ()
{
- if (image == null)
- loadImage (@"Images/Icons/icon_alert.gif");
+ if (image == null && hSVG == null)
+ loadRessourceSvg ("go.image.icons.question_mark");
return imgSize + Margin*2;
}
-
+ void loadRessourceSvg(string resId)
+ {
+ Stream s = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resId);
+ using (MemoryStream ms = new MemoryStream ()) {
+ s.CopyTo (ms);
+ hSVG = new Rsvg.Handle (ms.ToArray ());
+ imgSize = new Size (hSVG.Dimensions.Width, hSVG.Dimensions.Height);
+ _imgPath = resId;
+ //loadImage (@"Images/Icons/question_mark.svg");
+ }
+ }
//load image via System.Drawing.Bitmap, cairo load png only
public void loadImage (string path)
{
if (!File.Exists(path))
return;
- loadImage (new System.Drawing.Bitmap (path));
+ if (path.EndsWith (".svg", true,System.Globalization.CultureInfo.InvariantCulture)) {
+ hSVG = new Rsvg.Handle (path);
+ imgSize = new Size (hSVG.Dimensions.Width, hSVG.Dimensions.Height);
+ }else
+ loadImage (new System.Drawing.Bitmap (path));
_imgPath = path;
}
@@ -97,19 +111,25 @@ namespace go
protected override void onDraw (Context gr)
{
base.onDraw (gr);
- float ratio = 1f;
+
float widthRatio = (float)ClientRectangle.Width / imgSize.Width;
float heightRatio = (float)ClientRectangle.Height / imgSize.Height;
+ float ratio = Math.Min (widthRatio, heightRatio);
- ratio = Math.Min (widthRatio, heightRatio);
Rectangle rImg = ClientRectangle;
-
+ gr.Save ();
gr.Scale (widthRatio, heightRatio);
- using (ImageSurface imgSurf = new ImageSurface(image, Format.Argb32,
- imgSize.Width, imgSize.Height, 4 * imgSize.Width)) {
- gr.SetSourceSurface (imgSurf, (int)(rImg.X / widthRatio), (int)(rImg.Y / heightRatio));
- gr.Paint ();
+ if (hSVG == null) {
+ using (ImageSurface imgSurf = new ImageSurface (image, Format.Argb32,
+ imgSize.Width, imgSize.Height, 4 * imgSize.Width)) {
+ gr.SetSourceSurface (imgSurf, (int)(rImg.X / widthRatio), (int)(rImg.Y / heightRatio));
+ gr.Paint ();
+ }
+ } else {
+ gr.Translate (rImg.X/widthRatio, rImg.Y/heightRatio);
+ hSVG.RenderCairo (gr);
}
+ gr.Restore ();
}
}
}
diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs
index 91f53291..37e2b8c7 100755
--- a/src/GraphicObjects/Label.cs
+++ b/src/GraphicObjects/Label.cs
@@ -115,7 +115,7 @@ namespace go
string[] lines = getLines;
- using (ImageSurface img = new ImageSurface (Format.Argb32, 1, 1)) {
+ using (ImageSurface img = new ImageSurface (Format.Argb32, 10, 10)) {
using (Context gr = new Context (img)) {
//Cairo.FontFace cf = gr.GetContextFontFace ();
diff --git a/src/GraphicObjects/ProgressBar.cs b/src/GraphicObjects/ProgressBar.cs
index ad43fc23..ed3c09df 100644
--- a/src/GraphicObjects/ProgressBar.cs
+++ b/src/GraphicObjects/ProgressBar.cs
@@ -91,6 +91,7 @@ namespace go
if (BorderWidth > 0)
rBack.Inflate(-BorderWidth, -BorderWidth);
+
rBack.Width = (int)((double)rBack.Width / Maximum * Value);
gr.Color = Foreground;
diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs
new file mode 100644
index 00000000..750478da
--- /dev/null
+++ b/src/GraphicObjects/Window.cs
@@ -0,0 +1,12 @@
+using System;
+
+namespace go
+{
+ public class Window : Container
+ {
+ public Window ()
+ {
+ }
+ }
+}
+