GUI/SharpDisplay.cs
branchMiniDisplay
changeset 446 0cb7b9f6a6f8
parent 445 fe4c711fd7f8
child 447 af40a92d480d
     1.1 --- a/GUI/SharpDisplay.cs	Sun Sep 21 21:55:36 2014 +0200
     1.2 +++ b/GUI/SharpDisplay.cs	Mon Sep 22 21:59:11 2014 +0200
     1.3 @@ -30,15 +30,18 @@
     1.4          private IComputer computer;
     1.5          private PersistentSettings settings;
     1.6          private UnitManager unitManager;
     1.7 -        private List<SensorSharpDisplay> list = new List<SensorSharpDisplay>();
     1.8 +        private List<SensorSharpDisplay> iSensors = new List<SensorSharpDisplay>();
     1.9          private global::SharpDisplay.Client iClient;
    1.10          TextField iTextFieldTop;
    1.11          TextField iTextFieldBottom;
    1.12 +        TextField iTextFieldTopRight;
    1.13 +        TextField iTextFieldBottomRight;
    1.14 +
    1.15          TextField[] iTextFields;
    1.16  
    1.17          private int iNextSensorToDisplay = 0;
    1.18          private int iTickCounter = 0;
    1.19 -
    1.20 +        bool iPacked = false;
    1.21  
    1.22          public SharpDisplay(IComputer computer, PersistentSettings settings, UnitManager unitManager)
    1.23          {
    1.24 @@ -54,6 +57,9 @@
    1.25              //
    1.26              iTextFieldTop = new TextField(0);
    1.27              iTextFieldBottom = new TextField(1);
    1.28 +            iTextFieldTopRight = new TextField(2, "", ContentAlignment.MiddleRight);
    1.29 +            iTextFieldBottomRight = new TextField(3, "", ContentAlignment.MiddleRight);
    1.30 +
    1.31              iTextFields = new TextField[] { iTextFieldTop, iTextFieldBottom };
    1.32  
    1.33          }
    1.34 @@ -108,7 +114,7 @@
    1.35  
    1.36          public void Dispose()
    1.37          {
    1.38 -            foreach (SensorSharpDisplay icon in list)
    1.39 +            foreach (SensorSharpDisplay icon in iSensors)
    1.40                  icon.Dispose();
    1.41  
    1.42              Quit();            
    1.43 @@ -125,19 +131,45 @@
    1.44              string packedSecondLine = "";
    1.45              int count = 0;
    1.46  
    1.47 -            string time = DateTime.Now.ToShortTimeString();
    1.48 +            //string time = DateTime.Now.ToShortTimeString();
    1.49 +            string time = DateTime.Now.ToLongTimeString();
    1.50 +
    1.51 +            if (iSensors.Count > 0)
    1.52 +            {
    1.53 +                if (iPacked != aPacked)
    1.54 +                {
    1.55 +                    //Remember mode
    1.56 +                    iPacked = aPacked;
    1.57 +
    1.58 +                    if (iPacked)
    1.59 +                    {
    1.60 +                        //We just switched to packed mode                    
    1.61 +                        //Make sure our layout is proper
    1.62 +                        TableLayout layout = new TableLayout(2, 2);
    1.63 +                        iClient.SetLayout(layout);
    1.64 +                    }
    1.65 +                    else
    1.66 +                    {
    1.67 +                        //Non packed mode
    1.68 +                        TableLayout layout = new TableLayout(1, 2);
    1.69 +                        iClient.SetLayout(layout);
    1.70 +                    }
    1.71 +                }
    1.72 +            }
    1.73 +
    1.74  
    1.75              //Update all sensors from our front view
    1.76 -            foreach (SensorSharpDisplay sensor in list)
    1.77 +            foreach (SensorSharpDisplay sensor in iSensors)
    1.78              {
    1.79                  count++;
    1.80                  sensor.Update();
    1.81  
    1.82                  if (aDisplayTime && count == 1)
    1.83                  {
    1.84 -                    //First slot is take by time display
    1.85 +                    //First slot is taken by time display
    1.86                      count++;
    1.87 -                    packedFirstLine = time + " ";
    1.88 +                    iTextFieldTop.Text = time;
    1.89 +                    iClient.SetText(iTextFieldTop);
    1.90                  }
    1.91  
    1.92                  if (aPacked)
    1.93 @@ -147,39 +179,33 @@
    1.94                      packedText = sensor.iFirstLine.Substring(0, 3) + ":" + sensor.iSecondLine;
    1.95                      if (count == 1)
    1.96                      {
    1.97 -                        packedFirstLine = packedText + " "; //Minimum one space to separate sensors on the same line
    1.98 +                        iTextFieldTop.Text = packedText;
    1.99 +                        iClient.SetText(iTextFieldTop);
   1.100                      }
   1.101                      else if (count == 2)
   1.102                      {
   1.103 -                        //Add enough spaces to align to right hand side
   1.104 -                        while (packedFirstLine.Length + packedText.Length < KMaxCharacterPerLine)
   1.105 -                        {
   1.106 -                            packedFirstLine += " ";
   1.107 -                        }
   1.108 -                        packedFirstLine += packedText;
   1.109 +                        iTextFieldBottom.Text = packedText;
   1.110 +                        iClient.SetText(iTextFieldBottom);
   1.111                      }
   1.112                      else if (count == 3)
   1.113                      {
   1.114 -                        packedSecondLine = packedText + " "; //Minimum one space to separate sensors on the same line
   1.115 +                        iTextFieldTopRight.Text = packedText;
   1.116 +                        iClient.SetText(iTextFieldTopRight);
   1.117                      }
   1.118                      else if (count == 4)
   1.119                      {
   1.120 -                        //Add enough spaces to align to right hand side
   1.121 -                        while (packedSecondLine.Length + packedText.Length < KMaxCharacterPerLine)
   1.122 -                        {
   1.123 -                            packedSecondLine += " ";
   1.124 -                        }
   1.125 -                        packedSecondLine += packedText;
   1.126 +                        iTextFieldBottomRight.Text = packedText;
   1.127 +                        iClient.SetText(iTextFieldBottomRight);
   1.128                      }
   1.129                  }
   1.130 -                //SetText(sensor.iFirstLine, sensor.iSecondLine);
   1.131              }
   1.132  
   1.133              //Alternate between sensors 
   1.134 -            if (list.Count > 0)
   1.135 +            if (iSensors.Count > 0)
   1.136              {
   1.137                  if (aPacked)
   1.138                  {
   1.139 +                    //Review that stuff cause as it is it's probably useless
   1.140                      //string packedLine = "";
   1.141                      iTickCounter++;
   1.142                      if (iTickCounter == KNumberOfTickBeforeSwitch) //Move to the next sensor only every so many tick
   1.143 @@ -194,16 +220,10 @@
   1.144                              iNextSensorToDisplay = 1;
   1.145                          }
   1.146                      }
   1.147 -
   1.148 -                    //TODO: Do something like that to cycle lines if ever we want to
   1.149 -                    //SetText(time, (iNextSensorToDisplay == 1 && packedSecondLine.Length > 0 ? packedSecondLine : packedFirstLine));
   1.150 -
   1.151 -                    //Display packed sensors on our FrontView display
   1.152 -                    SetText(packedFirstLine, packedSecondLine);
   1.153                  }
   1.154                  else
   1.155                  {
   1.156 -                    string secondLine = list[iNextSensorToDisplay].iSecondLine;
   1.157 +                    string secondLine = iSensors[iNextSensorToDisplay].iSecondLine;
   1.158                      if (aDisplayTime)
   1.159                      {
   1.160                          //Add enough spaces
   1.161 @@ -214,7 +234,7 @@
   1.162                          secondLine += time;
   1.163                      }
   1.164                      //Display current sensor on our FrontView display
   1.165 -                    SetText(list[iNextSensorToDisplay].iFirstLine, secondLine);
   1.166 +                    SetText(iSensors[iNextSensorToDisplay].iFirstLine, secondLine);
   1.167                      iTickCounter++;
   1.168                      if (iTickCounter == KNumberOfTickBeforeSwitch) //Move to the next sensor only every so many tick
   1.169                      {
   1.170 @@ -224,7 +244,7 @@
   1.171                  }
   1.172              }
   1.173  
   1.174 -            if (iNextSensorToDisplay == list.Count)
   1.175 +            if (iNextSensorToDisplay == iSensors.Count)
   1.176              {
   1.177                  //Go back to first sensor
   1.178                  iNextSensorToDisplay = 0;
   1.179 @@ -235,7 +255,7 @@
   1.180  
   1.181          public bool Contains(ISensor sensor)
   1.182          {
   1.183 -            foreach (SensorSharpDisplay icon in list)
   1.184 +            foreach (SensorSharpDisplay icon in iSensors)
   1.185                  if (icon.Sensor == sensor)
   1.186                      return true;
   1.187              return false;
   1.188 @@ -250,11 +270,11 @@
   1.189              else
   1.190              {
   1.191                  //SL:
   1.192 -                list.Add(new SensorSharpDisplay(this, sensor, balloonTip, settings, unitManager));
   1.193 +                iSensors.Add(new SensorSharpDisplay(this, sensor, balloonTip, settings, unitManager));
   1.194                  //UpdateMainIconVisibilty();
   1.195                  settings.SetValue(new Identifier(sensor.Identifier, "SharpDisplay").ToString(), true);
   1.196                  iNextSensorToDisplay = 0;
   1.197 -                if (list.Count == 1)
   1.198 +                if (iSensors.Count == 1)
   1.199                  {
   1.200                      //Just added first sensor in FrontView, unable FrontView plug-in mode
   1.201                      Init();
   1.202 @@ -267,7 +287,7 @@
   1.203          {
   1.204              Remove(sensor, true);
   1.205              iNextSensorToDisplay = 0;
   1.206 -            if (list.Count == 0)
   1.207 +            if (iSensors.Count == 0)
   1.208              {
   1.209                  //No sensor to display in FrontView, just disable FrontView plug-in mode
   1.210                  Uninit();
   1.211 @@ -283,12 +303,12 @@
   1.212                    new Identifier(sensor.Identifier, "SharpDisplay").ToString());
   1.213              }
   1.214              SensorSharpDisplay instance = null;
   1.215 -            foreach (SensorSharpDisplay icon in list)
   1.216 +            foreach (SensorSharpDisplay icon in iSensors)
   1.217                  if (icon.Sensor == sensor)
   1.218                      instance = icon;
   1.219              if (instance != null)
   1.220              {
   1.221 -                list.Remove(instance);
   1.222 +                iSensors.Remove(instance);
   1.223                  //UpdateMainIconVisibilty();
   1.224                  instance.Dispose();
   1.225              }