private void OnCharacterLoaded(object diablo2File) { m_file = (Diablo2File)diablo2File; int offsetX = 0; int offsetY = 0; switch (Location) { case ItemLocation.Inventory: offsetX = 25; offsetY = 235; break; case ItemLocation.Stash: offsetX = 22; offsetY = 129; break; case ItemLocation.Cube: offsetX = 22; offsetY = 24; break; } var items = m_file.Items.GetItems(); foreach (var item in items.Where(i => i.Location == Location)) { RectItems.Add(new ItemModel { X = (item.PositionX * GridSize) + offsetX, Y = (item.PositionY * GridSize) + offsetY, Width = GridSize, Height = GridSize, Item = item }); } }
/// <summary> /// Метод для отрисовки расписания /// </summary> private void DrawSchedule() { var machines = (Schedule ?? throw new ArgumentNullException()).Select(m => m.Machine).Distinct().OrderBy(m => m.Name).ToList(); var y = 10; var timeLinePoint = 0; foreach (var machine in machines) { TextItems.Add(new TextDetails(10, y - 35, 50, 50, machine.Name)); RectItems.Add(new RectItem(10, y, 50, 50, "Black")); var batches = Schedule.Where(m => m.Machine.Id == machine.Id).Select(b => b.Batch).ToList(); var x = 65; foreach (var b in batches) { var color = b.NomenclatureId switch { 0 => "Gold", 1 => "Silver", 2 => "LightSteelBlue", _ => "Black" }; timeLinePoint += machine.TimeDictionary[b.NomenclatureId]; var widthFromTime = machine.TimeDictionary[b.NomenclatureId] + 15; TextItems.Add(new TextDetails(x + widthFromTime, y + 32, 20, 20, timeLinePoint.ToString())); TextItems.Add(new TextDetails(x, y, widthFromTime, 20, b.Nomenclature.Name.Substring(0, 3))); RectItems.Add(new RectItem(x, y, widthFromTime, 50, color)); x += widthFromTime + 2; } TimeLines.Add(new TimeLine(10, y + 23, x + 10, y + 23)); y += 90; timeLinePoint = 0; } } }
private void _DrawDots() { Random rand = new Random(); mre = new ManualResetEvent(false); ThreadColorPair = new ConcurrentDictionary <int, int>(); _lock = new object(); _rectLock = new object(); IsSettingsEnabled = false; IsButtonStartEnabled = false; void callbackAction() { if (mre.WaitOne(0)) { return; } Debug.WriteLine($"{Thread.CurrentThread.ManagedThreadId} - current thread id"); var x = rand.NextDouble() * WidthOfCanvas; var y = rand.NextDouble() * HeightOfCanvas; var color = Colors[_FindColorForGivenThread()]; var item = new RectItem { X = x, Y = y, Width = 1, Height = 1, Color = color }; if (App.Current == null) { return; } App.Current.Dispatcher.Invoke((Action) delegate { RectItems.Add(item); }); }; MyPool = new PoolManager(NumberOfThreads); Task runner = Task.Run(() => { while (!MyPool.IsDisposed) { var _speed = 1000 / SpeedOfDrawing; MyPool.QueueTask(callbackAction); Thread.Sleep(_speed); } }).ContinueWith((o) => { Debug.WriteLine("Drawing has stopped and threads are disposed."); }); }
/** * @brief drawRectangle * @note RectangleとTextBlock1つ描いて、 * 次の描き開始位置を計算 */ void drawRectangle() { RectItems.Add(new RectItem { X = rectX, Y = 10, Width = RECTANGLE_HEIGH_WIDTH, Height = RECTANGLE_HEIGH_WIDTH, RadiusX = 2, RadiusY = 2, Fill = new SolidColorBrush(Colors.Aqua) } ); TxtBlkItems.Add(new TxtBlkItem { Text = rectNo.ToString(), X = rectX, Y = 10, Width = RECTANGLE_HEIGH_WIDTH, Height = RECTANGLE_HEIGH_WIDTH } ); rectX = rectX + RECTANGLE_HEIGH_WIDTH + 1; // 次に描くX座標を変更 rectNo++; }