Changeset 78

Show
Ignore:
Timestamp:
08/01/08 22:37:15 (4 months ago)
Author:
kaarna
Message:

Shadows.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/pihlaja/src/dsss.conf

    r76 r78  
    4545    #buildflags += -debug=FBO 
    4646    #buildflags += -debug=Shiraz 
    47     buildflags += -debug=Theme 
     47    #buildflags += -debug=Theme 
    4848    #buildflags += -debug=ProjectWindow 
    4949    #buildflags += -debug=Window 
    5050    #buildflags += -debug=GtkOpenGLCanvas 
    5151    #buildflags += -debug=SubWindow 
    52     buildflags += -debug=Menu 
     52    #buildflags += -debug=Menu 
    5353    #buildflags += -debug=Widget 
    5454    #buildflags += -debug=Rectangle 
     
    5959    #buildflags += -debug=FindLeaf #warning: very much output 
    6060    #buildflags += -debug=Animator 
    61     buildflags += -debug=Animator2 
    62     buildflags += -debug=Image 
     61    #buildflags += -debug=Animator2 
     62    #buildflags += -debug=Image 
    6363} 
    6464version(Windows) { 
  • trunk/pihlaja/src/pihlaja/PihlajaMain.d

    r77 r78  
    134134         
    135135        videoViewerWindow = new SubWindow("Viewer", WindowHeaderType.SMALL, WindowHeaderType.SMALL); 
     136        videoViewerWindow.shadowType = ShadowType.NONE; 
    136137        //videoViewerWindow.isClipByParent = false; 
    137138         
     
    275276         
    276277        myWindow4 = new SubWindow("Timeline", WindowHeaderType.SMALL, WindowHeaderType.SMALL); 
     278        myWindow4.shadowType = ShadowType.NONE; 
    277279        //myWindow4.isClipByParent = false; 
    278280        myWindow4.moveTo( -0.3f, 0.4f ); 
     
    366368         
    367369        SubWindow awin28 = new SubWindow("Timeline", WindowHeaderType.SMALL, WindowHeaderType.SMALL); 
     370        awin28.shadowType = ShadowType.NONE; 
    368371        //awin28.isClipByParent = false; 
    369372        awin28.defaultSize( 0.4f, 0.4f ); 
  • trunk/pihlaja/src/shiraz/canvas/Image.d

    r77 r78  
    1515 * along with Shiraz; if not, write to the Free Software 
    1616 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 * 
     18 * The functions boxBlur() and fastBlur() were taken from librsvg-2.15.90 
     19 * rsvg-filter.c and are Copyright (C) 2004 Caleb Moore. 
     20 * Author: Caleb Moore <c.moore@student.unsw.edu.au> 
     21 * They are licenced as LGPL. 
    1722 */ 
    18  
     23  
    1924module shiraz.canvas.Image; 
    2025 
     
    984989    void blur(float blur_amount) 
    985990    { 
    986         fast_blur(this, this, blur_amount, blur_amount ); 
     991        fastBlur(this, this, blur_amount, blur_amount ); 
    987992    } 
    988993     
     
    11081113    */ 
    11091114     
    1110 //The following two functions were taken from librsvg-2.15.90. 
    1111 //And modified to fit this class. 
    1112 //Here's the licence: 
    1113  
    1114 /* 
    1115    rsvg-filter.c: Provides filters 
    1116  
    1117    Copyright (C) 2004 Caleb Moore 
    1118  
    1119    This program is free software; you can redistribute it and/or 
    1120    modify it under the terms of the GNU Library General Public License as 
    1121    published by the Free Software Foundation; either version 2 of the 
    1122    License, or (at your option) any later version. 
    1123  
    1124    This program is distributed in the hope that it will be useful, 
    1125    but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1126    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
    1127    Library General Public License for more details. 
    1128  
    1129    You should have received a copy of the GNU Library General Public 
    1130    License along with this program; if not, write to the 
    1131    Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
    1132    Boston, MA 02111-1307, USA. 
    1133  
    1134    Author: Caleb Moore <c.moore@student.unsw.edu.au> 
    1135 */ 
    1136  
    11371115 
    11381116static void 
    1139 box_blur (Image input, Image output, GLubyte[] intermediate, int kw, 
     1117boxBlur (Image input, Image output, GLubyte[] intermediate, int kw, 
    11401118          int kh )//, RsvgIRect boundarys, RsvgFilterPrimitiveOutput op) 
    11411119{ 
     
    12851263} 
    12861264 
    1287 static void fast_blur(Image input, Image output, float blur_amount_x, 
     1265static void fastBlur(Image input, Image output, float blur_amount_x, 
    12881266           float blur_amount_y )//, RsvgIRect boundarys, RsvgFilterPrimitiveOutput op) 
    12891267{ 
     
    12981276    scope GLubyte[] intermediate = new GLubyte[max(kx, ky)]; 
    12991277 
    1300     box_blur (input, output, intermediate, kx, 
     1278    boxBlur (input, output, intermediate, kx, 
    13011279              ky );//, boundarys, op); 
    1302     box_blur (output, output, intermediate, kx, 
     1280    boxBlur (output, output, intermediate, kx, 
    13031281              ky );//, boundarys, op); 
    1304     box_blur (output, output, intermediate, kx, 
     1282    boxBlur (output, output, intermediate, kx, 
    13051283              ky );//, boundarys, op); 
    13061284 
  • trunk/pihlaja/src/shiraz/canvas/PlainRectangle.d

    r76 r78  
    5050import shiraz.canvas.IShape; 
    5151import shiraz.canvas.ShapeRectangle; 
     52import shiraz.canvas.ShapeShadow; 
    5253import shiraz.canvas.Image; 
    5354import shiraz.canvas.Gradient; 
     
    6061import shiraz.canvas.rtree.Node; 
    6162import shiraz.canvas.rtree.Index; 
     63 
     64public enum ShadowType 
     65{ 
     66    NONE, 
     67    SQUARE, 
     68    ROUND 
     69} 
    6270 
    6371/* 
     
    10681076    protected IShape shape; 
    10691077     
     1078    //Shadows: 
     1079    public ShadowType shadowType(ShadowType set) 
     1080    { 
     1081        if( set == m_shadowType ) 
     1082        { 
     1083            return m_shadowType; 
     1084        } 
     1085     
     1086        m_shadowType = set; 
     1087     
     1088        if( set == ShadowType.NONE ) 
     1089        { 
     1090            if( shapeShadow !is null ) 
     1091                delete shapeShadow; 
     1092        } 
     1093        else 
     1094        { 
     1095            if( shapeShadow is null ) 
     1096                shapeShadow = new ShapeShadow(ix1, iy1, ix2, iy2); 
     1097            updateShadowTexture(); 
     1098        } 
     1099        return m_shadowType; 
     1100    } 
     1101    public ShadowType shadowType() { return m_shadowType; } 
     1102    protected ShadowType m_shadowType = ShadowType.NONE; 
     1103    //protected Shadow shadow; 
     1104    protected IShape shapeShadow; 
     1105     
     1106    protected void updateShadowTexture() 
     1107    { 
     1108        if( shapeShadow is null ) 
     1109            return; 
     1110     
     1111        if( shadowType == ShadowType.SQUARE ) 
     1112        { 
     1113            shapeShadow.texture = g_shiraz.getTextureFromTheme("Shiraz.ShapeShadow.square"); 
     1114        } 
     1115        else if( shadowType == ShadowType.ROUND ) 
     1116        { 
     1117            shapeShadow.texture = g_shiraz.getTextureFromTheme("Shiraz.ShapeShadow.round"); 
     1118        } 
     1119        else Trace.formatln("PlainRectangle.updateShadowTexture() strange parameter for a shadow: ShadowType.NONE."); 
     1120    } 
     1121     
    10701122    /* 
    10711123    TODO interface IShape 
     
    11351187                //draw.colour(); 
    11361188                //draw.gradient( gradient ); 
     1189                 
     1190                renderShadow(draw); 
    11371191                 
    11381192                //TODO 
     
    11661220             
    11671221         
     1222    } 
     1223     
     1224    void renderShadow( Draw draw ) 
     1225    { 
     1226        if( shadowType != ShadowType.NONE ) 
     1227        { 
     1228            glColor4f(1.0f, 1.0f, 1.0f, a); 
     1229             
     1230            //HARDCODED PIXEL SIZE! 
     1231            float hard_tex_width = (w / g_shiraz.pixel)+102.0f;//102.0f; 
     1232            float hard_tex_height = (h / g_shiraz.pixel)+102.0f;//102.0f; 
     1233             
     1234            shapeShadow.bounds( 
     1235                //roundToPixels(  
     1236                icx - (pixel*hard_tex_width*0.5f), 
     1237                //roundToPixels(  
     1238                icy + 0.005f - (pixel*hard_tex_height*0.5f), 
     1239                //roundToPixels(  
     1240                icx + (pixel*hard_tex_width*0.5f), 
     1241                //roundToPixels(  
     1242                icy + 0.005f + (pixel*hard_tex_height*0.5f), 
     1243                iz); 
     1244             
     1245            draw.fill( shapeShadow ); 
     1246        } 
    11681247    } 
    11691248     
     
    12981377    void renderPixelPerPixel( Draw draw, float hard_tex_width, float hard_tex_height ) 
    12991378    { 
    1300         debug(clipping) Trace.formatln("PlainRectangle.render() START. name: {}", fullName() ); 
     1379        debug(clipping) Trace.formatln("PlainRectangle.renderPixelPerPixel() START. name: {}", fullName() ); 
    13011380     
    13021381        beginRender(draw); 
    13031382         
    1304             draw.pushTexture( texture ); 
     1383            //draw.pushTexture( texture ); 
    13051384                //These should be handled by the Shape: 
    13061385                //draw.colour(); 
     
    13291408                 
    13301409                draw.fill( shape ); 
    1331             draw.popTexture(); 
     1410            //draw.popTexture(); 
    13321411                 
    13331412                /*if(isOutline) 
     
    13541433    void renderPixelPerPixelHeight( Draw draw, float hard_tex_height ) 
    13551434    { 
    1356         debug(clipping) Trace.formatln("PlainRectangle.render() START. name: {}", fullName() ); 
     1435        debug(clipping) Trace.formatln("PlainRectangle.renderPixelPerPixelHeight() START. name: {}", fullName() ); 
    13571436     
    13581437        beginRender(draw); 
  • trunk/pihlaja/src/shiraz/canvas/Rectangle.d

    r77 r78  
    3939 
    4040 
    41 import shiraz.canvas.ICanvasItem; 
    42 import shiraz.canvas.PlainRectangle; 
     41public import shiraz.canvas.ICanvasItem; 
     42public import shiraz.canvas.PlainRectangle; 
    4343import shiraz.canvas.IRootWindow; 
    4444import shiraz.canvas.Draw; 
  • trunk/pihlaja/src/shiraz/core/Theme.d

    r77 r78  
    112112        createTopWindowHeaderImage(); 
    113113        createBottomWindowHeaderImage(); 
     114        createWindowShadowImage(); 
    114115    } 
    115116     
     
    122123        addImage( "Shiraz.Menu", my_image ); 
    123124    } 
     125     
     126    void createWindowShadowImage() 
     127    { 
     128        Image my_image = new Image(256, 256, 4); 
     129        my_image.name = "Shiraz.ShapeShadow.round"; 
     130        drawWindowShadow(my_image, true); 
     131        my_image.blur(6.0f); 
     132        my_image.writeToPng("/home/joonaz/testi/WindowShadow.png"); 
     133        my_image.createTexture(); 
     134        addImage( "Shiraz.ShapeShadow.round", my_image ); 
     135         
     136        Image my_image2 = new Image(256, 256, 4); 
     137        my_image2.name = "Shiraz.ShapeShadow.square"; 
     138        drawWindowShadow(my_image2, false); 
     139        my_image2.blur(6.0f); 
     140        my_image2.writeToPng("/home/joonaz/testi/WindowShadowSquare.png"); 
     141        my_image2.createTexture(); 
     142        addImage( "Shiraz.ShapeShadow.square", my_image2 ); 
     143    } 
     144     
     145    void drawWindowShadow( Image an_image, bool is_rounded = true ) 
     146    { 
     147        cairo_format_t form = cairo_format_t.ARGB32; 
     148         
     149        if( an_image.channels == 4 ) 
     150            form = cairo_format_t.ARGB32; 
     151        else if( an_image.channels == 3 ) 
     152            form = cairo_format_t.RGB24; 
     153        else if( an_image.channels == 1 ) 
     154            form = cairo_format_t.A8; 
     155        //TODO other cairo_format_t. 
     156     
     157        ImageSurface imageSurface = ImageSurface.createForData(an_image.imageData.ptr, form, an_image.width, an_image.height, an_image.width * an_image.channels); 
     158        scope(exit) delete imageSurface;     
     159        auto cr = Context.create(imageSurface); 
     160        scope(exit) delete cr; 
     161     
     162        //TODO theme the SMALL and NORMAL window sizes... 
     163        float hei = g_shiraz.getValueFromTheme("Shiraz.WindowHeader.SMALL.defaultHeight") / g_shiraz.pixel; 
     164     
     165        cr.save(); 
     166            cr.setLineWidth(1.0); 
     167            float xRender = an_image.width/5; 
     168            float yRender = an_image.height/5;//32.0f;//(an_image.height - hei) * 0.5f;//an_image.height/3; 
     169            float x2Render = an_image.width - xRender; 
     170            float y2Render = an_image.height - yRender;//(an_image.height - yRender) + hei; 
     171            double curve_size = hei * 0.5f;//(y2Render - yRender) * 0.5f; 
     172             
     173             
     174            //Clipping: 
     175             
     176            //cr.rectangle( xRender, yRender, x2Render, y2Render ); 
     177            //cr.clip(); 
     178             
     179            /* 
     180            Gradient gradient; 
     181            //gradient = g_shiraz.getGradientFromTheme("Shiraz.Button"); 
     182            gradient = getGradient("Shiraz.WindowHeader.Top"); 
     183             
     184            scope Pattern linear = Pattern.createLinear( xRender, yRender, xRender, yRender + hei );//(0.0, 0.0, 0.0, 20.0) ); 
     185            ColourStop last_colourstop; 
     186            foreach( ColourStop colstop; gradient ) 
     187            { 
     188                //We store the last colourstop: 
     189                last_colourstop = colstop; 
     190             
     191                //BGRA 
     192                //I checked, and with the current settings the cairo images 
     193                //are BGRA and not RGBA. That's why I found it easiest to just 
     194                //swap the order here, in the drawing phase: 
     195             
     196                //linear.addColorStopRgba( colstop.position, colstop.colour.r, colstop.colour.g, colstop.colour.b, colstop.colour.a ); 
     197                linear.addColorStopRgba( colstop.position, colstop.colour.b, colstop.colour.g, colstop.colour.r, colstop.colour.a ); 
     198            } 
     199     
     200            if( is_top == true ) 
     201            { 
     202                cr.setSource( linear ); 
     203            } 
     204            else 
     205            { 
     206                cr.setSourceRgba(last_colourstop.colour.b, last_colourstop.colour.g, last_colourstop.colour.r, last_colourstop.colour.a); 
     207                cr.translate(0.0f, -hei); 
     208            } 
     209            */ 
     210     
     211            cr.setSourceRgba(0.0f, 0.0f, 0.0f, 0.5f); 
     212     
     213            if( is_rounded == true ) 
     214            { 
     215                cr.moveTo(xRender, yRender + curve_size);//up-left, lowerpoint 
     216                            cr.curveTo(xRender, yRender + curve_size, xRender, yRender, xRender + curve_size, yRender);//up-left, upperpoint 
     217                            cr.lineTo(x2Render - curve_size, yRender);//up-right, upperpoint 
     218                            cr.curveTo(x2Render - curve_size, yRender, x2Render, yRender, x2Render, yRender + curve_size);//up-right, lowerpoint 
     219                            cr.lineTo(x2Render, y2Render - curve_size);//down-right, upperpoint 
     220                            cr.curveTo(x2Render, y2Render - curve_size, x2Render, y2Render, x2Render - curve_size, y2Render);//down-right, lowerpoint 
     221                            cr.lineTo(xRender + curve_size, y2Render);//down-left, lowerpoint 
     222                            cr.curveTo(xRender + curve_size, y2Render, xRender, y2Render, xRender, y2Render - curve_size);//down-left, upperpoint 
     223                            cr.lineTo(xRender, yRender + curve_size);//up-left, lowerpoint 
     224            } 
     225            else 
     226            { 
     227                cr.rectangle( xRender, yRender, x2Render-xRender, y2Render-yRender ); 
     228            } 
     229             
     230            cr.fill;//Preserve(); 
     231                    //cr.setSourceRgba(0.0, 0.0, 0.0, 1.0); 
     232                    //cr.setSourceRgba( outlineColour.r, outlineColour.g, outlineColour.b, outlineColour.a ); 
     233                    //cr.stroke(); 
     234                 
     235        cr.restore(); 
     236         
     237        cr.destroy(); 
     238        imageSurface.destroy(); 
     239    } 
     240     
    124241     
    125242    void createButtonImage() 
     
    177294            //cr.setSourceRgba(set_colour[0], set_colour[1], set_colour[2], set_colour[3]); 
    178295             
    179             float xRender = an_image.width/8
     296            float xRender = an_image.width/5
    180297            float yRender = an_image.height/3; 
    181298            float x2Render = an_image.width - xRender; 
     
    209326            { 
    210327                cr.setSourceRgba(0.0f, 0.0f, 0.0f, 0.5f); 
    211                 cr.translate(1.0f, 3.5f); 
     328                cr.translate(0.0f, 3.5f); 
    212329            } 
    213330     
     
    292409        cr.save(); 
    293410            cr.setLineWidth(1.0); 
    294             float xRender = an_image.width/8
     411            float xRender = an_image.width/5
    295412            float yRender = (an_image.height - hei) * 0.5f;//an_image.height/3; 
    296413            float x2Render = an_image.width - xRender; 
     
    300417            //Clipping: 
    301418             
    302             cr.rectangle( xRender, yRender, x2Render, y2Render ); 
     419            //cr.rectangle( xRender, yRender, x2Render, y2Render ); 
     420            cr.rectangle( xRender, yRender, x2Render-xRender, y2Render-yRender ); 
    303421            cr.clip(); 
    304422             
     
    352470        cr.restore(); 
    353471         
    354         imageSurface.writeToPng("/home/joonaz/testi/TopWindowHeader.png"); 
     472        //imageSurface.writeToPng("/home/joonaz/testi/TopWindowHeader.png"); 
    355473         
    356474        cr.destroy(); 
  • trunk/pihlaja/src/shiraz/ui/Button.d

    r76 r78  
    190190        //TODO Naturally we'd want to get rid of these hardcoded sizes... 
    191191        //renderPixelPerPixel( draw, 128.0f, 64.0f ); 
    192         renderPixelPerPixel( draw, (w / g_shiraz.pixel)+64.0f, 64.0f ); 
     192        //a = 0.5f; 
     193         
     194        //102.0f is from (256.0f / 5) * 2.0f = 102.4f ~ in pixels 102.0f. 
     195        //So (256 / 5) is the size of the button texture's left and right side. 
     196        renderPixelPerPixel( draw, (w / g_shiraz.pixel)+102.0f, 64.0f ); 
     197        //super.render(draw); 
    193198        //renderPixelPerPixelHeight( draw, 64.0f ); 
    194199    } 
  • trunk/pihlaja/src/shiraz/ui/SubWindow.d

    r76 r78  
    935935        isFrontSide = set_is_frontside; 
    936936         
     937        if( set_bottom_header_type == WindowHeaderType.NONE )//&& set_top_header_type == WindowHeaderType.NONE ) 
     938        { 
     939            //We only evaluate bottomheader for the shadow roundness, for now. 
     940            //Because we only have round or square from both ends shadows. 
     941            //And because the bottom is where the shadow is shown most. 
     942            shadowType = ShadowType.SQUARE; 
     943        } 
     944        else 
     945        { 
     946            shadowType = ShadowType.ROUND; 
     947        } 
     948         
     949         
    937950        //g_shiraz.registerWindow(this); 
    938951         
     
    12471260             
    12481261        beginRender( draw );     
     1262             
     1263            renderShadow(draw); 
    12491264             
    12501265            draw.pushTexture( framebufferObject ); 
     
    17971812    } 
    17981813 
    1799      
     1814    public ShadowType shadowType(ShadowType set) 
     1815    { 
     1816        side2.shadowType = set; 
     1817        return side1.shadowType = set; 
     1818    } 
     1819    public ShadowType shadowType() { return side1.shadowType; } 
    18001820 
    18011821    PlainWindow side1; 
  • trunk/pihlaja/src/shiraz/ui/Window.d

    r76 r78  
    694694        plainWindow = new PlainWindow(set_name, WindowHeaderType.NONE, WindowHeaderType.NONE, true, false );//isfrontside=true, use_fbo_clipping=false 
    695695        addToCanvas(plainWindow); 
     696        plainWindow.shadowType = shiraz.canvas.PlainRectangle.ShadowType.NONE;//Remove the shadow from here as it isn't even shown. 
    696697         
    697698        Trace.formatln("After Window.super().");