/// <summary> /// Initializes a new instance of the BookmarkManager class. /// </summary> /// <param name="parent">The parent of this window.</param> public BookmarkManager(MainDisplay parent) { InitializeComponent(); this.DataGridBookmarks.DataContext = parent.Configuration.Bookmarks; this.bookmarks = parent.Configuration.Bookmarks; }
public void InvalidatePictures() { LabelsDisplay.Invalidate(); LabelsDisplay.Update(); MainDisplay.Invalidate(); MainDisplay.Update(); }
static void Main(string[] args) { WeatherData data = new WeatherData(); MainDisplay display = new MainDisplay(data); data.start(); }
/// <summary> /// Starts the application. /// </summary> private void Application_Startup(object sender, StartupEventArgs e) { //Loads associated extension files and files by command-line. if (e.Args.Length >= 1) { //Loads the project and displays the main interface with it. if (File.Exists(e.Args[0])) { MainDisplay display = new MainDisplay( Project.Load(e.Args[0]), e.Args[0]); display.Show(); } //Displays a new project dialog on failure to load. else { DlgNewProject dlg = new DlgNewProject(); dlg.Show(); } } //Displays a new project dialog for new files. else { DlgNewProject dlg = new DlgNewProject(); dlg.Show(); } }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); var initial = e.Args.Length > 0 ? e.Args[0] : null; _mainWindow = new MainDisplay(initial); _mainWindow.Show(); }
/// <summary> /// Creates a new project. /// </summary> private void GuiNew_Click(object sender, RoutedEventArgs e) { MainDisplay display = new MainDisplay(); //Show the new display and close this one. display.Show(); gui.Close(); }
static void Main(string[] args) { // For Bulgarian text Console.OutputEncoding = Encoding.UTF8; Console.InputEncoding = Encoding.GetEncoding("windows-1251"); // Main Menu MainDisplay.Display(); }
//이미지 불러오기 private void button1_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog() { Filter = "bmp|*.bmp" }; if (dialog.ShowDialog() == DialogResult.OK) { CogImage8Grey cogImage = new CogImage8Grey(new Bitmap(dialog.FileName)); MainDisplay.Image = cogImage; MainDisplay.Fit(); PMTool.InputImage = cogImage; } }
public Form1() { InitializeComponent(); manager = new TextureManager(this); map = new Map(32, 32); map.AddLayer(); KeyPreview = true; MainDisplay.Enabled = false;//making sure you cant click before you load ImageHolder.VerticalScroll.Enabled = true; ImageHolder.AutoScroll = true; MainDisplay.AutoSize = true; addTexturesToolStripMenuItem.Click += new EventHandler(manager.AddTextureClick); tabControl1.SelectedIndexChanged += new EventHandler(manager.TabChangedHandler); g = MainDisplay.CreateGraphics(); }
private void roll_click() { IList <int> stat_set = new List <int>() { 0, 0, 0, 0, 0, 0 }; var stat_min_val = Convert.ToInt32(stat_min.Text); var stat_total_min_val = Convert.ToInt32(stat_total_min.Text); for (var i = 0; i < Convert.ToInt32(set_roll_num.Text); ++i) { do { for (var j = 0; j < 6; ++j) { stat_set[j] = roll_stat(); } } while (stat_set.Min() < stat_min_val || stat_set.Sum() < stat_total_min_val); if (radioOrderLow.Checked) { stat_set = stat_set.OrderBy(stat => stat).ToList(); } else if (radioOrderHigh.Checked) { stat_set = stat_set.OrderByDescending(stat => stat).ToList(); } var output = ""; foreach (var stat in stat_set) { output += stat.ToString(); output += " "; } output += "(Total:" + stat_set.Sum() + ")" + "\r\n"; //required in order to modify UI element from different thread than it was created in Invoke(new Action(() => { MainDisplay.AppendText(output); })); } Invoke(new Action(() => { MainDisplay.AppendText("\r\n"); })); }
private void ShowInfo() { MainDisplay.Clear(); FinalVUZ.Text = null; FinalVUZ.Text = currentUniver.Name; int facCounter = 1; int specCounter = 1; foreach (var fac in currentUniver.FacultetList) { MainDisplay.AppendText($"{facCounter}. Факультет {fac.NameOfFac} : {Environment.NewLine} {Environment.NewLine} Ціна за контракт: {fac.PayForContract} {Environment.NewLine}{Environment.NewLine} Спеціальності: {Environment.NewLine}"); facCounter++; specCounter = 1; foreach (var spec in fac.SpecList) { MainDisplay.AppendText($" {specCounter}. {spec.Name}; {Environment.NewLine} Мінімальный прохідний бал: {spec.Minbal} {Environment.NewLine} Популярність: {spec.Popular} заяв {Environment.NewLine} {Environment.NewLine}"); specCounter++; } } }
/// <summary> /// Opens a project. /// </summary> private void GuiOpen_Click(object sender, RoutedEventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.CheckPathExists = true; dlg.DefaultExt = ".mdat"; dlg.Filter = GlobalStrings.FilterOpenSaveDatabase; dlg.Title = GlobalStrings.CaptionLoadDatabase; bool?result = dlg.ShowDialog(); if (result == true) { //Constructs the project from the file, then uses //it to construct the visuals. MainDisplay display = new MainDisplay(Project.Load(dlg.FileName), dlg.FileName); //Show the new display and close this one. display.Show(); gui.Close(); } }
void RunSwarm() { Bitmap Background = new Bitmap(10, 10); IntPtr mainDC; IntPtr memDC; IntPtr tempDC; IntPtr OffscreenBmp; IntPtr oldBmp; IntPtr hBitmap = IntPtr.Zero; IntPtr prevBmp; IntPtr bugPen = Win32.CreatePen(Win32.PenStyles.PS_SOLID, 1, ColorBug); IntPtr bugBrush = Win32.CreateSolidBrush(ColorBug);; IntPtr optPen = Win32.CreatePen(Win32.PenStyles.PS_SOLID, 1, ColorOpt); IntPtr optBrush = Win32.CreateSolidBrush(ColorOpt); IntPtr oldPen; IntPtr oldBrush; int attempts = 0; int cycleTime = 0; Point displayPos = new Point(); float[] bugValue = new float[1]; while (!Shutdown) { ProcessEvent.WaitOne(); // draw background to offscreen if (Background.Width != MainDisplay.Width / Config.Scaling || Background.Height != MainDisplay.Height / Config.Scaling) { RefreshEvent.Set(); } if (Reset) { Reset = false; Time = 0; BestGlobalValue = new float[Objectives.Length]; bugValue = new float[Objectives.Length]; for (int i = 0; i < Objectives.Length; i++) { BestGlobalValue[i] = Max[i] ? float.MinValue : float.MaxValue; } BestGlobalCoord = new float[Config.Dimensions]; NonDominatingCoords.Clear(); NonDominatingValues.Clear(); } if (SetupSwarm) { SetupSwarm = false; Bugs.Clear(); if (TryGetFeasible(BestGlobalCoord)) { for (int i = 0; i < BestGlobalValue.Length; i++) { BestGlobalValue[i] = (float)Objectives[i].Invoke(BestGlobalCoord, Time); } } RefreshEvent.Set(); // ensures that when new setup loaded, it is viewed in right slice } if (LatestBG != null) { Background = LatestBG; LatestBG = null; if (hBitmap != IntPtr.Zero) { Win32.DeleteObject(hBitmap); hBitmap = IntPtr.Zero; } hBitmap = Background.GetHbitmap(); } // start drawing Graphics mainGraphics = MainDisplay.CreateGraphics(); mainDC = mainGraphics.GetHdc(); // create memeory DC and select an offscreen bmp into it memDC = Win32.CreateCompatibleDC(mainDC); OffscreenBmp = Win32.CreateCompatibleBitmap(mainDC, MainDisplay.Width, MainDisplay.Height); oldBmp = Win32.SelectObject(memDC, OffscreenBmp); tempDC = Win32.CreateCompatibleDC(mainDC); prevBmp = Win32.SelectObject(tempDC, hBitmap); Win32.StretchBlt(memDC, 0, 0, MainDisplay.Width, MainDisplay.Height, tempDC, 0, 0, Background.Width, Background.Height, (int)Win32.SRCCOPY); Win32.SelectObject(tempDC, prevBmp); Win32.DeleteDC(tempDC); // draw the swarm oldPen = Win32.SelectObject(memDC, bugPen); oldBrush = Win32.SelectObject(memDC, bugBrush); // add/remove bugs while (Bugs.Count > Config.Entities) { Bugs.RemoveAt(0); } if (Config.Entities > Bugs.Count) { int add = Bugs.Count; // AddBug can fail so we only interate a set amount for (int i = 0; i < Config.Entities - add; i++) { AddBug(); } } // use cycle time so that we can 'see' particles moving towards new destination, otherwise it looks like random jumps foreach (Particle bug in Bugs) { if (Play || Step) { if (cycleTime == 0) { // get velocity THIS IS THE MEAT if (Config.Replusion) { Particle randBug = Bugs[RndGen.Next(0, Bugs.Count - 1)]; for (int i = 0; i < Config.Dimensions; i++) { bug.TestV[i] = Config.Inertia * bug.Velocity[i] + Config.PersonalPref * (float)RndGen.NextDouble() * (bug.Best[i] - bug.Postion[i]) + -1 * Config.GlobalPref * (float)RndGen.NextDouble() * /* Config.Inertia */ (randBug.Best[i] - bug.Postion[i]) + 2 * (float)RndGen.NextDouble() * /* Config.Inertia */ (float)RndGen.NextDouble(); } } else { // choose a random best global to go towards var bestGlobal = BestGlobalCoord; if (NonDominatingCoords.Count > 0) { bestGlobal = NonDominatingCoords[RndGen.Next(NonDominatingCoords.Count)]; } for (int i = 0; i < Config.Dimensions; i++) { bug.TestV[i] = Config.Inertia * bug.Velocity[i] + Config.PersonalPref * (float)RndGen.NextDouble() * (bug.Best[i] - bug.Postion[i]) + Config.GlobalPref * (float)RndGen.NextDouble() * (bestGlobal[i] - bug.Postion[i]); } } bug.MoveNext = false; attempts = 20; while (attempts > 0) { // if new position feasible switch set velocity to the test if (IsFeasible(bug.Postion, bug.TestV)) { float[] velocity = bug.TestV; bug.TestV = bug.Velocity; bug.Velocity = velocity; bug.MoveNext = true; break; } // while outside bounds, halve velocity and recalc else { for (int i = 0; i < Config.Dimensions; i++) { bug.TestV[i] = bug.TestV[i] / 2; } attempts--; } } } // set next position if (bug.MoveNext) { for (int i = 0; i < Config.Dimensions; i++) { bug.Postion[i] = bug.Postion[i] + bug.Velocity[i] / Config.FlyTime; } } // let the particles fly a bit, take their values every so often if (cycleTime == 0) { // check for personal / global best for (int i = 0; i < Objectives.Length; i++) { bugValue[i] = (float)Objectives[i].Invoke(bug.Postion, Time); } // if time used in objectives, then values at coords need to be re-evaluated if (Config.TimeUsed) { for (int i = 0; i < Objectives.Length; i++) { BestGlobalValue[i] = (float)Objectives[i].Invoke(BestGlobalCoord, Time); } for (int i = 0; i < NonDominatingCoords.Count; i++) { for (int x = 0; x < Objectives.Length; x++) { NonDominatingValues[i][x] = (float)Objectives[x].Invoke(NonDominatingCoords[i], Time); } } } // if the position is better or non-dominates it's best if (NonDominatesPoint(bugValue, bug.BestValue)) { bugValue.CopyTo(bug.BestValue, 0); bug.Postion.CopyTo(bug.Best, 0); } // if the bug position is not dominated by prev solutions if (NonDominatesSet(bug.Postion, bugValue)) { bug.Postion.CopyTo(BestGlobalCoord, 0); // redraw if our view plane changed because a gobal optimal changed if (Config.Dimensions > 2) { RefreshEvent.Set(); } bugValue.CopyTo(BestGlobalValue, 0); // record points in non-dominating set var bestCoord = new float[BestGlobalCoord.Length]; var bestValue = new float[bugValue.Length]; BestGlobalCoord.CopyTo(bestCoord, 0); bugValue.CopyTo(bestValue, 0); NonDominatingCoords.Add(bestCoord); NonDominatingValues.Add(bestValue); if (NonDominatingCoords.Count > SolutionsKept) { NonDominatingCoords.RemoveAt(0); NonDominatingValues.RemoveAt(0); } BeginInvoke(new Voidhandler(StatusBarUpdate)); } } } // draw displayPos = GraphtoWindow(bug.Postion); Win32.Ellipse(memDC, displayPos.X - BugSize, displayPos.Y - BugSize, displayPos.X + BugSize, displayPos.Y + BugSize); } Win32.SelectObject(memDC, oldPen); Win32.SelectObject(memDC, oldBrush); // draw global optimum oldPen = Win32.SelectObject(memDC, optPen); oldBrush = Win32.SelectObject(memDC, optBrush); displayPos = GraphtoWindow(BestGlobalCoord); Win32.Ellipse(memDC, displayPos.X - BugSize, displayPos.Y - BugSize, displayPos.X + BugSize, displayPos.Y + BugSize); foreach (var coord in NonDominatingCoords) { displayPos = GraphtoWindow(coord); Win32.Ellipse(memDC, displayPos.X - 1, displayPos.Y - 1, displayPos.X + 1, displayPos.Y + 1); } Win32.SelectObject(memDC, oldPen); Win32.SelectObject(memDC, oldBrush); // copy to main screen Win32.BitBlt(mainDC, 0, 0, MainDisplay.Width, MainDisplay.Height, memDC, 0, 0, Win32.TernaryRasterOperations.SRCCOPY); // release objects Win32.SelectObject(memDC, oldBmp); Win32.DeleteObject(OffscreenBmp); Win32.DeleteDC(memDC); mainGraphics.ReleaseHdc(mainDC); // finish if (Play || Step) { cycleTime++; if (cycleTime >= Config.FlyTime) { cycleTime = 0; } if (Config.TimeInc != 0) { Time += Config.TimeInc; RefreshEvent.Set(); for (int i = 0; i < BestGlobalValue.Length; i++) { BestGlobalValue[i] = (float)Objectives[i].Invoke(BestGlobalCoord, Time); // value of best position has changed under the new time slice } } } Step = false; //Thread.Sleep(20); if (Play) { ProcessEvent.Set(); } } if (hBitmap != IntPtr.Zero) { Win32.DeleteObject(hBitmap); hBitmap = IntPtr.Zero; } }
private void CleanAll_Click(object sender, EventArgs e) { MainDisplay.Clear(); }
private void Show(MainDisplay iMainDisplay) { MainDisplay = iMainDisplay; }
/// <summary> /// Creates a new project dialog. /// </summary> public DlgNewProject() { gui = new DlgNewProjectGui(); gui.GuiNew.Click += GuiNew_Click; gui.GuiOpen.Click += GuiOpen_Click; gui.KeyDown += Gui_KeyDown; //Gets recently-opened URLs. var recentFiles = Utils.GetRecentlyOpened().Split('|').ToList(); //Adds an entry for each recent file. for (int i = 0; i < recentFiles.Count; i++) { //Skips files that don't exist. if (!File.Exists(recentFiles[i])) { continue; } //Builds a button for each file to open it. TextBlock txtblk = new TextBlock(); txtblk.Tag = recentFiles[i].ToString(); txtblk.Text = Path.GetFileName(recentFiles[i]); txtblk.ToolTip = txtblk.Tag; txtblk.Margin = new Thickness(4); txtblk.HorizontalAlignment = HorizontalAlignment.Center; if (txtblk.Text.Length > 40) { txtblk.Text = txtblk.Text.Substring(0, 40) + "..."; } //Highlights in bold when hovering the mouse. txtblk.MouseEnter += (a, b) => { txtblk.FontWeight = FontWeights.Bold; }; txtblk.MouseLeave += (a, b) => { txtblk.FontWeight = FontWeights.Normal; }; //Attempts to load the given file. txtblk.MouseDown += (a, b) => { if (File.Exists((string)txtblk.Tag)) { //Constructs project from the file. MainDisplay display = new MainDisplay(Project.Load((string)txtblk.Tag), (string)txtblk.Tag); //Shows the new display and close this one. display.Show(); gui.Close(); } else { //Removes the file if it can't be found. MessageBox.Show(GlobalStrings.DlgProjectNotFoundA + (string)txtblk.Tag + GlobalStrings.DlgProjectNotFoundB); Utils.RegRemoveRecentlyOpen((string)txtblk.Tag); gui.GuiPanel.Children.Remove(txtblk); } }; gui.GuiPanel.Children.Add(txtblk); } //Constructs a textblock noting recent files. if (gui.GuiPanel.Children.Count > 0) { TextBlock txtblkRecentFiles = new TextBlock(); txtblkRecentFiles.Text = GlobalStrings.NewProjectRecent; txtblkRecentFiles.Foreground = Brushes.DarkGray; txtblkRecentFiles.Margin = new Thickness(4); txtblkRecentFiles.HorizontalAlignment = HorizontalAlignment.Center; gui.GuiPanel.Children.Insert(0, txtblkRecentFiles); } }