Share Pastebin
Guest
Public paste!

TiZ

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