Confusion about parameters to UnifiedAreaRect

Use this forum for:
- Discussion regarding unofficial CEGUI related tools, scripts and utilities.
- User to user help for the obsoleted CELayoutEditor and CEImagesetEditor tools.

Moderators: CEGUI MVP, CEGUI Team

Evenstar
Not too shy to talk
Not too shy to talk
Posts: 26
Joined: Tue Feb 28, 2006 23:14

Confusion about parameters to UnifiedAreaRect

Postby Evenstar » Tue Feb 28, 2006 23:34

Hi,

I've recently started looking at CEGUI and have run into a problem. I am confused as to why the following code performs like it does.

Code: Select all

<?xml version="1.0" ?>
<GUILayout>
 <Window Type="DefaultWindow" Name="root">
  <Window Type="WindowsLook/FrameWindow" Name="testWindow">
   <Property Name="Position" Value="x:0 y:0" />
   <Property Name="AbsoluteHeight" Value="150" />
   <Property Name="AbsoluteWidth" Value="320" />
   <Property Name="Text" Value="Object Totals" />
   
   <Window Type="WindowsLook/StaticText" Name="CrateTotal" >
    <Property Name="BackgroundColours" Value="tl:00DFDFDF tr:00DFDFDF bl:00DFDFDF br:00DFDFDF" />
    <Property Name="Font" Value="Tahoma-12" />
    <Property Name="FrameEnabled" Value="false" />
    <Property Name="InheritsAlpha" Value="false" />
    <Property Name="ClippedByParent" Value="true" />
    <Property Name="Text" Value="test text" />
    <Property Name="TextColours" Value="tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000" />
    <Property Name="UnifiedAreaRect" Value="{{0,100},{0, 20},{1,0},{1,0}}" />
    <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" />
   </Window>

   <Window Type="WindowsLook/StaticText" Name="StaticText.000" >
    <Property Name="BackgroundColours" Value="tl:00DFDFDF tr:00DFDFDF bl:00DFDFDF br:00DFDFDF" />
    <Property Name="Font" Value="Tahoma-12" />
    <Property Name="FrameEnabled" Value="false" />
    <Property Name="InheritsAlpha" Value="false" />
    <Property Name="ClippedByParent" Value="true" />
    <Property Name="Text" Value="Crates:" />
    <Property Name="TextColours" Value="tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000" />
    <Property Name="UnifiedAreaRect" Value="{{0,10},{1, -200},{1,0},{1,0}}" />
    <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" />
   </Window>


   <Window Type="WindowsLook/StaticText" Name="SphereTotal" >
    <Property Name="BackgroundColours" Value="tl:00DFDFDF tr:00DFDFDF bl:00DFDFDF br:00DFDFDF" />
    <Property Name="Font" Value="Tahoma-12" />
    <Property Name="FrameEnabled" Value="false" />
    <Property Name="InheritsAlpha" Value="false" />
    <Property Name="ClippedByParent" Value="true" />
    <Property Name="Text" Value="test text" />
    <Property Name="TextColours" Value="tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000" />
    <Property Name="UnifiedAreaRect" Value="{{0,100},{1, -160},{1,0},{1,0}}" />
    <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" />
   </Window>

   <Window Type="WindowsLook/StaticText" Name="StaticText.001" >
    <Property Name="BackgroundColours" Value="tl:00DFDFDF tr:00DFDFDF bl:00DFDFDF br:00DFDFDF" />
    <Property Name="Font" Value="Tahoma-12" />
    <Property Name="FrameEnabled" Value="false" />
    <Property Name="InheritsAlpha" Value="false" />
    <Property Name="ClippedByParent" Value="true" />
    <Property Name="Text" Value="Spheres:" />
    <Property Name="TextColours" Value="tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000" />
    <Property Name="UnifiedAreaRect" Value="{{0,10},{1, -160},{1,0},{1,0}}" />
    <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" />
   </Window>



   <Window Type="WindowsLook/StaticText" Name="CylinderTotal" >
    <Property Name="BackgroundColours" Value="tl:00DFDFDF tr:00DFDFDF bl:00DFDFDF br:00DFDFDF" />
    <Property Name="Font" Value="Tahoma-12" />
    <Property Name="FrameEnabled" Value="false" />
    <Property Name="InheritsAlpha" Value="false" />
    <Property Name="ClippedByParent" Value="true" />
    <Property Name="Text" Value="test text" />
    <Property Name="TextColours" Value="tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000" />
    <Property Name="UnifiedAreaRect" Value="{{0,100},{1, -120},{1,0},{1,0}}" />
    <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" />
   </Window>

   <Window Type="WindowsLook/StaticText" Name="StaticText.002" >
    <Property Name="BackgroundColours" Value="tl:00DFDFDF tr:00DFDFDF bl:00DFDFDF br:00DFDFDF" />
    <Property Name="Font" Value="Tahoma-12" />
    <Property Name="FrameEnabled" Value="false" />
    <Property Name="InheritsAlpha" Value="false" />
    <Property Name="ClippedByParent" Value="true" />
    <Property Name="Text" Value="Cylinders:" />
    <Property Name="TextColours" Value="tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000" />
    <Property Name="UnifiedAreaRect" Value="{{0,10},{1, -120},{1,0},{1,0}}" />
   </Window>
  </Window>
 </Window>
</GUILayout>


The code puts the text, "test text" in the upper left hand corner. However, the document describing how to use the UnifiedAreaRect property states that the first of the two values in the curly braces represents the scale factor, and the other represents the pixel count.

What is confusing is that the absolute height of the window is set to 150. Why, then, is the text visible at all? It is supposed to appear 200 pixels above the bottom of the window (or 50 pixels above the window itself).

Calculation: (scale factor * window height) - pixel offset

or (1 * 150) + (-200) = -50

Even more perplexing is that a scale factor of 0 and a height of 10

Code: Select all


<Property Name="UnifiedAreaRect" Value="{{0,10},{0, 10},{1,0},{1,0}}" />



puts the text in the middle of the screen vertically, not at (10, 10) as would be expected. Again, the x component is correct.

Perhaps I'm missing something obvious. But it is strange that it works in the x dimension one way, and the y dimension a completely different way.

Is this a bug, or am I doing something wrong?

Thanks,
Brian

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Wed Mar 01, 2006 09:13

Hi,

to clarify: i don't see a -200 in the "test text" widget, but in the "Crates:" one.

According to your sample, i think the "test text" widget should be at 100,20 absolute.

I should run the entire file at home, to have a more in-depth look. But -50 absolute should not be visible i guess.

Evenstar
Not too shy to talk
Not too shy to talk
Posts: 26
Joined: Tue Feb 28, 2006 23:14

Postby Evenstar » Wed Mar 01, 2006 15:24

scriptkid wrote:Hi,

to clarify: i don't see a -200 in the "test text" widget, but in the "Crates:" one.


That would be because it says {0, 20}.... oops. That's what I get for trying "one more thing" before posting. It should read {-1, 200}

scriptkid wrote:According to your sample, i think the "test text" widget should be at 100,20 absolute.

I should run the entire file at home, to have a more in-depth look. But -50 absolute should not be visible i guess.


Interestingly enough, I had thought the same. In reality, however, the "test text" appears 100 pixels from the left (correct) and almost centered vertically (incorrect).

Sorry for the typo.

[edit]
I stepped into the code that processes the UnifiedAreaRect and discovered that in the Window::setWindowArea(const UVector2& pos, const UVector2& size) function, the value for size is:

size.d_x.d_scale = 1.0
size.d_x.d_offset = -100
size.d_y.d_scale = 0.0
size.d_y.d_offset = 200

The original text was "{{0,100},{1, -200},{1,0},{1,0}}"

These values seem exactly opposite. Without knowing how the code works, I can only ask if this correct?


[edit]

Further testing reveals that using

Code: Select all

<Property Name="UnifiedAreaRect" Value="{{0,0},{0, 0},{1,0},{1,0}}" />


positions the text on the left edge of the screen, centered vertically.

Code: Select all

<Property Name="UnifiedAreaRect" Value="{{0,0},{1, -12},{1,0},{1,0}}" />


positions the text on the left edge and displays the top half portion of the text (it peeks above the bottom-most edge)

Code: Select all

<Property Name="UnifiedAreaRect" Value="{{0,0},{1, -24},{1,0},{1,0}}" />


positions the text on the left edge even with the bottom of the window.

Because I'm using a 12pt font, it appears that the calculation is way off. First, it is seeing (0, 0) as the leftmost center. Second, the fact I have to offset double what I should implies there is a wrong scale factor somewhere.

Hope this helps.
Brian

Evenstar
Not too shy to talk
Not too shy to talk
Posts: 26
Joined: Tue Feb 28, 2006 23:14

Postby Evenstar » Wed Mar 01, 2006 17:53

I discovered what I am doing wrong. I needed to add the following properties to my static text items...

Code: Select all

<Property Name="VertFormatting" Value="TopAligned" />
<Property Name="HorzFormatting" Value="LeftAligned" />


Now they show up close to where I think they should.

:hammer:


Brian

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Wed Mar 01, 2006 21:17

Hi,

good to hear! I've loaded your layout in the editor and played around for a bit. When you don't add the alignment properties is seems to center the height, what you were saying. This is correct, since 150/2 - 20/2 = 65, which is the location of the text.

But i don't know why the offsets are swapped (your previous message). I will have to look into the code to be sure.

Good luck anyway and thanks for all the details of your research :-)

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Thu Mar 02, 2006 10:26

I sense a bit of confusion about the unified system, and especially the scale parameter. The things are explained in the introduction to UDim in the Falagard docs, before you get to the UnifiedRect parts, but here is the info for UnifiedAreaRect presented in a different way...

The core of the system is the UDim, and the compund structs (URect, UVector2) are built out of UDIms, so the information is extended to those.

A UDIm has a 'scale' component, which forms a value that is relative to the parent object (not the pixel offset, or any other value), and an 'offset' value, which is added to the result of the scale component:

If this were a co-ord on the x axis:

Code: Select all

{0.5,300}

The calculation is this:

Code: Select all

final_x = ((0.5 * parent_width) + 300


So, you just extend this theory for each of the component parts of the UnifiedAreaRect. In this we have four discreet component UDim specifications, the first is for the left edge, the second for the top edge, the third for the right edge, and the last is for the bottom edge. The important thing is that they are seperate entities, no part of the inner {s,o} components have any effect on any of the other 3.

HTH

CE


Return to “Unofficial CEGUI-Related Tools”

Who is online

Users browsing this forum: No registered users and 13 guests