FS2004 What does RelClip mean? FS2004 Gauge Code

#1
Hey all,

What does this mean?

<RelClip Left="0" Top="0" Width="1000" Height="500"/>

RelClip...

Reel Clipping of video footage? Reflective Ethylene Laminates clippings? Realizational elemental Lamentations texts? Really expensive lines clippages? Realestate in Ethiopian Lombatu district?

Dare I go on... My XML Code References that has things even from other worlds concerning FS9 coding, does not have this... Maybe my security clearance isnt good enough. :(


Bill of the gray people.. well. I guess my hair is white now... Bill of the white haired people...
 
#2
RelClip and Clip are used to crop element display objects like bmps, polygons, gps maps... The attributes are Top, Left, Bottom, Right, Width, and Height. Note that what is "clipped" remains displayed, not cut out.

RelClip is short for Relative Clip and its top left position is relative to the top left position of the affected image. With Clip, on the other hand, top and left are absolute references.

The clips in the two Elements below do the same thing, but demonstrate the difference between Clip and RelClip
XML:
<Element>
    <Position X="200" Y="300"/>          
        <Image Name="PictureA.bmp"/>
        <RelClip Top="0" Left="0" Width="75" Height="20"/>
</Element>  

<Element>
    <Position X="200" Y="300"/>          
        <Image Name="PictureA.bmp"/>
        <Clip Top="300" Left="200" Width="75" Height="20"/>
</Element>

Bob
 
#5
Another couple of points regarding Clip and RelClip:

  • Height and Width can be varied dynamically (as the sim is running) using <HeightCode> and <WidthCode>. For example: (umm, still working this one ...)
XML:
<Element Name="PURPLE RECTANGLE HEIGHTCODE EXAMPLE">
    <Position X="5" Y="300"/>
    <Rectangle Width="100" Height="200" FillColor="purple" Bright="Yes" />
        <RelClip>
            <HeightCode>(L:HeightCode, number)</HeightCode>
            <WidthCode>(L:WidthCode, number)</WidthCode>   
        </RelClip>
</Element>
As (L:HeightCode, number) and (L:WidthCode, number) change, so will the clip area.

  • AFAIK, Clip and RelClip can be applied only to individual Elements. I've tried to apply a clip to a collection, a group, of Elements, but always without success. So far.

  • As well, <HeightCode> and <WidthCode> can be applied to the Rectangle object itself. I don't believe these can be applied to <Image> objects, however ...
XML:
<Element Name="PURPLE RECTANGLE HEIGHTCODE EXAMPLE 2">
    <Position X="5" Y="300"/>
    <Rectangle Width="100" Height="200" FillColor="purple" Bright="Yes">
        <HeightCode>(L:HeightCode, enum)</HeightCode>
        <WidthCode>(L:WidthCode, enum)</WidthCode>           
    </Rectangle>   
</Element>
Other examples of RelClip, HeightCode and WidthCode can be found in the stock gps_500.xml gauge.

BTW, tested using FS9 schema xml test gauges.

Bob
 
Last edited:

Heretic

Resource contributor
#10
Dynamic width and height sizes are great for something like progress or fluid level bars.

Here's an example that takes its values from various macros defined at the beginning of the gauge, so that you won't have to dig through the entire rest of it if you want to change a property.
You'll need a background box defined before your progress bar to have it drawn first, hence the first element.
The "Shift" element controls the top left corner of the "dynamic rectangle" and is controlled by a bit of math with a value cap to avoid it being drawn out of the visual boundary rectangle defined above. Since this is a vertical bar, y scale is "-1".
The rectangle object of the element is then used to dynamically "fill" the boundary box from the top left corner to the bottom.
Code:
<Element><Position X="@PayloadBox9_X" Y="@PayloadBox9_Y"/>
<Element><Rectangle Width="@PayloadBox9_W" Height="@PayloadBox9_H" Color="@StnBoxFrmClr" FillColor="@StnBoxFillClr" LineWidth="1" Bright="Yes"/></Element>
<Element><Position X="0" Y="@PayloadBox9_H"/>
<Shift><Value>(A:PAYLOAD STATION WEIGHT:@PayloadBox9_Index, pounds) @PayloadBox9_H @PayloadBox9_Limit / * @PayloadBox9_H min</Value><Scale Y="-1"/></Shift>
<Rectangle Width="@PayloadBox9_W" Height="@PayloadBox9_H" Color="@StnBoxFrmClr" FillColor="@StnBoxBarClr" LineWidth="1" Bright="Yes"><HeightCode>(A:PAYLOAD STATION WEIGHT:@PayloadBox9_Index, pounds) @PayloadBox9_H @PayloadBox9_Limit / * @PayloadBox9_H min</HeightCode></Rectangle>
</Element>
</Element>
Horizontal bars are a bit less tricky as their top left corner doesn't need to be shifted (unless you want a bar to fill from right to left).
 
#11
Bill L. and Bjoern, those are great examples to give readers ideas of how <HeightCode> can be used. I think it adds quite a lot to this discussion, so thanks very much.

Bjoern, instead of adjusting the height of the progress bar, what about a "100%" progress rectangle overlain by a <HeightCode> "mask" rectangle (e.g., FillColor="#101010 or appropriate) whose height expands downward as progress diminishes?

Bob
 

Heretic

Resource contributor
#12
Bjoern, instead of adjusting the height of the progress bar, what about a "100%" progress rectangle overlain by a <HeightCode> "mask" rectangle (e.g., FillColor="#101010 or appropriate) whose height expands downward as progress diminishes?
Possible, yes, but too simple. :p
 

Heretic

Resource contributor
#14
Good point. What was I thinking?
It also depends on the background coloring. If you want things to appear transparent or something, you'd have to get the color of the mask exactly right, which would make it difficult when using a background bitmap image.
 
#15
I am trying to break down how this code works and with Bjoerns coding with Macros, I just dont see how this works...

Bjoern, you say that you are moving this both ways in your code (on another post) and I see a math system using / * above;

Code:
<Element><Position X="@PayloadBox9_X" Y="@PayloadBox9_Y"/>
<Element><Rectangle Width="@PayloadBox9_W" Height="@PayloadBox9_H" Color="@StnBoxFrmClr" FillColor="@StnBoxFillClr" LineWidth="1" Bright="Yes"/></Element>
<Element><Position X="0" Y="@PayloadBox9_H"/>
<Shift><Value>(A:PAYLOAD STATION WEIGHT:@PayloadBox9_Index, pounds) @PayloadBox9_H @PayloadBox9_Limit / * @PayloadBox9_H min</Value><Scale Y="-1"/></Shift>
<Rectangle Width="@PayloadBox9_W" Height="@PayloadBox9_H" Color="@StnBoxFrmClr" FillColor="@StnBoxBarClr" LineWidth="1" Bright="Yes"><HeightCode>(A:PAYLOAD STATION WEIGHT:@PayloadBox9_Index, pounds) @PayloadBox9_H @PayloadBox9_Limit / * @PayloadBox9_H min</HeightCode></Rectangle>
</Element>
</Element>
Its like, with this Macro going on, I see blah blah blah blah... with / *
I do not understand this one bit... :(
You are leading me to see a timer in this. Where in the world would the timer be?
 

Heretic

Resource contributor
#16
Put the timer aside for now.

Here's the macro section that belongs to the bar's code posted above:
Code:
<!--
Macro PayloadBox[n]_Index - Is the payload station index as specified in the aircraft.cfg or FSX load manager (start count at 1)
Macro PayloadBox[n]_Limit - Is the payload station weight limit in lbs (1 lbs = 0.453592 kg)
Macro PayloadBox[n]_X - X axis position of payload station box in the aircraft manager window
Macro PayloadBox[n]_Y - Y axis position of payload station box in the aircraft manager window
Macro PayloadBox[n]_W - Width of the payload station box
Macro PayloadBox[n]_H - Height of the payload station box
-->
<Macro Name="PayloadBox9_Index">9</Macro>
<Macro Name="PayloadBox9_Limit">3300</Macro>
<Macro Name="PayloadBox9_X">200</Macro><Macro Name="PayloadBox9_Y">470</Macro>
<Macro Name="PayloadBox9_W">40</Macro><Macro Name="PayloadBox9_H">80</Macro>

<!-- FRAME COLOR of the payload/fuel station boxes -->
<Macro Name="StnBoxFrmClr">#fafafa</Macro>
<!-- FILL COLOR of the payload/fuel/door station boxes -->
<Macro Name="StnBoxFillClr">#747474</Macro>
<!-- BAR COLOR of the payload/fuel station boxes -->
<Macro Name="StnBoxBarClr">darkgreen</Macro>
Macros provide an easy way to avoid having to write repetitive code. The gauge parser stores the names and the associated values of the macros in memory and when it encounters references to said names (the "@..." thingys) in the remainder of the gauge script, it will assign the values it has stored for those names. "Height=@PayloadBox9_H" will therefor turn into "Height=80". Like variables in algebra.
Replace all the "@..." macro references in my above script with the associated value from the macro section and you will see what I mean.

The equation to shift the Y position of the top left corner of the rectangle that is used to fill the bar is necessary because gauge rectangles are always drawn from the top left. Good for horizontal bars, bad for vertical bars that are supposed to fill from the bottom. If you look closely, the equation is duplicated to specify the height of the rectangle itself as well.

This is the equation driving the origin and height of the bar graph:
Code:
(A:PAYLOAD STATION WEIGHT:@PayloadBox9_Index, pounds) @PayloadBox9_H @PayloadBox9_Limit / * @PayloadBox9_H min
With the numbers from the macros filled in:
Code:
(A:PAYLOAD STATION WEIGHT:9, pounds) 80 3300 / * 80 min
The frame of the bar graph indicating the payload station's weight has a fixed height of 80 pixel, but the payload station can take any value, i.e. weight that I want. So without that equation, any station weight greater than 80 lbs would make the bar grow beyond its frame.
Since this would look awfully dumb, I need something to limit the bar, therefor I assign a maximum value to the station, in this case 3300 lbs*. However, 3300 lbs is still way too high a number for the frame. So therefor, I need a scale value to slow the bar's height growth and to ensure that it's completely filled at 3300 lbs. Hence, I didvide the maximum height for the bar by the maximum value for the payload station: 80 / 3300 = 0.024242424.... For every lbs of payload, the bar will increase its height by 0.0242424... pixel. Multiplied with the current payload station weight, say 695 lbs, the resulting bar will therefor be 16.848484... = 17 pixel high (automatic rounding).
As a last safeguard, I tell the gauge parser that 80 pixel really is the absolute maximum value that the result of this mathematical operation should have. Hence the "80 min" (remember XML's handling of minimum and maximum values).

And that's all there is to it.
If you have a simulation variable that can't have values greater than 100 (e.g. landing gear percentage) and your bar's frame is 100 pixel high, you can even do away with the scaling factor and maximum value limiter. But I like to keep them in.


If you got this worked out, we can talk about how to drive the bar height's control variable with a timer.



(* How to limit payload station weights is an entirely different bit of science. It involves XMLTools.)
 
Last edited:
Top