public static void CenterChildToParent(Gtk.Window parent,Gtk.Window child) { if (parent==null || child == null) return; int parentX = 0; int parentY = 0; int parentW = 0; int parentH = 0; parent.GetPosition(out parentX,out parentY); parent.GetSize(out parentW,out parentH); int w = 0; int h = 0; child.GetSize(out w,out h); var x = parentX + Convert.ToInt32( (parentW-w) / 2); var y = parentY + Convert.ToInt32( (parentH-h) / 2); if (x<=0) x =0; if (y<=0) y =0; child.Move(x,y); child.KeepAbove = true; }
public static void FadeIn(Gtk.Window window, uint millisecondsTimeout) { int screenHeight = window.Screen.Height; int winWidth, winHeight; int winX, winY; // Hide Window At Bottom of The Screen window.GetPosition(out winX, out winY); //int firstWinY = winY; window.GetSize(out winWidth, out winHeight); window.Move(winX, screenHeight); // Rise Window do { window.GetPosition(out winX, out winY); window.Move(winX, winY - 1); //System.Threading.Thread.Sleep(millisecondsTimeout); TimeUtils.Sleep(millisecondsTimeout); //} while (winY >= firstWinY); } while (winY > (screenHeight - winHeight)); }
public static void ResizeIfNeeded(Gtk.Window win) { int winX, winY; win.GetSize(out winX, out winY); int maxY = ScreenHeightFitted(true); if(winY > maxY) win.Resize(winX, maxY); }
/// <summary>Centers a window relative to its parent.</summary> static void CenterWindow(Gtk.Window child, Gtk.Window parent) { child.Child.Show (); int w, h, winw, winh, x, y, winx, winy; if (child.Visible) child.GetSize (out w, out h); else { w = child.DefaultSize.Width; h = child.DefaultSize.Height; } parent.GetSize (out winw, out winh); parent.GetPosition (out winx, out winy); x = Math.Max (0, (winw - w) /2) + winx; y = Math.Max (0, (winh - h) /2) + winy; child.Move (x, y); }
public void SaveViewerGeometry(Gtk.Window w) { int width, height; w.GetSize (out width, out height); gconfClient.Set ("/apps/csboard/viewer/session/width", width); gconfClient.Set ("/apps/csboard/viewer/session/height", height); }
/// <summary> /// Writes the configuration file for this application. /// </summary> /// <param name="window"> /// A <see cref="Gtk.Window"/> that is the main application's window /// </param> /// <param name="cfgFileName"> /// A <see cref="System.String"/> containing the name of the config file. /// </param> /// <param name="recentFiles"> /// A <see cref="System.Array"/> containing the recently used files. /// The first one, lastFiles[ 0 ] is the last file used by the application. /// </param> public static void WriteConfiguration(Gtk.Window window, string cfgFileName, string[] recentFiles) { int width; int height; string lastFile = ""; StringBuilder recentFilesLine = null; // Prepare window size window.GetSize( out width, out height ); // Prepare last file name. It is the first of the recent files. if ( recentFiles.Length > 0 ) { lastFile = recentFiles[ 0 ]; } // Prepare last files - first one is the current open if ( recentFiles.Length > 1 ) { recentFilesLine = new StringBuilder(); for(int i = 1; i < recentFiles.Length; ++i) { recentFilesLine.Append( recentFiles[ i ] ); recentFilesLine.Append( ',' ); } // Remove last ',' recentFilesLine.Remove( recentFilesLine.Length -1, 1 ); } // Write configuration try { var file = new StreamWriter( cfgFileName ); // Write window size file.WriteLine( "{0}={1}", EtqWidth, width ); file.WriteLine( "{0}={1}", EtqHeight, height ); // Write last file name if ( lastFile.Length > 0 ) { file.WriteLine( "{0}={1}", EtqLastFile, lastFile ); } // Write list of recent files if ( recentFilesLine != null ) { file.WriteLine( "{0}={1}", EtqRecent, recentFilesLine.ToString() ); } file.WriteLine(); file.Close(); } catch(Exception exc) { Util.MsgError( window, window.Title, exc.Message ); } return; }
/// <summary> /// Reads a configuration file for this application. /// </summary> /// <param name="window"> /// A <see cref="Gtk.Window"/> that is the main window of the application. /// </param> /// <param name="cfgFileName"> /// A <see cref="System.String"/> the name of the configuration file. /// </param> /// <returns> /// A <see cref="System.Array"/> with the list of recently used files. /// </returns> public static string[] ReadConfiguration(Gtk.Window window, string cfgFileName) { string lastFileName = ""; string[] recentFiles = new string[]{}; List<string> files = null; int width; int height; StreamReader file = null; string line; window.GetSize( out width, out height ); try { try { file = new StreamReader( cfgFileName ); } catch(Exception) { return null; } line = file.ReadLine(); while( !file.EndOfStream ) { if ( line.ToLower().StartsWith( EtqLastFile, StringComparison.InvariantCulture ) ) { int pos = line.IndexOf( '=' ); if ( pos > 0 ) { lastFileName = line.Substring( pos + 1 ).Trim(); } } else if ( line.ToLower().StartsWith( EtqWidth, StringComparison.InvariantCulture ) ) { int pos = line.IndexOf( '=' ); if ( pos > 0 ) { width = System.Convert.ToInt32( line.Substring( pos + 1 ).Trim() ); } } else if ( line.ToLower().StartsWith( EtqHeight, StringComparison.InvariantCulture ) ) { int pos = line.IndexOf( '=' ); if ( pos > 0 ) { height = System.Convert.ToInt32( line.Substring( pos + 1 ).Trim() ); } } else if ( line.ToLower().StartsWith( EtqRecent, StringComparison.InvariantCulture ) ) { int pos = line.IndexOf( '=' ); if ( pos > 0 ) { recentFiles = line.Substring( pos + 1 ).Split( ',' ); } } line = file.ReadLine(); } file.Close(); // Now apply cfg ApplyNewSize( window, width, height ); // Create list of recent files, plus the last file files = new List<string>(); files.Add( lastFileName ); foreach(var f in recentFiles) { files.Add( f ); } return files.ToArray(); } catch(Exception exc) { Util.MsgError( window, window.Title, exc.Message ); } return null; }
/// <summary>Centers a window relative to its parent.</summary> static void CenterWindow(Gtk.Window child, Gtk.Window parent) { child.Child.Show (); int w, h, winw, winh, x, y, winx, winy; child.GetSize (out w, out h); parent.GetSize (out winw, out winh); parent.GetPosition (out winx, out winy); x = Math.Max (0, (winw - w) /2) + winx; y = Math.Max (0, (winh - h) /2) + winy; child.Move (x, y); }
private static void getWindowSize(Gtk.Window win) { win.GetSize(out winHeight , out winWidth); }