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); } }
public override void Run() { using (var bitmap = new Bitmap(Dimensions.Width, Dimensions.Height)) { using (var img = Resources.GetBitmap(Resources.BitmapResources.compass2)) { int da = 3; for (int angle = 0; angle <= 360 && angle >= 0; angle += da) { bitmap.DrawRectangle(Colors.White, 0, 0, 0, Dimensions.Width, Dimensions.Height, 0, 0, Colors.White, 0, 0, Colors.White, 0, 0, Bitmap.OpacityOpaque); int xdst = (Dimensions.Width - img.Width)/2, ydst = (Dimensions.Height - img.Height)/2; bitmap.RotateImage(angle, xdst, ydst, img, 0, 0, img.Width, img.Height, 0x00); bitmap.Flush(); if (angle > 180) da = -da; } } } }
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++) { var fillColor = (Color)rand.Next(0xFFFFFF); bmp.DrawRectangle((Color) rand.Next(0xFFFFFF), rand.Next(1), rand.Next(Dimensions.Width), rand.Next(Dimensions.Height), rand.Next(Dimensions.Width), rand.Next(Dimensions.Height), 0, 0, fillColor, 0, 0, fillColor, 0, 0, (ushort) rand.Next(256)); bmp.Flush(); } } Pass = true; } catch (Exception e) { UnexpectedException(e); } }
protected internal override void RenderRectangle(Bitmap bmp, Pen pen, int x, int y, int width, int height) { Color outlineColor = (pen != null) ? pen.Color : (Color)0x0; ushort outlineThickness = (pen != null) ? pen.Thickness : (ushort)0; int x1, y1; int x2, y2; switch (MappingMode) { case BrushMappingMode.RelativeToBoundingBox: x1 = x + (int)((long)(width - 1) * StartX / RelativeBoundingBoxSize); y1 = y + (int)((long)(height - 1) * StartY / RelativeBoundingBoxSize); x2 = x + (int)((long)(width - 1) * EndX / RelativeBoundingBoxSize); y2 = y + (int)((long)(height - 1) * EndY / RelativeBoundingBoxSize); break; default: //case BrushMappingMode.Absolute: x1 = StartX; y1 = StartY; x2 = EndX; y2 = EndY; break; } bmp.DrawRectangle((MSMedia.Color)outlineColor, outlineThickness, x, y, width, height, 0, 0, (MSMedia.Color)StartColor, x1, y1, (MSMedia.Color)EndColor, x2, y2, Opacity); }
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); } }
static void Main(string[] args) { int screenWidth, screenHeight, bitsPerPixel, orientationDeg; HardwareProvider.HwProvider.GetLCDMetrics(out screenWidth, out screenHeight, out bitsPerPixel, out orientationDeg); Bitmap bmp = new Bitmap(screenWidth, screenHeight); //drawing white background bmp.DrawRectangle(Color.White, // outline color 0, // outline thickness 0, 0, // x and y of top left corner bmp.Width, bmp.Height, // width and height 0, 0, // y and y corner radius Color.White, // gradient start color 0, 0, // gradient start coordinates Color.White, // gradient end color 0, 0, // gradient end coordinates Bitmap.OpacityOpaque); // reduced opacity Color[] colors = new Color[] { ColorUtility.ColorFromRGB(0xFF, 0, 0), // red ColorUtility.ColorFromRGB(0, 0xFF, 0), // green ColorUtility.ColorFromRGB(0, 0, 0xFF) // blue }; for (int i = 0; i < colors.Length; ++i) { Color color = colors[i]; bmp.DrawRectangle(color, // outline color 0, // outline thickness 50 + i * 20, 50 + i * 20, // x and y of top left corner 200, 100, // width and height 0, 0, // x and y corner radius color, // gradient start color 0, 0, // gradient start coordinates color, // gradient end color 0, 0, // gradient end coordinates 64); // reduced opacity } bmp.Flush(); Thread.Sleep(-1); //do not terminate app to see result }
public static void Main() { int screenWidth, screenHeight, bitsPerPixel, orientationDeg; HardwareProvider.HwProvider.GetLCDMetrics(out screenWidth, out screenHeight, out bitsPerPixel, out orientationDeg); //prepare background with a color gradient Bitmap backgroundImg = new Bitmap(screenWidth, screenHeight); backgroundImg.DrawRectangle(Color.White, // outline color 0, // outline thickness 0, 0, // x and y of top left corner backgroundImg.Width, // width backgroundImg.Height, // height 0, 0, // x and y corner radius Color.White, // gradient start color 0, 0, // gradient start coordinates Color.Black, // gradient end color backgroundImg.Width, // gradient end x coordinate backgroundImg.Height, // gradient end y coordinate Bitmap.OpacityOpaque); // opacity //prepare a working buffer to hold graphics before flushing to display Bitmap bufferImg = new Bitmap(screenWidth, screenHeight); //our ball Bitmap soccerBallImg = Resources.GetBitmap(Resources.BitmapResources.SoccerBall); //make background of the ball transparent //using the color of top left corner pixel soccerBallImg.MakeTransparent(soccerBallImg.GetPixel(0, 0)); int x = 100; int y = 50; int xOfs = 1; int yOfs = 1; while (true) { //copy background to buffer bufferImg.DrawImage(0, 0, backgroundImg, 0, 0, backgroundImg.Width, backgroundImg.Height); //paint moving sprite object bufferImg.DrawImage(x, y, // destination coordinates soccerBallImg, // source image 0, 0, // source coordinates soccerBallImg.Width, soccerBallImg.Height, Bitmap.OpacityOpaque); bufferImg.Flush(); //flush buffer to display Thread.Sleep(10); //invert direction if ball bounces at a wall if (x <= 0 || x >= screenWidth - soccerBallImg.Width) xOfs = -xOfs; if (y <= 0 || y >= screenHeight - soccerBallImg.Height) yOfs = -yOfs; //calculate new coordinates x += xOfs; y += yOfs; } }
protected internal override void RenderRectangle(Bitmap bmp, Pen pen, int x, int y, int width, int height, int xCornerRadius, int yCornerRadius) { if (Stretch == Stretch.None) bmp.DrawImage(x, y, BitmapSource, 0, 0, BitmapSource.Width, BitmapSource.Height, Opacity); else if (width == BitmapSource.Width && height == BitmapSource.Height) bmp.DrawImage(x, y, BitmapSource, 0, 0, width, height, Opacity); else bmp.StretchImage(x, y, BitmapSource, width, height, Opacity); if (pen != null && pen.Thickness > 0) bmp.DrawRectangle((MSMedia.Color)pen.Color, pen.Thickness, x, y, width, height, xCornerRadius, yCornerRadius, (MSMedia.Color)0, 0, 0, (MSMedia.Color)0, 0, 0, 0); }
protected override void DrawItem(Bitmap screen, int x, int y, int width, int height, ref int index, object it, Style cStyle) { bool selected = _selIndex == index; RadioStationItem item = (RadioStationItem)it; 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); Color textColor = item.IsConnecting ? Colors.Yellow : (item.IsPlaying ? Colors.LightGreen : (Enabled ? (selected ? cStyle.TextBoxPressedTextColor : cStyle.TextBoxEnabledTextColor) : cStyle.TextBoxDisabledTextColor)); screen.DrawText(item.Name, nameFont, textColor, x + 5, y + 2); screen.DrawText(item.Address, textFont, textColor, x + 5, y + 2 + nameFont.Height + 2); }
static public void DrawString(Font font, String text, int x, int y, UInt32 text_color, UInt32 back_color) { int width = 0; for (int i = 0; i < text.Length; i++) { width+=font.CharWidth((char)(text[i])); } Bitmap bmp = new Bitmap(width, font.Height); bmp.DrawRectangle((Microsoft.SPOT.Presentation.Media.Color)back_color, 100, 0, 0, width, font.Height, 0, 0, (Microsoft.SPOT.Presentation.Media.Color)back_color, 0, 0, (Microsoft.SPOT.Presentation.Media.Color)back_color, 0, 0, 0); bmp.DrawText(text, font, (Microsoft.SPOT.Presentation.Media.Color)text_color, 0, 0); Image imge = new Image(bmp); // Note: Maybe out of memory here DrawImage(imge, x, y); bmp.Dispose(); bmp = null; imge.Dispose(); imge = null; }
static void Main(string[] args) { int screenWidth, screenHeight, bitsPerPixel, orientationDeg; HardwareProvider.HwProvider.GetLCDMetrics(out screenWidth, out screenHeight, out bitsPerPixel, out orientationDeg); Bitmap bmp = new Bitmap(screenWidth, screenHeight); bmp.DrawRectangle(Color.White, // outline color 1, // outline thickness 100, 100, // x and y of top left corner 200, 100, // width and height 10, 30, // x and y corner radius Color.White, // gradient start color 0, 0, // gradient start coordinate Color.White, // gradient end color 0, 0, // gradient end coordinate Bitmap.OpacityOpaque); // opacity bmp.Flush(); Thread.Sleep(-1); //do not terminate app to see result }
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); } } }
public void Render(Bitmap screen, Font font, int height, int width, int borderBuffer, Color ForegroundColor, Color BackgroundColor) { if (Text != null && Text != "") { Color forColor = ForegroundColor; Color bColor = BackgroundColor; if (Selected) { forColor = BackgroundColor; bColor = ForegroundColor; } screen.DrawRectangle(forColor, 1, Point.X, Point.Y, width + borderBuffer * 2, height + borderBuffer * 2, 0, 0, bColor, 0, 0, bColor, 0, 0, 255); screen.DrawText(Text, font, forColor, Point.X + borderBuffer, Point.Y + borderBuffer); } }
public override void Run() { try { using (var bmp = new Bitmap(Dimensions.Width, Dimensions.Height)) { var fonts = new[] { new FontItem {Name = "Arial 10", FontId = Resources.FontResources.arial10}, new FontItem {Name = "Small", FontId = Resources.FontResources.small}, new FontItem {Name = "Courier 11", FontId = Resources.FontResources.courier11} }; const string s = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; foreach (var font in fonts) { bmp.Clear(); Font fnt = Resources.GetFont(font.FontId); bmp.DrawRectangle((Color)0xFF0000, 0, 0, 0, Dimensions.Width, Dimensions.Height, 0, 0, (Color)0xFF0000, 0, 0, (Color)0xFF0000, 0, 0, Bitmap.OpacityOpaque); const Color color = (Color)0x0000FF; bmp.DrawTextInRect(font.Name + " " + s, 0, 0, Dimensions.Width, Dimensions.Height, Bitmap.DT_WordWrap | Bitmap.DT_AlignmentLeft, color, fnt); bmp.Flush(); Thread.Sleep(5000); } } Pass = true; } catch (Exception e) { UnexpectedException(e); } }
public static void Main() { int screenWidth, screenHeight, bitsPerPixel, orientationDeg; HardwareProvider.HwProvider.GetLCDMetrics(out screenWidth, out screenHeight, out bitsPerPixel, out orientationDeg); Bitmap bmp = new Bitmap(screenWidth, screenHeight); Font font = Resources.GetFont(Resources.FontResources.NinaB); string text = "There is another overload of the DrawTextInRect " + "method. That method comes along with reference " + "parameters for the input string and the x and y " + "drawing positions. After drawing text, the " + "method updates the x and y positions to tell you " + "where on the display the drawing of the text " + "finished. This allows you to draw parts of the text " + "with a different color or font. Also, if the method " + "cannot display the complete text within the specified " + "rectangle, it returns the remaining text. " + "In this case, the method returns false to indicate " + "that there is some text left that could not " + "displayed. This enables you to build up a display " + "to show text over mulitple pages."; bool completed; do { int x = 0; int y = 0; //draw frame around text and clear old contents bmp.DrawRectangle(Color.White, 1, 20, 20, 150, 150, 0, 0, Color.Black, 0, 0, Color.Black, 0, 0, Bitmap.OpacityOpaque); completed = bmp.DrawTextInRect( ref text, ref x, ref y, // x and y text position 20, 20, // x and y (rectangle top left) 150, 150, // width and height of rectangle Bitmap.DT_AlignmentLeft | Bitmap.DT_WordWrap, Color.White, // color font); // font bmp.Flush(); Thread.Sleep(3000); //display each page for three seconds } while (!completed); Thread.Sleep(-1); }
public override void Run() { try { Font font = Resources.GetFont(Resources.FontResources.small); using (var bmp = new Bitmap(Dimensions.Width, Dimensions.Height)) { uint[] flags = { Bitmap.DT_WordWrap | Bitmap.DT_AlignmentLeft, Bitmap.DT_WordWrap | Bitmap.DT_AlignmentCenter, Bitmap.DT_WordWrap | Bitmap.DT_AlignmentRight }; const string s = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; for (int i = 0; i < flags.Length; i++) { bmp.DrawRectangle((Color) 0xFF0000, 0, 0, 0, Dimensions.Width, Dimensions.Height, 0, 0, (Color) 0xFF0000, 0, 0, (Color) 0xFF0000, 0, 0, Bitmap.OpacityOpaque); const Color color = (Color)0x0000FF; bmp.DrawTextInRect(s, 0, 0, Dimensions.Width, Dimensions.Height, flags[i], color, font); bmp.Flush(); Thread.Sleep(2000); } } Pass = true; } catch (Exception e) { UnexpectedException(e); } }
public static void Main() { string key = "jk4c6nbf6huccmwp"; string label = ".NETmf TOTP"; Bitmap screen = new Bitmap(320, 240); // emulator display size Font font = Resources.GetFont(Resources.FontResources.NinaB); otp = new OTP(key); Bitmap qrcode = otp.QRCode(key, label); screen.DrawImage(10, 10, qrcode, 0, 0, qrcode.Width, qrcode.Height); // by design (at least ms and google authenticator) change every 30 seconds(@ 0 and 30) while (DateTime.Now.Second != 0 && DateTime.Now.Second != 30) ; while (true) { screen.DrawRectangle(Color.Black, 1, 220, 10, 100, 32, 0, 0, Color.Black, 0, 0, Color.Black, 50, 30, 0xff); screen.DrawText(otp.TOTP, font, Color.White, 220, 10); screen.Flush(); Thread.Sleep(30000); } }
public void Render(Bitmap screen) { Screen = screen; if (Buttons != null) { screen.Clear(); foreach (CalculatorButton button in Buttons) { button.Render(screen, font, ButtonHeight, ButtonWidth, ButtonBorder, ForegroundColor, BackgroundColor); } //calculation result screen.DrawText(input, font, BackgroundColor, 2, 2); screen.DrawText(secondInput + op, font, BackgroundColor, 2, 2 + font.Height + 2); //draw a simple border for the digit display screen.DrawRectangle(ForegroundColor, 1, 1, 1, Program.AgentSize, 28, 0, 0, BackgroundColor, 0, 0, BackgroundColor, 0, 0, 0); //draw a simple border screen.DrawRectangle(Color.White, 1, 1, 1, Program.AgentSize, Program.AgentSize, 0, 0, BackgroundColor, 0, 0, BackgroundColor, 0, 0, 0); screen.Flush(); } }
/// <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); } }
protected override void DrawItem(Bitmap screen, int x, int y, int width, int height, ref int index, object item, Style cStyle) { bool selected = _selItem == item; if (selected) { screen.DrawRectangle(Colors.Blue, 0, x, y, width, height, 0, 0, cStyle.ListBoxSelectedItemBack1, x, y, cStyle.ListBoxSelectedItemBack2, x, y + height, 256); } Font textFont = cStyle.LabelFont; Color textColor = selected ? cStyle.TextBoxPressedTextColor : cStyle.TextBoxEnabledTextColor; screen.DrawTextInRect(item.ToString(), x + 5, y + (height - textFont.Height) / 2, width - 10, height, Bitmap.DT_AlignmentLeft, textColor, textFont); const int rdMargin = 3; int rdX = x + _width - ItemHeight - rdMargin, rdY = y + rdMargin, rdRadius = (ItemHeight - rdMargin * 2) / 2; Color bColor = cStyle.RadioButtonEnabledBack; screen.DrawEllipse(cStyle.RadioButtonEnabledBorder, 1, rdX + rdRadius, rdY + rdRadius, rdRadius, rdRadius, bColor, 0, 0, bColor, 0, 0, 256); if (selected) { const int margin = 6; Color pointColor = cStyle.RadioButtonEnabledPoint; _desktopOwner._screenBuffer.DrawEllipse(pointColor, 0, rdX + rdRadius, rdY + rdRadius, rdRadius - margin, rdRadius - margin, pointColor, 0, 0, pointColor, 0, 0, 256); } }
/// <summary> /// Draws a string to the display. /// </summary> /// <param name="text">The text to write.</param> /// <param name="x">The x coordinate where to draw.</param> /// <param name="y">The y coordinate where to draw.</param> /// <param name="font">The font to use.</param> /// <param name="foreColor">The color of the text.</param> /// <param name="backColor">The background color of the text.</param> public static void Draw(string text, int x, int y, Font font, Color foreColor, Color backColor) { int width = 0; for (int i = 0; i < text.Length; i++) { width += font.CharWidth((char)(text[i])); } Bitmap bmp = new Bitmap(width, font.Height); bmp.DrawRectangle(backColor, 100, 0, 0, width, font.Height, 0, 0, backColor, 0, 0, backColor, 0, 0, 0); bmp.DrawText(text, font, foreColor, 0, 0); Display.Draw(new TinyBitmap(bmp), x, y); }
/// <summary> /// Handles multi-touch gesture events. Multitouch gestures are performed on the emulator by /// holding down CTRL+[Z|P|R] and inking (to change the angle/zoom level). /// </summary> /// <param name="e">Touch gesture event data</param> protected override void OnTouchGestureChanged(TouchGestureEventArgs e) { base.OnTouchGestureChanged(e); Bitmap b; switch (e.Gesture) { /// /// Zoom gesture magnifies the original bitmap by the gesture value contained in e.Arguments /// case TouchGesture.Zoom: if (_bmpGesture != null) { b = new Bitmap(_bitmap.Width, _bitmap.Height); b.DrawRectangle(Color.Black, 1, 0, 0, b.Width - 2, b.Height - 2, 0, 0, Color.White, 0, 0, Color.White, b.Width, b.Height, Bitmap.OpacityOpaque); b.StretchImage(-(e.Arguments), -(e.Arguments), _bmpGesture, _bmpGesture.Width + 2 * (e.Arguments), _bmpGesture.Height + 2 * (e.Arguments), Bitmap.OpacityOpaque); _bitmap = b; Invalidate(); } break; /// /// Pan (zoom out) gesture shrinks the original bitmap by the gesture value contained in e.Arguments /// case TouchGesture.Pan: if (_bmpGesture != null) { b = new Bitmap(_bitmap.Width, _bitmap.Height); b.DrawRectangle(Color.Black, 1, 0, 0, b.Width - 2, b.Height - 2, 0, 0, Color.White, 0, 0, Color.White, b.Width, b.Height, Bitmap.OpacityOpaque); b.StretchImage((e.Arguments), (e.Arguments), _bmpGesture, _bmpGesture.Width - 2 * (e.Arguments), _bmpGesture.Height - 2 * (e.Arguments), Bitmap.OpacityOpaque); _bitmap = b; Invalidate(); } break; /// /// Rotate gesture spins the original bitmap by the gesture value contained in e.Angle (0-360). /// case TouchGesture.Rotate: if (_bmpGesture != null) { b = new Bitmap(_bitmap.Width, _bitmap.Height); b.DrawRectangle(Color.Black, 1, 0, 0, b.Width, b.Height, 0, 0, Color.White, 0, 0, Color.White, b.Width, b.Height, Bitmap.OpacityOpaque); b.RotateImage((int)e.Angle, 1, 1, _bmpGesture, 1, 1, _bmpGesture.Width - 2, _bmpGesture.Height - 2, Bitmap.OpacityOpaque); _bitmap = b; Invalidate(); } break; } }
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); }
protected override void DrawItem(Bitmap screen, int x, int y, int width, int height, ref int index, object it, Style cStyle) { bool selected = _selIndex == index; FsItem item = (FsItem)it; 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); Color textColor = _playing == it ? Colors.Green : (Enabled ? (selected ? cStyle.TextBoxPressedTextColor : cStyle.TextBoxEnabledTextColor) : cStyle.TextBoxDisabledTextColor); Bitmap toDraw = item.IsBack ? fsBack : (item.IsDirectory ? fsFolder : (item.IsMusicFile ? fsMusic : fsNone)); screen.DrawImage(x + 5, y + (ItemHeight - 16) / 2, toDraw, 0, 0, 16, 16); screen.DrawText(item.Name, nameFont, textColor, x + 26, y + (ItemHeight - nameFont.Height) / 2); }
protected internal override void RenderRectangle(Bitmap bmp, Pen pen, int x, int y, int width, int height, int xCornerRadius, int yCornerRadius) { Color outlineColor = (pen != null) ? pen.Color : (Color)0x0; ushort outlineThickness = (pen != null) ? pen.Thickness : (ushort)0; if (bmp != null) { if (xCornerRadius > 0 && yCornerRadius > 0) { // background color doesn't render when corners != 0 // render background w/o corners: bmp.DrawRectangle((MSMedia.Color)outlineColor, 0, x, y, width, height, 0, 0, (MSMedia.Color)Color, 0, 0, (MSMedia.Color)Color, 0, 0, Opacity); } bmp.DrawRectangle((MSMedia.Color)outlineColor, outlineThickness, x, y, width, height, xCornerRadius, yCornerRadius, (MSMedia.Color)Color, 0, 0, (MSMedia.Color)Color, 0, 0, Opacity); } }
protected override void RenderRectangle(Bitmap bmp, Pen outline, int x, int y, int width, int height) { bmp.DrawRectangle(Colors.Blue, 1, x, y, width, height, 0, 0, Colors.Blue, 0, 0, Colors.Blue, 0, 0, Opacity); }
/// <summary> /// Draws polygon from list of points and fill it with specififed pattern. /// </summary> /// <param name="screen">Bitmap to draw on</param> /// <param name="points">Array of points defining polygon</param> /// <param name="borderColor">Color of poly border</param> /// <param name="borderWidth">Poly border width</param> /// <param name="fillColor">Color to use to fill poly</param> /// <param name="polyFill">Fill patern. Empty will simply draw unfilled poly</param> public void DrawPoly(Bitmap screen, Point[] points, Color borderColor, short borderWidth, Color fillColor, PolyFill polyFill) { if (points.Length < 3) return; // we need at least 3 point for poly if (borderWidth < 1) borderWidth = 1; Color fgColor, bgColor; if (fillColor == Color.Black) { fgColor = Color.Black; bgColor = Color.White; } else { fgColor = Color.White; bgColor = Color.Black; } if (polyFill == PolyFill.POLYFILL_EMPTY) _DrawUnfilledPoly(screen, points, borderColor, borderWidth, new Point(0, 0)); else { Point br = new Point(0, 0), tl = new Point(screen.Width, screen.Height); // find bounding box for (int i = 0; i < points.Length; ++i) { tl.X = (tl.X > points[i].X) ? points[i].X : tl.X; tl.Y = (tl.Y > points[i].Y) ? points[i].Y : tl.Y; br.X = (br.X < points[i].X) ? points[i].X : br.X; br.Y = (br.Y < points[i].Y) ? points[i].Y : br.X; } // adjust binding box to fit thick border. Foê some reason SPOT.Bitmap double the border width (at least on emulator) if (borderWidth > 1) { tl.X = (short)((tl.X > borderWidth) ? tl.X - borderWidth * 2 : 0); tl.Y = (short)((tl.Y > borderWidth) ? tl.Y - borderWidth * 2 : 0); br.X = (short)((br.X + borderWidth < (screen.Width - 1)) ? br.X + borderWidth * 1.5 : 0); br.Y = (short)((br.Y + borderWidth < (screen.Width - 1)) ? br.Y + borderWidth * 1.5 : 0); } // we need separate bitmap to draw poly as one specififed can have some drawing already and we won't be able to detect border properly Bitmap buffer = new Bitmap((br.X - tl.X + 1), (br.Y - tl.Y + 1)); // fill bitmap with color opposite to border color if (borderColor == Color.Black) buffer.DrawRectangle(Color.White, 0, 0, 0, buffer.Width, buffer.Height, 0, 0, Color.White, 0, 0, Color.White, buffer.Width, buffer.Height, 0xFF); else buffer.DrawRectangle(Color.Black, 0, 0, 0, buffer.Width, buffer.Height, 0, 0, Color.Black, 0, 0, Color.Black, buffer.Width, buffer.Height, 0xFF); _DrawUnfilledPoly(buffer, points, borderColor, borderWidth, tl); // scan created bitmap bool isInside = false, onBorder = false; int startX = -1, borderStart = -1; for (int y = 0; y < buffer.Height; ++y) { isInside = false; onBorder = false; startX = -1; borderStart = -1; for (int x = 0; x < buffer.Width; ++x) { if (buffer.GetPixel(x, y) == borderColor) { if (onBorder) { // still on border screen.SetPixel(x + tl.X, y + tl.Y, borderColor); } else { // we have reached border from inside/outside if (isInside) { //isInside = false; if (startX >= 0) { // draw pattern line for (int k = startX; k < x; ++k) { if (polyFill == PolyFill.POLYFILL_SOLID) screen.SetPixel(k + tl.X, y + tl.Y, fgColor); else if (polyFill == PolyFill.POLYFILL_HORIZONTAL) screen.SetPixel(k + tl.X, y + tl.Y, (polyfill_horizontal[k % 3 + 3 * (y % 3)] == 0xFF) ? fgColor : bgColor); else if (polyFill == PolyFill.POLYFILL_HORIZONTAL) screen.SetPixel(k + tl.X, y + tl.Y, (polyfill_horizontal[k % 3 + 3 * (y % 3)] == 0xFF) ? fgColor : bgColor); else if (polyFill == PolyFill.POLYFILL_VERTICAL) screen.SetPixel(k + tl.X, y + tl.Y, (polyfill_vertical[k % 3 + 3 * (y % 3)] == 0xFF) ? fgColor : bgColor); else if (polyFill == PolyFill.POLYFILL_DOTS) screen.SetPixel(k + tl.X, y + tl.Y, (polyfill_dots[k % 3 + 3 * (y % 3)] == 0xFF) ? fgColor : bgColor); else if (polyFill == PolyFill.POLYFILL_GRID) screen.SetPixel(k + tl.X, y + tl.Y, (polyfill_grid[k % 3 + 3 * (y % 3)] == 0xFF) ? fgColor : bgColor); else if (polyFill == PolyFill.POLYFILL_CROSS_LEFT) screen.SetPixel(k + tl.X, y + tl.Y, (polyfill_cross_left[k % 3 + 3 * (y % 3)] == 0xFF) ? fgColor : bgColor); else if (polyFill == PolyFill.POLYFILL_CROSS_RIGHT) screen.SetPixel(k + tl.X, y + tl.Y, (polyfill_cross_right[k % 3 + 3 * (y % 3)] == 0xFF) ? fgColor : bgColor); } startX = -1; } } onBorder = true; borderStart = x; screen.SetPixel(x + tl.X, y + tl.Y, borderColor); } } else { if (onBorder) { // end of border if (!((x - borderStart) > borderWidth * 4)) // if long this is not border, this is poly edge - we are still on the same side isInside = !isInside; onBorder = false; borderStart = -1; if (isInside) startX = x; } } } } buffer.Dispose(); } }
private void Refresh(Bitmap screen) { if (_weather == null) { Style cStyle = StyleManager.CurrentStyle; screen.DrawRectangle(cStyle.BackgroundColor, 0, ScreenLeft, ScreenTop, Width, Height, 0, 0, cStyle.BackgroundColor, 0, 0, cStyle.BackgroundColor, 0, 0, 256); screen.DrawTextInRect("No weather information, invalid location or no network connection available!", ScreenLeft + 20, ScreenTop + 30, Width - 40, Height - 60, Bitmap.DT_AlignmentCenter | Bitmap.DT_WordWrap, StyleManager.CurrentStyle.TextBoxEnabledInvalidBorder, Fonts.ArialItalic); } else { if (_remakeBuffer) { RemakeControlBuffer(); _remakeBuffer = false; } screen.DrawImage(ScreenLeft, ScreenTop, _buffer, 0, 0, _buffer.Width, _buffer.Height, (ushort)(Enabled ? 256 : 128)); } }
/// <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; }
private void WriteLineSelected(string str, uint x, uint y) { int size = 15; Bitmap textBmp = new Bitmap((int)_Screen.Width, (int)size); textBmp.DrawRectangle(GT.Color.White, 0, 0, 0, (int)_Screen.Width, size, 0, 0, GT.Color.White, 0, 0, GT.Color.White, 0, 0, 0xFF); textBmp.DrawText(str, _FontTitle, GT.Color.Black, 0, 0); _Screen.Draw(textBmp, x, y); textBmp.Dispose(); }