{}
public BmpPicture (string path) : base(path)
{}
-
- protected override void loadFromRessource (string resId)
+ protected override void loadFromStream (Stream stream)
{
- Stream stream = null;
-
- //first, search for ressource in main executable assembly
- stream = System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceStream(resId);
- if (stream == null)//try to find ressource in golib assembly
- stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resId);
- if (stream == null)
- return;
-
using (MemoryStream ms = new MemoryStream ()) {
stream.CopyTo (ms);
loadBitmap (new System.Drawing.Bitmap (ms));
}
}
- protected override void loadFromFile (string path)
- {
- if (!File.Exists(path))
- return;
-
- loadBitmap (new System.Drawing.Bitmap (path));
- }
-
//load image via System.Drawing.Bitmap, cairo load png only
void loadBitmap (System.Drawing.Bitmap bitmap)
{
if (stream == null)//try to find ressource in golib assembly
stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resId);
if (stream == null)
- return null;
+ throw new Exception ("Resource not found: " + path);
} else {
if (!File.Exists (path))
- return null;
- stream = new FileStream (path, FileMode.Open);
+ throw new FileNotFoundException ("File not found: ", path);
+ stream = new FileStream (path, FileMode.Open, FileAccess.Read);
}
return stream;
}
{
string root = "Object";
- Stream stream = GetStreamFromPath (path);
- if (stream == null)
- throw new FileNotFoundException ("GOML file not found", path);
-
- using (XmlReader reader = XmlReader.Create (stream)) {
- while (reader.Read()) {
- // first element is the root element
- if (reader.NodeType == XmlNodeType.Element) {
- root = reader.Name;
- break;
+ using (Stream stream = GetStreamFromPath (path)) {
+
+ #region Pre-read first node to set GraphicObject class for loading
+ using (XmlReader reader = XmlReader.Create (stream)) {
+ while (reader.Read()) {
+ // first element is the root element
+ if (reader.NodeType == XmlNodeType.Element) {
+ root = reader.Name;
+ break;
+ }
}
}
- }
- Type t = Type.GetType("go." + root);
- //var go = Activator.CreateInstance(t);
- stream.Seek(0,SeekOrigin.Begin);
- GraphicObject tmp = Load(stream, t, hostClass);
- stream.Dispose ();
- return tmp;
+ Type t = Type.GetType("go." + root);
+ //var go = Activator.CreateInstance(t);
+ stream.Seek(0,SeekOrigin.Begin);
+ #endregion
+
+ return Load(stream, t, hostClass);
+ }
}
static GraphicObject Load(Stream stream, Type type, object hostClass = null)
{
#region Image Loading
public void LoadImage (string path)
{
- if (path.StartsWith ("#"))
- loadFromRessource (path.Substring (1));
- else
- loadFromFile (path);
+ loadFromStream (Interface.GetStreamFromPath (path));
Path = path;
}
-
- protected abstract void loadFromRessource(string resId);
- protected abstract void loadFromFile(string path);
+
+ protected abstract void loadFromStream(Stream stream);
#endregion
public abstract void Paint(Context ctx, Rectangle rect, string subPart = "");
{}
public SvgPicture (string path) : base(path)
{}
-
- protected override void loadFromRessource (string resId)
+ protected override void loadFromStream (Stream stream)
{
- Stream stream = null;
-
- //first, search for ressource in main executable assembly
- stream = System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceStream(resId);
- if (stream == null)//try to find ressource in golib assembly
- stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resId);
- if (stream == null)
- return;
-
using (MemoryStream ms = new MemoryStream ()) {
stream.CopyTo (ms);
Dimensions = new Size (hSVG.Dimensions.Width, hSVG.Dimensions.Height);
}
}
-
- protected override void loadFromFile (string path)
- {
- if (!File.Exists(path))
- return;
-
- hSVG = new Rsvg.Handle (path);
- Dimensions = new Size (hSVG.Dimensions.Width, hSVG.Dimensions.Height);
- }
-
+
public override void Paint (Cairo.Context gr, Rectangle rect, string subPart = "")
{
float widthRatio = (float)rect.Width / Dimensions.Width;
public List<XCursor> Cursors = new List<XCursor>();
- static XCursorFile loadFromRessource (string resId)
- {
- Stream stream = null;
-
- //first, search for ressource in main executable assembly
- stream = System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceStream(resId);
- if (stream == null)//try to find ressource in golib assembly
- stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resId);
- if (stream == null) {
- Debug.WriteLine ("Ressource not found: " + resId);
- return null;
- }
- using (MemoryStream ms = new MemoryStream ()) {
- stream.CopyTo (ms);
- ms.Seek (0, SeekOrigin.Begin);
- return loadFromStream (ms);
- }
- }
- static XCursorFile loadFromFile (string path)
- {
- using (Stream s = new FileStream (path,
- FileMode.Open, FileAccess.Read)) {
- return loadFromStream (s);
- }
- }
static XCursorFile loadFromStream(Stream s)
{
List<toc> tocList = new List<toc> ();
public static XCursorFile Load(string path)
{
- if (path.StartsWith ("#"))
- return loadFromRessource (path.Substring(1));
- else
- return loadFromFile (path);
+ return loadFromStream (Interface.GetStreamFromPath (path));
}
static XCursor imageLoad(BinaryReader sr)