private void Pict_MouseMove(object sender, MouseEventArgs e) { // Graphics g = Pict.CreateGraphics(); if (drag) { Pict.CreateGraphics().FillRectangle(new SolidBrush(Color.White), x, y, w, h); switch (shape) { case 'd': if ((e.Button & MouseButtons.Left) == MouseButtons.Left) { size = Convert.ToDouble(txtSize.Text); Pict.CreateGraphics().DrawLine(new Pen(Color.FromArgb(R, G, B)), LastP, e.Location); g.DrawLine(new Pen(Color.FromArgb(R, G, B), (float)size), LastP, e.Location); LastP = e.Location; } break; case 'e': if ((e.Button & MouseButtons.Left) == MouseButtons.Left) { size = Convert.ToDouble(txtSize.Text); g.DrawEllipse(new Pen(Color.White, (float)size), x, y, Convert.ToInt32(size), Convert.ToInt32(size)); x = e.X; y = e.Y; } break; } } }
private void Pict_MouseUp(object sender, MouseEventArgs e) { w = Math.Abs(e.X - x); if (e.X < x) { x = e.X; } h = Math.Abs(e.Y - y); if (e.Y < y) { y = e.Y; } //Graphics g = Pict.CreateGraphics(); size = Convert.ToDouble(txtSize.Text); switch (shape) { case 'r': Pict.CreateGraphics().DrawRectangle(new Pen(Color.FromArgb(R, G, B)), x, y, w, h); g.DrawRectangle(new Pen(Color.FromArgb(R, G, B), (float)size), x, y, w, h); break; case 'c': Pict.CreateGraphics().DrawEllipse(new Pen(Color.FromArgb(R, G, B)), x, y, w, h); g.DrawEllipse(new Pen(Color.FromArgb(R, G, B), (float)size), x, y, w, h); break; } drag = false; //g.Dispose(); }
/// <summary> /// Constructor of a FormatButton. The different <c>PictureBox</c>es must be at exactly the same possition. Their visibility is /// set according to the start status. /// </summary> /// <param name="inUnsetPict">The <c>PictureBox</c> that shows unset status.</param> /// <param name="inSetPict">The <c>PictureBox</c> that shows set status.</param> /// <param name="inPressedPict">The <c>PictureBox</c> that shows the status when the button is pressed.</param> /// <param name="inSetOverPict">The <c>PictureBox</c> that shows the status when the mouse is over the set button. This is typically a /// supplementary visible frame around the button</param> /// <param name="inSetAct">The method that must be called when the button is set</param> /// <param name="inUnsetAct">The method that must be called when the button is unset</param> /// <param name="startState"><c>true</c> means set, <c>false</c> means unset</param> public FormatButtonHandler2(PictureBox inPictBox, Image inUnsetPict, Image inSetPict, Image inPressedPict, Image inSetOverPict, Action inSetAct, Action inUnsetAct, bool startState) { logger.ConditionalTrace("Contructor FormatButtonHandler"); picts = new Image[(int)Pict.nrPict]; theBox = inPictBox; picts[(int)Pict.pressedPict] = inPressedPict; picts[(int)Pict.setOverPict] = inSetOverPict; picts[(int)Pict.setPict] = inSetPict; picts[(int)Pict.unsetPict] = inUnsetPict; setFormat = inSetAct; unsetFormat = inUnsetAct; activePict = Pict.nrPict; // no picture displayed yet if (startState) { state = State.set; } else { state = State.unset; } ActivatePict(state); theBox.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pbx_MouseDown); theBox.MouseEnter += new System.EventHandler(this.pbx_MouseEnter); theBox.MouseLeave += new System.EventHandler(this.pbx_MouseLeave); theBox.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pbx_MouseUp); }
/// <inheritdoc/> public static void SaveAsPict(this Bitmap bitmap, Stream output) { var image = bitmap.ToImageDetails(); var encoder = new Pict(); encoder.Encode(output, image); }
//Give mover a pict public Pict CreatePict(Mover m) { Pict pict; pict = new Pict(); PictAndId(pict,m.Id); pict.Height = pict.Image.Size.Height; pict.Width = pict.Image.Size.Width; return pict; }
private void ActivatePict(State s) { logger.ConditionalTrace("ActivatePict for state {0}", s.ToString()); Pict p = pictForState[(int)s]; if (p != activePict) { theBox.Image = picts[(int)p]; activePict = p; } logger.ConditionalTrace("EXIT ActivatePict. Picture {0} is active", activePict.ToString()); }
/// <summary> /// Encodes the image to the specified stream from the <see cref="Image{TPixel}"/>. /// </summary> /// <typeparam name="TPixel">The pixel format.</typeparam> /// <param name="image">The <see cref="ImageFrame{TPixel}"/> to encode from.</param> /// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param> /// <param name="cancellationToken">The token to request cancellation.</param> public void Encode <TPixel>(Image <TPixel> image, Stream stream, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel <TPixel> { ImageMetadata metadata = image.Metadata; IndexedImageFrame <TPixel>?quantized = default; PictSharp.PaletteEntry[] palette; ImageDetails imageDetails; this.width = image.Width; this.height = image.Height; #pragma warning disable CS8604 // Possible null reference argument. Func <int, byte[]> getScanLine = new Func <int, byte[]>(y => this.GetScanLine(image, quantized, y).ToArray()); #pragma warning restore CS8604 // Possible null reference argument. if (options.IsIndexed) { quantized = this.CreateQuantizedImage(image); palette = this.GetPalette(quantized); imageDetails = new ImageDetails( this.width, this.height, (uint)this.options.PictBpp, metadata.HorizontalResolution, metadata.VerticalResolution, palette, getScanLine); } else { imageDetails = new ImageDetails( this.width, this.height, (uint)this.options.PictBpp, (uint)(((int)this.options.PictBpp) < 32 ? 3 : 4), // todo calculate this metadata.HorizontalResolution, metadata.VerticalResolution, getScanLine); } PictSharp.Pict encoder = new Pict(); encoder.Encode(stream, imageDetails, cancellationToken); stream.Flush(); quantized?.Dispose(); }
private void Pict_Paint(object sender, PaintEventArgs e) { Pict.Show(); }
//Renew Controls and Enable timer1. Check the end of a game private void UpdateAll() { pictureBox1.Width = this.Width - 20; pictureBox1.Height = this.Height - 120; label1.Text = InfoBox.Text; WeaponPict.Left = this.Width - 78; Pict wp = new Pict(); PictAndId(wp, game.player.weapon.Id); WeaponPict.Image = wp.Image; cntTimer = 0; timer1.Enabled = true; if (!game.Playing()) { timer2.Enabled = false; if (!game.player.Alive) { Bat.cntKilled = 0; MessageBox.Show("Ooops, you failed!", "Game Over"); } else { MessageBox.Show("Congratulations, you win!", "Game Over"); switch (level) { case 1: Player.weaponGet[1] = true; break; case 3: Player.weaponGet[3] = true; break; case 4: Player.weaponGet[4] = true; break; } ++level; if (level > game.maxLevel) { Bat.cntKilled = 0; MessageBox.Show("You've passed all the levels. Well done!", "All Pass!"); level = 1; } } NewGame(); } }
//Match PictId and the picture resource private void PictAndId(Pict pict,PictId id) { if (pict == null) return; switch (id) { case PictId.Iplayer: pict.Image = Properties.Resources.player; break; case PictId.Ibat: pict.Image = Properties.Resources.bat; break; case PictId.Ighoul: pict.Image = Properties.Resources.ghoul; break; case PictId.Isword: //1 pict.Image = Properties.Resources.sword; break; case PictId.Ibow: //2 pict.Image = Properties.Resources.bow; break; case PictId.Imace: //3 pict.Image = Properties.Resources.mace; break; case PictId.Ishield: //4 pict.Image = Properties.Resources.shield; break; case PictId.Isparkblue: pict.Image = Properties.Resources.sparkblue; pict.Front = true; pict.Visible = false; break; case PictId.Isparkred: pict.Image = Properties.Resources.sparkred; pict.Front = true; pict.Visible = false; break; } }