Share Pastebin
Guest
Public paste!

TiZ

By: a guest | Mar 21st, 2010 | Syntax: None | Size: 3.16 KB | Hits: 39 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. // Copyright (c) 2010 Trent McPheron <twilightinzero@gmail.com>
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE.
  20.  
  21. using Gdk;
  22.  
  23. ///////////////////
  24. // Theme
  25. ///////////////////
  26.  
  27. public struct Theme
  28. {
  29.         ///////////////////
  30.         // Fields / Props
  31.         ///////////////////
  32.        
  33.         public bool valid;
  34.         public string name;
  35.         public Pixbuf[] pixbufs;
  36.        
  37.        
  38.         ///////////////////
  39.         // Constructor
  40.         ///////////////////
  41.        
  42.         // Loads a theme from a directory.
  43.         public Theme (File dir)
  44.         {
  45.                 // Set properties and fields.
  46.                 name = dir.get_basename();
  47.                 valid = true;
  48.                 pixbufs = new Pixbuf[24];
  49.                
  50.                 // First check if the dir exists.
  51.                 if (!dir.query_exists(null))
  52.                 {
  53.                         // Invalid, obviously.
  54.                         stdout.printf(@"The directory $(dir.get_path()) doesn't exist.\n");
  55.                         valid = false;
  56.                 }
  57.                
  58.                 // Create arrays for buttons to load.
  59.                 string[] win_states = { "active", "passive" };
  60.                 string[] buttons = { "minimize", "maximize", "restore", "close" };
  61.                 string[] but_states = { "normal", "hover", "pressed" };
  62.                
  63.                 // Iterate through each button and load it.
  64.                 for (uint8 a = 0; a < 2; a++)
  65.                 for (uint8 b = 0; b < 4; b++)
  66.                 for (uint8 c = 0; c < 3; c++)
  67.                 {
  68.                         // Create file object for the current image.
  69.                         File buf_file = dir.get_child(win_states[a]).get_child(
  70.                                         buttons[b] + "_" + but_states[c]);
  71.                        
  72.                         // Create index based on position in loop.
  73.                         uint8 i = (a * 12) + (b * 3) + c;
  74.                        
  75.                         try
  76.                         {
  77.                                 // Try loading it into a pixbuf.
  78.                                 InputStream stream = buf_file.read(null);
  79.                                 pixbufs[i] = new Pixbuf.from_stream(stream, null);
  80.                         }
  81.                         catch
  82.                         {
  83.                                 // Didn't work...
  84.                                 stdout.printf(@"Can't read $(buf_file.get_path())\n");
  85.                                 valid = false;
  86.                         }
  87.                 }
  88.         }
  89.        
  90.        
  91.         ///////////////////
  92.         // Functions
  93.         ///////////////////
  94.        
  95.         // Gets a pixbuf from the loaded theme.
  96.         public Pixbuf get_pixbuf (bool active, ThemeButton tb, ButtonState bs)
  97.         {
  98.                 uint8 i = (active ? 0 : 6) + tb + bs;
  99.                 return pixbufs[i];
  100.         }
  101. }
  102.  
  103.  
  104. ///////////////////
  105. // Enums
  106. ///////////////////
  107.  
  108. public enum ThemeButton
  109. {
  110.         MINIMIZE = 0,
  111.         MAXIMIZE = 3,
  112.         RESTORE = 6,
  113.         CLOSE = 9
  114. }
  115.  
  116. public enum ButtonState
  117. {
  118.         NORMAL = 0,
  119.         HOVER = 1,
  120.         PRESSED = 2
  121. }