using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TradeIdeas.TIProGUI.RealTimeStockRace
{
public partial class RealTimeStockRaceControl: UserControl
{
int _laneNumber = 0;
private PictureBox _flagPictureBox;
private LaneSizeMode _laneSize;
//private bool _showRaceCountdown = false; // Take out countdown seconds - RVH20220309
//private int _seconds; // Take out countdown seconds - RVH20220309
private const float RACE_START_SECONDS = 30;
private enum RaceLightStatus { Green, Yellow, Red };
private RaceLightStatus _raceLightStatus = RaceLightStatus.Red;
//private RaceStartControl _raceStartControl;
//RaceLaneControl _raceLaneControl;
public RealTimeStockRaceControl()
{
InitializeComponent();
}
///
/// Reset the lane number to zero.
///
public void ResetLaneNumber()
{
_laneNumber = 0;
}
public LaneSizeMode LaneSize
{
get { return _laneSize; }
set { _laneSize = value; }
}
public RaceLaneControl AddRaceLane(int top, string symbol, LaneSizeMode laneSize, double startBasedOn, string basedOnCode, string units, bool showComplimentUnits, Color symbolTextColor, int symbolWidth, bool useCompanyLogo, double? startBasedOnCompliment = null, string basedOnComplimentCode = null, bool biggestLoserWins = false, bool enableFastUpdates = true)
{
_laneSize = laneSize;
// Add a race car control
_laneNumber++;
RaceCarControl raceCarControl = new RaceCarControl(symbol, _laneNumber, symbolTextColor, symbolWidth, useCompanyLogo)
{
Top = 2,
Left = 0
};
// Add a race lane control
RaceLaneControl raceLaneControl = new RaceLaneControl(raceCarControl, symbol, _laneSize, startBasedOn, basedOnCode, units, showComplimentUnits, startBasedOnCompliment, basedOnComplimentCode, biggestLoserWins, enableFastUpdates) {
Top = top,
Left = 0,
Width = this.Width,
Anchor = AnchorStyles.Left | AnchorStyles.Right
};
this.Controls.Add(raceLaneControl);
return raceLaneControl;
}
public void RemoveAllRaceCarLanes()
{
List controlsToRemove = new List();
foreach (Control control in Controls)
{
RaceLaneControl raceLaneControl = control as RaceLaneControl;
if (raceLaneControl != null)
controlsToRemove.Add(raceLaneControl);
}
foreach (Control control in controlsToRemove)
{
Controls.Remove(control);
control.Dispose();
}
}
public void ResizeAllRaceCarLanes()
{
int lanePosition = 0;
foreach (Control control in Controls)
{
RaceLaneControl raceLaneControl = control as RaceLaneControl;
if (raceLaneControl != null)
{
raceLaneControl.Top = lanePosition;
raceLaneControl.Width = this.Width;
raceLaneControl.Invalidate();
lanePosition += RealTimeStockRaceForm.CalculateLaneRowSize(_laneSize); //LANE_HEIGHT; //30;
}
}
}
public void ShowFinishFlag()
{
_flagPictureBox = new PictureBox()
{
Image = TIProGUI.Properties.Resources.race_flag_10,
SizeMode = PictureBoxSizeMode.StretchImage,
Size = this.Size,
Location = new Point(0, 0),
BackColor = Color.Transparent
};
this.Controls.Add(_flagPictureBox);
_flagPictureBox.BringToFront();
}
public void HideFinishFlag()
{
this.Controls.Remove(_flagPictureBox);
_flagPictureBox.Dispose();
}
public void ShowRaceStart()
{
// Take out countdown seconds - RVH20220309
//_showRaceCountdown = true;
picRaceLights.Visible = true;
UpdateRaceStart(true);
// Take out countdown seconds - RVH20220309
//lblCountDown.Visible = true;
}
public void UpdateRaceStart(bool reset)
{
if (reset)
{
// Reset status to red light.
_raceLightStatus = RaceLightStatus.Red;
}
else
{
// Update status to next light.
if (_raceLightStatus == RaceLightStatus.Red)
{
// Set status to yello light.
_raceLightStatus = RaceLightStatus.Yellow;
}
else if (_raceLightStatus == RaceLightStatus.Yellow)
{
// Set status to green light.
_raceLightStatus = RaceLightStatus.Green;
}
}
// Update race light image.
switch (_raceLightStatus)
{
case RaceLightStatus.Green:
picRaceLights.Image = TIProGUI.Properties.Resources.racelights_green;
break;
case RaceLightStatus.Yellow:
picRaceLights.Image = TIProGUI.Properties.Resources.racelights_yellow;
break;
case RaceLightStatus.Red:
picRaceLights.Image = TIProGUI.Properties.Resources.racelights_red;
break;
}
}
// Take out countdown seconds - RVH20220309
//public void ShowRaceStartSeconds(int seconds)
//{
// _seconds = seconds;
// lblCountDown.Text = seconds.ToString();
// this.Invalidate();
// this.Update();
//}
public void HideRaceStart()
{
// Take out countdown seconds - RVH20220309
//_showRaceCountdown = false;
picRaceLights.Visible = false;
// Take out countdown seconds - RVH20220309
//lblCountDown.Visible = false;
//this.Invalidate();
//this.Update();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// Draw lines on race lane.
using (Pen pen = new Pen(Color.White)
{
Width = 2
})
{
e.Graphics.DrawLine(pen, Convert.ToSingle(this.Width * 0.25), 0, Convert.ToSingle(this.Width * 0.25), this.Height);
e.Graphics.DrawLine(pen, Convert.ToSingle(this.Width * 0.50), 0, Convert.ToSingle(this.Width * 0.50), this.Height);
e.Graphics.DrawLine(pen, Convert.ToSingle(this.Width * 0.75), 0, Convert.ToSingle(this.Width * 0.75), this.Height);
}
// Take out countdown seconds - RVH20220309
//if (_showRaceCountdown)
//{
// // Draw circle around seconds.
// using (Pen pen = new Pen(Color.White)
// {
// Width = 3
// })
// {
// //e.Graphics.DrawEllipse(pen, ClientRectangle);
// e.Graphics.DrawEllipse(pen, this.Width / 2 - 50, this.Height / 2 - 50, 100, 100);
// }
// // Draw arc around seconds.
// using (Pen pen = new Pen(Color.Black)
// {
// Width = 3
// })
// {
// //e.Graphics.DrawEllipse(pen, ClientRectangle);
// e.Graphics.DrawArc(pen, this.Width / 2 - 50, this.Height / 2 - 50, 100, 100, 0F, 360F * ((float)_seconds / RACE_START_SECONDS));
// }
//}
}
private void RealTimeStockRaceControl_Resize(object sender, EventArgs e)
{
picRaceLights.Left = (this.Width - picRaceLights.Width) / 2;
picRaceLights.Top = (this.Height - picRaceLights.Height) / 2;
// Take out countdown seconds - RVH20220309
//lblCountDown.Left = (this.Width - lblCountDown.Width) / 2;
//lblCountDown.Top = (this.Height - lblCountDown.Height) / 2;
ResizeAllRaceCarLanes();
Invalidate();
}
}
}