void OnMousePress(object source, ButtonPressEventArgs args) { Start.X = args.Event.X; Start.Y = args.Event.Y; End.X = args.Event.X; End.Y = args.Event.Y; isDrawing = true; area.QueueDraw(); }
/// <summary> /// Request a refresh of drawing area /// </summary> private void Refresh() { Gtk.Application.Invoke(delegate { drawingArea.QueueDraw(); }); }
private bool Redraw() { while (simulation.updateLock) { continue; } drawingArea.QueueDraw(); return(true); }
private void AfterUpdate() { _canvas.QueueDraw(); _iterationLbl.Text = "i = " + _model.ActiveRun.Get().Iteration + ", e = " + _model.ActiveRun.Get().ElapsedTime / 1000 + "s" + ", a = " + Math.Round(_model.ActiveRun.Get().AverageIterationTime, 2) + "ms"; }
bool OnTimer() { if (!timer) { return(false); } darea.QueueDraw(); return(true); }
private void DrawingArea_KeyPressEvent(object o, KeyPressEventArgs args) { var @event = args.Event; if (CurrentTool?.KeyPressed(this, @event) ?? false) { // The tool consumed this keypress. args.RetVal = true; return; } var modifier = @event.State & Accelerator.DefaultModMask; // Check that control is the only modifier pressed. if ((modifier ^ ModifierType.ControlMask) == 0) { if (@event.Key == Gdk.Key.z) { // This is ctrl-z, i.e. undo if (Transactions.TryUndo(out var transaction)) { // We do the no push variant here because // TryUndo already modified the undo stack. UndoTransactionNoPush(transaction); Console.WriteLine($"Undid transaction: {transaction}"); DrawingArea.QueueDraw(); } } else if (@event.Key == Gdk.Key.y) { // This is ctrl-y, i.e. redo if (Transactions.TryRedo(out var transaction)) { // We do no push here because TryRedo already did the push. DoTransactionNoPush(transaction); Console.WriteLine($"Redid transaction: {transaction}"); DrawingArea.QueueDraw(); } } } // Check that control and shift are the only modifiers pressed. if ((modifier ^ (ModifierType.ControlMask | ModifierType.ShiftMask)) == 0) { if (@event.Key == Gdk.Key.Z) { // This is ctrl-shift-z, i.e. redo if (Transactions.TryRedo(out var transaction)) { // We do no push here because TryRedo already did the push. DoTransactionNoPush(transaction); Console.WriteLine($"Redid transaction: {transaction}"); DrawingArea.QueueDraw(); } } } }
private bool Loop() { if (!_engine.GameCycled()) { return(_keepLooping); } _area.QueueDraw(); return(_keepLooping && _engine.GameIsRunning); }
/// <summary> /// Translates cartesian to barycentric coordinates and updates /// the marker location, label text and internal variable value /// but does update the model/presenter. /// </summary> /// <param name="point"></param> private void MoveTo(PointD point) { // Coordinates must be adjusted according to offset/scale. double posX = (point.X - offsetX) / sideLength; double posY = (point.Y - offsetY) / sideLength; Z = MathUtilities.Bound(Total * (1 - 2 * posY / Math.Sqrt(3)), 0, Total); Y = MathUtilities.Bound((2 * posX * Total - Z) / 2, 0, Total - Z); X = MathUtilities.Bound(Total - Y - Z, 0, Total); chart.QueueDraw(); }
void OnMousePress(object source, ButtonPressEventArgs args) { surface = new ImageSurface(Format.Argb32, Convert.ToInt32(Element.Width), Convert.ToInt32(Element.Height)); point.X = args.Event.X; point.Y = args.Event.Y; currentLine = new Line() { Points = new System.Collections.ObjectModel.ObservableCollection <Point>() { new Point(point.X, point.Y) } }; previousPoint = point; isDrawing = true; area?.QueueDraw(); if (!Element.MultiLineMode) { Element.Lines.Clear(); } }
private void Button_Released(object sender, ButtonEventArgs e) { var widget = sender as Widget; var gdkWindow = widget.GdkWindow; if (e.Button == Buttons.Left && e.IsButtonRelease) { button.Label = $"{++clicks} click(s)"; } drawingArea.QueueDraw(); }
/// <summary> /// Unselect any selected objects. /// </summary> public void UnSelect() { nodes.ForEach(node => { node.Selected = false; }); arcs.ForEach(arc => { arc.Selected = false; }); SelectedObject = null; SelectedObject2 = null; mouseDown = false; isDragging = false; // Redraw area. drawable.QueueDraw(); OnGraphObjectSelected?.Invoke(this, new GraphObjectSelectedArgs(null)); }
// timeout handler to regenerate the frame bool timeout() { background.CopyArea(0, 0, backWidth, backHeight, frame, 0, 0); double f = (double)(frameNum % CycleLen) / CycleLen; int xmid = backWidth / 2; int ymid = backHeight / 2; double radius = Math.Min(xmid, ymid) / 2; for (int i = 0; i < images.Length; i++) { double ang = 2 * Math.PI * (double)i / images.Length - f * 2 * Math.PI; int iw = images[i].Width; int ih = images[i].Height; double r = radius + (radius / 3) * Math.Sin(f * 2 * Math.PI); int xpos = (int)Math.Floor(xmid + r * Math.Cos(ang) - iw / 2.0 + 0.5); int ypos = (int)Math.Floor(ymid + r * Math.Sin(ang) - ih / 2.0 + 0.5); double k = (i % 2 == 1) ? Math.Sin(f * 2 * Math.PI) : Math.Cos(f * 2 * Math.PI); k = 2 * k * k; k = Math.Max(0.25, k); Rectangle r1, r2, dest; r1 = new Rectangle(xpos, ypos, (int)(iw * k), (int)(ih * k)); r2 = new Rectangle(0, 0, backWidth, backHeight); dest = Rectangle.Intersect(r1, r2); if (!dest.IsEmpty) { images[i].Composite(frame, dest.X, dest.Y, dest.Width, dest.Height, xpos, ypos, k, k, InterpType.Nearest, (int)((i % 2 == 1) ? Math.Max(127, Math.Abs(255 * Math.Sin(f * 2 * Math.PI))) : Math.Max(127, Math.Abs(255 * Math.Cos(f * 2 * Math.PI))))); } } drawingArea.QueueDraw(); frameNum++; return(true); }
bool OnTimer() { if (!timer) { return(false); } // Let the Actor do it's thing actor.Do(); // Render the updates to the Drawables darea.QueueDraw(); return(true); }
TimerApp() { win = new Window("Timer Example"); win.SetDefaultSize(260, 110); da = new DrawingArea(); // For DeleteEvent Observable.FromEventPattern <DeleteEventArgs>(win, "DeleteEvent") .Subscribe(delegate { Application.Quit(); }); // For Timer Observable.Interval(TimeSpan.FromSeconds(1)) .Subscribe(_ => { Gtk.Application.Invoke(delegate { da.QueueDraw(); }); }); // For DrawingArea event Observable.FromEventPattern <DrawnArgs>(da, "Drawn") .Subscribe(args => { Cairo.Context cr = args.EventArgs.Cr; cr.SetSourceRGB(0.5, 0.5, 0.5); cr.Paint(); cr.SetFontSize(48); cr.MoveTo(20, 68); string date = DateTime.Now.ToString("HH-mm-ss"); cr.SetSourceRGB(0.2, 0.23, 0.9); cr.ShowText(date); cr.Fill(); ((IDisposable)cr).Dispose(); args.EventArgs.RetVal = true; }); win.Add(da); win.ShowAll(); }
void Go(Pos p) { if (!IsInside(p)) { return; } if (map[p.x, p.y] == Cell.Goal) { current = p; Start(); } else if (map[p.x, p.y] == Cell.Nothing || map[p.x, p.y] == Cell.Start) { current = p; } area.QueueDraw(); }
private void DrawingArea_KeyPressEvent(object o, KeyPressEventArgs args) { var @event = args.Event; if (CurrentTool?.KeyPressed(this, @event) ?? false) { // The tool consumed this keypress. args.RetVal = true; return; } var modifier = @event.State & Accelerator.DefaultModMask; // Check that control is the only modifier pressed. if ((modifier ^ ModifierType.ControlMask) == 0) { if (@event.Key == Gdk.Key.z) { // This is ctrl-z, i.e. undo if (Scene.Undo()) { DrawingArea.QueueDraw(); } } else if (@event.Key == Gdk.Key.y) { // This is ctrl-y, i.e. redo if (Scene.Redo()) { DrawingArea.QueueDraw(); } } } // Check that control and shift are the only modifiers pressed. if ((modifier ^ (ModifierType.ControlMask | ModifierType.ShiftMask)) == 0) { if (@event.Key == Gdk.Key.Z) { // This is ctrl-shift-z, i.e. redo if (Scene.Redo()) { DrawingArea.QueueDraw(); } } } }
static void Main(string[] args) { var assembly = typeof(Program).Assembly; var fileVersion = assembly.GetCustomAttribute <AssemblyFileVersionAttribute>(); #if DEBUG var buildType = "Debug"; #else var buildType = "Release"; #endif Console.WriteLine($"OpenPackage (HydraEd {fileVersion.Version}/{buildType})"); if (args.Length == 0) { Console.WriteLine("Error: Run this tool again with the file path specified."); return; } var filename = string.Join(' ', args); using var file = File.OpenRead(filename); var package = new Package(file); Application.Init(); var app = new Application("com.alex.hydra.devtool", GLib.ApplicationFlags.None); app.Register(GLib.Cancellable.Current); var win = new Window(WindowType.Toplevel); var drawingArea = new DrawingArea(); win.SetSizeRequest(256, 256); drawingArea.SetSizeRequest(256, 256); var actorTree = new ActorTree(package); var gtkRenderer = new GtkRenderer(drawingArea); var hydra = new HydraEngine(actorTree, gtkRenderer); gtkRenderer.LinkTo(hydra); win.DeleteEvent += (object sender, DeleteEventArgs args) => { Application.Quit(); }; win.Child = drawingArea; app.AddWindow(win); win.ShowAll(); drawingArea.QueueDraw(); Application.Run(); }
private bool onframetick(Widget widget, Gdk.FrameClock frame_clock) { if (this.player != null) { if (!this.player.CheckDeviceEnable()) { this.player.Dispose(); this.player = null; Bass.Free(); Bass.Init(); this._labeltitle.Text = "Device Disconnected"; this._labelpath.Text = ""; this._labellooptime.Text = ""; this._labelnowtime.Text = ""; return(true); } if (this._labelseektimemenu.Active) { this._labelnowtime.Text = this.player.TimePosition.ToString(@"hh\:mm\:ss\.ff") + " / " + this.player.TotalTime.ToString(@"hh\:mm\:ss\.ff"); } else if (this._labelelpsedtimemenu.Active) { this._labelnowtime.Text = "+" + (this.player.LoopCount * (this.player.LoopEndTime - this.player.LoopStartTime) + this.player.TimePosition).ToString(@"hh\:mm\:ss\.ff") + " / " + this.player.TotalTime.ToString(@"hh\:mm\:ss\.ff"); } else if (this._labelremainingtimemenu.Active) { this._labelnowtime.Text = "-" + (this.player.TotalTime - this.player.TimePosition).ToString(@"hh\:mm\:ss\.ff") + " / " + this.player.TotalTime.ToString(@"hh\:mm\:ss\.ff"); } } Endsita(); _seekbararea.QueueDraw(); return(true); }
bool OnTimer() { darea.QueueDraw(); return(true); }
private void XorAgents() { List <NeatAgent> population = new List <NeatAgent>(); List <NeatAgent> nextPopulation = new List <NeatAgent>(); int popSize = 300; int gens = 10; for (int i = 0; i < popSize; i++) { population.Add(new NeatAgent()); } for (int j = 0; j < gens; j++) { for (int i = 0; i < population.Count; i++) { currentAgent = population[i]; drawingArea.QueueDraw(); double error = 0; error += -1 - population[i].Activate(new double[] { -1, -1 })[0]; error += -1 + population[i].Activate(new double[] { 1, -1 })[0]; error += -1 + population[i].Activate(new double[] { -1, 1 })[0]; error += -1 - population[i].Activate(new double[] { -1, -1 })[0]; population[i].fitness = error; } population.Sort(); population.Reverse(); nextPopulation.Clear(); for (int i = 0; i < popSize; i++) { int mate1 = RandomInt(popSize); int mate2 = RandomInt(popSize); while (mate1 == mate2) { mate2 = RandomInt(popSize); } nextPopulation.Add((NeatAgent)population[mate1].CrossOver(population[mate2])); } population.Clear(); for (int i = 0; i < nextPopulation.Count; i++) { population.Add(nextPopulation[i]); } Here((String.Format("pop {0}", j))); } population.Sort(); population.Reverse(); Console.WriteLine(population[0].Activate(new double[] { -1, -1 })[0]); Console.WriteLine(population[0].Activate(new double[] { 1, -1 })[0]); Console.WriteLine(population[0].Activate(new double[] { -1, 1 })[0]); Console.WriteLine(population[0].Activate(new double[] { 1, 1 })[0]); partner1 = population[0]; partner2 = population[1]; offspring = population[2]; currentAgent = partner1; }
private void DrawingArea_DrawnEvent(object sender, DrawnArgs args) { _context.SetGtkContext(args); _hydra.GetScheduler().DoUpdate(); _area.QueueDraw(); }
bool OnTimer() { count += 1; darea.QueueDraw(); return(true); }
private void DrawingArea_KeyPressEvent(object o, KeyPressEventArgs args) { var @event = args.Event; // Check that control is the only modifier pressed. if ((@event.State ^ ModifierType.ControlMask) == 0) { if (@event.Key == Gdk.Key.z) { // This is ctrl-z, i.e. undo if (Transactions.TryUndo(out var transaction)) { switch (transaction) { case WireTransaction wt: Wires.RevertTransaction(wt); break; case GateTransaction gt: Gates.RevertGateTransaction(gt); break; default: throw new Exception($"Unknown transaction type! {transaction.GetType()}"); } Console.WriteLine($"Undid transaction: {transaction}"); DrawingArea.QueueDraw(); } } else if (@event.Key == Gdk.Key.y) { // This is ctrl-y, i.e. redo if (Transactions.TryRedo(out var transaction)) { switch (transaction) { case WireTransaction wt: Wires.ApplyTransaction(wt); break; case GateTransaction gt: Gates.ApplyTransaction(gt); break; default: throw new Exception($"Unknown transaction type! {transaction.GetType()}"); } Console.WriteLine($"Redid transaction: {transaction}"); DrawingArea.QueueDraw(); } } } if ((@event.State ^ (ModifierType.ControlMask | ModifierType.ShiftMask)) == 0) { if (@event.Key == Gdk.Key.Z) { // This is ctrl-shift-z, i.e. redo if (Transactions.TryRedo(out var transaction)) { switch (transaction) { case WireTransaction wt: Wires.ApplyTransaction(wt); break; case GateTransaction gt: Gates.ApplyTransaction(gt); break; default: throw new Exception($"Unknown transaction type! {transaction.GetType()}"); } Console.WriteLine($"Redid transaction: {transaction}"); DrawingArea.QueueDraw(); } } } }
private void HandleModelChanged(object model) { Canvas.QueueDraw(); }
public void InvalidatePreviewArea() { previewArea.QueueDraw(); }
public void InvalidateDesignArea() { designArea.QueueDraw(); }
public void SwitchImages() { MainArea.QueueDraw(); }
/** * we need to call QueueDraw () on each of the drawing areas to avoid * some nasty unpainted rect artifacts on win32 **/ protected override void OnSizeAllocated(Rectangle a) { base.OnSizeAllocated(a); Requisition hbar_r = hbar.SizeRequest(), vbar_r = vbar.SizeRequest(); /** * tmp variables to store the scrollbar visibilities, as flipping * the .Visible property can cause infinite OnSizeAllocated() loop **/ bool hbar_v, vbar_v; hbar_v = hbar_policy == PolicyType.Always || (hbar_policy == PolicyType.Automatic && LeftWidth + FieldWidth + BorderWidth > a.Width); vbar_v = vbar_policy == PolicyType.Always || (vbar_policy == PolicyType.Automatic && TopHeight + FieldHeight + BorderWidth + (hbar_v ? hbar_r.Height : 0) > a.Height); if (!vbar_v) { vbar_r = Requisition.Zero; } else { /** * the horizontal space used to show the vbar may now * cause the hbar to be needed **/ hbar_v = hbar_policy == PolicyType.Always || (hbar_policy == PolicyType.Automatic && LeftWidth + FieldWidth + BorderWidth + vbar_r.Width > a.Width); } if (!hbar_v) { hbar_r = Requisition.Zero; } hbar.Visible = hbar_v; vbar.Visible = vbar_v; Rectangle wa; wa = new Rectangle(a.X, a.Y, LeftWidth, TopHeight); cda.Allocation = wa; cda.QueueDraw(); wa = new Rectangle(cda.Allocation.Right, a.Y, a.Width - LeftWidth - (int)BorderWidth - (vbar_span != ScrollbarSpan.HeaderOverlap ? vbar_r.Width : 0), TopHeight); tvp.Allocation = wa; tvp.QueueDraw(); wa = new Rectangle(a.X, cda.Allocation.Bottom, LeftWidth, a.Height - TopHeight - (int)BorderWidth - (hbar_span != ScrollbarSpan.HeaderOverlap ? hbar_r.Height : 0)); lvp.Allocation = wa; lvp.QueueDraw(); wa = new Rectangle(a.X + LeftWidth, a.Y + TopHeight, a.Width - LeftWidth - (int)BorderWidth - vbar_r.Width, a.Height - TopHeight - (int)BorderWidth - hbar_r.Height); fvp.Allocation = wa; fvp.QueueDraw(); int gap; if (hbar.Visible) { gap = hbar_span == ScrollbarSpan.Full ? 0 : LeftWidth; wa = new Rectangle(a.X + gap, a.Bottom - hbar_r.Height, a.Width - gap - vbar_r.Width, hbar_r.Height); hbar.Allocation = wa; } if (vbar.Visible) { gap = vbar_span == ScrollbarSpan.Full ? 0 : TopHeight; wa = new Rectangle(a.Right - vbar_r.Width, a.Y + gap, vbar_r.Width, a.Height - gap - hbar_r.Height); vbar.Allocation = wa; } }