@@ -1468,7 +1468,7 @@ public CABViewControlTypes GetControlType()
14681468 /// Gets the requested Locomotive data and returns it as a fraction (from 0 to 1) of the range between Min and Max values.
14691469 /// </summary>
14701470 /// <returns>Data value as fraction (from 0 to 1) of the range between Min and Max values</returns>
1471- public float GetRangeFraction ( )
1471+ public float GetRangeFraction ( bool offsetFromZero = false )
14721472 {
14731473 var data = Locomotive . GetDataOf ( Control ) ;
14741474 if ( data < Control . MinValue )
@@ -1479,7 +1479,7 @@ public float GetRangeFraction()
14791479 if ( Control . MaxValue == Control . MinValue )
14801480 return 0 ;
14811481
1482- return ( float ) ( ( data - Control . MinValue ) / ( Control . MaxValue - Control . MinValue ) ) ;
1482+ return ( float ) ( ( data - ( offsetFromZero && Control . MinValue < 0 ? 0 : Control . MinValue ) ) / ( Control . MaxValue - Control . MinValue ) ) ;
14831483 }
14841484
14851485 public CABViewControlStyles GetStyle ( )
@@ -1630,7 +1630,8 @@ public CabViewGaugeRenderer(Viewer viewer, MSTSLocomotive locomotive, CVCFirebox
16301630
16311631 public color GetColor ( out bool positive )
16321632 {
1633- if ( Locomotive . GetDataOf ( Control ) < 0 ) { positive = false ; return Gauge . NegativeColor ; }
1633+ if ( Locomotive . GetDataOf ( Control ) < 0 )
1634+ { positive = false ; return Gauge . NegativeColor ; }
16341635 else { positive = true ; return Gauge . PositiveColor ; }
16351636 }
16361637
@@ -3251,45 +3252,46 @@ public void UpdateDigit()
32513252
32523253 Material UsedMaterial = FindMaterial ( ) ;
32533254
3254- float length = CVFR . GetRangeFraction ( ) ;
3255+ float length = CVFR . GetRangeFraction ( true ) ;
32553256
32563257 CVCGauge gauge = CVFR . GetGauge ( ) ;
32573258
32583259 var len = maxLen * length ;
3260+ var absLen = Math . Abs ( len ) ;
32593261 Vertex v1 , v2 , v3 , v4 ;
32603262
32613263 //the left-bottom vertex if ori=0;dir=0, right-bottom if ori=0,dir=1; left-top if ori=1,dir=0; left-bottom if ori=1,dir=1;
32623264 v1 = new Vertex ( 0f , 0f , 0.002f , 0 , 0 , - 1 , 0f , 0f ) ;
32633265
32643266 if ( Orientation == 0 )
32653267 {
3266- if ( Direction == 0 ) //moving right
3268+ if ( Direction == 0 ^ len < 0 ) //moving right
32673269 {
32683270 //other vertices
32693271 v2 = new Vertex ( 0f , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3270- v3 = new Vertex ( len , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3271- v4 = new Vertex ( len , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3272+ v3 = new Vertex ( absLen , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3273+ v4 = new Vertex ( absLen , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
32723274 }
32733275 else //moving left
32743276 {
32753277 v4 = new Vertex ( 0f , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3276- v3 = new Vertex ( - len , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3277- v2 = new Vertex ( - len , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3278+ v3 = new Vertex ( - absLen , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3279+ v2 = new Vertex ( - absLen , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
32783280 }
32793281 }
32803282 else
32813283 {
3282- if ( Direction == 1 ) //up
3284+ if ( Direction == 1 ^ len < 0 ) //up
32833285 {
32843286 //other vertices
3285- v2 = new Vertex ( 0f , len , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3286- v3 = new Vertex ( width , len , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3287+ v2 = new Vertex ( 0f , absLen , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3288+ v3 = new Vertex ( width , absLen , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
32873289 v4 = new Vertex ( width , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
32883290 }
32893291 else //moving down
32903292 {
3291- v4 = new Vertex ( 0f , - len , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3292- v3 = new Vertex ( width , - len , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3293+ v4 = new Vertex ( 0f , - absLen , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3294+ v3 = new Vertex ( width , - absLen , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
32933295 v2 = new Vertex ( width , 0 , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
32943296 }
32953297 }
0 commit comments