void InitUI() { if (initialized) { return; } initialized = true; MUISkin.Init(); if (!MUISkin.drawSkinFlag && MUISkin.initialized) // for firt window { MUISkin.drawSkinFlag = true; win.titleColor = MUISkin.config.titlebarColor; win.titleOffset = MUISkin.config.titleOffset; win.closeButtonOffset = MUISkin.config.closeButtonOffset; win.resizeButtonOffset = MUISkin.config.resizeButtonOffset; } if (titleTextture == null) { titleTextture = new Texture2D(1, 1); } if (resizeTextture == null) { resizeTextture = new Texture2D(1, 1); } if (closeTextture == null) { closeTextture = new Texture2D(1, 1); } if (winTexture == null) { winTexture = new Texture2D(1, 1); winTexture.SetPixel(0, 0, win.backgroundColor); winTexture.Apply(); } if (titleStyle == null) { titleStyle = new GUIStyle(GUI.skin.label); titleStyle.alignment = TextAnchor.MiddleLeft; titleStyle.fontStyle = FontStyle.Bold; } UpdateStates(states); }
public virtual void OnGUI() { if (isVisible) { OnDrawWindow(); } if (Input.anyKeyDown && ((options & Options.IsPopup) == Options.IsPopup)) { if ((Event.current.keyCode == 0)) { var pos = Input.mousePosition; pos.y = Screen.height - pos.y; if (((m_draw != null) && !m_draw.rect.Contains(pos))) { this.Close(); } } else { this.Close(); } } if (m_draw != null) { m_draw.enabled = isVisible && (((options & Options.InFreeCamera) == Options.InFreeCamera) ? true : !MUISkin.comeraController.m_freeCamera); if (Title == "") { m_titleHeight = 8; } else { m_titleHeight = MUISkin.CalcTextHeight(); } if (m_resize != null) { var ratio = UIView.GetAView().ratio; m_resize.relativePosition = new Vector3(m_draw.resizeRect.x * ratio, m_draw.resizeRect.y * ratio, 0); } } }
public virtual void DrawLabel() { OnDrawLabel(); var r = new Rect(MUISkin.UIToScreen(relativePosition.x), MUISkin.UIToScreen(relativePosition.y), MUISkin.UIToScreen(size.x), MUISkin.UIToScreen(size.y)); var _fColor = lableStyle.normal.textColor; var _fStyle = lableStyle.fontStyle; lableStyle.normal.textColor = this.textColor; lableStyle.fontSize = this.fontSize; lableStyle.fontStyle = this.fontStyle; switch (this.textAlignment) { case UIHorizontalAlignment.Left: lableStyle.alignment = TextAnchor.MiddleLeft; break; case UIHorizontalAlignment.Right: lableStyle.alignment = TextAnchor.MiddleRight; break; default: lableStyle.alignment = TextAnchor.MiddleCenter; break; } //GUI.DrawTexture(r, ExtendedPanel.lineTexture); GUI.Label(r, text, lableStyle); lableStyle.normal.textColor = _fColor; lableStyle.fontStyle = _fStyle; lableStyle.alignment = TextAnchor.MiddleLeft; lableStyle.fontSize = defaultFontSize; }
public void UpdateWindow() { if (Title == "") { m_titleHeight = 8; } else { m_titleHeight = MUISkin.CalcTextHeight(); } if (m_drag != null) { m_drag.width = width; if ((options & Options.FullDragabled) == Options.FullDragabled) { float h = height; if (m_resize != null) { if (height < 50) { m_drag.width = width - m_resize.width - 2; } else { h = height - m_resize.height - 2; } } m_drag.height = h; } else { if (m_titleHeight > 0) { m_drag.height = m_titleHeight - 2; } else { m_drag.height = 20; } } } if (m_resize != null) { m_resize.relativePosition = new Vector3(width - m_resize.width - 1, height - m_resize.height - 1); } //this.m_MinSize = minSize; if (m_draw != null) { var ratio = UIView.GetAView().ratio; m_draw.rect = new Rect(absolutePosition.x / ratio, absolutePosition.y / ratio, width / ratio, height / ratio); if (m_resize != null) { m_draw.resizeRect = new Rect(m_draw.rect.width - MUISkin.config.resizeButtonWidth - 3, m_draw.rect.height - MUISkin.config.resizeButtonWidth + 4, MUISkin.config.resizeButtonWidth + 2, MUISkin.config.resizeButtonWidth - 5); } } }
void UpdateStates(States s) { var color = win.titleColor; // MUISkin.config.titlebarColor; if ((s & States.HoverInTitlebar) == States.HoverInTitlebar) { color = MUIUtil.BrightenColor(color, 0.2f, color[3]); titleTextture.SetPixel(0, 0, color); titleStyle.normal.textColor = MUISkin.config.titleTextHoverColor; } else { titleTextture.SetPixel(0, 0, color); titleStyle.normal.textColor = MUISkin.config.titleTextColor; } color = win.backgroundColor; if (color == Color.clear) { color = Color.gray; color[3] = 0.5f; // alpha } if ((s & States.HoverInResize) == States.HoverInResize) { color = MUIUtil.BrightenColor(color, 0.8f, 1.0f); } else { color = MUIUtil.BrightenColor(color, 0.5f, color[3]); } if (MUISkin.isStyleExists("button_resize")) { resizeTextture = MUISkin.skin.FindStyle("button_resize").normal.background; } else { resizeTextture.SetPixel(0, 0, color); } color = new Color(0.8f, 0.0f, 0.0f, MUISkin.config.titlebarColor[3]); if ((s & States.HoverInCloseButton) == States.HoverInCloseButton) { closeTextture.SetPixel(0, 0, MUIUtil.BrightenColor(color, 0.65f, 1.0f)); if (MUISkin.isStyleExists("button_close")) { closeTextture = MUISkin.skin.FindStyle("button_close").hover.background; } } else { closeTextture.SetPixel(0, 0, color); if (MUISkin.isStyleExists("button_close")) { closeTextture = MUISkin.skin.FindStyle("button_close").normal.background; } } _states = s; titleTextture.Apply(); closeTextture.Apply(); resizeTextture.Apply(); }
void DoDrawWindow() { var h = win.titleHeight; if ((win.options & MUIWindow.Options.TitleBar) == MUIWindow.Options.TitleBar) { titleRect = new Rect(win.titleOffset.x, win.titleOffset.y, rect.width - win.titleOffset.x * 3, h); } else { titleRect = new Rect(0, 0, 0, 0); } if ((win.options & MUIWindow.Options.CloseButton) == MUIWindow.Options.CloseButton) { float size = win.closeButtonSize; if (size == 0) { size = 16.0f; } var offset = win.closeButtonOffset; closeRect = new Rect(rect.width - size + offset.x - 0.0f, offset.y, size, titleRect.y + (size / 2) + 2.0f); if (MUISkin.isStyleExists("button_close")) { size = win.closeButtonSize; if (size == 0) { size = h; } if (MUISkin.UIView.ratio > 1.0) { size /= MUISkin.UIView.ratio; } closeRect = new Rect(rect.width - size + offset.x, (h - size) / 2 + offset.y, size, size); } } else { closeRect = new Rect(0, 0, 0, 0); } if (!titleRect.IsEmpty()) { GUI.DrawTexture(titleRect, titleTextture, ScaleMode.StretchToFill); GUI.DrawTexture(closeRect, closeTextture, ScaleMode.ScaleAndCrop); titleStyle.alignment = win.titleAlignment; GUI.Label(new Rect(titleRect.x + 3.0f, titleRect.y, rect.width - 3.0f, titleRect.height), win.Title, titleStyle); } if (!resizeRect.IsEmpty()) { if (MUISkin.isStyleExists("button_resize")) { resizeRect = new Rect(rect.width - resizeButton_size + win.resizeButtonOffset.x - 2.0f, rect.height - resizeButton_size + win.resizeButtonOffset.y - 2.0f, resizeButton_size, resizeButton_size); } GUI.DrawTexture(resizeRect, resizeTextture, ScaleMode.StretchToFill); } }