/**************************************************************************** Copyright (c) 2011-2013,WebJet Business Division,CYOU http://www.genesis-3d.com.cn Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ using System; using System.Collections.Generic; using System.Text; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ScriptGUI { /// /// 用户界面接口类 /// public partial class GUI { /// /// 执行结果 /// public static ExecuteResult ExecuteResult { get { return mExecuteResult; } } private static ExecuteResult mExecuteResult; internal static ExecuteResult setResult(ExecuteResult ret) { mExecuteResult = ret; return ret; } // ------------------------------ public ----------------------------------------------------------------- //public static ExecuteResult SetProperty(FString widget_name) //{ // return ExecuteResult.False; //} /// /// 设置界面坐标 /// /// 界面名称 /// 坐标 /// 结果 public static ExecuteResult SetLayoutCoord(FString layout_name, IntCoord int_coord) { Layout layout; if (sRegWinTable.GetLayout(layout_name, out layout)) { if (!layout.IsLoaded) { layout.Load(); } layout.Root.Coord = int_coord; return setResult(ExecuteResult.Success); } return setResult(ExecuteResult.LayoutNotExist); } /// /// 获取场景大小 /// /// 场景大小 public static IntSize GetScreenSize() { IntSize size; ICall_getScreenSize(out size); return size; } /// /// 获取分辨率 /// /// 分辨率 public static IntSize GetResolution() { IntSize size; ICall_getResolution(out size); return size; } /// /// 设置分辨率 /// /// 分辨率 public static void SetResolution(IntSize size) { ICall_setResolution(ref size); } /// /// 自动分辨率宽度 /// /// 分辨率宽度 public bool AutoResolutionWidth() { return AutoResolutionWidth(); } /// /// 自动分辨率高度 /// /// 分辨率高度 public bool AutoResolutionHeight() { return AutoResolutionHeight(); } /// /// 设置控件变灰 /// /// 界面名称 /// 控件名称 /// 是否变灰 /// 结果 public static ExecuteResult SetGrayRender(FString layout_name, FString widget_name, bool value) { Widget widget = null; ExecuteResult ret = FindWidget(layout_name, widget_name, out widget); if (ExecuteResult.Success == ret) { widget.SetGray(value); } return ret; } // ------------------------------ internal ----------------------------------------------------------------- #region internal internal static Instance LoadLayout(Widget parent, String file_name) { if (null == parent) { return ICall_loadLayout(IntPtr.Zero, file_name); } return ICall_loadLayout(parent.Instance.Ptr, file_name); } internal static ExecuteResult UnloadLayout(FString layout_name) { Layout layout; if (sRegWinTable.GetLayout(layout_name, out layout)) { layout.Unload(); sRegWinTable.Remove(layout_name); return setResult(ExecuteResult.Success); } return setResult(ExecuteResult.LayoutNotExist); } internal static void DisposeWidget(Instance widget_inst) { if (widget_inst.IsValid) { ICall_destroyWidget(widget_inst.Ptr); } } internal static bool SearchLayout(Instance inst, out Layout layout) { return sRegWinTable.GetLayout(inst, out layout); } internal static ExecuteResult FindWidget(FString layout_name, FString widget_name, out Widget widget) { Layout layout = null; widget = null; ExecuteResult ret = ExecuteResult.Success; if (sRegWinTable.GetLayout(layout_name, out layout)) { if (!layout.IsLoaded) { layout.Load(); } if (!layout.FindWidget(widget_name, out widget)) { ret = ExecuteResult.WidgetNotExist; } } else { ret = ExecuteResult.LayoutNotExist; } return setResult(ret); } internal static ExecuteResult FindUI(FString layout_name, FString widget_name, out T widget) where T : Widget { widget = null; Widget wd = null; ExecuteResult ret = FindWidget(layout_name, widget_name, out wd); if (ExecuteResult.Success == ret) { widget = wd as T; if (null == widget) { ret = ExecuteResult.TypeError; return setResult(ret); } } return ret; } internal static IntPtr FindWidget(IntPtr parent, String widget_name) { return ICall_findWidget(parent, widget_name); } private static LayoutCollection sRegWinTable = new LayoutCollection(); #endregion #region CPP Interface // - internal call declare, follow the turn which function appears [MethodImplAttribute(MethodImplOptions.InternalCall)] extern private static IntPtr ICall_loadLayout(IntPtr parent, String file_name); [MethodImplAttribute(MethodImplOptions.InternalCall)] extern private static void ICall_destroyWidget(IntPtr widget_ptr); [MethodImplAttribute(MethodImplOptions.InternalCall)] extern private static IntPtr ICall_findWidget(IntPtr parent, String widget_name); [MethodImplAttribute(MethodImplOptions.InternalCall)] extern private static void ICall_getScreenSize(out IntSize value); [MethodImplAttribute(MethodImplOptions.InternalCall)] extern private static void ICall_getResolution(out IntSize value); [MethodImplAttribute(MethodImplOptions.InternalCall)] extern private static void ICall_setResolution(ref IntSize value); [MethodImplAttribute(MethodImplOptions.InternalCall)] extern private static bool ICall_autoResolutionWidth(); [MethodImplAttribute(MethodImplOptions.InternalCall)] extern private static bool ICall_autoResolutionHeight(); #endregion } }