Sophie

Sophie

distrib > Mageia > 1 > i586 > by-pkgid > c87dfbd6f7f653536d7b07ed7038c9d8 > files > 28

clanlib0.8-docs-0.8.1-6.mga1.i586.rpm


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>GUI Resources - ClanLib Game SDK</title>
<link rel="stylesheet" type="text/css" href="../../default.css">
</head>
<body style="background-color: #a4daea; color: black; margin: 1em 3em 1em 3em;">
<div style="border-style: solid; border-width:thin; border-color: black;">
<div style="background-color: white; color: black; padding: .3em 1em .3em 1em; border-bottom-style: dotted; border-bottom-width: 2px;">
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td align="center">
<h1>
<a href="http://www.clanlib.org"><img style="border-style: none; padding-right: 130px;" src="../../gfx/clanlib.png" alt="ClanLib"></a>
</h1>
</td>
</tr>
</table>
<!--<div class="menu">
  <a href="index.html">News</a>
  <a href="intro.html">About</a>
  <a href="download.html">Download</a>
  <a href="cvs.html">CVS</a>
  <a class="active" href="docs.html">Docs</a>
  <a href="games.html">Games</a>
  <a href="contact.html">Contact</a>
  <a href="links.html">Links</a>
</div>-->
</div>
<div style="background-color: white; padding: 1em 3em 1em 3em;">
<!-- clanlib header end -->

<div style="border-bottom-style: dotted;  border-bottom-width: 1px; margin-bottom: 1em;"><h2>GUI Resources</h2></div>



<p align="center">
<a href="#component">Component</a> |
<a href="#button">Button</a> |
<a href="#frame">Frame</a> |
<a href="#image">Image</a> |
<a href="#inputbox">InputBox</a> |
<a href="#label">Label</a> |
<a href="#listbox">ListBox</a> |
<a href="#progressbar">ProgressBar</a> |
<a href="#radiobutton">RadioButton</a> |
<a href="#scrollbar">ScrollBar</a> |
<a href="#window">Window</a>
</p>

<div style="border-bottom-style: dotted;  border-bottom-width: 1px;"><h3>GUI definition files (.xml)</h3></div>
<p>
Instead of hardcoding every GUI components by code, you can use a GUI definition file to define the placement,
attributes and hierarchy of GUI components. The GUI definition format looks a lot like the ClanLib resource
manager format, so if you're familiar with that, you should easily get acquainted with the GUI definition
format. GUI files do not have sections. Instead, components can contain child-components within a <components>
tag, simply function as "sections". This means that the hierarchical structure of the GUI is directly readable
from the GUI definition file. Let's look at a small example;
</p>
<ul><pre><font face="Arial,Courier New,Courier">&lt;components&gt;
   &lt;window name="my_window" x="10" y="10" width="600" height="400" title="My Window" &gt; 
      &lt;components&gt;
         &lt;button name="my_button" x="25" y="25" width="100" height="20" text="My Button" /&gt;
         &lt;label name="my_label" x="25" y="50" text="My label" /&gt;
      &lt;/components&gt;
   &lt;/window&gt;
&lt;/components&gt;
</font></pre></ul>

<p>A window named my_window is the top-level component here. As this component is at the top of the component
hierarchy, the x, y position is directly mapped to the parent GUI item. Since this window has no GUI parent, 
the coordinates aremapped to your <a href="../Reference/html/CL_DisplayWindow.html">CL_DisplayWindow</a>. Each sub-somponent's x/y values are
relative to the current position of their parent. This means that my_button will always be offset (25, 25)
pixels from the upper-left corner of the client area of the window, and that both my_button and my_label
will be dragged along if my_window is moved. Width and height is not relative to any parents, and is measured
in pixels also. However, all sub-components are clipped within the screen area of the parent.
</p>

<p>Every component type recognize different sets of values in the .xml file. Some values
are mandatory for a component (they have to exist in the .xml-file for the initialization to succeed), 
and some are optional, and have default values in case they don't exist. All component types require
the 'x' and 'y' value, describing the position/offset of the component in question.
</p>

<p>Note that all components need to be within a &lt;components&gt; tag. This goes for
the root items, and also children of other components.</p>

<p>Example code to load a GUI definition file:</p>

<ul><pre><font face="Arial,Courier New,Courier">CL_ResourceManager resources("resources.xml");
CL_StyleManager_Silver style(&resources);
CL_GUIManager gui(&style);

CL_ComponentManager manager("mygui.xml", &gui);

gui.run();
</font></pre></ul>

<p>This code is fairly simple, but a few things need to be explained.</p>
<ul>
<li>The "resources.xml" file <b>must</b> contain items that describe the GUI style. The easiest way to do this is to copy the files required from the "Resources" directory of your ClanLib distribution.</li>
<li>The "mygui.xml" file contains the GUI layout code, as listed above.</li>
<li>Finally, calling "gui.run();" will block all further execution. This may, or may not be what you want. You can call "gui.show();" to draw the GUI to the screen exactly once. For more information, see <a href="../Reference/html/CL_GUIManager.html">CL_GUIManager</a>.</li>
</ul>
<p>To access individual components from a definition file, you use the 
CL_ComponentManager::get_component function. Some examples:</p>

<ul><pre><font face="Arial,Courier New,Courier">// Hook up the button click signal to a function
CL_Button *my_button = (CL_Button *) manager.get_component("my_button");
CL_Slot s = my_button-&gt;sig_clicked().connect(this, &App::on_button_clicked);
</font></pre></ul>

<p>If you have RTTI enabled in your project, you can also use the following approach:</p>
<ul><pre><font face="Arial,Courier New,Courier">CL_Button *my_button;
manager.get_component("my_button", &my_button);
</font></pre></ul>

<br/>
<div style="border-bottom-style: dotted;  border-bottom-width: 1px;"><h3>Methods for running a GUI and rendering game graphics</h3></div>
<p>If you want to draw directly to the screen <b>and</b> run a GUI at the same time, there are two options 
available to you.</p>
<h4>Option 1: Use gui.show()</h4>
<p>Instead of calling "gui.run()" in the above example, you can simply call "gui.show()" every time the GUI needs
to be drawn to the screen. It's up to you to decide how often to redraw the GUI. Calling "gui.show()" from within 
your own render loop is very easy to do, but is slow without code to detect when the GUI needs to be redrawn.</p>
<h4>Option 2: Use the sig_paint event.</h4>
<p>A sig_paint signal is emitted every time the GUI is redrawn. You can use this event to draw your own graphics 
before the GUI is drawn to the screen. Simply connect one of your own methods to the paint event:</p>
<ul><pre><font face="Arial,Courier New,Courier">CL_Slot m_slotOnPaint = gui.sig_paint().connect(this, &Game::OnRender);
</font></pre></ul>
<p>All you need to do is create the "Game::OnRender" class (obviously replace "Game" with the name of your class).</p>
<div style="border-bottom-style: dotted;  border-bottom-width: 1px;"><h3>Putting GUI definitions inside ClanLib resource files</h3></div>

<p>
Now that ClanLib uses XML for both the resources and the gui definitions, you can actually put them
both into the same file.
</p>

<ul><pre><font face="Arial,Courier New,Courier">&lt;resources&gt;
   &lt;!-- Include all resources from the silver theme here too --&gt;
   &lt;surface name="button_up" file="resources/button_up.tga" /&gt;

   &lt;components name="gui"&gt;
      &lt;button x="10" y="190" surface_up="button_up" /&gt;
   &lt;/components&gt;
&lt;/resources&gt;
</font></pre></ul>

<p>And some code to load it:</p>
<ul><pre><font face="Arial,Courier New,Courier">CL_ResourceManager resources("resources.xml");
CL_StyleManager_Silver style(&resources);
CL_GUIManager gui(&style);

CL_ComponentManager manager("gui", &resources, &gui);

gui.run();
</font></pre></ul>

<br/>
<div style="border-bottom-style: dotted;  border-bottom-width: 1px;"><h3>Component options</h3></div>

<p>The following section describes all the component attributes available for
each component.</p>

<br/>
<h4><a name="component">Component</a></h4>

<p>This is the base class all other components inherit. So every other component
has these basic attributes.</p>

<p>Tag name: <b>&lt;component&gt;</b><br/>
Class name: <a href="../Reference/html/CL_Component.html">CL_Component</a></p>

<ul>
<li>Attribute <b>name</b>: Name of gui component.<br/>
  <i>Valid values</i>: String<br>
  <i>Default value</i>: ""
</li>
<li>Attribute <b>x</b>: Position x of component.<br/>
  <i>Valid values</i>: Integer<br>
  <i>Default value</i>: 0
</li>
<li>Attribute <b>y</b>: Position y of component.<br/>
  <i>Valid values</i>: Integer<br>
  <i>Default value</i>: 0
</li>
<li>Attribute <b>width</b>: Width of component.<br/>
  <i>Valid values</i>: Integer<br>
  <i>Default value</i>: 0
</li>
<li>Attribute <b>height</b>: Height of component.<br/>
  <i>Valid values</i>: Integer<br>
  <i>Default value</i>: 0
</li>
<li>Attribute <b>visible</b>: Visibility of component.<br/>
  <i>Valid values</i>: Boolean<br>
  <i>Default value</i>: true
</li>
<li>Attribute <b>enabled</b>: If the component is enabled or disabled.<br/>
  <i>Valid values</i>: Boolean<br>
  <i>Default value</i>: true
</li>
<li>Attribute <b>tab_id</b>: Tab id.<br/>
  <i>Valid values</i>: Integer<br>
  <i>Default value</i>: 0
</li>
</ul>

<p>Examples:</p>
<ul><pre><font face="Arial,Courier New,Courier">&lt;component name="component1" x="10" y="10" width="100" height="20" /&gt;
&lt;component name="component2" x="10" y="30" width="70" height="20" enabled="false" tab_id="3"/&gt;
&lt;component name="component3" x="10" y="50" width="80" height="40" visible="false" /&gt;
</font></pre></ul>

<br/>
<h4><a name="button">Button</a></h4>

<p>Tag name: <b>&lt;button&gt;</b><br/>
Class name: <a href="../Reference/html/CL_Button.html">CL_Button</a></p>

<ul>
<li>Attribute <b>text</b>: The text on the button.<br/>
  <i>Valid values</i>: String<br>
  <i>Default value</i>: ""
</li>
<li>Attribute <b>toggled</b>: If the button is toggled by default or not.<br/>
  <i>Valid values</i>: Boolean<br>
  <i>Default value</i>: false
</li>
<li>Attribute <b>togglemode</b>: The togglemode, if false the button is sticky.<br/>
  <i>Valid values</i>: Boolean<br>
  <i>Default value</i>: false
</li>
</ul>

<p>Examples:</p>
<ul><pre><font face="Arial,Courier New,Courier">&lt;button name="button1" togglemode="true" x="10" y="10" width="100" height="20" text="Stick me!" /&gt;
&lt;button name="button2" x="10" y="40" width="100" height="20" text="Press me!" /&gt;
&lt;button name="button3" x="10" y="70" text="Auto size" /&gt;
</font></pre></ul>

<br/>
<h4><a name="frame">Frame</a></h4>

<p>Tag name: <b>&lt;frame&gt;</b><br/>
Class name: <a href="../Reference/html/CL_Frame.html">CL_Frame</a></p>

<ul>
<li>Attribute <b>filled</b>: If the frame should be filled or transparent.<br/>
  <i>Valid values</i>: Boolean<br/>
  <i>Default value</i>: false
</li>
</ul>

<p>Examples:</p>
<ul><pre><font face="Arial,Courier New,Courier">&lt;frame name="frame1" x="10" y="10" width="100" height="20" filled="true" /&gt;
&lt;frame x="10" y="35" width="100" height="20" /&gt;
</font></pre></ul>

<br/>
<h4><a name="image">Image</a></h4>

<p>Tag name: <b>&lt;image&gt;</b><br/>
Class name: <a href="../Reference/html/CL_Image.html">CL_Image</a></p>

<ul>
<li>Attribute <b></b>:<br/>
  <i>Valid values</i>: <br>
  <i>Default value</i>: 
</li>
</ul>

<p>Example:</p>
<ul><pre><font face="Arial,Courier New,Courier"></font></pre></ul>

<br/>
<h4><a name="inputbox">InputBox</a></h4>

<p>Tag name: <b>&lt;inputbox&gt;</b><br/>
Class name: <a href="../Reference/html/CL_InputBox.html">CL_InputBox</a></p>

<ul>
<li>Attribute <b>text</b>: Default input of the inputbox.<br/>
  <i>Valid values</i>: String<br>
  <i>Default value</i>: ""
</li>
<li>Attribute <b>passwordmode</b>: Password mode sets if the inputbox should display only * when entering text.<br/>
  <i>Valid values</i>: Boolean<br>
  <i>Default value</i>: false
</li>
<li>Attribute <b>read_only</b>: If read only, it is not possible to enter text into the inputbox.<br/>
  <i>Valid values</i>: Boolean<br>
  <i>Default value</i>: false
</li>
<li>Attribute <b>max_length</b>: Max number of characters allowed.<br/>
  <i>Valid values</i>: Integer<br>
  <i>Default value</i>: unlimited
</li>
</ul>

<p>Examples:</p>
<ul><pre><font face="Arial,Courier New,Courier">&lt;inputbox name="inputbox1" x="10" y="10" width="100" height="20" text="Default value" /&gt;
&lt;inputbox name="inputbox2" x="10" y="35" width="100" height="20" max_length="4" passwordmode="true" /&gt;
</font></pre></ul>

<br/>
<h4><a name="label">Label</a></h4>

<p>Tag name: <b>&lt;label&gt;</b><br/>
Class name: <a href="../Reference/html/CL_Label.html">CL_Label</a></p>

<ul>
<li>Attribute <b>text</b>: The text of the label.<br/>
  <i>Valid values</i>: String<br>
  <i>Default value</i>: ""
</li>
</ul>

<p>Example:</p>
<ul><pre><font face="Arial,Courier New,Courier">&lt;label x="10" y="10" width="100" height="20" text="Welcome to ClanGUI!" /&gt;
</font></pre></ul>

<br/>
<h4><a name="listbox">ListBox</a></h4>

<p>Tag name: <b>&lt;listbox&gt;</b><br/>
Class name: <a href="../Reference/html/CL_ListBox.html">CL_ListBox</a></p>

<ul>
<li>Child element <b>item</b>: Defines a item in the listbox.
  <ul>
  <li>Attribute <b>value</b>: Text of the listitem.<br/>
    <i>Valid values</i>: String<br>
    <i>Default value</i>: ""
  </li>
  </ul>
</li>
</ul>

<p>Example:</p>
<ul><pre><font face="Arial,Courier New,Courier">&lt;listbox name="listbox1" x="10" y="10" width="100" height="100"&gt;
	&lt;item value="Item 1" /&gt;
	&lt;item value="Item 2" /&gt;
	&lt;item value="Item 3" /&gt;
&lt;/listbox&gt;
</font></pre></ul>

<br/>
<h4><a name="progressbar">ProgressBar</a></h4>

<p>Tag name: <b>&lt;progressbar&gt;</b><br/>
Class name: <a href="../Reference/html/CL_ProgressBar.html">CL_ProgressBar</a></p>

<ul>
<li>Attribute <b>steps</b>: Number of steps in the progressbar.<br/>
  <i>Valid values</i>: Integer<br>
  <i>Default value</i>: 0
</li>
</ul>

<p>Example:</p>
<ul><pre><font face="Arial,Courier New,Courier">&lt;progressbar name="progressbar1" x="10" y="10" width="100" height="20" steps="100" /&gt;
</font></pre></ul>

<br/>
<h4><a name="radiobutton">RadioButton</a></h4>

<p>Tag name: <b>&lt;radiobutton&gt;</b><br/>
Class name: <a href="../Reference/html/CL_RadioButton.html">CL_RadioButton</a></p>

<ul>
<li>Attribute <b></b>:<br/>
  <i>Valid values</i>: <br>
  <i>Default value</i>: 
</li>
</ul>

<p>Example:</p>
<ul><pre><font face="Arial,Courier New,Courier"></font></pre></ul>

<br/>
<h4><a name="scrollbar">ScrollBar</a></h4>

<p>Tag name: <b>&lt;scrollbar&gt;</b><br/>
Class name: <a href="../Reference/html/CL_ScrollBar.html">CL_ScrollBar</a></p>

<ul>
<li>Attribute <b>orientation</b>: The orientation of the scrollbar, horizontal or vertical.<br/>
  <i>Valid values</i>: hor, horz, horizontal, 1 = horizontal orientation - ver, vert, vertical, 0 = vertical orientation<br>
  <i>Default value</i>: vertical 
</li>
<li>Attribute <b>min</b>: Minimum value of the scrollbar range.<br/>
  <i>Valid values</i>: Integer<br>
  <i>Default value</i>: 0 
</li>
<li>Attribute <b>max</b>: Maximum value of the scrollbar range.<br/>
  <i>Valid values</i>: Integer<br>
  <i>Default value</i>: value of minimum
</li>
<li>Attribute <b>value</b>: Current value of the scrollbar range.<br/>
  <i>Valid values</i>: Integer<br>
  <i>Default value</i>: value of minimum
</li>
<li>Attribute <b>tracking</b>: Enables or disables tracking.<br/>
  <i>Valid values</i>: Boolean<br>
  <i>Default value</i>: false
</li>
</ul>

<p>Examples:</p>
<ul><pre><font face="Arial,Courier New,Courier">&lt;scrollbar name="scrollbar1" x="160" y="10" width="20" height="220" min="0" orientation="ver" max="100" /&gt;
&lt;scrollbar name="scrollbar2" x="10" y="230" width="150" height="20" min="0" max="10" orientation="hor" /&gt;
</font></pre></ul>

<br/>
<h4><a name="window">Window</a></h4>

<p>Tag name: <b>&lt;window&gt;</b><br/>
Class name: <a href="../Reference/html/CL_Window.html">CL_Window</a></p>

<ul>
<li>Attribute <b>title</b>: Title of the window.<br/>
  <i>Valid values</i>: String<br>
  <i>Default value</i>: ""
</li>
</ul>

<p>Example:</p>
<ul><pre><font face="Arial,Courier New,Courier">&lt;window name="window1" x="10" y="10" width="400" height="300" title="This is a window" /&gt;
</font></pre></ul>

<!-- clanlib footer begin -->
<div style="margin-top: 0em; text-align: center; color: #a0a0a0; border-top-style: dotted; border-top-width: 1px;">
              Questions or comments, write to the <a href="http://clanlib.org/contact.html">ClanLib mailing list</a>.
            </div>
</div>
</div>
</body>
</html>