Changes between Initial Version and Version 1 of GUI_-_Sprites


Ignore:
Timestamp:
Feb 23, 2008, 4:18:58 AM (16 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • GUI_-_Sprites

    v1 v1  
     1A sprite is an object consisting of a number of properties that define an image which be used by the GUI. Sprites are defined in ''<sprite1.xml>''.
     2
     3The sprite system is quite complex, but very powerful once understood. An image can consist of a number of textures, arranged in a collage, and they can be placed and tiled in a quite dynamic way. For example, one could create a dialog box with fixed edges, but a resizeable tile inside.
     4
     5Take the resizeable button illustrated in the image below, for example:
     6
     7[[Image(http://www.wildfiregames.com/~code/resources/wiki/gui/sprite_example.gif)]]
     8
     9All the corners have a static size (the size of the border texture), but the length dynamically tiles. The central image also tiles. Here's how we'd define that sprite, assuming that the border's texture is size 20x20:
     10
     11{{{
     12  <sprites>
     13      <sprite name="button">
     14            <!-- Starting with top left corner continuing in a clockwise manner -->
     15            <image texture="t1.jpg"
     16                   size="0 0 20 20"
     17                   texture_size="0 0 20 20"
     18            />
     19            <image texture="t2.jpg"
     20                   size="20 0 100%-20 20"
     21                   texture_size="0 0 20 20"
     22            />
     23            <image texture="t3.jpg"
     24                   size="100%-20 0 100% 20"
     25                   texture_size="0 0 20 20"
     26            />
     27            <image texture="t4.jpg"
     28                   size="100%-20 20 100% 100%-20"
     29                   texture_size="0 0 20 20"
     30            />
     31            <image texture="t5.jpg"
     32                   size="100%-20 100%-20 100% 100%"
     33                   texture_size="0 0 20 20"
     34            />
     35            <image texture="t6.jpg"
     36                   size="20 100%-20 100%-20 100%"
     37                   texture_size="0 0 20 20"
     38            />
     39            <image texture="t7.jpg"
     40                   size="0 100%-20 20 100%"
     41                   texture_size="0 0 20 20"
     42            />
     43            <image texture="t8.jpg"
     44                   size="0 20 20 100%-20"
     45                   texture_size="0 0 20 20"
     46            />
     47            <!-- middle -->
     48            <image texture="t9.jpg"
     49                   size="20 20 100%-20 100%-20"
     50                   texture_size="0 0 100 100"
     51            />
     52      </sprite>
     53  </sprites>
     54}}}
     55
     56We just created a sprite with its texture stretched to its every corner with the image stretched to the object�s corners. Within the <sprite> and </sprite> you can have as many <image /> as you like, they are each real sprites; they all together form the entire collage.
     57
     58== sprite ==
     59
     60Within <sprites></sprites>, you can define as many <sprite></sprite>s as you wish.
     61
     62=== ''name'' ===
     63
     64Each sprite has a unique name. This is referenced by properties such as ''sprite'' and ''sprite_over'' to tell the control to use this sprite as its image under the appropriate circumstances.
     65
     66=== image ===
     67
     68The sprite can consist of any number of images, forming a collage. Each image is derived from a single texture.
     69
     70The image in turn has a number of definable properties:
     71
     72==== backcolor ====
     73 * default: ?
     74 * value: color
     75
     76Regular RGB colour stamp including transparency eg backcolor="255 0 255 50" (see GUIColor). If no ''texture'' property is specified, the area is filled with this colour.
     77
     78==== border ====
     79 * default: "false"
     80 * value: bool "(true|false)"
     81
     82If set to ''true'', the texture's area is surrounded by a border in ''bordercolor'', starting at the edge of the image. As the object's ''buffer_zone'' increases, the border thickens inwards from the edge.
     83
     84If ''false'', no border is displayed.
     85
     86==== bordercolor ====
     87 * default: ?
     88 * value: color
     89
     90If ''border'' is ''true'', this property indicates the RGB colour of the border (see GUIColor).
     91
     92Useless if border is not true.
     93
     94==== [wiki:cell_size] ====
     95
     96It�s often more efficient to put multiple sprites of the same size in a grid, rather than storing each as a separate texture (for example, a series of unit portraits). Although we can reference different areas of a texture and store it in a sprite, each element in a sheet of icons would have to be assigned its own sprite, which would be highly repetitive.
     97
     98With this method, we can keep all 64x64 Celtic entity portraits in one sprite, for example, and reference the individual cells.
     99
     100To activate this feature, just add ''cell_size="<cell_width> <cell_height>" (with appropriate numbers for the width and length of each cell) to the <image> attributes to tell the sprite parser the size of the individual cells:
     101
     102{{{
     103  <sprite name="new_name">
     104          <image texture="texture-from-texture-database"
     105                 cell-size="64 64"
     106                 size="0 0 100% 100%"
     107                 texture_size="0 0 100% 100%"
     108          />
     109  </sprite>
     110}}}
     111
     112The GUI control <object>s have a corresponding ''cell_id'' attribute to specify which cell of the sprite they should display at the moment; "0" is the 1st element in the sprite.
     113
     114==== <font color="red">delta_z</font> ====
     115
     116<font color="red">Replaced with ''z_level''? Confirm.</font>
     117
     118==== real_texture_placement ====
     119 * default: "0 0 0 0"
     120 * value: client area
     121
     122This is a recent addition to get around the problem of having to '''very''' precisely define objects with a percentage size (eg buttons that should adjust to fit the current resolution, and always take up the same amount of space onscreen). This led to definitions like:
     123
     124{{{
     125  <image texture="ui_pregame_mainmenu_background.png"
     126         size="0 0 100% 100%"
     127         texture-size="0 0 100% 133.333333333%"
     128  />
     129}}}
     130
     131To get around this, we have the property ''real_texture_placement'', which specifies the size of the '''real''' texture, not the texture file. So the above example becomes:
     132
     133{{{
     134  <image texture="ui_pregame_mainmenu_background.png"
     135         real-texture-placement="0 0 1024 768"
     136         size="0 0 100% 100%"
     137  />
     138}}}
     139
     140This feature could also be used to store several textures in a file and specify a certain area of the source texture and cut out that area as the sprite's texture.
     141
     142Since it just processes the texture coordinates, it doesn't cut out the texture, so you can't tile a cut out texture, because the rest of the image will be shown too.
     143
     144==== size ====
     145 * default: "0 0 100% 100%"
     146 * value: client area
     147
     148Indicates size and position of the image relative to object size.
     149
     150For single-textured sprites, it's recommended to leave the size as "0 0 100% 100%", and let the size of the object dictate the size of the sprite.
     151
     152==== texture ====
     153 * default: "null"
     154 * value: name
     155
     156The name and path of the texture file to use as the source image for this texture. A number of file formats are available, including .jpg, .gif and .dds.
     157
     158==== texture_size ====
     159 * default: "0 0 100% 100%"
     160 * value: client area
     161
     162Where the texture should be placed within the image; outside this size it will tile. If set to a percentage (eg "0 0 100% 100%"), it will stretch beyond this size instead of tile.
     163
     164Note that "0 0 100% 100%" is the default, so if you need a sprite that simply stretches to fit its control object, you don't need to specify ''texture_size''.
     165
     166==== <font color="green">z_level</font> ====
     167 * default: 0
     168 * value: int
     169
     170This is the sprite equivalent of an object's ''z''. Specifying the textures in the right sequence and leaving ''delta_z'' alone should normally be sufficient, but if you want to move a texture up or down the layers of the collage, you can specify its ''delta_z'' value.
     171
     172=== Skip a step ===
     173
     174When using sprites it�s very important to know the difference between the sprite name and the texture name. You can�t just go ''sprite="example_texture.jpg'' and expect that to work. You have to setup a sprite with that texture first.
     175
     176Because a 100%-stretched single texture sprite is such a regular occurrence, however, there's a template to skip that step and directly reference the texture. You can do that by using ''stretched:'' in the object's ''string='' property:
     177
     178{{{
     179  sprite="stretched:example_texture.jpg"
     180}}}
     181
     182The above is perfectly valid code, the equivalent of:
     183
     184{{{
     185  <sprite name="new_name">
     186          <image texture="texture-from-texture-database"
     187                 size="0 0 100% 100%"
     188                 texture_size="0 0 100% 100%"
     189          />
     190  </sprite>
     191}}}
     192
     193=== effect ===
     194
     195Effects are special features that can be added to a sprite when it is first created. For example, the brightness of all images in a sprite can be altered from their base image so they appear lit (to create an illuminated hover version of a button, for example, without having to create a duplicate texture and alter its brightness in PhotoShop).
     196
     197Effects are specified in the <effect/> tag, which must always appear before any <image>s in a <sprite> declaration.
     198
     199{{{
     200  <!-- Creates a stretched texture that's bled of all colour (grayscale), and brighter than the source image. -->
     201  <sprite name="new_name_over">
     202          <effect add_color=�42 42 42 0�
     203                  grayscale=""
     204          />
     205          <image texture="texture-from-texture-database"
     206                 size="0 0 100% 100%"
     207                 texture_size="0 0 100% 100%"
     208          />
     209  </sprite>
     210}}}
     211
     212==== add_color ====
     213
     214The add_color effect adds a specified RGB value to the colour value of the sprite. For example, add-color="42 42 42" increases the overall brightness of the sprite when displayed, particularly useful for buttons that illuminate when the cursor hovers over them.
     215
     216==== multiply_color ====
     217
     218Similar to ''add_color'', except it multiples each component (where they�re in the range 0-1 rather 0-255); in other words, ''multiply-color'' will always leave black parts black, but brighten other parts, rather like a contrast adjustment.
     219
     220Due to an OpenGL clamping restriction, components can never be > 255, so ''multiply_color'' cannot make an image brighter (though ''add_color'' can).
     221
     222==== <font color="green">grayscale</font> ====
     223
     224This effect removes all colour from the sprite, replacing colours with shades of gray. This is particularly useful for disabled versions of sprites.