Source for file GUIComponentUtility.class.php

Documentation is available at GUIComponentUtility.class.php

  1. <?php
  2. /**
  3. * @since 8/15/2006
  4. * @package polyphony.guiwizardcomponents
  5. *
  6. * @copyright Copyright &copy; 2006, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: GUIComponentUtility.class.php,v 1.5 2007/09/19 14:04:46 adamfranco Exp $
  10. */
  11.  
  12.  
  13.  
  14. /**
  15. * This class allows for the modification of an entire "level" of theme.
  16. *
  17. * @since 8/09/2006
  18. * @package polyphony.guiwizardcomponents
  19. *
  20. * @copyright Copyright &copy; 2006, Middlebury College
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  22. *
  23. * @version $Id: GUIComponentUtility.class.php,v 1.5 2007/09/19 14:04:46 adamfranco Exp $
  24. */
  25.  
  26.  
  27. class GUIComponentUtility{
  28. /**
  29. *
  30. * Make an array of colors complete with styles. The colors are arranged by hue families.
  31. *
  32. * @param int slices The number of families. 6-15 is probably good.
  33. * @param int trisize Proportional with the square root of the size of each family 4 to 6 is probably good.
  34. * @return array an array with the values at 'options' and styles in 'styles'
  35. */
  36. function makeColorArrays($slices, $triSize){
  37. $options = array();
  38. $styles = array();
  39. $options[''] = "Default";
  40. $styles[''] = "";
  41.  
  42.  
  43. for($dark = 0; $dark <=$triSize; $dark++){
  44. $goalDark = 255.99 * $dark / $triSize;
  45. $arr = GUIComponentUtility::addColor($goalDark,$goalDark,$goalDark);
  46. $val0 = $arr[0];
  47. $val1 = $arr[1];
  48. $options[$val0]=$val0;
  49. $styles[$val0]=$val1;
  50. }
  51.  
  52.  
  53. for($rot = 0; $rot<$slices; $rot++){
  54. $angle_R = ($rot /$slices) * 2 * M_PI+M_PI*1/3;
  55. $angle_G = ($rot /$slices) * 2 * M_PI+M_PI*5/3;
  56. $angle_B = ($rot /$slices) * 2 * M_PI+M_PI*3/3;
  57.  
  58. $baseR = 128+ 127.99*sin($angle_R);
  59. $baseG = 128+ 127.99*sin($angle_G);
  60. $baseB = 128+ 127.99*sin($angle_B);
  61.  
  62. for($dark = $triSize; $dark > 0; $dark--){
  63. $baseDarknessR = $baseR * $dark / $triSize;
  64. $baseDarknessG = $baseG * $dark / $triSize;
  65. $baseDarknessB = $baseB * $dark / $triSize;
  66.  
  67.  
  68. $goalDark = 255.99 * $dark / $triSize;
  69.  
  70. for($gray = 0; $gray < $dark; $gray++){
  71.  
  72. $actual_r = $baseDarknessR * ($dark -$gray) + $goalDark*$gray;
  73. $actual_g = $baseDarknessG * ($dark -$gray) + $goalDark*$gray;
  74. $actual_b = $baseDarknessB * ($dark -$gray) + $goalDark*$gray;
  75.  
  76. $actual_r /= $dark;
  77. $actual_g /= $dark;
  78. $actual_b /= $dark;
  79. $arr = GUIComponentUtility::addColor($actual_r,$actual_g,$actual_b);
  80. $val0 = $arr[0];
  81. $val1 = $arr[1];
  82. $options[$val0] = $val0;
  83. $styles[$val0] = $val1;
  84. }
  85. }
  86. }
  87.  
  88.  
  89. //this hack takes care of the fact that I really want to return them both.
  90. $ret = array();
  91. $ret['options'] = $options;
  92. $ret['styles'] = $styles;
  93.  
  94. return $ret;
  95. }
  96.  
  97. function addColor($r, $g, $b){
  98. $hexR = strtoupper(dechex(intval($r)));
  99. if($r <16) $hexR = "0".$hexR;
  100. $hexG = strtoupper(dechex(intval($g)));
  101. if($g <16) $hexG = "0".$hexG;
  102. $hexB = strtoupper(dechex(intval($b)));
  103. if($b <16) $hexB = "0".$hexB;
  104. $val = '#'.$hexR.$hexG.$hexB;
  105.  
  106. //num measures the "brightness" of the color.
  107. //I think green is "brighter" than red and red "brighter" than blue.
  108. $num = $r*2+$g*3+$b;
  109. //Our threshold is 750.
  110. if($num > 750){
  111. $col = "#000000";
  112. }else{
  113. $col = "#FFFFFF";
  114. }
  115. return array($val,"font-family: monospace; color: ".$col."; background-color:".$val.";");
  116. }
  117.  
  118. function makeFontArray(){
  119. $options = array("serif","sans-serif","cursive","fantasy","monospace");
  120. foreach($options as $option){
  121. $ret[$option]=$option;
  122. }
  123. return $ret;
  124. }
  125.  
  126. function makeFontSizeArray(){
  127. $options = array("8pt","10pt","12pt","14pt","16pt","18pt","20pt","22pt","24pt","26pt");
  128. foreach($options as $option){
  129. $ret[$option]=$option;
  130. }
  131. return $ret;
  132. }
  133. function makeBorderSizeArrays(){
  134. $arr = array("0px","1px","2px","3px","4px","5px","6px","8px","10px","14px");
  135. foreach($arr as $option){
  136. $options[$option]=$option;
  137. $styles[$option]="border-width: ".$option."; margin 3; padding 3;";
  138. }
  139. $ret = array('options'=>$options,'styles'=>$styles);
  140. return $ret;
  141. }
  142. function makeMarginAndPaddingArray(){
  143. $arr = array("0px","1px","2px","3px","4px","5px","6px","8px","10px","12px","16px","20px","25px","30px","35px","40px","45px","50px","60px","70px","80px","100px","125px","150px","175px","200px","225px","250px","275px","300px","350px","400px","-0px","-1px","-2px","-3px","-4px","-5px","-6px","-8px","-10px","-12px","-16px","-20px","-25px","-30px","-35px","-40px","-45px","-50px","-60px","-70px","-80px","-100px","-125px","-150px","-175px","-200px","-225px","-250px","-275px","-300px","-350px","-400px","2%","5%","10%","15%","20%","25%","30%","35%","40%","50%","60%","75%","-2%","-5%","-10%","-15%","-20%","-25%","-30%","-35%","-40%","-50%","-60%","-75%","-100%","-125%","-150%","-200%","-250%","-300%","-400%");
  144. foreach($arr as $option){
  145. $options[$option]=$option;
  146. }
  147. return $options;
  148. }
  149. function makeBorderStyleArrays(){
  150. $arr = array("none", "dotted", "dashed",
  151. "solid", "groove", "ridge",
  152. "inset", "outset", "double");
  153. foreach($arr as $option){
  154. $options[$option]=$option;
  155. $styles[$option]="margin: 6px 3px; padding: 3px; border-style: ".$option.";";
  156. }
  157. $ret = array('options'=>$options,'styles'=>$styles);
  158. return $ret;
  159. }
  160. function makeSpacingArray(){
  161. $arr = array("normal","-5px", "-3px", "-2px","-1px", "0px","1px", "2px","3px","5px", "7px", "10px");
  162. foreach($arr as $option){
  163. $options[$option]=$option;
  164. }
  165. return $options;
  166. }
  167. function makeLineSpacingArray(){
  168. $options = array("normal","50%","75%","90%","100%","125%","150%","175%","200%","250%");
  169. foreach($options as $option){
  170. $ret[$option]=$option;
  171. }
  172. return $ret;
  173. }
  174. function makeAlignArray(){
  175. $options = array("left","center","right","justified");
  176. foreach($options as $option){
  177. $ret[$option]=$option;
  178. }
  179. return $ret;
  180. }
  181. }

Documentation generated on Wed, 19 Sep 2007 10:23:29 -0400 by phpDocumentor 1.3.0RC3