AnimatGuiCtrls.Controls.TimeRuler.DrawControl C# (CSharp) Method

DrawControl() private method

private DrawControl ( Graphics graphics ) : void
graphics System.Drawing.Graphics
return void
		private void DrawControl(Graphics graphics)
		{
			if(this.Width == 0 || this.Height == 0)
				return;

			_bInsideDraw = true;
			Graphics g = null;

			if(_CurrentFrame == null)
			{
				_CurrentFrame = new KeyFrameCurrent(_lCurrentMillisecond);
				_aryKeyFrames.Add(_CurrentFrame, true);
			}

			RecalculateZoom();
			RecalculateTimeScale();

			if (_Bitmap == null)
			{

				//Debug.WriteLine("TimeRuler Size: (" + this.Width.ToString() + ", " + this.Height.ToString() + ")");

				// Create a bitmap
				_Bitmap = new Bitmap(this.Width, this.Height);

				g = Graphics.FromImage(_Bitmap);

				try
				{
					// Wash the background with BackColor
					//Lets wash the whole thing out with the parent back color
					g.FillRectangle(new SolidBrush(this.Parent.BackColor), 0, 0, _Bitmap.Width, _Bitmap.Height);

					//Lets only draw the ruler portion of this in the control back color.
					if (this.Orientation == enumOrientation.orHorizontal)
					{
						int iHeight = _Bitmap.Height - _iHeaderOffset;
						g.FillRectangle(new SolidBrush(this.BackColor), _iSideOffset, _iHeaderOffset, _iDisplaySize, iHeight);
						Line(g, _iSideOffset, _iHeaderOffset, (_iDisplaySize + _iSideOffset), _iHeaderOffset);
					}
					else
					{
						int iWidth = _Bitmap.Width - _iHeaderOffset;
						g.FillRectangle(new SolidBrush(this.BackColor), _iHeaderOffset, _iSideOffset, iWidth, _iDisplaySize);
						Line(g, _iHeaderOffset, _iSideOffset, _iHeaderOffset, (_iDisplaySize + _iSideOffset));
					}

					DrawTimeScale(g);
					DrawProgressBars(g);
					_aryKeyFrames.Draw(g);

					// Paint the lines on the image
					int iScale = (int) _Scale;
					int intScale = (int) _Scale;

					int iStart = Start();
					int iEnd = iStart + _iDisplaySize + 1;
					float fltStart = (float) iStart;
					float fltEnd = (float) iEnd;

					int j;
					for(float fltJ = fltStart; fltJ <= fltEnd; fltJ += _Scale)
					{
						j = (int) fltJ;
						int iLeft = (int) _Scale;  // Make an assumption that we're starting at zero or on a major increment
						int jOffset = j+_ScaleStartValue;

						if (_RulerAlignment != enumRulerAlignment.raMiddle)
						{
							if (this.Orientation == enumOrientation.orHorizontal)
								Line(g, j, _iHeaderOffset, j, Height);
							else
								Line (g, _iHeaderOffset, j, Width, j);
						}

						iLeft = intScale;     // Set the for loop increment

						iScale = iLeft;

						int iValue = (((jOffset-iStart)/intScale)+1) * _iMajorInterval;
						DrawValue(g, iValue, j - iStart, iScale);

						int iUsed = 0;

						//Draw small lines
						for(int i = 0; i < _iNumberOfDivisions; i++)
						{
							int iX = Convert.ToInt32(Math.Round((double)(_Scale-iUsed)/(double)(_iNumberOfDivisions - i),0)); // Use a spreading algorithm rather that using expensive floating point numbers
							iUsed += iX;

							if (iUsed >= (intScale-iLeft))
							{
								iX = iUsed+j-(intScale-iLeft);

								// Is it an even number and, if so, is it the middle value?
								bool bMiddleMark = ((_iNumberOfDivisions & 0x1) == 0) & (i+1==_iNumberOfDivisions/2);
								bool bShowMiddleMark = bMiddleMark;
								bool bLastDivisionMark = (i+1 == _iNumberOfDivisions);
								bool bLastAlignMiddleDivisionMark =  bLastDivisionMark & (_RulerAlignment == enumRulerAlignment.raMiddle);
								bool bShowDivisionMark = !bMiddleMark & !bLastAlignMiddleDivisionMark;

								if( _RulerAlignment == enumRulerAlignment.raMiddle || !bLastDivisionMark )
								{
									if (bShowMiddleMark)
									{
										DivisionMark(g, iX, _MiddleMarkFactor);  // Height or Width will be 1/3
									} 
									else if (bShowDivisionMark)
									{
										DivisionMark(g, iX, _DivisionMarkFactor);  // Height or Width will be 1/5
									}
								}
							}
						}
					}
					
					if (_i3DBorderStyle != Border3DStyle.Flat)
						ControlPaint.DrawBorder3D(g, this.ClientRectangle, this._i3DBorderStyle );

				}
				catch(Exception ex)
				{
					System.Diagnostics.Debug.WriteLine(ex.Message);
				}
				finally 
				{
					g.Dispose();
				}
			}

			g = graphics;

			try
			{

				// Always draw the bitmap
				g.DrawImage(_Bitmap, this.ClientRectangle);

				RenderTrackLine(g);
			}
			catch(Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.Message);
			}
			finally
			{
				_bInsideDraw = false;
				GC.Collect();
			}

		}