Changeset 66

Show
Ignore:
Timestamp:
06/29/08 12:32:16 (2 months ago)
Author:
kaarna
Message:

textWidth in Label. followsChildWidth. Menu is better.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/pihlaja/src/shiraz/Shiraz.d

    r64 r66  
    5959    float tempparam1 = 53.1f; 
    6060 
    61  
     61    //The height of one pixel in Height coordinates. 
     62    //to convert pixels to Height coordinates: 
     63    //  inPixels * pixel() 
     64    //to convert Height coordinates to pixels: 
     65    //  inHCoord / pixel() 
    6266    float pixel() { return 1.0f/screenHeightP; } 
    6367    //This returns and accepts Height coordinates 
  • trunk/pihlaja/src/shiraz/canvas/Draw.d

    r62 r66  
    385385} 
    386386 
    387 static void showText( char[] set_text, GLubyte[] image, uint wid, uint hei, uint chan, float[4] set_colour
     387static void showText( char[] set_text, GLubyte[] image, uint wid, uint hei, uint chan, float[4] set_colour, out float get_text_width, out float get_text_height
    388388{ 
    389389    cairo_format_t form = cairo_format_t.ARGB32; 
     
    416416   */ 
    417417     
    418 font_options.setHintStyle(cairo_hint_style_t.DEFAULT); 
    419     //font_options.setHintStyle(cairo_hint_style_t.NONE); 
     418   //font_options.setHintStyle(cairo_hint_style_t.DEFAULT); 
     419    font_options.setHintStyle(cairo_hint_style_t.NONE); 
    420420  //font_options.setHintStyle(cairo_hint_style_t.SLIGHT); 
    421421    //font_options.setHintStyle(cairo_hint_style_t.MEDIUM); 
    422422    //font_options.setHintStyle(cairo_hint_style_t.FULL); 
    423423     
    424     font_options.setHintMetrics(cairo_hint_metrics_t.DEFAULT); 
    425     //font_options.setHintMetrics(cairo_hint_metrics_t.OFF); 
     424    //font_options.setHintMetrics(cairo_hint_metrics_t.DEFAULT); 
     425    font_options.setHintMetrics(cairo_hint_metrics_t.OFF); 
    426426    //font_options.setHintMetrics(cairo_hint_metrics_t.ON); 
    427427 
    428     font_options.setAntialias(cairo_antialias_t.DEFAULT); 
    429     //font_options.setAntialias(cairo_antialias_t.GRAY); 
     428    //font_options.setAntialias(cairo_antialias_t.DEFAULT); 
     429    font_options.setAntialias(cairo_antialias_t.GRAY); 
    430430    //font_options.setAntialias(cairo_antialias_t.NONE); 
    431431    //font_options.setAntialias(cairo_antialias_t.SUBPIXEL); 
     
    464464            //double x = wid-((extents.width/2.0) + extents.xBearing); 
    465465            //double y = hei-((extents.height/2.0) + extents.yBearing); 
     466             
     467            //TODO What about + or - xBearing here?? 
     468            get_text_width = extents.width; 
     469            get_text_height = extents.height; 
    466470             
    467471            double x = (wid/2.0)-((extents.width/2.0) + extents.xBearing); 
  • trunk/pihlaja/src/shiraz/canvas/Image.d

    r63 r66  
    675675    } 
    676676     
    677     static Image createFromText( char[] set_text, float[4] set_colour
     677    static Image createFromText( char[] set_text, float[4] set_colour, out float get_text_width, out float get_text_height
    678678    { 
    679679        Image img = new Image(); 
     
    681681        //img.magFilter = GL_NEAREST; 
    682682        //img.minFilter = GL_NEAREST; 
    683         img.showText(set_text, set_colour); 
     683        img.showText(set_text, set_colour, get_text_width, get_text_height ); 
    684684         
    685685        return img; 
    686686    } 
    687687     
    688     void showText( char[] set_text, float[4] set_colour
     688    void showText( char[] set_text, float[4] set_colour, out float get_text_width, out float get_text_height
    689689    { 
    690690        width = 128; 
     
    692692        channels = 4; 
    693693        scope GLubyte[] image = new GLubyte[(width*height)*channels]; 
    694         Draw.showText( set_text, image, width, height, channels, set_colour ); 
     694        Draw.showText( set_text, image, width, height, channels, set_colour, get_text_width, get_text_height ); 
    695695        createTextureFromData( image, width, height, channels ); 
    696696    } 
  • trunk/pihlaja/src/shiraz/canvas/Rectangle.d

    r65 r66  
    27742774    //float border = 0.002f; 
    27752775    //float padding = 0.005f; 
     2776     
     2777    //TODO use: 
     2778    float inPadding = 0.0f; 
     2779    //float outPadding = 0.0f; 
    27762780    float padding = 0.0f; 
    27772781     
     2782    //TODO: Anchor NOT USED AT THE MOMENT: 
     2783    /* 
    27782784    public void anchor() { return m_anchor; } 
    27792785    public void anchor(Anchor set) { return m_anchor = set; } 
    27802786    protected Anchor m_anchor = Anchor.TOP_LEFT; 
     2787    */ 
    27812788     
    27822789    /* 
     
    28132820    public ArrangeType arrangeType(ArrangeType set) { return m_arrangeType = set; } 
    28142821    protected ArrangeType m_arrangeType = ArrangeType.VBOX; 
     2822     
     2823    bool followsChildWidth = false; 
     2824    bool followsChildHeight = false; 
    28152825     
    28162826    /* 
     
    29712981        if( result == 0.0f ) 
    29722982            return minWidth;//This propably makes no sense, but 
     2983            //currently it should work. As minHeight is set for 
     2984            //all Widgets. 
     2985             
     2986        return result; 
     2987    } 
     2988     
     2989    float childrenDefaultHeight() 
     2990    { 
     2991        float result = 0.0f; 
     2992         
     2993        switch( arrangeType ) 
     2994        { 
     2995            default: 
     2996            case ArrangeType.FREE: 
     2997                 
     2998            break; 
     2999            case ArrangeType.LAYER: 
     3000             
     3001            break; 
     3002            case ArrangeType.HBOX: 
     3003                foreach( Rectangle wid; itemList ) 
     3004                { 
     3005                    //debug(arrange) Trace.formatln("wid.name: {} height: {}", wid.name, cast(double) wid.h ); 
     3006                    if( result < (wid.ifDefaultHeight + wid.padding*2.0f) ) 
     3007                        result = (wid.ifDefaultHeight + wid.padding*2.0f); 
     3008                } 
     3009            break; 
     3010            case ArrangeType.VBOX: 
     3011                foreach( Rectangle wid; itemList ) 
     3012                { 
     3013                    result = result + (wid.ifDefaultHeight + wid.padding*2.0f); 
     3014                } 
     3015            break; 
     3016        } 
     3017         
     3018        if( result == 0.0f ) 
     3019            return ifDefaultHeight;//This propably makes no sense, but 
     3020            //currently it should work. As minHeight is set for 
     3021            //all Widgets. 
     3022             
     3023        return result; 
     3024    } 
     3025     
     3026    float childrenDefaultWidth() 
     3027    { 
     3028        float result = 0.0f; 
     3029         
     3030        switch( arrangeType ) 
     3031        { 
     3032            default: 
     3033            case ArrangeType.FREE: 
     3034                 
     3035            break; 
     3036            case ArrangeType.LAYER: 
     3037             
     3038            break; 
     3039            case ArrangeType.HBOX: 
     3040                foreach( Rectangle wid; itemList ) 
     3041                { 
     3042                    result = result + (wid.ifDefaultWidth + wid.padding*2.0f); 
     3043                } 
     3044            break; 
     3045            case ArrangeType.VBOX: 
     3046                foreach( Rectangle wid; itemList ) 
     3047                { 
     3048                    //Trace.formatln("wid.name: {} height: {}", wid.name, cast(double) wid.h ); 
     3049                    if( result < (wid.ifDefaultWidth + wid.padding*2.0f) ) 
     3050                        result = (wid.ifDefaultWidth + wid.padding*2.0f); 
     3051                } 
     3052            break; 
     3053        } 
     3054         
     3055        if( result == 0.0f ) 
     3056            return ifDefaultWidth;//This propably makes no sense, but 
    29733057            //currently it should work. As minHeight is set for 
    29743058            //all Widgets. 
     
    34893573        } 
    34903574         
    3491  
     3575        if( followsChildWidth == true ) 
     3576        { 
     3577            defaultWidthN = childrenDefaultWidth() + (inPadding*2.0f); 
     3578        } 
     3579         
     3580        if( followsChildHeight == true ) 
     3581        { 
     3582            defaultHeightN = childrenDefaultHeight() + (inPadding*2.0f); 
     3583        } 
    34923584         
    34933585         
     
    37043796        return m_defaultWidth; 
    37053797    } 
     3798    public float defaultWidthN(float set) 
     3799    { 
     3800        hasDefaultWidth = true; 
     3801        m_defaultWidth = set; 
     3802        if( m_minWidth > m_defaultWidth ) 
     3803            m_minWidth = m_defaultWidth; 
     3804        if( m_maxWidth < m_defaultWidth ) 
     3805            m_maxWidth = m_defaultWidth; 
     3806             
     3807        wN(defaultWidth);//was wc() 
     3808         
     3809        //arrange(); 
     3810        return m_defaultWidth; 
     3811    } 
    37063812    protected float m_defaultWidth = 1.0f; 
    37073813     
     
    37433849        return m_defaultHeight; 
    37443850    } 
     3851    public float defaultHeightN(float set) 
     3852    { 
     3853        hasDefaultHeight = true; 
     3854        m_defaultHeight = set; 
     3855        if( m_minHeight > m_defaultHeight ) 
     3856            m_minHeight = m_defaultHeight; 
     3857        if( m_maxHeight < m_defaultHeight ) 
     3858            m_maxHeight = m_defaultHeight; 
     3859             
     3860        hN(defaultHeight);//was hc() 
     3861         
     3862        //arrange(); 
     3863        return m_defaultHeight; 
     3864    } 
    37453865    protected float m_defaultHeight = 1.0f; 
    37463866     
  • trunk/pihlaja/src/shiraz/ui/Button.d

    r61 r66  
    7474        //set( 0.0f, 0.0f, 0.6f, 0.2f ); 
    7575         
     76        inPadding = 0.015f; 
    7677        padding = 0.005f; 
    77         //xPackOptions = PackOptions.SHRINK; 
     78        xPackOptions = PackOptions.SHRINK; 
    7879        yPackOptions = PackOptions.SHRINK; 
    7980        defaultHeight = 0.04; 
     
    8586        label.colour(1.0, 1.0, 1.0, 1.0);//White 
    8687        label.xPackOptions = PackOptions.EXPAND; 
     88 
     89        //Now that we have the label set up, it knows it's 
     90        //width, and we can use it to set our defaultWidth. 
     91        //using padding here is just funny. We should really have 
     92        //a system with inPadding and outPadding. 
     93        defaultWidth = label.textWidth + (padding * 6.0f); 
     94        followsChildWidth = true; 
     95         
    8796        add(label); 
    88          
     97 
    8998        signalMouseButtonPress.attach(&buttonHandler); 
    9099        signalMouseButtonRelease.attach(&buttonHandler); 
  • trunk/pihlaja/src/shiraz/ui/Label.d

    r52 r66  
    5959        //set( 0.0f, 0.0f, 0.6f, 0.2f ); 
    6060         
    61         texture = Image.createFromText( name, m_textColourData ); 
     61        texture = Image.createFromText( name, m_textColourData, textWidth, textHeight ); 
     62        //Image gives the text size in pixels, we'll have to convert them to 
     63        //Height Coordinates. 
     64        textWidth = textWidth * pixel; 
     65        textHeight = textHeight * pixel; 
     66         
     67        defaultWidth = textWidth; 
     68        defaultHeight = textHeight; 
     69         
     70        Trace.formatln("textWidth: {}", cast(double) textWidth ); 
     71        Trace.formatln("textHeight: {}", cast(double) textHeight ); 
    6272         
    6373        padding = 0.0f; 
     
    7181         
    7282    } 
     83     
     84    float textWidth = 0.0f; 
     85    float textHeight = 0.0f; 
    7386     
    7487    /+public Widget root(Widget set)///Don't use this yourself. 
     
    216229        r = sr; g = sg; b = sb; a = sa; 
    217230        if( texture !is null ) 
    218             texture.showText( name, m_textColourData ); 
     231        { 
     232            texture.showText( name, m_textColourData, textWidth, textHeight ); 
     233            //Image gives the text size in pixels, we'll have to convert them to 
     234            //Height Coordinates. 
     235            textWidth = textWidth * pixel; 
     236            textHeight = textHeight * pixel; 
     237        } 
    219238    } 
    220239     
  • trunk/pihlaja/src/shiraz/ui/Paned.d

    r65 r66  
    7575         
    7676        //rectangle. 
    77         colour(0.92f, 0.12f, 0.12f, 1.0f); 
     77        colour(0.12f, 0.12f, 0.12f, 1.0f); 
     78        isOutline = false; 
    7879        //rectangle. 
    7980        //set( 0.0f, 0.0f, 0.6f, 0.2f ); 
    8081         
    81         texture = g_shiraz.getTextureFromTheme("Shiraz.Button"); 
     82        //texture = g_shiraz.getTextureFromTheme("Shiraz.Button"); 
    8283         
    8384        padding = 0.000f; 
  • trunk/pihlaja/src/shiraz/ui/SubWindow.d

    r64 r66  
    15691569        isOutline = false; 
    15701570         
     1571        xPackOptions = PackOptions.SHRINK; 
     1572        yPackOptions = PackOptions.SHRINK; 
     1573         
     1574        inPadding = 0.015f; 
    15711575        padding = 0.0f; 
    15721576         
    15731577        texture = null; 
     1578         
     1579        /* 
     1580        menuButton = new Button(set_name); 
     1581        menuButton.texture = null; 
     1582        menuButton.padding = 0.0f; 
     1583        add(menuButton); 
     1584        */ 
     1585         
     1586        //keyShortCutLabel = new Label("Key"); 
     1587        //add(keyShortCutLabel); 
    15741588         
    15751589    } 
     
    15991613    void arrange() 
    16001614    { 
     1615        super.arrange(); 
     1616         
    16011617        if( menuWindow !is null ) 
    16021618        { 
    1603             menuWindow.yPos = yPos2c + ((h*0.5) + (menuWindow.h*0.5)); 
    1604             menuWindow.xPos = xPos2c
     1619            menuWindow.yPos = yPos2c + ((h*0.5f) + (menuWindow.h*0.5f)); 
     1620            menuWindow.xPos = xPos2c + (menuWindow.w*0.5f) - (w*0.5f)
    16051621        } 
    16061622    } 
     
    16351651    } 
    16361652     
     1653    //Button menuButton; 
     1654    Label keyShortCutLabel; 
    16371655    MenuWindow menuWindow; 
    16381656} 
     
    16471665     
    16481666        super("MenuWindow", WindowHeaderType.NONE, WindowHeaderType.NONE ); 
     1667         
     1668        followsChildWidth = true; 
     1669        followsChildHeight = true; 
    16491670         
    16501671         
  • trunk/pihlaja/src/shiraz/ui/Window.d

    r64 r66  
    10591059         
    10601060        gtkWindow.setSizeRequest( cast(int)set_width, cast(int)set_height ); 
     1061        //Doesn't work?: 
     1062        //gtkWindow.setDefaultSize( cast(int)set_width, cast(int)set_height ); 
    10611063    } 
    10621064