private void SelectResolution(ResolutionV2 resolution, ToolStripMenuItem resolutionMenuItem, ButtonX resolutionButton) { if (resolution == null || resolutionMenuItem == null || resolutionButton == null) { throw new ArgumentNullException("resolution", "选择分辨率时传入了无效的参数."); } // 先 deselect 之前选中的分辨率 if (m_selectedResolutionMenuItem != null) { m_selectedResolutionMenuItem.Checked = false; } if (m_selectedResolutionButton != null) { m_selectedResolutionButton.Checked = false; } m_selectedResolution = resolution; m_resolutionLabel.Text = string.Format("当前分辨率 - {0}: {1}x{2}", m_resolutionCategories[m_selectedResolution.category], m_selectedResolution.width, m_selectedResolution.height); if (!string.IsNullOrEmpty(m_selectedResolution.tag)) { m_resolutionLabel.Text += string.Format(" ({0})", m_selectedResolution.tag);; } m_renderBuffer.ResWidth = m_selectedResolution.width; m_renderBuffer.ResHeight = m_selectedResolution.height; // 选中新的分辨率对应的菜单和按钮 m_selectedResolutionMenuItem = resolutionMenuItem; m_selectedResolutionMenuItem.Checked = true; m_selectedResolutionButton = resolutionButton; m_selectedResolutionButton.Checked = true; }
private void m_resolutionMenuItemClicked(object sender, EventArgs e) { ToolStripMenuItem mi = sender as ToolStripMenuItem; if (mi != null) { ResolutionV2 res = mi.Tag as ResolutionV2; Control ctrl = FindButtonByCategory(res.category); SelectResolution(res, mi, ctrl as ButtonX); } }
private static ResolutionV2 GetDefaultResolution() { MoonSharp.Interpreter.Table t = LuaRuntime.Instance.BootstrapScript.Globals["Resolutions"] as MoonSharp.Interpreter.Table; foreach (var res in t.Values) { if (res.Type == MoonSharp.Interpreter.DataType.Table && Convert.ToBoolean(res.Table["default"])) { ResolutionV2 resolution = new ResolutionV2(); resolution.width = Convert.ToInt32(res.Table["w"]); resolution.height = Convert.ToInt32(res.Table["h"]); resolution.category = Convert.ToInt32(res.Table["cat"]); resolution.tag = (string)res.Table["tag"]; return(resolution); } } return(null); }
public PreviewForm(Scene scn, SceneEd scnEd) { InitializeComponent(); m_renderBuffer.SetScene(scn); if (!m_renderBuffer.InitContext()) { throw new ucore.AppInitError_Fatal("failed to init GL render buffer."); } m_renderBuffer.Paint += new System.Windows.Forms.PaintEventHandler(this.glControl_Paint); ftime = new List <long>(); stopwatch = new Stopwatch(); m_defaultResolution = null; MoonSharp.Interpreter.Table t = LuaRuntime.Instance.BootstrapScript.Globals["Resolutions"] as MoonSharp.Interpreter.Table; foreach (var res in t.Values) { if (res.Type == MoonSharp.Interpreter.DataType.Table) { ResolutionV2 resolution = new ResolutionV2(); resolution.width = Convert.ToInt32(res.Table["w"]); resolution.height = Convert.ToInt32(res.Table["h"]); resolution.category = Convert.ToInt32(res.Table["cat"]); resolution.tag = (string)res.Table["tag"]; Control ctrl = FindButtonByCategory(resolution.category); if (ctrl != null) { ToolStripMenuItem tsi = new ToolStripMenuItem(); if (string.IsNullOrEmpty(resolution.tag)) { tsi.Text = string.Format("{0}x{1}", resolution.width, resolution.height); } else { tsi.Text = string.Format("{0}x{1} ({2})", resolution.width, resolution.height, resolution.tag); } tsi.Tag = resolution; tsi.Click += m_resolutionMenuItemClicked; ctrl.ContextMenuStrip.Items.Add(tsi); if (Convert.ToBoolean(res.Table["default"])) { m_defaultResolution = resolution; m_defaultResolutionMenuItem = tsi; m_defaultResolutionButton = ctrl as ButtonX; } } } } // 如果没有在脚本中正确地设置默认分辨率,这里选择使用桌面分辨率的第一个作为默认分辨率 if (m_defaultResolution == null) { ucore.SysPost.AssertException(m_btResDesktop.ContextMenuStrip.Items.Count > 0, "The context menu of 'Desktop' button is not empty."); ToolStripMenuItem mi = m_btResDesktop.ContextMenuStrip.Items[0] as ToolStripMenuItem; if (mi != null) { ResolutionV2 res = m_btResDesktop.ContextMenuStrip.Items[0].Tag as ResolutionV2; if (res != null) { m_defaultResolution = res; m_defaultResolutionMenuItem = mi; m_defaultResolutionButton = m_btResDesktop; } } } ucore.SysPost.AssertException(m_defaultResolution != null, "The default resolution is not set properly."); SelectResolution(m_defaultResolution, m_defaultResolutionMenuItem, m_defaultResolutionButton); }