public void HandleHit(PaintBrush brush) { Quaternion rotation = NormalToCameraRotation(brush.Normal); float width = brush.mRadius; float height = brush.mRadius; if (brush.mDecal != null) { if (brush.mDecal.width > brush.mDecal.height) { height *= (float)brush.mDecal.height / (float)brush.mDecal.width; } else { width *= (float)brush.mDecal.width / (float)brush.mDecal.height; } } Vector3 size = new Vector3(width, height, brush.mDepth); cachedMatrix = Matrix4x4.TRS(brush.Point, rotation, size); cachedDirection = rotation * Vector3.forward; cachedBrush = brush; }
/// <summary> /// Read method through XmlReader /// </summary> /// <param name="filePath"></param> /// <returns></returns> public static List <IFigure> XmlRead(String filePath) { List <IFigure> figures = new List <IFigure>(); XmlReader reader = XmlReader.Create(filePath); while (reader.Read()) { if (reader.Name == "material") { String value = reader.ReadInnerXml(); switch (value) { case "Paper": FiguresAdd(reader, figures, Material.Paper); reader.Read(); Paints paint = (Paints)int.Parse(reader.ReadInnerXml()); PaintBrush.PaintFigure(figures[figures.Count - 1], paint); break; case "Film": FiguresAdd(reader, figures, Material.Film); break; } } } reader.Close(); return(figures); }
// Use this for initialization void Start() { renderer = GetComponent <MeshRenderer>(); meshFilter = GetComponent <MeshFilter>(); rigidbody = GetComponentInParent <Rigidbody>(); _audioSource = gameObject.AddComponent <AudioSource>(); _audioSource.loop = true; _audioSource.playOnAwake = false; _audioSource.outputAudioMixerGroup = outputAudioMixerGroup; _audioSource.clip = shootSound; _audioSource.spatialBlend = 1; _audioSource.minDistance = 5; gunStartOrientation = gunMesh.rotation; //mesh = meshFilter.mesh; for (int i = 0; i < count; i++) { positions.AddFirst((SpurtPosition)null); } paintBrush = GameObject.FindGameObjectWithTag("Paintbrush").GetComponent <PaintBrush>(); tanks = GetComponentsInChildren <PaintTank>(); }
// Send a shape to the clients private static void SendStrangeShape(Vector2 position, PaintBrush primaryBrush, PaintBrush secondaryBrush, int seed, bool isRandomShape, NetConnection sc) { NetOutgoingMessage om = server.CreateMessage(); om.Write((byte)MessageDataType.RandomShape); om.Write(position.X); om.Write(position.Y); om.Write(primaryBrush.brushColor.R); om.Write(primaryBrush.brushColor.G); om.Write(primaryBrush.brushColor.B); om.Write(primaryBrush.brushColor.A); om.Write(primaryBrush.brushSize); om.Write(primaryBrush.hardness); om.Write((byte)primaryBrush.brushType); om.Write(secondaryBrush.brushColor.R); om.Write(secondaryBrush.brushColor.G); om.Write(secondaryBrush.brushColor.B); om.Write(secondaryBrush.brushColor.A); om.Write(secondaryBrush.hardness); om.Write(seed); om.Write(isRandomShape); if (sc == null) { server.SendToAll(om, NetDeliveryMethod.ReliableOrdered); } else { server.SendToAll(om, sc, NetDeliveryMethod.ReliableOrdered, 1); } }
public static Task ShowMenuCommandWatcher( AutoResetEvent autoResetEvent, DialogProvider dialogProvider, Menu <MenuAction> menu, PaintBrush brush) { return(Task.Run(() => { do { if (!Console.KeyAvailable) { Thread.Sleep(100); continue; } var key = Console.ReadKey(false).Key; switch ((int)key) { case (int)MenuAction.ServiceStart: Action = MenuAction.ServiceStart; break; case (int)MenuAction.ServiceStop: Action = MenuAction.ServiceStop; break; case (int)MenuAction.ServicePause: Action = MenuAction.ServicePause; break; case (int)MenuAction.ServiceContinue: Action = MenuAction.ServiceContinue; break; case (int)MenuAction.ServiceShutdown: Action = MenuAction.ServiceShutdown; break; case (int)MenuAction.Exit: Action = MenuAction.Exit; break; case (int)ConsoleKey.F1: lock (ConsoleGuardian) { Console.WriteLine("\n" + menu); } continue; default: continue; } autoResetEvent.Set(); } while (Action != MenuAction.Exit); })); }
/// <summary> /// Read method through StreamReadr /// </summary> /// <param name="filePath"></param> /// <returns></returns> public static List <IFigure> StreamRead(string filePath) { List <IFigure> figures = new List <IFigure>(); StreamReader stream = new StreamReader(filePath); XDocument document = XDocument.Load(stream); XElement xRoot = document.Element("figures"); foreach (XElement xe in xRoot.Elements("figure").ToList()) { switch (xe.Element("material").Value) { case "Paper": FiguresAdd(xe, figures, Material.Paper); Paints paint = (Paints)int.Parse(xe.Element("color").Value); PaintBrush.PaintFigure(figures[figures.Count - 1], paint); break; case "Film": FiguresAdd(xe, figures, Material.Film); break; } } stream.Close(); return(figures); }
// Draw and send lines private void DrawLine(Vector2 oldPosition, Vector2 newPosition, PaintBrush receiveBrush) { if (paintImage.PaintLine(oldPosition, newPosition, receiveBrush)) { SendLine(oldPosition - paintImage.upperLeft, newPosition - paintImage.upperLeft, receiveBrush); } }
// Send a shape to the server private void SendStrangeShape(Vector2 position, PaintBrush primaryBrush, PaintBrush secondaryBrush, int seed, bool isRandomShape) { if (client.ServerConnection != null) { NetOutgoingMessage om = client.CreateMessage(); om.Write((byte)MessageDataType.RandomShape); om.Write(position.X); om.Write(position.Y); om.Write(primaryBrush.brushColor.R); om.Write(primaryBrush.brushColor.G); om.Write(primaryBrush.brushColor.B); om.Write(primaryBrush.brushColor.A); om.Write(primaryBrush.brushSize); om.Write(primaryBrush.hardness); om.Write((byte)primaryBrush.brushType); om.Write(secondaryBrush.brushColor.R); om.Write(secondaryBrush.brushColor.G); om.Write(secondaryBrush.brushColor.B); om.Write(secondaryBrush.brushColor.A); om.Write(secondaryBrush.hardness); om.Write(seed); om.Write(isRandomShape); client.SendMessage(om, NetDeliveryMethod.ReliableOrdered); client.FlushSendQueue(); } }
// Draw a strange shape and send it to the server private void DrawStrangeShape(Vector2 position, PaintBrush primaryBrush, PaintBrush secondaryBrush, int seed, bool isRandomShape) { if (paintImage.PaintStrangeShape(position, primaryBrush, secondaryBrush, seed, isRandomShape)) { SendStrangeShape(position, primaryBrush, secondaryBrush, seed, isRandomShape); } }
// todo Implement PromtUser method // todo Implement ShowNotification/overload for AskUser method // todo Add overload taking string[] param for multiple-row message // todo Add param for more display positions (center, top-left etc..) /// <summary> /// Shows one-row long message /// </summary> /// <param name="message"></param> /// <param name="brush"></param> /// <returns></returns> public CancellationTokenSource ShowNotification(string message, PaintBrush brush) { CancellationTokenSource cts = new CancellationTokenSource(); Task.Run(() => { Canvas notificationCanvas = new Canvas { Width = message.Length + 4, Height = 5, RenderPosition = RenderPosition.TopLeft }; // render brush.RenderCanvas(notificationCanvas); for (int i = 0; i < message.Length; i++) { brush.Render( notificationCanvas, new Position(notificationCanvas.CenterXPosition - (int)Math.Ceiling(message.Length / 2.0) + i, 1), message[i]); } // wait for cancelation WaitHandle.WaitAll(new[] { cts.Token.WaitHandle }); // derender brush.DerenderCanvas(notificationCanvas); }, cts.Token); return(cts); }
internal float ApplyColorAtNoSync(BetterPaintMod mymod, PaintLayerType layer, PaintBrushType brushType, Color color, byte glow, PaintBrushSize brushSize, float pressurePrecent, int randSeed, int worldX, int worldY) { if (Main.netMode == 2) { throw new ModHelpersException("No server."); } PaintBrush brush = mymod.Modes[brushType]; float paintsUsed = 0f; switch (layer) { case PaintLayerType.Background: paintsUsed += brush.Apply(this.Background, color, glow, brushSize, pressurePrecent, randSeed, worldX, worldY); break; case PaintLayerType.Foreground: paintsUsed += brush.Apply(this.Foreground, color, glow, brushSize, pressurePrecent, randSeed, worldX, worldY); break; case PaintLayerType.Anyground: paintsUsed += brush.Apply(this.Background, color, glow, brushSize, pressurePrecent, randSeed, worldX, worldY); paintsUsed += brush.Apply(this.Foreground, color, glow, brushSize, pressurePrecent, randSeed, worldX, worldY); break; default: throw new ModHelpersException("Not implemented."); } return(paintsUsed); }
//列项点击 private async void BrushListView_ItemClick(object sender, ItemClickEventArgs e) { if (e.ClickedItem is PaintBrush) { PaintBrush pb = e.ClickedItem as PaintBrush; //画笔四大参数 App.Setting.PaintWidth = pb.Width; App.Setting.PaintHard = pb.Hard; App.Setting.PaintOpacity = pb.Opacity; App.Setting.PaintSpace = pb.Space; //如果不是位图 if (pb.isBitmap == false) { App.Setting.isPaintBitmap = false; App.Setting.PaintSet(App.Model.VirtualControl, App.Setting.PaintWidth, App.Model.Color); } else if (pb.isBitmap == true) { App.Setting.isPaintBitmap = true; App.Setting.PaintBitmap = await CanvasBitmap.LoadAsync(App.Model.VirtualControl, pb.Bitmap); App.Setting.PaintSet(App.Model.VirtualControl, App.Setting.PaintBitmap, App.Setting.PaintWidth, App.Model.Color); } } }
// Send a line to the clients private static void SendLine(Vector2 oldPosition, Vector2 newPosition, PaintBrush sendBrush, NetConnection sc) { // Make sure the pixel is not outside the bounds of the image NetOutgoingMessage om = server.CreateMessage(); om.Write((byte)MessageDataType.Line); om.Write(oldPosition.X); om.Write(oldPosition.Y); om.Write(newPosition.X); om.Write(newPosition.Y); om.Write(sendBrush.brushColor.R); om.Write(sendBrush.brushColor.G); om.Write(sendBrush.brushColor.B); om.Write(sendBrush.brushColor.A); om.Write(sendBrush.brushSize); om.Write(sendBrush.hardness); om.Write((byte)sendBrush.brushType); if (sc == null) { server.SendToAll(om, NetDeliveryMethod.ReliableOrdered); } else { server.SendToAll(om, sc, NetDeliveryMethod.ReliableOrdered, 1); } }
protected void CreateBrush() { if (this.m_brush.IsValid) { this.DestroyBrush(); } this.m_brush = PaintBrush.Create(!this.m_square.Value, this.m_radius.Value, this.m_hardness.Value, this.m_opacity.Value, this.m_distortion.Value * this.m_radius.Value * 0.7f); }
// Use this for initialization void Start() { pref_PaintContact = Resources.Load <GameObject>("Prefabs/pref_PaintContact"); particleSystem = GameObject.Instantiate <GameObject>(pref_PaintContact).GetComponent <ParticleSystem>(); particleSystem.enableEmission = false; wheelCollider = GetComponent <WheelCollider>(); paintBrush = PaintBrush.Locate(); }
private static SKPaint GetSKPaint(PaintBrush paint) { if (!s_paintCache.TryGetValue(paint, out SKPaint skPaint)) { skPaint = paint.ToSkia(); s_paintCache.Add(paint, skPaint); } return(skPaint); }
// Draw a strange shape and send it to the clients private static void DrawStrangeShape(Vector2 position, PaintBrush primaryBrush, PaintBrush secondaryBrush, int seed, bool isRandomShape, NetConnection sc) { if (!notReady.Contains(sc)) { if (paintImage.PaintStrangeShape(position, primaryBrush, secondaryBrush, seed, isRandomShape)) { SendStrangeShape(position, primaryBrush, secondaryBrush, seed, isRandomShape, sc); } } }
// Receive line data private static void DrawLine(Vector2 oldPosition, Vector2 newPosition, PaintBrush receiveBrush, NetConnection sc) { if (!notReady.Contains(sc)) { if (paintImage.PaintLine(oldPosition + paintImage.upperLeft, newPosition + paintImage.upperLeft, receiveBrush)) { SendLine(oldPosition, newPosition, receiveBrush, sc); } } }
public void ImpossibleToPaintTest(Material material, params double[] values) { TestDelegate func = delegate { IFigure figure = factory.CreateFigure(material, values); PaintBrush.PaintFigure(figure, Paints.Black); PaintBrush.PaintFigure(figure, Paints.Blue); }; Assert.Catch <ImpossibleToPaintException>(func); }
public void WriteStreamReadStreamPaper() { Box box = InitializeFigures(); box.StreamWritePaper(@"D:\Mega\Learning\Semester5\Training.by\Tasks\Task3\resources\figures.xml"); box = new Box(); box.StreamRead(@"D:\Mega\Learning\Semester5\Training.by\Tasks\Task3\resources\paperFigures.xml"); IFigure figure = factory.GetFigure(Material.Paper, 7); PaintBrush.PaintFigure(figure, Paints.Azure); Assert.IsTrue(box.GetFigure(1).Equals(figure)); Assert.AreEqual(box.GetFiguresCount(), 3); }
private void SelectNewOption <TReturnType>(Menu <TReturnType> menu, PaintBrush brush, int newIndex) { lock (consoleGuardian) { brush.DeselectChoice(menu); } menu.SelectedChoice = menu.Choices.ToList()[newIndex]; lock (consoleGuardian) { brush.SelectChoice(menu); } }
// todo Implement PromtUser method // todo Implement ShowNotification/overload for AskUser method // todo Add overload taking string[] param for multiple-row message // todo Add param for more display positions (center, top-left etc..) /// <summary> /// Shows one-row long message /// </summary> /// <param name="message"></param> /// <param name="brush"></param> /// <param name="slowWrite"></param> /// <returns></returns> public CancellationTokenSource ShowNotification(string message, PaintBrush brush, bool slowWrite = false) { CancellationTokenSource cts = new CancellationTokenSource(); Task.Run(() => { Canvas notificationCanvas = new Canvas { Width = message.Length + 5, Height = 5, RenderPosition = RenderPosition.TopLeft }; // render lock (consoleGuardian) { brush.RenderCanvas(notificationCanvas); } lock (consoleGuardian) { if (slowWrite) { for (int i = 0; i < message.Length; i++) { brush.Render( notificationCanvas, new Position(notificationCanvas.CenterXPosition - (int)Math.Ceiling(message.Length / 2.0) + i, 1), message[i]); } } else { notificationCanvas.SetCursorPosition(notificationCanvas.CenterXPosition - (int)Math.Ceiling(message.Length / 2.0), 1); Console.Write(message); } } // wait for cancelation WaitHandle.WaitAll(new[] { cts.Token.WaitHandle }); // derender lock (consoleGuardian) { brush.DerenderCanvas(notificationCanvas); } }, cts.Token); return(cts); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { //// Create a new SpriteBatch, which can be used to draw textures. this.spriteBatch = new SpriteBatch(this.GraphicsDevice); //// this.graphicsEngine = new GraphicsEngine(this.spriteBatch); this.controller = new ControllerUserInput(); ITextureHandler textureHandler = new TextureHandler(this.Content); IPaintInterface painter = new PaintBrush(textureHandler, this.graphicsEngine); this.engine = new Engine(this.controller, painter); //// this.gameLoader = new GameLoader(new UnitOfWork(), this.engine); this.consoleHandler = new ConsoleHandler(this.console, this.gameLoader); }
private Box InitializeFigures() { Box box = new Box(); box.AddFigure(factory.GetFigure(Material.Film, 1)); box.AddFigure(factory.GetFigure(Material.Film, 2, 3)); box.AddFigure(factory.GetFigure(Material.Film, 4, 5, 6)); box.AddFigure(factory.GetFigure(Material.Paper, 7)); PaintBrush.PaintFigure(box.GetFigure(box.GetFiguresCount()), Paints.Azure); box.AddFigure(factory.GetFigure(Material.Paper, 8, 9)); PaintBrush.PaintFigure(box.GetFigure(box.GetFiguresCount()), Paints.Orange); box.AddFigure(factory.GetFigure(Material.Paper, 10, 11, 12)); PaintBrush.PaintFigure(box.GetFigure(box.GetFiguresCount()), Paints.Pink); return(box); }
private void Form1_Load(object sender, EventArgs e) { IUserInputInterface controller = new ControllerUserInput(this); //IPaintInterface painter = new PaintBrush(this); IPaintInterface painter = new PaintBrush(this, controller); var engine = new Engine(controller, painter, TIME_INTERVAL); var timer = new Timer { Interval = 30 }; timer.Tick += (s, args) => { engine.Update(); }; timer.Start(); }
public bool[,] DeadFill( bool[,] field, Canvas canvas, PaintBrush brush, List <Data.Base.Position> excludes, Context ctx) { void CheckNeighbors(Position basePosition, List <Position> checkedListInternal) { if (excludes.Any(x => x.X == basePosition.X && x.Y == basePosition.Y)) { return; } List <Position> neighbors = basePosition.GetAvaibleNeighbors(field, checkedListInternal, ctx); if (neighbors.Count > 1) { return; } //brush.Render(canvas, new Data.Base.Position(basePosition.X, basePosition.Y), CharacterMap.LightTrail); if (neighbors.Count == 0) { return; } checkedListInternal.Add(neighbors.First()); CheckNeighbors(neighbors.First(), checkedListInternal); } for (int i = 0; i < 2; i++) { for (int y = 0; y < field.GetLength(0); y++) { for (int x = 0; x < field.GetLength(1); x++) { //if (field[y, x]) continue; CheckNeighbors(new Position(x, y), new List <Position>()); } } } return(field); }
protected override void OnDrawItem(StatusBarDrawItemEventArgs e) { if (e.Panel.GetType().ToString().EndsWith("StatusBarPanelEx")) { StatusBarPanelEx ProgressPanel = (StatusBarPanelEx)e.Panel; //if this panel style!=ProgressBar? dont draw if (!(ProgressPanel.Style.ToString().EndsWith("ProgressBar"))) { return; } //draw if progress bar if (ProgressPanel.Value > ProgressPanel.Minimum) { int NewWidth = (int)(((double)ProgressPanel.Value / (double)ProgressPanel.Maximum) * (double)ProgressPanel.Width); Rectangle NewBounds = e.Bounds; //select brush type Brush PaintBrush; if (ProgressPanel.Style == StatusBarPanelStyleEx.SmoothProgressBar) { PaintBrush = new SolidBrush(ProgressPanel.ForeColor); } else { PaintBrush = new HatchBrush(ProgressPanel.HatchedProgressBarStyle, ProgressPanel.ForeColor, this.Parent.BackColor); } NewBounds.Width = NewWidth; e.Graphics.FillRegion(PaintBrush, new Region(NewBounds)); PaintBrush.Dispose(); } else { base.OnDrawItem(e); } } else { base.OnDrawItem(e); } }
private void UseTool(MarchingTerrain terrain) { if (!IsReady()) { return; } switch (m_terrainEditorUtility.currentProps.currentToolType) { case ToolType.CircleBrush: CircleBrush.Execute(terrain, m_terrainEditorUtility.currentProps, m_hotkeyUtility.IsInvertedMode()); break; case ToolType.SphereBrush: SphereBrush.Execute(terrain, m_terrainEditorUtility.currentProps, m_hotkeyUtility.IsInvertedMode()); break; case ToolType.Smooth: SmoothBrush.Execute(terrain, m_terrainEditorUtility.currentProps, m_hotkeyUtility.IsInvertedMode()); break; case ToolType.Noise: NoiseBrush.Execute(terrain, m_terrainEditorUtility.currentProps, m_hotkeyUtility.IsInvertedMode()); break; case ToolType.Paint: PaintBrush.Execute(terrain, m_terrainEditorUtility.currentProps, m_hotkeyUtility.IsInvertedMode()); break; } }
protected override void OnBuildToolBar(Toolbar tb) { base.OnBuildToolBar(tb); // Change the cursor when the BrushWidth is changed. brush_width.ComboBox.Changed += (sender, e) => SetCursor(DefaultCursor); if (brush_label == null) { brush_label = new ToolBarLabel(string.Format(" {0}: ", Catalog.GetString("Type"))); } if (brush_combo_box == null) { brush_combo_box = new ToolBarComboBox(100, 0, false); brush_combo_box.ComboBox.Changed += (o, e) => { Gtk.TreeIter iter; if (brush_combo_box.ComboBox.GetActiveIter(out iter)) { active_brush = (PaintBrush)brush_combo_box.Model.GetValue(iter, 1); } else { active_brush = default_brush; } }; foreach (var brush in PintaCore.PaintBrushes) { if (default_brush == null) { default_brush = (PaintBrush)brush; } brush_combo_box.Model.AppendValues(brush.Name, brush); } brush_combo_box.ComboBox.Active = 0; } tb.AppendItem(brush_label); tb.AppendItem(brush_combo_box); }
// Send a line to the server private void SendLine(Vector2 oldPosition, Vector2 newPosition, PaintBrush sendBrush) { if (client.ServerConnection != null) { NetOutgoingMessage om = client.CreateMessage(); om.Write((byte)MessageDataType.Line); om.Write(oldPosition.X); om.Write(oldPosition.Y); om.Write(newPosition.X); om.Write(newPosition.Y); om.Write(sendBrush.brushColor.R); om.Write(sendBrush.brushColor.G); om.Write(sendBrush.brushColor.B); om.Write(sendBrush.brushColor.A); om.Write(sendBrush.brushSize); om.Write(sendBrush.hardness); om.Write((byte)sendBrush.brushType); client.SendMessage(om, NetDeliveryMethod.ReliableOrdered); client.FlushSendQueue(); } }