/// <summary> /// Create the user interface instance. /// </summary> public UserInterface() { // sanity test if (_content == null) { throw new System.Exception("Cannot create a UserInterface before calling UserInterface.Initialize()!"); } // create draw utils DrawUtils = new DrawUtils(); // create input helper _input = new InputHelper(); // create the root panel Root = new RootPanel(); // set default cursor SetCursor(CursorType.Default); }
/// <summary> /// Initialize UI manager (mostly load resources and set some defaults). /// </summary> /// <param name="contentManager">Content manager.</param> /// <param name="theme">Which UI theme to use (see options in Content/GeonBit.UI/themes/). This basically affect the appearance of all textures and effects.</param> static public void Initialize(ContentManager contentManager, string theme = "hd") { // create draw utils DrawUtils = new DrawUtils(); // store the content manager _content = contentManager; // create input helper _input = new InputHelper(); // create the root panel _root = new RootPanel(); // load textures etc Resources.LoadContent(_content, theme); // set default cursor SetCursor(CursorType.Default); }
/// <summary> /// Create the user interface instance. /// </summary> public UserInterface() { // sanity test if (_content == null) { throw new Exceptions.InvalidStateException("Cannot create a UserInterface before calling UserInterface.Initialize()!"); } // create default input providers MouseInputProvider = new DefaultInputProvider(); KeyboardInputProvider = new DefaultInputProvider(); // create draw utils DrawUtils = new DrawUtils(); // create the root panel Root = new RootPanel(); // set default cursor SetCursor(CursorType.Default); }
/// <summary> /// Load all GeonBit.UI resources. /// </summary> /// <param name="content">Content manager to use.</param> /// <param name="theme">Which theme to load resources from.</param> static public void LoadContent(ContentManager content, string theme = "default") { InitialiseCharStringDict(); // set resources root path and store content manager _root = "GeonBit.UI/themes/" + theme + "/"; _content = content; // set Texture2D static fields HorizontalLineTexture = _content.Load <Texture2D>(_root + "textures/horizontal_line"); WhiteTexture = _content.Load <Texture2D>(_root + "textures/white_texture"); IconBackgroundTexture = _content.Load <Texture2D>(_root + "textures/icons/background"); VerticalScrollbarTexture = _content.Load <Texture2D>(_root + "textures/scrollbar"); VerticalScrollbarMarkTexture = _content.Load <Texture2D>(_root + "textures/scrollbar_mark"); ArrowDown = _content.Load <Texture2D>(_root + "textures/arrow_down"); ArrowUp = _content.Load <Texture2D>(_root + "textures/arrow_up"); ProgressBarTexture = _content.Load <Texture2D>(_root + "textures/progressbar"); ProgressBarFillTexture = _content.Load <Texture2D>(_root + "textures/progressbar_fill"); // load cursors metadata CursorsData = new CursorTextureData[Enum.GetValues(typeof(CursorType)).Length]; foreach (CursorType cursor in Enum.GetValues(typeof(CursorType))) { string cursorName = cursor.ToString().ToLowerInvariant(); CursorsData[(int)cursor] = content.Load <CursorTextureData>(_root + "textures/cursor_" + cursorName + "_md"); // special case for IBeam, we want it to be drawn in the middle. So when we select text it is easier if (cursor == CursorType.IBeam) { Point cursorActualSize = DrawUtils.GetActualTextureSize(Cursors[cursor]); CursorsData[(int)cursor].OffsetX -= cursorActualSize.X / 2; } } // load panels PanelData = new TextureData[Enum.GetValues(typeof(PanelSkin)).Length]; foreach (PanelSkin skin in Enum.GetValues(typeof(PanelSkin))) { // skip none panel skin if (skin == PanelSkin.None) { continue; } // load panels metadata string skinName = skin.ToString().ToLowerInvariant(); PanelData[(int)skin] = content.Load <TextureData>(_root + "textures/panel_" + skinName + "_md"); } // load scrollbar metadata VerticalScrollbarData = content.Load <TextureData>(_root + "textures/scrollbar_md"); // load slider metadata SliderData = new TextureData[Enum.GetValues(typeof(SliderSkin)).Length]; foreach (SliderSkin skin in Enum.GetValues(typeof(SliderSkin))) { string skinName = skin.ToString().ToLowerInvariant(); SliderData[(int)skin] = content.Load <TextureData>(_root + "textures/slider_" + skinName + "_md"); } // load fonts Fonts = new SpriteFont[Enum.GetValues(typeof(FontStyle)).Length]; foreach (FontStyle style in Enum.GetValues(typeof(FontStyle))) { Fonts[(int)style] = content.Load <SpriteFont>(_root + "fonts/" + style.ToString()); Fonts[(int)style].LineSpacing += 2; } // load buttons metadata ButtonData = new TextureData[Enum.GetValues(typeof(ButtonSkin)).Length]; foreach (ButtonSkin skin in Enum.GetValues(typeof(ButtonSkin))) { string skinName = skin.ToString().ToLowerInvariant(); ButtonData[(int)skin] = content.Load <TextureData>(_root + "textures/button_" + skinName + "_md"); } // load progress bar metadata ProgressBarData = content.Load <TextureData>(_root + "textures/progressbar_md"); // load effects DisabledEffect = content.Load <Effect>(_root + "effects/disabled"); SilhouetteEffect = content.Load <Effect>(_root + "effects/silhouette"); // load default styleSheets LoadDefaultStyles(ref Entity.DefaultStyle, "Entity", _root, content); LoadDefaultStyles(ref Paragraph.DefaultStyle, "Paragraph", _root, content); LoadDefaultStyles(ref Button.DefaultStyle, "Button", _root, content); LoadDefaultStyles(ref Button.DefaultParagraphStyle, "ButtonParagraph", _root, content); LoadDefaultStyles(ref CheckBox.DefaultStyle, "CheckBox", _root, content); LoadDefaultStyles(ref CheckBox.DefaultParagraphStyle, "CheckBoxParagraph", _root, content); LoadDefaultStyles(ref ColoredRectangle.DefaultStyle, "ColoredRectangle", _root, content); LoadDefaultStyles(ref DropDown.DefaultStyle, "DropDown", _root, content); LoadDefaultStyles(ref DropDown.DefaultParagraphStyle, "DropDownParagraph", _root, content); LoadDefaultStyles(ref DropDown.DefaultSelectedParagraphStyle, "DropDownSelectedParagraph", _root, content); LoadDefaultStyles(ref Header.DefaultStyle, "Header", _root, content); LoadDefaultStyles(ref HorizontalLine.DefaultStyle, "HorizontalLine", _root, content); LoadDefaultStyles(ref Icon.DefaultStyle, "Icon", _root, content); LoadDefaultStyles(ref Image.DefaultStyle, "Image", _root, content); LoadDefaultStyles(ref Label.DefaultStyle, "Label", _root, content); LoadDefaultStyles(ref Panel.DefaultStyle, "Panel", _root, content); LoadDefaultStyles(ref ProgressBar.DefaultStyle, "ProgressBar", _root, content); LoadDefaultStyles(ref ProgressBar.DefaultFillStyle, "ProgressBarFill", _root, content); LoadDefaultStyles(ref RadioButton.DefaultStyle, "RadioButton", _root, content); LoadDefaultStyles(ref RadioButton.DefaultParagraphStyle, "RadioButtonParagraph", _root, content); LoadDefaultStyles(ref SelectList.DefaultStyle, "SelectList", _root, content); LoadDefaultStyles(ref SelectList.DefaultParagraphStyle, "SelectListParagraph", _root, content); LoadDefaultStyles(ref Slider.DefaultStyle, "Slider", _root, content); LoadDefaultStyles(ref TextInput.DefaultStyle, "TextInput", _root, content); LoadDefaultStyles(ref TextInput.DefaultParagraphStyle, "TextInputParagraph", _root, content); LoadDefaultStyles(ref TextInput.DefaultPlaceholderStyle, "TextInputPlaceholder", _root, content); LoadDefaultStyles(ref VerticalScrollbar.DefaultStyle, "VerticalScrollbar", _root, content); LoadDefaultStyles(ref PanelTabs.DefaultButtonStyle, "PanelTabsButton", _root, content); LoadDefaultStyles(ref PanelTabs.DefaultButtonParagraphStyle, "PanelTabsButtonParagraph", _root, content); }