Changeset 230

Show
Ignore:
Timestamp:
07/02/11 23:22:28 (1 year ago)
Author:
JoeCoder
Message:

Style.fontFamily is now a string instead of a font resource. This allows us to work with Styles all we want before freetype is actually loaded.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/yage/gui/style.d

    r205 r230  
    270270     
    271271    /// Font properties 
    272     Font fontFamily; // TODO: Convert to string so FreeType doesn't have to be loaded in order to make Surfaces. 
     272    char[] fontFamily; 
    273273    CSSValue fontSize; /// ditto 
    274274    FontStyle fontStyle; /// ditto 
    275275    FontWeight fontWeight; /// ditto 
     276     
     277    private char[] lastFontFamily; 
     278    private Font internalFont; 
     279     
     280    Font getFont() 
     281    {   if (!internalFont || lastFontFamily != fontFamily) 
     282        {   lastFontFamily = fontFamily; 
     283            internalFont = ResourceManager.font(fontFamily); 
     284        } 
     285        return internalFont; 
     286    } 
    276287     
    277288    /// Text properties 
     
    350361                                fontSize = token; 
    351362                        } else if (i>0) 
    352                             fontFamily = ResourceManager.font(removeUrl(token)); 
     363                            fontFamily = removeUrl(token); 
    353364                    } 
    354365                    break; 
    355366                case "font-size":           fontSize = tokens[0];  break; 
    356                 case "font-family":         fontFamily = ResourceManager.font(removeUrl(tokens[0]));  break; 
     367                case "font-family":         fontFamily = removeUrl(tokens[0]);  break; 
    357368                case "font-style":          fontStyle = Style.stringToEnum!(FontStyle)(tokens[0]);  break; 
    358369                case "font-weight":         fontWeight = Style.stringToEnum!(FontWeight)(tokens[0]);  break; 
  • trunk/src/yage/gui/surface.d

    r211 r230  
    825825    static Style getDefaultStyle() 
    826826    {   if (!defaultStyle.fontFamily) // Create on first request 
    827         {   defaultStyle.fontFamily = ResourceManager.getDefaultFont(); // TODO: This prevents surfaces from being constructed before freetype!. 
     827        {   defaultStyle.fontFamily = ResourceManager.DEFAULT_FONT; 
    828828            defaultStyle.fontSize = 12; 
    829829            defaultStyle.fontStyle = Style.FontStyle.NORMAL; 
  • trunk/src/yage/gui/textblock.d

    r216 r230  
    606606    {    
    607607        InlineStyle result; 
    608         result.fontFamily = style.fontFamily ? style.fontFamily : ResourceManager.getDefaultFont(); 
     608        result.fontFamily = style.getFont(); 
    609609         
    610610        float fontSizePx = style.fontSize.toPx(0); // incorrect, should inherit from parent font size 
     
    627627    Style toStyle() 
    628628    {   Style result; 
    629         result.fontFamily = fontFamily
     629        result.fontFamily = fontFamily.toString()
    630630        result.fontSize = fontSize; 
    631631        result.color = color; 
  • trunk/src/yage/resource/manager.d

    r203 r230  
    5858        } 
    5959    } 
     60     
     61    static const DEFAULT_FONT = "__DEFAULT_FONT__"; // Used to specify the default font that's embedded as a resource in the yage executable. 
    6062     
    6163    private static char[][] paths = [""];       // paths to look for resources 
     
    161163     * If it has already been loaded, the in-memory copy will be returned. 
    162164     * If not, it will be loaded and then returned. 
    163      * Params: filename = The Font file that will be loaded. */ 
     165     * Params: filename = The Font file that will be loaded, or Resource.DEFAULT_FONT */ 
    164166    static Font font(char[] filename) 
    165167    { 
     168        if (filename==DEFAULT_FONT) 
     169            return getDefaultFont(); 
     170         
    166171        filename = resolvePath(filename); 
    167172        if (filename in fonts)