Changeset 49:bca7e2342d77

Show
Ignore:
Timestamp:
05/31/08 08:10:06 (7 months ago)
Author:
Diggory Hardy <diggory.hardy@gmail.com>
branch:
default
convert_revision:
ff010240373bc41302d578ef711f9723a8bfbcba
Message:

Enabled getting the size of a text block (before or after rendering).

committer: Diggory Hardy <diggory.hardy@gmail.com>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • codeDoc/jobs.txt

    r48 r49  
    5252 
    5353Done (for git log message): 
    54 Implemented font rendering (grayscale only; i.e. non-LCD). 
    55 FontTexture creates a texture and caches glyphs. 
    56 Font supports multiple styles/faces, loaded from config file (should probably be loaded via Options instead). 
    57 TextBlock cache for glyph placement within a string. 
     54Enabled getting the size of a text block (before or after rendering). 
  • mde/gl/draw.d

    r48 r49  
    3939     
    4040    gui.draw (); 
    41     FontStyle.drawTexture; 
     41    debug FontStyle.drawTexture; 
    4242     
    4343    GLenum err = glGetError(); 
  • mde/gui/widget/miscWidgets.d

    r48 r49  
    108108    this (IWindow wind, int[] data) { 
    109109        if (data.length != 1) throw new WidgetDataException; 
    110         mw = 100;   //FIXME: set properly 
    111         mh = 50; 
     110        if (font is null) font = FontStyle.get("default"); 
     111        font.updateBlock (str, textCache); 
     112        mw = textCache.w; 
     113        mh = textCache.h; 
    112114        super (wind,data); 
    113115    } 
     
    115117    void draw () { 
    116118        super.draw(); 
    117         if (font is null) font = FontStyle.get("default"); 
    118         font.textBlock (x,y, "|−|−| .,.,.", textCache); // test new-lines and unicode characters 
    119         //old string: "Text Widget\nαβγ − ΑΒΓ" 
     119        font.textBlock (x,y, str, textCache);   // test new-lines and unicode characters 
    120120    } 
    121121     
    122122protected: 
     123    const str = "Text Widget\nαβγ − ΑΒΓ"; 
    123124    TextBlock textCache; 
    124125    static FontStyle font; 
  • mde/resource/FontTexture.d

    r48 r49  
    2929import Utf = tango.text.convert.Utf; 
    3030import tango.util.log.Log : Log, Logger; 
    31 import tango.io.Stdout; 
    3231 
    3332private Logger logger; 
     
    9897        for (size_t i = 0; i < chrs.length; ++i) 
    9998        { 
    100             // First, get maxmimal yMax for the current line. 
     99            // First, find yMax for the current line. 
    101100            int yMax = 0;   // Maximal glyph height above baseline. 
    102101            for (size_t j = i; j < chrs.length; ++j) 
     
    148147                 
    149148                cache.chars ~= cc; 
     149                 
     150                // Update rect total size. Top and left coords should be zero, so make width and 
     151                // height maximal x and y coordinates. 
     152                if (cc.xPos + cc.ga.w > cache.w) 
     153                    cache.w = cc.xPos + cc.ga.w; 
     154                if (cc.yPos + cc.ga.h > cache.h) 
     155                    cache.h = cc.yPos + cc.ga.h; 
    150156            } 
    151157            // Now increment i and continue with the next line if there is one. 
     
    192198        debug scope (failure) 
    193199                logger.warn ("FontTexture.addGlyph failed!"); 
    194         //Stdout ("Adding glyph ")(chr).newline; 
     200         
    195201        auto gi = FT_Get_Char_Index (face, chr); 
    196202        auto g = face.glyph; 
     
    215221        ga.advanceX = g.advance.x >> 6; 
    216222        ga.index    = gi; 
    217         Stdout ("Glyph left is: ")(ga.left).newline; 
    218223         
    219224        foreach (ref t; tex) { 
  • mde/resource/font.d

    r48 r49  
    205205    /** Draw a block of text (may inlcude new-lines). 
    206206     * 
     207     * The text block is drawn with top-left corner at x,y. To put the text's baseline at a given 
     208     * y coordinate would require some changes. Line height is currently variable, depending on the 
     209     * highest glyph in the line. 
     210     * 
    207211     * As a CPU-side code optimisation, store a TextBlock (unique to str) and pass a reference as 
    208212     * the cache argument. This is the recommended method, although for one-time calls when you 
  • mde/scheduler/init2.d

    r48 r49  
    2626* Currently some external modules depend on InitFunctions, while some are set up from here. Once 
    2727* all are set up from here, the Init* modules can be rearranged. */ 
     28/* Idea: go back to init being controlled from elsewhere. Add a function to wait for another init 
     29 * function to complete (threaded; might need to be done differently for non-threaded). */ 
    2830module mde.scheduler.init2; 
    2931 
     
    4648    init.addFunc (&initInput, "initInput"); 
    4749    init.addFunc (&guiLoad, "guiLoad"); 
    48     init.addFunc (&initFreeType, "initFreeType"); 
    4950} 
    5051 
    5152void guiLoad () {   // init func 
    5253    try { 
     54        font.FontStyle.initialize; 
    5355        gui.load (GUI); 
    5456        cleanup.addFunc (&guiSave, "guiSave"); 
     
    8587} 
    8688 
    87 void initFreeType () {  // init func 
    88     try { 
    89         font.FontStyle.initialize; 
    90     } catch (Exception e) { 
    91         logger.fatal ("initFreeType failed: " ~ e.msg); 
    92         setInitFailure; 
    93     } 
    94 } 
    95  
    9689/+ Potential wrapper function: 
    9790// Template to call function, catching exceptions: