User Tools

Site Tools


hpl3:game:gui

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
hpl3:game:gui [2013/01/14 15:47]
thomas
hpl3:game:gui [2015/09/17 10:14] (current)
ian.thomas [In-Scene GUI Rendering]
Line 18: Line 18:
 The Immediate Mode Gui (ImGui) is a bit special to how you normally do GUI and works by essentially recreating the entire interface every update. On top of this also handles logic and graphical update in the very same function. Normally this is a sort of sin, but for this system it works really well and make it very easy to set up interfaces. The ImGui have been designed around this concept and the main focus have been to have a system that make GUI creation and iteration really fast.  The Immediate Mode Gui (ImGui) is a bit special to how you normally do GUI and works by essentially recreating the entire interface every update. On top of this also handles logic and graphical update in the very same function. Normally this is a sort of sin, but for this system it works really well and make it very easy to set up interfaces. The ImGui have been designed around this concept and the main focus have been to have a system that make GUI creation and iteration really fast. 
  
-Anyone who has used Unity'​s older GUI should get the basics of this and it is actually worth looking through [[http://​docs.unity3d.com/​Documentation/​Components/​GUIScriptingGuide.html|their manual]] for some extra information. This GUI has some extra tricks though and do somethings a bit differently so do not take this as a copy of the Unity one. One of the biggest changes is that it contains some state saving making it even easier to main things.+Anyone who has used Unity'​s older GUI should get the basics of this and it is actually worth looking through [[http://​docs.unity3d.com/​Documentation/​Components/​GUIScriptingGuide.html|their manual]] for some extra information. This GUI has some extra tricks though and do somethings a bit differently so do not take this as a copy of the Unity one. One of the biggest changes is that it contains some state saving making it even easier to maintain values.
  
-Another ​important ​feature of the ImGui is that it works seamlessly with both mouse, keyboard and gamepad input. The most important part of this is a system that calculates navigate with keys/stick on the fly so it is really easy to set up.+Another feature of the ImGui is that it works seamlessly with both mouse, keyboard and gamepad input. The most important part of this is a system that calculates navigate with keys/stick on the fly so it is really easy to set up.
  
 ===== Names and Ids ===== ===== Names and Ids =====
Line 29: Line 29:
 ===== Widgets ===== ===== Widgets =====
  
-Widgets are the different elements that make up an interface. Some of these are possible to interact with, while other are not. This is important to note so that you use the right kind of widget when you want a specific behavior. Worth noting is also that all widgets have one function that use the default data settings and one where a data class is needed as argument. All of the widget functions start with ImGui_Do*. 
  
-Some of the widgets have default values arguments, such as the ToggleButton,​ Slider, etc, which behave in a special way. The default value will only be used to set the initial value, and then as the value change through interaction,​ an internally saved value will be used instead. However, the default value is saved too, and if it changes then the changed default value will be used instead of the saved internal one. +Widgets are the different elements that make up an interface. Some of these are possible to interact with, while other are not. This is important to note so that you use the right kind of widget when you want a specific behavior. Worth noting is also that all widgets have one function that use the default data settings and one where a data class is needed as argument. All of the widget functions start with ImGui_Do%%*%%. 
 + 
 + 
 +Some of the widgets have default values arguments, such as the ToggleButton,​ Slider, etc, which behave in a special way. The default value will only be used to set the initial value, and then as the value change through interaction,​ an internally saved value will be used instead. However, the default value is saved too, and if it changes then the changed default value will be used instead of the saved internal one
 + 
 + 
 +Widget functions usually come in two version. One that uses the the default settings, which have been set up using ImGui_SetDefault%%*%%. The other comes with the data settings as an argument and have the suffix "​Ext"​ (in helper functions, when directly using the ImGui class).
  
-Widget functions usually come in two version. One that uses the the default settings, which have been set up using ImGui_SetDefault*. The other comes with the data settings as an argument and have the suffix "​Ext"​ (in helper functions, when directly using the ImGui class). 
  
 Finally it is only widgets that are affected by the layout, so never draw anything directly unless you know what you are doing. It is almost always much better to for instance use Label instead of DrawText to print a message. Finally it is only widgets that are affected by the layout, so never draw anything directly unless you know what you are doing. It is almost always much better to for instance use Label instead of DrawText to print a message.
  
-**Button**\\ 
-This is a normal button that returns true if it was pressed this update. ​ 
  
-**RepeatButton**\\+**Button** \\  
 +This is a normal button that returns true if it was pressed this update. 
 + 
 + 
 +**RepeatButton** \\ 
 Like Button, but will return true as long as it is being pressed. Like Button, but will return true as long as it is being pressed.
  
-**ToggleButton**\\ 
-Another version of the button that returns can be be turn on/off. It returns the current state. 
  
-**SliderHorizontal**\\ +**ToggleButton** \\  
-A slider button, which has values between two numbers. A step-size value can also be set to specify in which interval between min and max values can take. It returns the current value. ​+Another version of the button that can be turned on/off. It returns the current state. 
 + 
 + 
 +**SliderHorizontal** \\  
 +A slider button, which has values between two numbers. A step-size value can also be set to specify in which interval between min and max values can take. It returns the current value. 
  
-**SliderVertical**\\+**SliderVertical** \\ 
 Just like SliderHorizontal,​ but placed vertically. Just like SliderHorizontal,​ but placed vertically.
  
-**Label**\\+ 
 +**Label** \\ 
 The label does not have any interaction logic, but only displays a text string. If you need a text string with interaction use a button instead. The label does not have any interaction logic, but only displays a text string. If you need a text string with interaction use a button instead.
  
-**Image**\\+ 
 +**Image** \\ 
 This displays an image. Like Label it has no interaction. This displays an image. Like Label it has no interaction.
  
-**MultiToggle**\\ 
-A grid of toggle buttons, where only one can be active at a time. It returns the index (0=first) of the currently selected. In order to add items use ImGui_AddItem* functions. 
  
-**CheckBox**\\+**MultiToggle** \\  
 +A grid of toggle buttons, where only one can be active at a time. It returns the index (0=first) of the currently selected. In order to add items use ImGui_AddItem%%*%% functions. 
 + 
 + 
 +**CheckBox** \\ 
 A text next to a checkbox that can be on or off. Returns the current value. A text next to a checkbox that can be on or off. Returns the current value.
  
-**TextFrame**\\+ 
 +**TextFrame** \\ 
 A scrollable text of frame. It will return, in rows, the amount of text not outside of the window. For instance, if the text contains 5 rows, and only 4 are visible, 1 is the return value. This value is very useful when making a slider that can scroll the text. A scrollable text of frame. It will return, in rows, the amount of text not outside of the window. For instance, if the text contains 5 rows, and only 4 are visible, 1 is the return value. This value is very useful when making a slider that can scroll the text.
  
-**MultiSelect**\\ + 
-Here several different items can be selected. It returns the index of the currently selected one. In order to add items use ImGui_AddItem* functions.+**MultiSelect** \\  
 +Here several different items can be selected. It returns the index of the currently selected one. In order to add items use ImGui_AddItem%%*%% functions
 + 
 + 
 +**Frame\\  
 +** A visible frame made of graphical pieces. Has no interaction. 
 + 
 + 
 +**Window\\  
 +** Your usual graphical window. Displays a caption in its own frame and groups widgets inside it, given they are created between the ImGui_DoWindowStart and ImGui_DoWindowEnd calls. Has no interaction. 
 + 
 + 
 +**Gauge\\  
 +** Displays a horizontal or vertical bar showing progress or whatever it is meant to. Has no interaction also.
  
 ===== Modifiers ===== ===== Modifiers =====
Line 79: Line 106:
 The previous state is a set of properties that are set after a widget function have been called. All come in the form of: ImGui_Prev*. The previous state is a set of properties that are set after a widget function have been called. All come in the form of: ImGui_Prev*.
  
-They can be used to get all sort of information on the state of the most recently defined widget. Mostly, these are useful when doing custom Widgets, (see below) and can then be used to see if the widget just became into focus, or more importantly what as the absolute size and position used to draw it.+They can be used to get all sort of information on the state of the most recently defined widget. Mostly, these are useful when doing custom Widgets, (see below) and can then be used to see if the widget just became into focus, or more importantly what absolute size and position ​was used to draw it.
  
 ===== Groups and Layout ===== ===== Groups and Layout =====
Line 99: Line 126:
  
 Another important fade setting is the Type one. This will determine in what way the value will be faded between start and end. The available ones are:\\ Another important fade setting is the Type one. This will determine in what way the value will be faded between start and end. The available ones are:\\
-**Linear**: Constant change. +**Linear**: Constant change.\\ 
-**Sigmoid**:​ Starts and ends smoothly. +**Sigmoid**:​ Starts and ends smoothly.\\ 
-**Cosine**: Also smooth start and end, but slightly different. +**Cosine**: Also smooth start and end, but slightly different.\\ 
-**Cube**: Starts slow and accelerates. +**Cube**: Starts slow and accelerates.\\ 
-**InvCube**:​ Starts fast and decelerates.+**InvCube**:​ Starts fast and decelerates.\\
  
 Another way to use fading it so let it oscillate between two values. This is useful to a blinking button or some moving graphic. To do this use the ImGui_FadeOscillate functions. This are meant to be called every update when defining the value of some properties. Example: Another way to use fading it so let it oscillate between two values. This is useful to a blinking button or some moving graphic. To do this use the ImGui_FadeOscillate functions. This are meant to be called every update when defining the value of some properties. Example:
  
 <code c++> <code c++>
-cColor = cColor(1,​1)*ImGui_FadeOscillateFloat("​pulse",​1.0f,​ 0.25f,1);+cColor ​col = cColor(1,​1)*ImGui_FadeOscillateFloat("​pulse",​1.0f,​ 0.25f,1);
 </​code>​ </​code>​
- 
 ===== Timers ===== ===== Timers =====
  
Line 123: Line 149:
 Then flowerGfx can be used where ever it is needed. No need to neither load or destroy the asset. Then flowerGfx can be used where ever it is needed. No need to neither load or destroy the asset.
  
 +It is also possible to load graphics as textures or animations, by using the types ''​eImGuiGfx_Texture''​ and ''​eImGuiGfx_ImageAnimated''​.
 +
 +For texture:
 +<code c++>
 +cImGuiGfx flowerGfx("​flower.dds",​ eImGuiGfx_Texture);​
 +cImGuiGfx flowerGfx("​flower.dds",​ eGuiMaterial_Additive,​ eImGuiGfx_Texture);​
 +</​code>​
 +Note that it is now possible to load DXT format files!
 +
 +
 +For for animation:
 +<code c++>
 +cImGuiGfx flowerGfx("​flower.tga",​ eImGuiGfx_ImageAnimated);​
 +cImGuiGfx flowerGfx("​flower.tga",​ eGuiMaterial_Additive,​ eImGuiGfx_ImageAnimated);​
 +</​code>​
 +When loading an animation, an extension is required and the engine will load all the files named like "​flower00.tga",​ "​flower01.tga",​ etc for as long as it can find file names. These images will then be looped around in an animation loop. Control the animation speed by setting the member variable ''​mfAnimationTime''​ like this:
 +<code c++>
 +cImGuiGfx flowerGfx("​flower.tga",​ eImGuiGfx_ImageAnimated);​
 +flowerGfx.mfAnimationTime = 0.1;
 +</​code>​
 +This will make each frame play for 0.1 seconds. (default setting is 1).
 +
 +**Note on Graphics**
 +  * For non-texture graphics the size limit is 510x510. (1 pixel borders need for images).
 +  * Generally, You should NOT use the non-texture graphics for larger images. It is meant to be for smaller images so that you can batch the graphics (making it possible to draw most of the gui in 2-3 draw calls). If you need large images, use textures! Here you can easily go up to 1024x1024 (and beyond, should it be needed).
 ===== Custom Widgets ===== ===== Custom Widgets =====
  
Line 131: Line 182:
 ====== In-Scene GUI Rendering ====== ====== In-Scene GUI Rendering ======
  
-In order for the a game entity to have a GUI surfaces ​the following criteria must be met:+In order for the a game entity to have a GUI surface ​the following criteria must be met:
   * The surface that is to contain the GUI must be flat, consist of 4 vertices and have UV coords going from 0->1 where (0,0) is the upper left corner.   * The surface that is to contain the GUI must be flat, consist of 4 vertices and have UV coords going from 0->1 where (0,0) is the upper left corner.
   * The material of this surface must be translucent. It can be any blend mode though, making it possible to have transperant in-game GUI.   * The material of this surface must be translucent. It can be any blend mode though, making it possible to have transperant in-game GUI.
hpl3/game/gui.1358178475.txt.gz · Last modified: 2013/01/14 15:47 by thomas