public override void Run()
        {
            try
            {
                using (var bmp = new Bitmap(Dimensions.Width, Dimensions.Height))
                {
                    bmp.DrawLine(Colors.Red, 1,
                                 Dimensions.Width/2, Dimensions.Height/2,
                                 Dimensions.Width, Dimensions.Height/2);

                    bmp.DrawLine(Colors.Green, 1,
                                 Dimensions.Width/2, Dimensions.Height/2,
                                 Dimensions.Width/2, 0);

                    bmp.Flush();
                }

                Thread.Sleep(3000);
                Pass = true;
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#2
0
        public static void Main()
        {
            LCD myApplication = new LCD();

            Window mainWindow = myApplication.CreateWindow();
            
            // Start the application
            //myApplication.Run(mainWindow);

            Bitmap bitmap1 = new Bitmap(SystemMetrics.ScreenWidth,SystemMetrics.ScreenHeight);
            Bitmap bitmap2 = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);

            int ox = 0;
            int oy = 0;
            int rx = bitmap1.Width;
            int ry = bitmap1.Height;
            int sd=0;
            if (rx < ry)
                sd = rx;
            else
                sd = ry;


	    //
	    // Draw Diagonals
	    //
            bitmap1.DrawLine(Colors.Blue, 3, 0, 0, rx, ry);
            bitmap1.DrawLine(Colors.Blue, 3, rx, 0, 0, ry);

            bitmap2.DrawLine(Colors.Red, 3, 0, 0, rx, ry);
            bitmap2.DrawLine(Colors.Red, 3, rx, 0, 0, ry);


            for(int ioff=0; ioff < sd; ioff += 10)
	    {
		int oX  = ox+ioff;
		int oY  = oy+ioff;
		int wX  = rx - 2*ioff;
		int wY  = ry - 2*ioff;
                bitmap1.DrawRectangle(Colors.White, 1, oX, oY, wX, wY, 1, 1, 
                    Colors.Green, ox, oy, Colors.Green, rx, ry, 0xFF);
                bitmap2.DrawEllipse(Colors.White, rx/2, ry/2, wX, wY);
	    }

            


            while (true)
            {
                bitmap1.Flush();
                Thread.Sleep(250);
                bitmap2.Flush();
                Thread.Sleep(200);
            }

        }
示例#3
0
        public static void Main()
        {
            LCD myApplication = new LCD();

            Window mainWindow = myApplication.CreateWindow();
            
            // Start the application
            //myApplication.Run(mainWindow);

            Bitmap bitmap1 = new Bitmap(SystemMetrics.ScreenWidth,SystemMetrics.ScreenHeight);
            Bitmap bitmap2 = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);

            int ox = 0;
            int oy = 0;
            int rx = bitmap1.Width;
            int ry = bitmap1.Height;
            int sd=0;
            if (rx < ry)
                sd = rx;
            else
                sd = ry;


            bitmap1.DrawLine(Colors.Blue, 1, 0, 0, rx, ry);
            bitmap1.DrawLine(Colors.Blue, 1, rx, 0, 0, ry);
            bitmap1.DrawRectangle(Color.White, 10, ox, oy, rx, ry, 1, 1, 
                Color.White, ox, oy, Color.White, rx, ry, 0xFF);

            for(int i=0; i < sd; i += 10)
                bitmap1.DrawRectangle(Color.White, 1, ox+i, oy+i, rx-i, ry-i, 1, 1, 
                    Colors.Green, ox, oy, Colors.Green, rx, ry, 0xFF);

            
            bitmap2.DrawLine(Colors.Black, 1, 0, 0, rx, ry);
            bitmap2.DrawLine(Microsoft.SPOT.Presentation.Media.Color.Black, 1, rx, 0, 0, ry);

            for (int i = 0; i < sd; i += 10)
                bitmap1.DrawRectangle(Color.White, 1, ox + i, oy + i, rx - i, ry - i, 1, 1,
                    Colors.Green, ox, oy, Colors.Green, rx, ry, 0xFF);

            while (true)
            {
                bitmap1.Flush();
                Thread.Sleep(50);
                bitmap2.Flush();
                Thread.Sleep(50);
            }

        }
示例#4
0
        public void Render(Bitmap screen, bool military, ArrayList forecast)
        {
            DateTime now = DateTime.Now;
            string display = "";
            string hour, minute = now.Minute.ToString();
            if (military)
            {
                hour = now.Hour.ToString();
            }
            else
            {
                int h = now.Hour;
                if (h >= 12) h = h - 12;
                if (h == 0) h = 12;
                hour = h.ToString();
            }
            if (minute.Length == 1) minute = "0" + minute;

            display = hour + ":" + minute;
            screen.DrawLine(Color.White, 2, 0, Program.AgentSize/2, Program.AgentSize, Program.AgentSize/2);

            int left = Program.AgentSize - Program.MeasureString(display, bigfont);
            screen.DrawText(display, bigfont, Color.White, left, (Program.AgentSize/2) +2);
 
            string dow = System.Globalization.DateTimeFormatInfo.CurrentInfo.DayNames[(int) now.DayOfWeek];
            screen.DrawText(dow.ToString(), font, Color.White, 5, 10);

            string date = System.Globalization.DateTimeFormatInfo.CurrentInfo.MonthNames[(int) now.Month];
            date = date + " " + now.Day.ToString();
            screen.DrawText(date, font, Color.White, 5, 30);

        }
示例#5
0
        public void Render(Bitmap screen, bool military, ArrayList forecast)
        {
            screen.DrawLine(Color.White, 2, 0, Program.AgentSize / 2, Program.AgentSize, Program.AgentSize / 2);

            DateTime now = DateTime.Now;
            int counter = (int) now.DayOfWeek;
            counter++;
            int left =  buffer;
            Forecast nowForecast = null;
            bool needsDate = false;
            DateTime lastUpdated = DateTime.Now;
            for (int x = 0; x <= days; x++)
            {
                
                string dayName = System.Globalization.DateTimeFormatInfo.CurrentInfo.DayNames[counter];
                if (dayName.Length >= 3) dayName = dayName.Substring(0, 3);
                int width = Program.MeasureString(dayName, font);
                screen.DrawText(dayName, font, Color.White, left, top);
                if (forecast != null && forecast.Count > 0)
                {
                    Forecast current = null;
                    var startDate = now.Date.AddDays(x);
                    foreach (Forecast f in forecast)
                    {
                        if (f.Date.Year == now.Date.Year && f.Date.Month == now.Date.Month && f.Date.Day == now.Date.Day)
                            nowForecast = f;
                        if (startDate.Year == f.Date.Year && startDate.Month == f.Date.Month && startDate.Day == f.Date.Day)
                        {
                            Debug.Print("Found match");
                            current = f;
                            break;
                        }
                    }
                    if (current != null)
                    {
                        needsDate = true;
                        screen.DrawText(current.Current.ToString(), font, Color.White, left+4, top+font.Height + 2);
                        lastUpdated = current.LastUpdated;
                    }
                }
                counter++;
                if (counter > 6) counter = 0;
                left += width + buffer;
            }
            if (nowForecast != null)
            {
                string display = nowForecast.Current.ToString();
                int forecastLeft = Program.AgentSize - Program.MeasureString(display, bigfont);
                screen.DrawText(display, bigfont, Color.White, forecastLeft, (Program.AgentSize / 2) + 2);
                needsDate = true;
                lastUpdated = nowForecast.LastUpdated;
            }
            if (needsDate)
            {
                screen.DrawText(lastUpdated.ToString(), smallFont, Color.White, 3, (Program.AgentSize / 2)-smallFont.Height-1);
                
            }

        }
示例#6
0
        public void Draw(Bitmap DrawingSurface)
        {
            if (Thickness > 0)
            {
                DrawingSurface.DrawRectangle(Color.White, Thickness, 1, 1, Device.AgentSize, Device.AgentSize, 0, 0,
                                             Color.Black, 0, 0, Color.Black, 0, 0, 0);

                if (HeaderHeight > 0)
                {
                    DrawingSurface.DrawLine(Color.White, Thickness, 1, HeaderHeight, Device.AgentSize, HeaderHeight);

                }
                if (FooterHeight > 0)
                {
                    DrawingSurface.DrawLine(Color.White, Thickness, 1, Device.AgentSize - FooterHeight, Device.AgentSize, Device.AgentSize - FooterHeight);

                }
            }
        }
示例#7
0
        public static void SetupZeroBuffer()
        {
            //add it to our buffer context
            var bmp = new Bitmap(10, 10);
            bmp.DrawLine(Color.White, 1, 0, 0, 1, 1);
            _buffer.Add(bmp);

            //render it right away
            _screen.Clear();
            _screen.DrawImage(0, 0, bmp, 0, 0, bmp.Width, bmp.Height);
            _screen.Flush();
        }
示例#8
0
        void seePicture_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
        {
            if (pic != null)
            {
                Bitmap b = new Bitmap(320, 240);
                b.DrawLine(Colors.Red, 20, 0, 0, 319, 239);
                byte[] buff = new byte[320 * 240 * 3 + 54];
                GHIElectronics.NETMF.System.Util.BitmapToBMPFile(b.GetBitmap(), 320, 240, buff);

                GT.Picture picture = new GT.Picture(buff, GT.Picture.PictureEncoding.BMP);

                responder.Respond(picture);
            }
            else
                responder.Respond("Take picture first");
        }
示例#9
0
        public static void SetupOtherBuffers()
        {
            int lineLength = 10;
            for (int x = 1; x <= lineLength; x++)
            {
                int x0 = x;
                int y0 = x;
                int x1 = x0+x;
                int y1 = y0+x;
                //create the buffered image
                var bmp = new Bitmap(lineLength, lineLength);
                bmp.DrawLine(Color.White, x, x0, y0, x1, y1);
                //add it to our list of buffered images
                _buffer.Add(bmp);
            }

            evt.Set();
        }
示例#10
0
        public override void Render(Bitmap screen)
        {
            if (base._screen == null) _screen = screen;

 
            DateTime now = DateTime.Now;
            string display = "";
            string hour, minute = now.Minute.ToString();
            if (Settings.TimeInISONotatation)
            {
                hour = now.Hour.ToString();
            }
            else
            {
                int h = now.Hour;
                if (h >= 12) h = h - 12;
                if (h == 0) h = 12;
                hour = h.ToString();
            }
            if (minute.Length == 1) minute = "0" + minute;

            display = hour + ":" + minute;
            screen.DrawLine(Color.White, 2, 0, AGENT.Contrib.Device.Size/2, AGENT.Contrib.Device.Size, AGENT.Contrib.Device.Size/2);

            int left = AGENT.Contrib.Device.Size - base.drawing.MeasureString(display, bigfont);
            screen.DrawText(display, bigfont, Color.White, left, (AGENT.Contrib.Device.Size/2) + 2);

            string dow = System.Globalization.DateTimeFormatInfo.CurrentInfo.DayNames[(int) now.DayOfWeek];
            screen.DrawText(dow.ToString(), font, Color.White, 5, 15);

            string date = System.Globalization.DateTimeFormatInfo.CurrentInfo.MonthNames[(int) now.Month];
            date = date + " " + now.Day.ToString();
            screen.DrawText(date, font, Color.White, 5, 35);

            drawing.DrawTray(screen, _notificationProvider, smallFont);


        }
        public override void Run()
        {
            try
            {
                using (var bmp = new Bitmap(Dimensions.Width, Dimensions.Height))
                {
                    var rand = new Random();

                    for (int i = 0; i < 100; i++)
                    {
                        bmp.DrawLine((Color) rand.Next(0xFFFFFF), 1,
                                     rand.Next(Dimensions.Width), rand.Next(Dimensions.Height),
                                     rand.Next(Dimensions.Width), rand.Next(Dimensions.Height));
                        bmp.Flush();
                    }
                }
                Pass = true;
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#12
0
        public override void Run()
        {
            try
            {
                Bitmap bmp = new Bitmap( Dimensions.Width, Dimensions.Height );

                bmp.DrawLine( Utility.FromRGB( 255, 0, 0 ),
                    1,
                    Dimensions.Width / 2, Dimensions.Height / 2, Dimensions.Width, Dimensions.Height / 2 );

                bmp.DrawLine( Utility.FromRGB( 0, 255, 0 ),
                    1,
                    Dimensions.Width / 2, Dimensions.Height / 2, Dimensions.Width / 2, 0 );

                bmp.Flush();

                Thread.Sleep( 3000 );
                Pass = true;
            }
            catch(Exception e)
            {
                UnexpectedException( e );
            }
        }
示例#13
0
        /// <summary>
        /// Draw a simple battery to the screen
        /// </summary>
        /// <param name="screen"></param>
        /// <param name="batteryPosition"></param>
        /// <param name="batteryWidth"></param>
        /// <param name="batteryHeight"></param>
        /// <param name="borderThickness"></param>
        /// <param name="batteryColor"></param>
        /// <param name="backColor"></param>
        public Size DrawBattery(Bitmap screen, Point batteryPosition, int batteryWidth, int batteryHeight,
                                int borderThickness, Color batteryColor, Color backColor, bool charging, int batteryLevel)
        {
            
            //calculate filler
            double fillerWidth = (batteryWidth - (borderThickness*1));
            double percent = ((double)batteryLevel * 0.01);
            double actualFillerWidth = fillerWidth*percent;

            //calculate nub
            double nubHight = batteryHeight*0.5;
            double nubWidth = batteryHeight*0.1;
            double nubTop = (((double) batteryHeight)/2) - (nubHight/2);
            Point nubPosition = new Point(batteryPosition.X + batteryWidth,
                                          batteryPosition.Y + (int) System.Math.Floor(nubTop));

           //draw filler
            int paintedFiller = (int) actualFillerWidth;
            if (paintedFiller < 0) paintedFiller = 0;
            screen.DrawRectangle(backColor, 1, batteryPosition.X + 1, batteryPosition.Y + 1, paintedFiller,
                                 batteryHeight - 2, 0, 0, batteryColor, 0, 0, batteryColor, 0, 0, 255);

            //draw main battery outline
            screen.DrawRectangle(batteryColor, borderThickness, batteryPosition.X, batteryPosition.Y, batteryWidth,
                                 batteryHeight, 0, 0, backColor, 0, 0, backColor, 0, 0, 0);
            
            //draw battery nub
            screen.DrawRectangle(batteryColor, 1, nubPosition.X, nubPosition.Y, (int) nubWidth, (int) nubHight, 0, 0,
                                 batteryColor, 0, 0, batteryColor, 0, 0, 255);
            //draw inner border
            var batterySize = new Size(batteryWidth + (int) nubWidth, batteryHeight);
            if (charging)
            {
                //draw charging indicator
                double iconHeight = (int)(nubHight*0.20);
                double iconTop = batteryPosition.Y + ((double)batteryHeight/2 - iconHeight/2)+1;
                double iconLeft = batteryPosition.X + 4;
                double iconWidth = (int)(iconLeft + actualFillerWidth - 5);

                screen.DrawLine(backColor, (int)iconHeight, (int)iconLeft, (int)iconTop, (int)iconWidth, (int)iconTop);


            }
            return batterySize;
        }
示例#14
0
        private static void _DrawUnfilledPoly(Bitmap screen, Point[] points, Color borderColor, short borderWidth, Point basePoint)
        {
            for (int i = 0; i < points.Length - 1; ++i)
            {
                screen.DrawLine(borderColor, borderWidth, points[i].X - basePoint.X, points[i].Y - basePoint.Y, points[i + 1].X - basePoint.X, points[i + 1].Y - basePoint.Y);
            }

            screen.DrawLine(borderColor, borderWidth, points[0].X - basePoint.X, points[0].Y - basePoint.Y, points[points.Length - 1].X - basePoint.X, points[points.Length - 1].Y - basePoint.Y);
        }
示例#15
0
 /// <summary>
 /// Paint a line from two points
 /// </summary>
 /// <param name="screen"></param>
 /// <param name="color"></param>
 /// <param name="thickness"></param>
 /// <param name="start"></param>
 /// <param name="end"></param>
 public void PaintLine(Bitmap screen, Color color, int thickness, Point start, Point end)
 {
     screen.DrawLine(color, thickness, start.X, start.Y, end.X, end.Y);
 }
示例#16
0
文件: ToDoEvent.cs 项目: nicksi/tdw
        /// <summary>
        /// Draw event on 64 x 48 bitmap
        /// </summary>
        /// <param name="bitmap">Bitmap to draw on</param>
        /// <param name="time">Current time</param>
        public void PaintEvent(Bitmap bitmap, DateTime time)
        {
            Font timeFont = Resources.GetFont(Resources.FontResources.ubuntu16c);
            Font smallFont = Resources.GetFont(Resources.FontResources.ubuntu12c);
            Painter painter = new Painter(bitmap);
            TimeSpan ts = DueDate - time;
            Bitmap todotypes;

            // draw separator
            bitmap.DrawLine(Color.White, 1, 0, 0, 64, 0);

            // if inverse draw background and use inverted icons
            if (_inverse)
            {
                bitmap.DrawRectangle(Color.White, 0, 0, 3, 64, 18, 0, 0, Color.White, 0, 0, Color.White, 64, 48, 0xFF);
                todotypes = new Bitmap(Resources.GetBytes(Resources.BinaryResources.todotypes_inverted), Bitmap.BitmapImageType.Gif);
            }
            else
                todotypes = new Bitmap(Resources.GetBytes(Resources.BinaryResources.todotypes), Bitmap.BitmapImageType.Gif);

            //// draw icon
            bitmap.DrawImage(0, 5, todotypes, 0, (int)Type * 16, 16, 16);

            if (ts.Days > 0)

                bitmap.DrawTextInRect(
                    ts.Days + "days",
                    16,
                    0,
                    48,
                    18,
                    Bitmap.DT_AlignmentCenter,
                    _inverse?Color.Black:Color.White,
                    timeFont
                    );
            else if ( ts.Days == 0 && ts.Minutes <= 0 )
                bitmap.DrawTextInRect(
                    "NOW!",
                    16,
                    0,
                    48,
                    20,
                    Bitmap.DT_AlignmentCenter,
                    _inverse ? Color.Black : Color.White,
                    timeFont
                    );

            else
                bitmap.DrawTextInRect(
                    ts.Hours + "h " + ts.Minutes + "m",
                    16,
                    0,
                    48,
                    20,
                    Bitmap.DT_AlignmentCenter,
                    _inverse ? Color.Black : Color.White,
                    timeFont
                    );

            if (Label.Length > 0)
            {
                bitmap.DrawTextInRect(Label, 0, 19, 64, 30, Bitmap.DT_WordWrap|Bitmap.DT_TruncateAtBottom, Color.White, smallFont);
            }
        }
示例#17
0
		public override void Run()
		{
			try
			{
				Bitmap bmp = new Bitmap( Dimensions.Width, Dimensions.Height );
                Random rand = new Random();

				for(int i = 0; i < 1000; i++)
				{
					bmp.DrawLine( (Presentation.Media.Color)rand.Next( 0xFFFFFF ), 1,
                        rand.Next(Dimensions.Width), rand.Next(Dimensions.Height), rand.Next(Dimensions.Width), rand.Next(Dimensions.Height));
					bmp.Flush();
				}
				Pass = true;
			}
			catch(Exception e)
			{
				UnexpectedException( e );
			}
		}
示例#18
0
        public override void Render(Bitmap screen)
        {
            if (base._screen == null) _screen = screen;
            screen.DrawLine(Color.White, 2, 0, AGENT.Contrib.Device.Size/2 - 10, AGENT.Contrib.Device.Size, AGENT.Contrib.Device.Size/2 - 10);
            screen.DrawImage(0, AGENT.Contrib.Device.Size - monthGrid.Height, monthGrid, 0, 0, monthGrid.Width, monthGrid.Height);
            foreach (Day day in days)
            {
                if (day.Timestamp.Date == Settings.Now.Date)
                {
                    screen.DrawRectangle(Color.White, 1, day.Point.X-2, day.Point.Y+1, 19, 11, 0, 0, Color.White, 0, 0,
                                         Color.White, 0, 0, 255);
                    screen.DrawText(day.Text, font, Color.Black, day.Point.X, day.Point.Y);
                }
                else
                {
                    screen.DrawText(day.Text, font, Color.White, day.Point.X, day.Point.Y);
                }

            }

            string date = Settings.Now.ToString(System.Globalization.DateTimeFormatInfo.CurrentInfo.LongDatePattern);
            screen.DrawText(date, font, Color.White, 5, 15);


            string dow = "Day: " + Settings.Now.DayOfYear.ToString();
            screen.DrawText(dow.ToString(), font, Color.White, 5, 35);
         
            drawing.DrawTray(screen, _notificationProvider, smallFont);

        }
示例#19
0
        /// <summary>
        /// Basic algorithm uses scan lines to fill the polygon.
        /// No multiplication or division is needed, neither is floating point calculation.
        /// </summary>
        /// <param name="bmp"></param>
        /// <param name="outline"></param>
        /// <param name="points"></param>
        protected internal override void RenderPolygon(Bitmap bmp, Pen outline, int[] points)
        {
            int n = points.Length / 2; /// This is number of points and number of lines (closed polygon).

            /// Polygon to fill must have at least 3 points.
            if (n < 3)
                return;

            /// Nothing to do if this is a transparent brush.
            if (Opacity == Bitmap.OpacityTransparent)
                return;

            int i = 0;
            int y = 0;
            int yLow = 0;
            int yHigh = 0;

            LineSegment[] lines = new LineSegment[n];

            int[] xPoints = new int[n];

            /// Initialize line segments.
            for (i = 0; i < n; i++)
            {
                lines[i] = new LineSegment();
                lines[i].processedPts = 0;
                xPoints[i] = new int();

                lines[i].x1 = points[i * 2];
                lines[i].y1 = points[i * 2 + 1];
                if (i < (n - 1))
                {
                    lines[i].x2 = points[(i + 1) * 2];
                    lines[i].y2 = points[(i + 1) * 2 + 1];
                }
                else
                {
                    lines[i].x2 = points[0];
                    lines[i].y2 = points[1];
                }

                /// Reverse the points to make sure y1 <= y2 always.
                if (lines[i].y2 < lines[i].y1)
                {
                    Swap(ref lines[i].y2, ref lines[i].y1);
                    Swap(ref lines[i].x2, ref lines[i].x1);
                }

                /// Calculate slopes and increments.
                lines[i].dx = Abs(lines[i].x2 - lines[i].x1);
                lines[i].dy = Abs(lines[i].y2 - lines[i].y1);
                lines[i].cx = lines[i].x1;
                lines[i].e = 0;

                if (lines[i].dx < lines[i].dy)
                {
                    /// Angle is 45 degree or more. So y increases faster.
                    lines[i].highSlope = true;
                }
                else
                {
                    lines[i].highSlope = false;
                }

                /// Actual increment direction.
                if (lines[i].x2 > lines[i].x1) lines[i].ix = 1;
                else lines[i].ix = -1;

                if (i == 0)
                {
                    yLow = lines[i].y1;
                    yHigh = lines[i].y2;
                }
                else
                {
                    if (lines[i].y1 < yLow) yLow = lines[i].y1;
                    if (lines[i].y2 > yHigh) yHigh = lines[i].y2;
                }
            }

            /// Fill via scan lines between yLow and yHigh.
            for (y = yLow; y <= yHigh; y++)
            {
                int j = 0;
                for (i = 0; i < n; i++)
                {
                    xPoints[i] = Int32.MaxValue;
                }

                /// Find intersection points for given y.
                for (i = 0; i < n; i++)
                {
                    if (y < lines[i].y1) continue;
                    if (y > lines[i].y2) continue;

                    lines[i].processedPts++;

                    if (lines[i].dy != 0)
                    {
                        if (lines[i].highSlope)
                        {
                            /// For this y find the x, which either the same pixel
                            /// in last iteration or next one.
                            if (y == lines[i].y1) lines[i].cx = lines[i].x1;
                            else if (y == lines[i].y2) lines[i].cx = lines[i].x2;
                            else
                            {
                                lines[i].e += lines[i].dx;
                                if ((lines[i].e << 1) >= lines[i].dy)
                                {
                                    lines[i].cx += lines[i].ix;
                                    lines[i].e -= lines[i].dy;
                                }
                            }
                        }
                        else
                        {
                            /// In this case for every y pixel inc, x increases more than 1 pixel.
                            if (y == lines[i].y1) lines[i].cx = lines[i].x1;
                            else if (y == lines[i].y2) lines[i].cx = lines[i].x2;
                            else
                            {
                                for (; ; )
                                {
                                    lines[i].cx += lines[i].ix;

                                    lines[i].e += lines[i].dy;
                                    if ((lines[i].e << 1) >= lines[i].dx)
                                    {
                                        lines[i].e -= lines[i].dx;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    /// Insertion sort, do not insert back to back duplicates
                    int x1;
                    bool x1YMin;
                    int x2 = int.MaxValue;
                    bool x2YMin = false;

                    ///
                    /// add both x endpoints if the line is horizontal
                    ///
                    if (lines[i].dy == 0)
                    {
                        x1 = lines[i].x1;
                        x1YMin = true;

                        x2 = lines[i].x2;
                        x2YMin = true;

                        if (x2 < 0) x2 = 0;
                    }
                    else
                    {
                        x1 = lines[i].cx;
                        x1YMin = lines[i].processedPts == 1;
                    }

                    // We don't need to process negative values of x
                    if (x1 < 0) x1 = 0;

                    int idx1 = -1;
                    int idx2 = x2 == int.MaxValue ? x2 : -1;
                    int offset = 0;

                    ///
                    /// First we search for the indexes of x1 and x2 (if neccessary) and then we will insert the
                    /// items, by shifting the elements in the array
                    for (j = 0; j < n; j++)
                    {
                        int ix = (xPoints[j] & c_XValueMask);
                        bool isYMin = (xPoints[j] & c_YMinBit) != 0;

                        if (idx1 == -1)
                        {
                            ///
                            /// Only add duplicate x values if the intersection produces up (^) or down (v) angles
                            /// as opposed to right (<) or left (>) angles.
                            ///
                            if (ix == x1 && isYMin != x1YMin) { idx1 = int.MaxValue; }
                            else if (ix > x1) { idx1 = j + offset; offset++; }
                        }

                        if (idx2 == -1)
                        {
                            ///
                            /// Only add duplicate x values if the intersection produces up (^) or down (v) angles
                            /// as opposed to right (<) or left (>) angles.
                            ///
                            if (ix == x2 && isYMin != x2YMin) { idx2 = int.MaxValue; }
                            else if (ix > x2) { idx2 = j + offset; offset++; }
                        }

                        // don't break until we have found both indexes and then end of the list
                        if (idx1 != -1 && idx2 != -1 && xPoints[j] == int.MaxValue) break;
                    }

                    int idxMin = (idx1 < idx2 ? idx1 : idx2);

                    // Because we may have two values to insert, the index to the next item to be shifted
                    // can either be n-1 or n-2.
                    offset = (idx2 == int.MaxValue || idx1 == int.MaxValue ? 1 : 2);

                    // j is already one element past the last valid data item, so increase it by one if we are
                    // inserting two elements
                    j += (offset - 1);

                    // Make sure the index does not overflow
                    if (j >= xPoints.Length) j = xPoints.Length - 1;

                    for (; j >= idxMin; j--)
                    {
                        if (j == idx1) { xPoints[j] = x1YMin ? x1 | c_YMinBit : x1; offset--; continue; }
                        if (j == idx2) { xPoints[j] = x2YMin ? x2 | c_YMinBit : x2; offset--; continue; }

                        if (j < offset) break;

                        xPoints[j] = xPoints[j - offset];
                    }
                }

                /// Finally draw the line segments to fill.
                for (i = 0; i < xPoints.Length - 1; i += 2)
                {
                    int ix1 = (xPoints[i] & c_XValueMask);
                    int ix2 = (xPoints[i + 1] & c_XValueMask);

                    if ((ix1 == c_XValueMask) || (ix2 == c_XValueMask)) break;

                    if (bmp != null)
                        bmp.DrawLine((MSMedia.Color)Color, 1, ix1, y, ix2, y);
                }
            }
        }
示例#20
0
        protected override void DrawItem(Bitmap screen, int x, int y, int width, int height, ref int index, object item, Style cStyle)
        {
            bool selected = _allowMultipleSelection ? _selectedItems.Contains(item) : _selIndex == index;

            if (selected)
            {
                screen.DrawRectangle(Colors.Blue, 0, x, y, width, height, 0, 0,
                    cStyle.ListBoxSelectedItemBack1, x, y,
                    cStyle.ListBoxSelectedItemBack2, x, y + height, _enabled ? (ushort)256 : (ushort)128);
            }

            Font textFont = cStyle.LabelFont;
            Color textColor = _enabled ? (selected ? cStyle.TextBoxPressedTextColor : cStyle.TextBoxEnabledTextColor) : cStyle.TextBoxDisabledTextColor;
            screen.DrawTextInRect(item.ToString(), x + 5, y + (height - textFont.Height) / 2, width - 10, height, Bitmap.DT_AlignmentLeft, textColor, textFont);

            if (_allowMultipleSelection)
            {
                const int chkMargin = 3;

                int cX = x + width - ItemHeight,
                    cY = y + chkMargin,
                    cWidth = ItemHeight - chkMargin * 2,
                    cHeight = cWidth;

                screen.DrawRectangle(
                    _enabled ? cStyle.CheckBoxEnabledBorder : cStyle.CheckBoxDisabledBorder, 1, cX, cY, cWidth, cHeight, 0, 0,
                    _enabled ? cStyle.CheckBoxEnabledBack1 : cStyle.CheckBoxDisabledBack1, cX, cY,
                    _enabled ? cStyle.CheckBoxEnabledBack2 : cStyle.CheckBoxDisabledBack2, cX, cY + cHeight, 256);

                if (selected)
                {
                    const int margin = 4;
                    Color crossColor = _enabled ? cStyle.CheckBoxEnabledCross : cStyle.CheckBoxDisabledCross;

                    screen.DrawLine(crossColor, 2, cX + margin, cY + margin, cX + cWidth - margin, cY + cHeight - margin - 1);
                    screen.DrawLine(crossColor, 2, cX + cWidth - margin, cY + margin, cX + margin, cY + cHeight - margin - 1);
                }
            }
        }