1
0
forked from 0ad/0ad

Renamed icon-size/icon-id to cell-size/cell-id, and allowed cell-id to be used in <icon>s.

Added <effect>s to sprites/images - currently multiply-color and
add-color, though they're far from perfect.

This was SVN commit r1525.
This commit is contained in:
Ykkrosh 2004-12-18 13:32:00 +00:00
parent 5bb24a387f
commit ba0ebd6644
22 changed files with 278 additions and 122 deletions

View File

@ -32,7 +32,7 @@
font CDATA #IMPLIED
fov-wedge-color CDATA #IMPLIED
hotkey CDATA #IMPLIED
icon-id CDATA #IMPLIED
cell-id CDATA #IMPLIED
input-initvalue-destroyed-at-focus %bool; #IMPLIED
rectcolor-selected CDATA #IMPLIED
scrollbar %bool; #IMPLIED
@ -131,14 +131,16 @@
name CDATA #REQUIRED
texture CDATA #REQUIRED
size CDATA #REQUIRED
cell-id CDATA #IMPLIED
>
<!--
<sprites>
-->
<!ELEMENT sprites (sprite*)>
<!ELEMENT sprite (image+)>
<!ELEMENT image EMPTY>
<!ELEMENT sprite (effect?,image+)>
<!ELEMENT image (effect?)>
<!ELEMENT effect EMPTY>
<!ATTLIST sprite
name CDATA #REQUIRED
@ -149,9 +151,14 @@
size CDATA #IMPLIED
texture-size CDATA #IMPLIED
real-texture-placement CDATA #IMPLIED
icon-size CDATA #IMPLIED
cell-size CDATA #IMPLIED
backcolor CDATA #IMPLIED
bordercolor CDATA #IMPLIED
border %bool; #IMPLIED
z-level CDATA #IMPLIED
>
>
<!ATTLIST effect
add-color CDATA #IMPLIED
multiply-color CDATA #IMPLIED
>

View File

@ -133,7 +133,7 @@ function setPortrait(objectName, portraitString, portraitCell)
// If the source texture is a multi-frame image (icon sheet), specify correct cell.
if (portraitCell)
GUIObject["icon-id"] = portraitCell;
GUIObject["cell-id"] = portraitCell;
}
// ====================================================================

View File

@ -744,7 +744,7 @@ function UpdateStatusOrb()
if (selection[0].traits.up.rank > 1)
{
GUIObject.sprite = "ui_icon_sheet_statistic";
GUIObject["icon-id"] = stat_rank1 + (selection[0].traits.up.rank-2);
GUIObject["cell-id"] = stat_rank1 + (selection[0].traits.up.rank-2);
}
else
GUIObject.sprite = "";

View File

@ -159,27 +159,27 @@
<image backcolor="0 0 0" size="100% 0 100%+1 100%" />
</sprite>
<!-- Standard 0 A.D.-style framed window -->
<!-- Standard 0 A.D.-style framed window -->
<sprite name="0ad_window">
<!-- middle -->
<image texture="global/ui_gen_background_paper.png" texture-size="0 0 128 128" size="0%-10 0%-10 100%+10 100%+10" />
<!-- Starting with top left corner continuing in a clockwise manner -->
<image texture="global/ui_gen_border-corner-15px.png" real-texture-placement="0 0 15 15" size="0%-25 0%-25 0%-10 0%-10" />
<image texture="global/ui_gen_border-top-20px.png" texture-size="0 0 128 32" size="0%-10 0%-25 100%+10 0%+7" />
<image texture="global/ui_gen_border-corner-15px.png" real-texture-placement="0 0 15 15" size="100%+10 0%-25 100%+25 0%-10" />
<image texture="global/ui_gen_border-right-20px.png" texture-size="0 0 32 128" size="100%-6 0%-10 100%+26 100%+10" />
<image texture="global/ui_gen_border-corner-15px.png" real-texture-placement="0 0 15 15" size="100%+10 100%+10 100%+25 100%+25" />
<image texture="global/ui_gen_border-bottom-20px.png" texture-size="0 0 128 32" size="0%-10 100%-7 100%+10 100%+25" />
<image texture="global/ui_gen_border-corner-15px.png" real-texture-placement="0 0 15 15" size="0%-25 100%+10 0%-10 100%+25" />
<image texture="global/ui_gen_border-left-20px.png" texture-size="0 0 32 128" size="0%-25 0%-10 0%+7 100%+10" />
<image texture="global/ui_gen_border-corner-15px.png" real-texture-placement="0 0 15 15" size="0%-25 0%-25 0%-10 0%-10" />
<image texture="global/ui_gen_border-top-20px.png" texture-size="0 0 128 32" size="0%-10 0%-25 100%+10 0%+7" />
<image texture="global/ui_gen_border-corner-15px.png" real-texture-placement="0 0 15 15" size="100%+10 0%-25 100%+25 0%-10" />
<image texture="global/ui_gen_border-right-20px.png" texture-size="0 0 32 128" size="100%-6 0%-10 100%+26 100%+10" />
<image texture="global/ui_gen_border-corner-15px.png" real-texture-placement="0 0 15 15" size="100%+10 100%+10 100%+25 100%+25" />
<image texture="global/ui_gen_border-bottom-20px.png" texture-size="0 0 128 32" size="0%-10 100%-7 100%+10 100%+25" />
<image texture="global/ui_gen_border-corner-15px.png" real-texture-placement="0 0 15 15" size="0%-25 100%+10 0%-10 100%+25" />
<image texture="global/ui_gen_border-left-20px.png" texture-size="0 0 32 128" size="0%-25 0%-10 0%+7 100%+10" />
</sprite>
<!-- Standard 0 A.D.-style window's title bar -->
<!-- Standard 0 A.D.-style window's title bar -->
<sprite name="0ad_window_title">
<image texture="global/ui_gen_titlebar-left.png" real-texture-placement="0 0 64 32" size="0%+0 0%-10 5%+64 0%+22" />
<image texture="global/ui_gen_titlebar-middle.png" real-texture-placement="0 0 64 32" size="5%+64 0%-10 95%-64 0%+22" />
<image texture="global/ui_gen_titlebar-right.png" real-texture-placement="0 0 64 32" size="95%-64 0%-10 100%+0 0%+22" />
</sprite>
</sprite>
<!--
==========================================
@ -208,7 +208,7 @@
</sprite>
<sprite name="tooltip-background">
<image texture="black_16x16.png" texture-size="0 0 16 16" size="0 0 100% 100%" />
<image backcolor="0 0 0 85" size="0 0 100% 100%" />
</sprite>
<!--
@ -411,7 +411,7 @@
-->
<sprite name="ui_icon_sheet_statistic">
<image texture="ui_icon_sheet_statistic.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<image texture="ui_icon_sheet_statistic.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<!--
@ -425,7 +425,8 @@
<image texture="ui_portrait_default_circle.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
</sprite>
<sprite name="ui_portrait_default_circle-lit">
<image texture="ui_portrait_default_circle-lit.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
<effect add-color="26 26 26"/>
<image texture="ui_portrait_default_circle.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
</sprite>
<sprite name="ui_portrait_default_circle-grey">
<image texture="ui_portrait_default_circle-grey.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
@ -436,7 +437,8 @@
<image texture="ui_portrait_default_square.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
</sprite>
<sprite name="ui_portrait_default_square-lit">
<image texture="ui_portrait_default_square-lit.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
<effect add-color="26 26 26"/>
<image texture="ui_portrait_default_square.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
</sprite>
<sprite name="ui_portrait_default_square-grey">
<image texture="ui_portrait_default_square-grey.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
@ -449,13 +451,14 @@
-->
<sprite name="ui_portrait_sheet_action">
<image texture="ui_portrait_sheet_action.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<image texture="ui_portrait_sheet_action.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<sprite name="ui_portrait_sheet_action-lit">
<image texture="ui_portrait_sheet_action-lit.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<effect add-color="42 42 42"/>
<image texture="ui_portrait_sheet_action.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<sprite name="ui_portrait_sheet_action-grey">
<image texture="ui_portrait_sheet_action-grey.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<image texture="ui_portrait_sheet_action-grey.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<!--
@ -469,7 +472,8 @@
<image texture="ui_portrait_unit_dude.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
</sprite>
<sprite name="ui_portrait_unit_dude-lit">
<image texture="ui_portrait_unit_dude-lit.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
<effect add-color="42 42 42"/>
<image texture="ui_portrait_unit_dude.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
</sprite>
<sprite name="ui_portrait_unit_dude-grey">
<image texture="ui_portrait_unit_dude-grey.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
@ -480,7 +484,8 @@
<image texture="ui_portrait_unit_dudette.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
</sprite>
<sprite name="ui_portrait_unit_dudette-lit">
<image texture="ui_portrait_unit_dudette-lit.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
<effect add-color="42 42 42"/>
<image texture="ui_portrait_unit_dudette.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
</sprite>
<sprite name="ui_portrait_unit_dudette-grey">
<image texture="ui_portrait_unit_dudette-grey.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
@ -491,7 +496,8 @@
<image texture="ui_portrait_flora_deciduotree.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
</sprite>
<sprite name="ui_portrait_flora_deciduotree-lit">
<image texture="ui_portrait_flora_deciduotree-lit.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
<effect add-color="42 42 42"/>
<image texture="ui_portrait_flora_deciduotree.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
</sprite>
<sprite name="ui_portrait_flora_deciduotree-grey">
<image texture="ui_portrait_flora_deciduotree-grey.png" texture-size="0 0 100% 100%" size="0 0 100% 100%" />
@ -504,13 +510,14 @@
-->
<sprite name="ui_portrait_sheet_civ_celt">
<image texture="ui_portrait_sheet_civ_celt.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<image texture="ui_portrait_sheet_civ_celt.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<sprite name="ui_portrait_sheet_civ_celt-grey">
<image texture="ui_portrait_sheet_civ_celt-grey.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<image texture="ui_portrait_sheet_civ_celt-grey.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<sprite name="ui_portrait_sheet_civ_celt-lit">
<image texture="ui_portrait_sheet_civ_celt-lit.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<effect add-color="100 100 100"/>
<image texture="ui_portrait_sheet_civ_celt.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<!--
@ -520,13 +527,14 @@
-->
<sprite name="ui_portrait_sheet_civ_hele">
<image texture="ui_portrait_sheet_civ_hele.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<image texture="ui_portrait_sheet_civ_hele.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<sprite name="ui_portrait_sheet_civ_hele-grey">
<image texture="ui_portrait_sheet_civ_hele-grey.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<image texture="ui_portrait_sheet_civ_hele-grey.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<sprite name="ui_portrait_sheet_civ_hele-lit">
<image texture="ui_portrait_sheet_civ_hele-lit.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<effect add-color="100 100 100"/>
<image texture="ui_portrait_sheet_civ_hele.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<!--
@ -536,13 +544,14 @@
-->
<sprite name="ui_portrait_sheet_civ_iber">
<image texture="ui_portrait_sheet_civ_iber.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<image texture="ui_portrait_sheet_civ_iber.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<sprite name="ui_portrait_sheet_civ_iber-grey">
<image texture="ui_portrait_sheet_civ_iber-grey.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<image texture="ui_portrait_sheet_civ_iber-grey.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<sprite name="ui_portrait_sheet_civ_iber-lit">
<image texture="ui_portrait_sheet_civ_iber-lit.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<effect add-color="100 100 100"/>
<image texture="ui_portrait_sheet_civ_iber.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<!--
@ -552,13 +561,14 @@
-->
<sprite name="ui_portrait_sheet_civ_kart">
<image texture="ui_portrait_sheet_civ_kart.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<image texture="ui_portrait_sheet_civ_kart.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<sprite name="ui_portrait_sheet_civ_kart-grey">
<image texture="ui_portrait_sheet_civ_kart-grey.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<image texture="ui_portrait_sheet_civ_kart-grey.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<sprite name="ui_portrait_sheet_civ_kart-lit">
<image texture="ui_portrait_sheet_civ_kart-lit.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<effect add-color="100 100 100"/>
<image texture="ui_portrait_sheet_civ_kart.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<!--
@ -568,13 +578,14 @@
-->
<sprite name="ui_portrait_sheet_civ_pers">
<image texture="ui_portrait_sheet_civ_pers.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<image texture="ui_portrait_sheet_civ_pers.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<sprite name="ui_portrait_sheet_civ_pers-grey">
<image texture="ui_portrait_sheet_civ_pers-grey.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<image texture="ui_portrait_sheet_civ_pers-grey.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<sprite name="ui_portrait_sheet_civ_pers-lit">
<image texture="ui_portrait_sheet_civ_pers-lit.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<effect add-color="100 100 100"/>
<image texture="ui_portrait_sheet_civ_pers.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<!--
@ -584,13 +595,14 @@
-->
<sprite name="ui_portrait_sheet_civ_rome">
<image texture="ui_portrait_sheet_civ_rome.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<image texture="ui_portrait_sheet_civ_rome.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<sprite name="ui_portrait_sheet_civ_rome-grey">
<image texture="ui_portrait_sheet_civ_rome-grey.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<image texture="ui_portrait_sheet_civ_rome-grey.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<sprite name="ui_portrait_sheet_civ_rome-lit">
<image texture="ui_portrait_sheet_civ_rome-lit.png" icon-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
<effect add-color="100 100 100"/>
<image texture="ui_portrait_sheet_civ_rome.png" cell-size="64 64" texture-size="0 0 100% 100%" size="0 0 100% 100%"/>
</sprite>
<!--

View File

@ -24,7 +24,7 @@ CButton::CButton()
AddSetting(GUIST_CGUISpriteInstance, "sprite-over");
AddSetting(GUIST_CGUISpriteInstance, "sprite-pressed");
AddSetting(GUIST_CGUISpriteInstance, "sprite-disabled");
AddSetting(GUIST_int, "icon-id");
AddSetting(GUIST_int, "cell-id");
AddSetting(GUIST_EAlign, "text-align");
AddSetting(GUIST_EVAlign, "text-valign");
AddSetting(GUIST_CColor, "textcolor");
@ -126,13 +126,13 @@ void CButton::Draw()
float bz = GetBufferedZ();
CGUISpriteInstance *sprite, *sprite_over, *sprite_pressed, *sprite_disabled;
int icon_id;
int cell_id;
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-over", sprite_over);
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-pressed", sprite_pressed);
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-disabled", sprite_disabled);
GUI<int>::GetSetting(this, "icon-id", icon_id);
GUI<int>::GetSetting(this, "cell-id", cell_id);
DrawButton(m_CachedActualSize,
bz,
@ -140,7 +140,7 @@ void CButton::Draw()
*sprite_over,
*sprite_pressed,
*sprite_disabled,
icon_id);
cell_id);
CColor color = ChooseColor();
IGUITextOwner::Draw(0, color, m_TextPos, bz+0.1f);

View File

@ -408,7 +408,7 @@ void CGUI::Draw()
}
void CGUI::DrawSprite(CGUISpriteInstance& Sprite,
int IconID,
int CellID,
const float &Z,
const CRect &Rect,
const CRect &Clipping)
@ -422,7 +422,7 @@ void CGUI::DrawSprite(CGUISpriteInstance& Sprite,
glPushMatrix();
glTranslatef(0.0f, 0.0f, Z);
Sprite.Draw(Rect, IconID, m_Sprites);
Sprite.Draw(Rect, CellID, m_Sprites);
glPopMatrix();
@ -449,6 +449,10 @@ void CGUI::Destroy()
delete it->second;
}
for (std::map<CStr, CGUISprite>::iterator it2 = m_Sprites.begin(); it2 != m_Sprites.end(); ++it2)
for (std::vector<SGUIImage>::iterator it3 = it2->second.m_Images.begin(); it3 != it2->second.m_Images.end(); ++it3)
delete it3->m_Effects;
// Clear all
m_pAllObjects.clear();
m_Sprites.clear();
@ -523,16 +527,16 @@ IGUIObject* CGUI::FindObjectByName(const CStr& Name) const
// private struct used only in GenerateText(...)
struct SGenerateTextImage
{
float m_YFrom, // The images starting location in Y
m_YTo, // The images end location in Y
float m_YFrom, // The image's starting location in Y
m_YTo, // The image's end location in Y
m_Indentation; // The image width in other words
// Some help functions
// TODO Gee: CRect => CPoint ?
void SetupSpriteCall(const bool &Left, SGUIText::SSpriteCall &SpriteCall,
const float &width, const float &y,
const CSize &Size, const CStr& TextureName,
const float &BufferZone)
void SetupSpriteCall(const bool Left, SGUIText::SSpriteCall &SpriteCall,
const float width, const float y,
const CSize &Size, const CStr &TextureName,
const float BufferZone, const int CellID)
{
// TODO Gee: Temp hardcoded values
SpriteCall.m_Area.top = y+BufferZone;
@ -549,6 +553,7 @@ struct SGenerateTextImage
SpriteCall.m_Area.right = width-BufferZone;
}
SpriteCall.m_CellID = CellID;
SpriteCall.m_Sprite = TextureName;
m_YFrom = SpriteCall.m_Area.top-BufferZone;
@ -626,7 +631,7 @@ SGUIText CGUI::GenerateText(const CGUIString &string,
SGUIIcon icon = GetIcon(*it);
CSize size = icon.m_Size;
Image.SetupSpriteCall((j==CGUIString::SFeedback::Left), SpriteCall, Width, _y, size, icon.m_TextureName, BufferZone);
Image.SetupSpriteCall((j==CGUIString::SFeedback::Left), SpriteCall, Width, _y, size, icon.m_TextureName, BufferZone, icon.m_CellID);
// Check if image is the lowest thing.
Text.m_Size.cy = MAX(Text.m_Size.cy, Image.m_YTo);
@ -878,7 +883,7 @@ void CGUI::DrawText(SGUIText &Text, const CColor &DefaultColor,
it!=Text.m_SpriteCalls.end();
++it)
{
DrawSprite(it->m_Sprite, 0, z, it->m_Area + pos);
DrawSprite(it->m_Sprite, it->m_CellID, z, it->m_Area + pos);
}
// TODO To whom it may concern: Thing were not reset, so
@ -1375,6 +1380,8 @@ void CGUI::Xeromyces_ReadSprite(XMBElement Element, CXeromyces* pFile)
// Read Children (the images)
//
SGUIImageEffects* effects = NULL;
// Iterate children
XMBElementList children = Element.getChildNodes();
@ -1383,12 +1390,33 @@ void CGUI::Xeromyces_ReadSprite(XMBElement Element, CXeromyces* pFile)
// Get node
XMBElement child = children.item(i);
// All Elements will be of type "image" by DTD law
CStr ElementName (pFile->getElementString(child.getNodeName()));
// Call this function on the child
Xeromyces_ReadImage(child, pFile, sprite);
if (ElementName == "image")
{
Xeromyces_ReadImage(child, pFile, sprite);
}
else if (ElementName == "effect")
{
assert(! effects); // DTD should only allow one effect per sprite
effects = new SGUIImageEffects;
Xeromyces_ReadEffects(child, pFile, *effects);
}
else
{
debug_warn("Oops"); // DTD shouldn't allow this
}
}
// Apply the effects to every image (unless the image overrides it with
// different effects)
if (effects)
for (std::vector<SGUIImage>::iterator it = sprite.m_Images.begin(); it != sprite.m_Images.end(); ++it)
if (! it->m_Effects)
it->m_Effects = new SGUIImageEffects(*effects); // do a copy just so it can be deleted correctly later
delete effects;
//
// Add Sprite
//
@ -1452,12 +1480,12 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite
else image.m_TexturePlacementInFile = rect;
}
else
if (attr_name == "icon-size")
if (attr_name == "cell-size")
{
CSize size;
if (!GUI<CSize>::ParseString(attr_value, size))
ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
else image.m_IconSize = size;
else image.m_CellSize = size;
}
else
if (attr_name == "z-level")
@ -1491,7 +1519,28 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite
ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
else image.m_Border = b;
}
// We don't need no else when we're using DTDs.
else
{
debug_warn("Oops"); // DTD shouldn't allow this
}
}
// Look for effects
XMBElementList children = Element.getChildNodes();
for (int i=0; i<children.Count; ++i)
{
XMBElement child = children.item(i);
CStr ElementName (pFile->getElementString(child.getNodeName()));
if (ElementName == "effect")
{
assert(! image.m_Effects); // DTD should only allow one effect per sprite
image.m_Effects = new SGUIImageEffects;
Xeromyces_ReadEffects(child, pFile, *image.m_Effects);
}
else
{
debug_warn("Oops"); // DTD shouldn't allow this
}
}
//
@ -1501,6 +1550,34 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite
parent.AddImage(image);
}
void CGUI::Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects &effects)
{
XMBAttributeList attributes = Element.getAttributes();
for (int i=0; i<attributes.Count; ++i)
{
XMBAttribute attr = attributes.item(i);
CStr attr_name (pFile->getAttributeString(attr.Name));
CStr attr_value (attr.Value);
#define COLOR(xml, mem) \
if (attr_name == xml) \
{ \
CColor color; \
if (!GUI<CColor>::ParseString(attr_value, color)) \
ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str()); \
else effects.m_##mem = color; \
} \
else
COLOR("add-color", AddColor)
COLOR("multiply-color", MultiplyColor)
{
debug_warn("Oops"); // DTD shouldn't allow this
}
}
}
void CGUI::Xeromyces_ReadStyle(XMBElement Element, CXeromyces* pFile)
{
// style object we're adding
@ -1648,11 +1725,21 @@ void CGUI::Xeromyces_ReadIcon(XMBElement Element, CXeromyces* pFile)
{
CSize size;
if (!GUI<CSize>::ParseString(attr_value, size))
{
ReportParseError("Error parsing '%s' (\"%s\") when reading and <icon>.", attr_name.c_str(), attr_value.c_str());
}
ReportParseError("Error parsing '%s' (\"%s\") inside <icon>.", attr_name.c_str(), attr_value.c_str());
icon.m_Size = size;
}
else
if (attr_name == "cell-id")
{
int cell_id;
if (!GUI<int>::ParseString(attr_value, cell_id))
ReportParseError("Error parsing '%s' (\"%s\") inside <icon>.", attr_name.c_str(), attr_value.c_str());
icon.m_CellID = cell_id;
}
else
{
debug_warn("Oops"); // DTD shouldn't allow this
}
}
m_Icons[name] = icon;

View File

@ -108,13 +108,13 @@ public:
*
* @param Sprite Object refering to the sprite (which also caches
* calculations for faster rendering)
* @param IconID Number of the icon to use. (Ignored if this sprite doesn't
* have any images with "icon-size")
* @param CellID Number of the icon cell to use. (Ignored if this sprite doesn't
* have any images with "cell-size")
* @param Z Drawing order, depth value
* @param Rect Position and Size
* @param Clipping The sprite shouldn't be drawn outside this rectangle
*/
void DrawSprite(CGUISpriteInstance& Sprite, int IconID, const float &Z,
void DrawSprite(CGUISpriteInstance& Sprite, int CellID, const float &Z,
const CRect &Rect, const CRect &Clipping=CRect());
/**
@ -437,6 +437,9 @@ private:
*/
void Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite &parent);
// TODO: Documentation. (I'm feeling lazy at the moment.)
void Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects &effects);
/**
* Reads in the element <style> (the XMBElement) and stores the
* result in m_Styles.

View File

@ -17,13 +17,13 @@ CGUISpriteInstance &CGUISpriteInstance::operator=(CStr SpriteName)
return *this;
}
void CGUISpriteInstance::Draw(CRect Size, int IconID, std::map<CStr, CGUISprite> &Sprites)
void CGUISpriteInstance::Draw(CRect Size, int CellID, std::map<CStr, CGUISprite> &Sprites)
{
if (m_CachedSize != Size || m_CachedIconID != IconID)
if (m_CachedSize != Size || m_CachedCellID != CellID)
{
GUIRenderer::UpdateDrawCallCache(m_DrawCallCache, m_SpriteName, Size, IconID, Sprites);
GUIRenderer::UpdateDrawCallCache(m_DrawCallCache, m_SpriteName, Size, CellID, Sprites);
m_CachedSize = Size;
m_CachedIconID = IconID;
m_CachedCellID = CellID;
}
GUIRenderer::Draw(m_DrawCallCache);
}

View File

@ -46,6 +46,14 @@ gee@pyro.nu
// Declarations
//--------------------------------------------------------
struct SGUIImageEffects
{
CColor m_AddColor;
CColor m_MultiplyColor;
};
/**
* @author Gustav Larsson
*
@ -54,7 +62,7 @@ gee@pyro.nu
*/
struct SGUIImage
{
SGUIImage() : m_Border(false), m_DeltaZ(0.f) {}
SGUIImage() : m_Effects(NULL), m_Border(false), m_DeltaZ(0.f) {}
// Filename of the texture
CStr m_TextureName;
@ -71,10 +79,13 @@ struct SGUIImage
CRect m_TexturePlacementInFile;
// For textures that contain a collection of icons (e.g. unit portraits), this
// will be set to the size of one icon. An object's icon-id will determine
// will be set to the size of one icon. An object's cell-id will determine
// which part of the texture is used.
// Equal to CSize(0,0) for non-icon textures.
CSize m_IconSize;
// Equal to CSize(0,0) for non-celled textures.
CSize m_CellSize;
// Visual effects (e.g. colour modulation)
SGUIImageEffects* m_Effects;
// Color
CColor m_BackColor;
@ -91,6 +102,7 @@ struct SGUIImage
float m_DeltaZ;
};
/**
* @author Gustav Larsson
*
@ -130,7 +142,7 @@ public:
CGUISpriteInstance();
CGUISpriteInstance(CStr SpriteName);
CGUISpriteInstance &operator=(CStr SpriteName);
void Draw(CRect Size, int IconID, std::map<CStr, CGUISprite> &Sprites);
void Draw(CRect Size, int CellID, std::map<CStr, CGUISprite> &Sprites);
void Invalidate();
bool IsEmpty() const;
CStr GetName() { return m_SpriteName; }
@ -143,7 +155,7 @@ private:
// Relevant details of previously rendered sprite; the cache is invalidated
// whenever any of these values changes.
CRect m_CachedSize;
int m_CachedIconID;
int m_CachedCellID;
};
#endif

View File

@ -18,7 +18,7 @@ using namespace std;
CImage::CImage()
{
AddSetting(GUIST_CGUISpriteInstance, "sprite");
AddSetting(GUIST_int, "icon-id");
AddSetting(GUIST_int, "cell-id");
}
CImage::~CImage()
@ -32,10 +32,10 @@ void CImage::Draw()
float bz = GetBufferedZ();
CGUISpriteInstance *sprite;
int icon_id;
int cell_id;
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
GUI<int>::GetSetting(this, "icon-id", icon_id);
GUI<int>::GetSetting(this, "cell-id", cell_id);
GetGUI()->DrawSprite(*sprite, icon_id, bz, m_CachedActualSize);
GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
}
}

View File

@ -31,7 +31,7 @@ CInput::CInput() : m_iBufferPos(0)
AddSetting(GUIST_bool, "scrollbar");
AddSetting(GUIST_CStr, "scrollbar-style");
AddSetting(GUIST_CGUISpriteInstance, "sprite");
AddSetting(GUIST_int, "icon-id");
AddSetting(GUIST_int, "cell-id");
AddSetting(GUIST_CColor, "textcolor");
// TODO Gee: (2004-08-14)
// Add a setting for buffer zone
@ -342,11 +342,11 @@ void CInput::Draw()
if (GetGUI())
{
CGUISpriteInstance *sprite;
int icon_id;
int cell_id;
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
GUI<int>::GetSetting(this, "icon-id", icon_id);
GUI<int>::GetSetting(this, "cell-id", cell_id);
GetGUI()->DrawSprite(*sprite, icon_id, bz, m_CachedActualSize);
GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
float scroll=0.f;
if (scrollbar)

View File

@ -59,19 +59,19 @@ void CProgressBar::Draw()
float bz = GetBufferedZ();
CGUISpriteInstance *sprite_background, *sprite_bar;
int icon_id;
int cell_id;
float value;
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-background", sprite_background);
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-bar", sprite_bar);
GUI<int>::GetSetting(this, "icon-id", icon_id);
GUI<int>::GetSetting(this, "cell-id", cell_id);
GUI<float>::GetSetting(this, "caption", value);
GetGUI()->DrawSprite(*sprite_background, icon_id, bz, m_CachedActualSize);
GetGUI()->DrawSprite(*sprite_background, cell_id, bz, m_CachedActualSize);
// Get size of bar (notice it is drawn slightly closer, to appear above the background)
CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top,
m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(value/100.f), m_CachedActualSize.bottom);
GetGUI()->DrawSprite(*sprite_bar, icon_id, bz+0.01f, bar_size);
GetGUI()->DrawSprite(*sprite_bar, cell_id, bz+0.01f, bar_size);
}
}

View File

@ -26,7 +26,7 @@ CText::CText()
AddSetting(GUIST_bool, "scrollbar");
AddSetting(GUIST_CStr, "scrollbar-style");
AddSetting(GUIST_CGUISpriteInstance, "sprite");
AddSetting(GUIST_int, "icon-id");
AddSetting(GUIST_int, "cell-id");
AddSetting(GUIST_CColor, "textcolor");
// TODO Gee: (2004-08-14)
// Add a setting for buffer zone
@ -163,11 +163,11 @@ void CText::Draw()
if (GetGUI())
{
CGUISpriteInstance *sprite;
int icon_id;
int cell_id;
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
GUI<int>::GetSetting(this, "icon-id", icon_id);
GUI<int>::GetSetting(this, "cell-id", cell_id);
GetGUI()->DrawSprite(*sprite, icon_id, bz, m_CachedActualSize);
GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
float scroll=0.f;
if (scrollbar)

View File

@ -42,7 +42,7 @@ Handle_rfcnt_tex& Handle_rfcnt_tex::operator=(Handle h_)
// Functions to perform drawing-related actions:
void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect &Size, int IconID, std::map<CStr, CGUISprite> &Sprites)
void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect &Size, int CellID, std::map<CStr, CGUISprite> &Sprites)
{
// This is called only when something has changed (like the size of the
// sprite), so it doesn't need to be particularly efficient.
@ -114,14 +114,14 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect
if (cit->m_TexturePlacementInFile != CRect())
BlockTex = cit->m_TexturePlacementInFile;
// Check whether this sprite has "icon-size" set
else if (cit->m_IconSize != CSize())
// Check whether this sprite has "cell-size" set
else if (cit->m_CellSize != CSize())
{
int cols = t_w / (int)cit->m_IconSize.cx;
int col = IconID % cols;
int row = IconID / cols;
BlockTex = CRect(cit->m_IconSize.cx*col, cit->m_IconSize.cy*row,
cit->m_IconSize.cx*(col+1), cit->m_IconSize.cy*(row+1));
int cols = t_w / (int)cit->m_CellSize.cx;
int col = CellID % cols;
int row = CellID / cols;
BlockTex = CRect(cit->m_CellSize.cx*col, cit->m_CellSize.cy*row,
cit->m_CellSize.cx*(col+1), cit->m_CellSize.cy*(row+1));
}
// Use the whole texture
@ -167,6 +167,7 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect
Call.m_BackColor = cit->m_BackColor;
Call.m_BorderColor = cit->m_Border ? cit->m_BorderColor : CColor();
Call.m_DeltaZ = cit->m_DeltaZ;
Call.m_Effects = cit->m_Effects;
Calls.push_back(Call);
}
@ -180,8 +181,6 @@ void GUIRenderer::Draw(DrawCalls &Calls)
// Iterate through each DrawCall, and execute whatever drawing code is being called
for (DrawCalls::const_iterator cit = Calls.begin(); cit != Calls.end(); ++cit)
{
glColor4f(cit->m_BackColor.r, cit->m_BackColor.g, cit->m_BackColor.b, cit->m_BackColor.a);
if (cit->m_EnableBlending)
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -193,7 +192,26 @@ void GUIRenderer::Draw(DrawCalls &Calls)
// TODO: Handle the GL state in a nicer way
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
bool done = false;
if (cit->m_Effects)
{
if (cit->m_Effects->m_MultiplyColor != CColor())
{
glColor4fv(cit->m_Effects->m_MultiplyColor.FloatArray());
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
done = true;
}
else if (cit->m_Effects && cit->m_Effects->m_AddColor != CColor())
{
glColor4fv(cit->m_Effects->m_AddColor.FloatArray());
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
done = true;
}
}
if (! done)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
tex_bind(cit->m_TexHandle.h);
@ -218,6 +236,8 @@ void GUIRenderer::Draw(DrawCalls &Calls)
{
glDisable(GL_TEXTURE_2D);
glColor4fv(cit->m_BackColor.FloatArray());
glBegin(GL_QUADS);
glVertex3f(cit->m_Vertices.right, cit->m_Vertices.bottom, cit->m_DeltaZ);
glVertex3f(cit->m_Vertices.left, cit->m_Vertices.bottom, cit->m_DeltaZ);
@ -228,7 +248,7 @@ void GUIRenderer::Draw(DrawCalls &Calls)
if (cit->m_BorderColor != CColor())
{
glColor4f(cit->m_BorderColor.r, cit->m_BorderColor.g, cit->m_BorderColor.b, cit->m_BorderColor.a);
glColor4fv(cit->m_BorderColor.FloatArray());
glBegin(GL_LINE_LOOP);
glVertex3f(cit->m_Vertices.left, cit->m_Vertices.top+1.f, cit->m_DeltaZ);
glVertex3f(cit->m_Vertices.right-1.f, cit->m_Vertices.top+1.f, cit->m_DeltaZ);

View File

@ -6,6 +6,8 @@
#include "ps/CStr.h"
#include <vector>
struct SGUIImageEffects;
namespace GUIRenderer
{
struct Handle_rfcnt_tex
@ -24,6 +26,8 @@ namespace GUIRenderer
bool m_EnableBlending;
SGUIImageEffects* m_Effects;
CRect m_Vertices;
CRect m_TexCoords;
float m_DeltaZ;
@ -39,7 +43,7 @@ namespace GUIRenderer
namespace GUIRenderer
{
void UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect& Size, int IconID, std::map<CStr, CGUISprite> &Sprites);
void UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect& Size, int CellID, std::map<CStr, CGUISprite> &Sprites);
void Draw(DrawCalls &Calls);
}

View File

@ -154,6 +154,7 @@ void CGUIString::GenerateTextCall(SFeedback &Feedback,
}
SpriteCall.m_Sprite = icon.m_TextureName;
SpriteCall.m_CellID = icon.m_CellID;
// Add sprite call
Feedback.m_SpriteCalls.push_back(SpriteCall);

View File

@ -55,6 +55,8 @@ struct SGUIText
*/
struct SSpriteCall
{
SSpriteCall() : m_CellID(0) {}
/**
* Size and position of sprite
*/
@ -64,6 +66,8 @@ struct SGUIText
* Sprite from global GUI sprite database.
*/
CGUISpriteInstance m_Sprite;
int m_CellID;
};
/**

View File

@ -40,11 +40,16 @@ bool __ParseString(const CStr& Value, T &tOutput);
// you use them in text owned by different objects... Such as CText.
struct SGUIIcon
{
SGUIIcon() : m_CellID(0) {}
// Texture name of icon
CStr m_TextureName;
// Size
CSize m_Size;
// Cell of texture to use; ignored unless the texture has specified cell-size
int m_CellID;
};

View File

@ -92,7 +92,7 @@ void IGUIButtonBehavior::DrawButton(const CRect &rect,
CGUISpriteInstance& sprite_over,
CGUISpriteInstance& sprite_pressed,
CGUISpriteInstance& sprite_disabled,
int icon_id)
int cell_id)
{
if (GetGUI())
{
@ -101,16 +101,16 @@ void IGUIButtonBehavior::DrawButton(const CRect &rect,
if (!enabled)
{
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_disabled, sprite), icon_id, z, rect);
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_disabled, sprite), cell_id, z, rect);
}
else
if (m_MouseHovering)
{
if (m_Pressed)
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_pressed, sprite), icon_id, z, rect);
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_pressed, sprite), cell_id, z, rect);
else
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_over, sprite), icon_id, z, rect);
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_over, sprite), cell_id, z, rect);
}
else GetGUI()->DrawSprite(sprite, icon_id, z, rect);
else GetGUI()->DrawSprite(sprite, cell_id, z, rect);
}
}

View File

@ -73,8 +73,8 @@ public:
* @param sprite_over Sprite drawn when m_MouseHovering is true
* @param sprite_pressed Sprite drawn when m_Pressed is true
* @param sprite_disabled Sprite drawn when "enabled" is false
* @param icon_id Identifies the icon to be used (if the sprite contains
* icon-using images)
* @param cell_id Identifies the icon to be used (if the sprite contains
* cell-using images)
*/
void DrawButton(const CRect &rect,
const float &z,
@ -82,7 +82,7 @@ public:
CGUISpriteInstance& sprite_over,
CGUISpriteInstance& sprite_pressed,
CGUISpriteInstance& sprite_disabled,
int icon_id);
int cell_id);
/**
* Choosing which color of the following according to

View File

@ -32,6 +32,9 @@ struct CColor
return !(*this==color);
}
// For passing to glColor[34]fv:
const float* FloatArray() const { return &r; }
float r, g, b, a;
};

View File

@ -1,4 +1,4 @@
/* $Id: XeroXMB.h,v 1.7 2004/11/11 07:09:32 markt Exp $
/* $Id$
Xeromyces - XMB reading library
@ -33,8 +33,6 @@ Theoretical file structure:
XMB_File {
char Header[4]; // because everyone has one; currently "XMB0"
int Checksum; // CRC32 of original XML file, to detect changes
int ElementNameCount;
ZStrA ElementNames[];