public void Load(SafeUri uri) { if (is_disposed) { return; } //First, send a thumbnail if we have one if ((thumb = App.Instance.Container.Resolve <IThumbnailService> ().TryLoadThumbnail(uri, ThumbnailSize.Large)) != null) { pixbuf_orientation = ImageOrientation.TopLeft; AreaPrepared?.Invoke(this, new AreaPreparedEventArgs(true)); AreaUpdated?.Invoke(this, new AreaUpdatedEventArgs(new Rectangle(0, 0, thumb.Width, thumb.Height))); } using (var image_file = App.Instance.Container.Resolve <IImageFileFactory> ().Create(uri)) { image_stream = image_file.PixbufStream(); pixbuf_orientation = image_file.Orientation; } Loading = true; // The ThreadPool.QueueUserWorkItem hack is there cause, as the bytes to read are present in the stream, // the Read is CompletedAsynchronously, blocking the mainloop image_stream.BeginRead(buffer, 0, count, delegate(IAsyncResult r) { ThreadPool.QueueUserWorkItem(delegate { HandleReadDone(r); }); }, null); }
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null) { base.OnPropertyChanged(propertyName); if (new List <string> { nameof(X), nameof(Y), nameof(Width), nameof(Height) }.Contains(propertyName) && !Batched) { OverlayArea = Bounds; } if (propertyName == nameof(OverlayArea)) { AreaUpdated?.Invoke(this, EventArgs.Empty); } }
public void UpdateArea() { if (_client.IsLoggedIn) { if (MapDump.Areas != null && MapDump.Areas.Count > 1) { foreach (MAPAPI.Response.Area area in MapDump.Areas) { if (_client.PlayerX >= area.StartX && _client.PlayerX <= area.EndX && _client.PlayerY >= area.StartY && _client.PlayerY <= area.EndY) { if (CurrentArea.AreaName.ToLowerInvariant() != area.AreaName.ToLowerInvariant()) { AreaUpdated?.Invoke(); CurrentArea = area; DimensionX = area.EndX; DimensionY = area.EndY; } break; } } } if (CurrentArea is null) { DimensionX = Width; DimensionY = Height; if (MapDump.Areas is null is false && MapDump.Areas.Count == 1) { CurrentArea = MapDump.Areas.FirstOrDefault(); if (CurrentArea != null) { CurrentArea.EndX = Width; CurrentArea.EndY = Height; AreaUpdated?.Invoke(); return; } } CurrentArea = new Area { AreaName = MapDump.Settings.MapName, EndX = Width, EndY = Height, StartX = 0, StartY = 0 }; AreaUpdated?.Invoke(); } } }
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null) { base.OnPropertyChanged(propertyName); if (propertyName == nameof(OverlayArea)) { AreaUpdated?.Invoke(this, EventArgs.Empty); } if (propertyName == nameof(Content) || propertyName == nameof(ControlTemplate)) { if (_controller != null) { var controller = _controller; (this as IOverlayOutput).Controller = null; controller.Layout(new Rectangle(0, 0, -1, -1)); Device.BeginInvokeOnMainThread(() => (this as IOverlayOutput).Controller = controller); } } }
void HandleReadDone(IAsyncResult ar) { if (is_disposed) { return; } int byte_read = image_stream.EndRead(ar); lock (sync_handle) { if (byte_read == 0) { image_stream.Close(); Close(); Loading = false; notify_completed = true; } else { try { if (!is_disposed && Write(buffer, (ulong)byte_read)) { image_stream.BeginRead(buffer, 0, count, HandleReadDone, null); } } catch (ObjectDisposedException) { } catch (GLib.GException) { } } } GLib.Idle.Add(delegate { //Send the AreaPrepared event if (notify_prepared) { notify_prepared = false; if (thumb != null) { thumb.Dispose(); thumb = null; } AreaPrepared?.Invoke(this, new AreaPreparedEventArgs(false)); } //Send the AreaUpdated events if (damage != Rectangle.Zero) { AreaUpdated?.Invoke(this, new AreaUpdatedEventArgs(damage)); damage = Rectangle.Zero; } //Send the Completed event if (notify_completed) { notify_completed = false; OnCompleted(); } return(false); }); }
private void ProcessAreas() { if (_client.IsLoggedIn) { if (MapDump.Areas != null && MapDump.Areas.Count > 1) { foreach (MAPAPI.Response.Area area in MapDump.Areas) { if (_client.PlayerX >= area.StartX && _client.PlayerX <= area.EndX && _client.PlayerY >= area.StartY && _client.PlayerY <= area.EndY) { CurrentArea = area; DimensionX = area.EndX; DimensionY = area.EndY; break; } } } if (CurrentArea is null) { DimensionX = Width; DimensionY = Height; if (MapDump.Areas is null is false && MapDump.Areas.Count == 1) { CurrentArea = MapDump.Areas.FirstOrDefault(); if (CurrentArea != null) { CurrentArea.EndX = Width; CurrentArea.EndY = Height; AreaUpdated?.Invoke(); return; } } CurrentArea = new Area { AreaName = MapDump.Settings.MapName, EndX = Width, EndY = Height, StartX = 0, StartY = 0 }; } } if (MapDump.Areas is null) { return; } foreach (var ar in MapDump.Areas) { var destination = ar.AreaName.ToUpperInvariant(); if (!AreaLinks.ContainsKey(destination)) { AreaLinks.Add(destination, new List <Tuple <int, int> >()); } var linky = ar.EndY; for (int y = ar.StartY; y <= ar.EndY; ++y) { for (int x = ar.StartX; x <= ar.EndX; ++x) { if (GetCollider(x, y) != 1) { if (IsInArea(ar, x, y)) { AreaLinks[destination].Add(new Tuple <int, int>(x, y)); } else if (IsInArea(ar, x, y - 1) && !(y - 1 < ar.StartY)) { AreaLinks[destination].Add(new Tuple <int, int>(x, y - 1)); } else if (IsInArea(ar, x, y + 1) && !(y + 1 > ar.EndY)) { AreaLinks[destination].Add(new Tuple <int, int>(x, y + 1)); } else if (IsInArea(ar, x - 1, y) && !(x - 1 < ar.StartX)) { AreaLinks[destination].Add(new Tuple <int, int>(x - 1, y)); } else if (IsInArea(ar, x + 1, y) && !(x + 1 > ar.EndX)) { AreaLinks[destination].Add(new Tuple <int, int>(x + 1, y)); } } } } } }