@@ -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
@@ -3247,45 +3248,46 @@ public void UpdateDigit()
32473248
32483249 Material UsedMaterial = FindMaterial ( ) ;
32493250
3250- float length = CVFR . GetRangeFraction ( ) ;
3251+ float length = CVFR . GetRangeFraction ( true ) ;
32513252
32523253 CVCGauge gauge = CVFR . GetGauge ( ) ;
32533254
32543255 var len = maxLen * length ;
3256+ var absLen = Math . Abs ( len ) ;
32553257 Vertex v1 , v2 , v3 , v4 ;
32563258
32573259 //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;
32583260 v1 = new Vertex ( 0f , 0f , 0.002f , 0 , 0 , - 1 , 0f , 0f ) ;
32593261
32603262 if ( Orientation == 0 )
32613263 {
3262- if ( Direction == 0 ) //moving right
3264+ if ( Direction == 0 ^ len < 0 ) //moving right
32633265 {
32643266 //other vertices
32653267 v2 = new Vertex ( 0f , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3266- v3 = new Vertex ( len , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3267- v4 = new Vertex ( len , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3268+ v3 = new Vertex ( absLen , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3269+ v4 = new Vertex ( absLen , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
32683270 }
32693271 else //moving left
32703272 {
32713273 v4 = new Vertex ( 0f , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3272- v3 = new Vertex ( - len , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3273- v2 = new Vertex ( - len , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3274+ v3 = new Vertex ( - absLen , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3275+ v2 = new Vertex ( - absLen , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
32743276 }
32753277 }
32763278 else
32773279 {
3278- if ( Direction == 1 ) //up
3280+ if ( Direction == 1 ^ len < 0 ) //up
32793281 {
32803282 //other vertices
3281- v2 = new Vertex ( 0f , len , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3282- v3 = new Vertex ( width , len , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3283+ v2 = new Vertex ( 0f , absLen , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3284+ v3 = new Vertex ( width , absLen , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
32833285 v4 = new Vertex ( width , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
32843286 }
32853287 else //moving down
32863288 {
3287- v4 = new Vertex ( 0f , - len , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3288- v3 = new Vertex ( width , - len , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3289+ v4 = new Vertex ( 0f , - absLen , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3290+ v3 = new Vertex ( width , - absLen , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
32893291 v2 = new Vertex ( width , 0 , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
32903292 }
32913293 }
0 commit comments