예제 #1
0
        public LuaMapImage AddImage(LuaPoint geoPoint, String path, String icon, float width)
        {
            MapImage mi = null;

            if (icon != null)
            {
                LuaStream ls = LuaResource.GetResource(path, icon);
                if (ls != null && ls.GetStream() != null)
                {
                    BitmapImage bi = new BitmapImage();
                    bi.SetSource(
#if NETFX_CORE
                        new MemoryRandomAccessStream((Stream)ls.GetStream())
#else
                        (Stream)ls.GetStream()
#endif
                        );
                    mi = new MapImage(bi);
                    mi.setDimensions(width);
                    mi.setPosition(geoPoint.ToPoint());
                }
            }
            else
            {
                Log.e("LGMapView", "Image is needed for LuaMapImage");
            }

            if (mi != null)
            {
                LuaMapImage lmi = new LuaMapImage(mi);
                return(lmi);
            }
            return(null);
        }
예제 #2
0
        void SetImage(LuaStream stream)
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                Defines.CopyStream((Stream)stream.GetStream(), memoryStream);
                BitmapImage imageSource = new BitmapImage();

#if NETFX_CORE
                //TODO:Is there any other elegant solution for this.
                imageSource.SetSource(memoryStream.AsRandomAccessStream());
#else
                imageSource.SetSource(memoryStream);
#endif

                // Assign the Source property of your image
                ((Image)view).Source = imageSource;
            }
#if !NETFX_CORE
            ((Stream)stream.GetStream()).Close();
#endif
        }
        LGDrawableReturn ParseXML(String filename)
        {
            LuaStream dat = LuaResource.GetResource(LuaEngine.LUA_DRAWABLE_FOLDER, filename + ".xml");
            XDocument parse;

            try {
                parse = XDocument.Load((Stream)dat.GetStream());
                String name = parse.Root.Name.LocalName;

                XElement root = parse.Root;
                if (name == "bitmap" ||
                    name == "nine-patch")
                {
                    return(ParseBitmap(root));
                }
                else if (name == "layer-list")
                {
                    return(ParseLayer(root));
                }
                else if (name == "selector")
                {
                    return(ParseStateList(root));
                }
                else if (name == "shape")
                {
                    return(ParseShape(root));
                }
            }
            catch (Exception ex)
            {
                LGDrawableReturn ret = new LGDrawableReturn();
                return(ret);
            }

            return(null);
        }
예제 #4
0
        private void ParseValues(Lua.lua_State L)
        {
#if WINDOWS_PHONE
            String valueDirectoriesString = "";
            Lua.lua_getglobal(L, "WP7ValueDirectories");
            if (Lua.lua_isstring(L, -1) != 0)
            {
                valueDirectoriesString = Lua.lua_tostring(L, -1).toString();
            }
            Lua.lua_pop(L, 1);

            String[] valueDirectories = valueDirectoriesString.Split(new char[] { ',' });
#else
            String[] valueDirectories = LuaResource.GetResourceDirectories(LuaEngine.LUA_VALUES_FOLDER);
#endif

            List <DynamicResource> clearedDirectoryList = new List <DynamicResource>();
            //Eliminate non version type values
            Tester(valueDirectories, LuaEngine.LUA_VALUES_FOLDER, ref clearedDirectoryList);

#if WINDOWS_PHONE
            String valueFilesString = "";
            Lua.lua_getglobal(L, "WP7ValueFiles");
            if (Lua.lua_isstring(L, -1) != 0)
            {
                valueFilesString = Lua.lua_tostring(L, -1).toString();
            }
            Lua.lua_pop(L, 1);

            String[] valueFiles = valueFilesString.Split(new char[] { ',' });

            //System.Threading.Thread.CurrentThread.CurrentCulture
            //((PhoneApplicationFrame)Application.Current.RootVisual).Orientation

            foreach (String valueFile in valueFiles)
            {
                String[] fileArr     = valueFile.Split(new char[] { '|' });
                String   directory   = valueDirectories[Convert.ToInt32(fileArr[0])];
                bool     found       = false;
                int      orientation = 0;
                foreach (DynamicResource dr in clearedDirectoryList)
                {
                    if (((String)dr.data) == directory)
                    {
                        found       = true;
                        orientation = dr.orientation;
                        break;
                    }
                }
                if (!found)
                {
                    continue;
                }
                LuaStream dat = LuaResource.GetResource(LuaEngine.LUA_RESOURCE_FOLDER + "/" + LuaEngine.Instance.GetUIRoot() + "/" + directory + "/", fileArr[1]);
                if (dat.GetStream() != null)
                {
                    XDocument parse;
                    try
                    {
                        parse = XDocument.Load((Stream)dat.GetStream());
                        String name = parse.Root.Name.LocalName;
                        if (name == "resources")
                        {
                            foreach (XElement child in parse.Root.Elements())
                            {
                                String childName = child.Name.LocalName;
                                if (childName == "color")
                                {
                                    ColorParser.ParseXML(orientation, child);
                                }
                                else if (childName == "dimen")
                                {
                                    DimensionParser.ParseXML(orientation, child);
                                }
                                else if (childName == "string")
                                {
                                    StringParser.ParseXML(orientation, child);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
#else
            foreach (DynamicResource dr in clearedDirectoryList)
            {
                String[] filesOfClearFolder = LuaResource.GetResourceFiles((String)dr.data);
                foreach (String file in filesOfClearFolder)
                {
                    LuaStream dat = LuaResource.GetResource(LuaEngine.LUA_RESOURCE_FOLDER + "/" + LuaEngine.Instance.GetUIRoot() + "/" + dr.data + "/", file);
                    if (dat.GetStream() != null)
                    {
                        XDocument parse;
                        try
                        {
                            parse = XDocument.Load((Stream)dat.GetStream());
                            String name = parse.Root.Name.LocalName;
                            if (name == "resources")
                            {
                                foreach (XElement child in parse.Root.Elements())
                                {
                                    String childName = child.Name.LocalName;
                                    if (childName == "color")
                                    {
                                        ColorParser.ParseXML(dr.orientation, child);
                                    }
                                    else if (childName == "dimen")
                                    {
                                        DimensionParser.ParseXML(dr.orientation, child);
                                    }
                                    else if (childName == "string")
                                    {
                                        StringParser.ParseXML(dr.orientation, child);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
#endif
        }