Changeset 43

Show
Ignore:
Timestamp:
07/10/07 22:57:32 (1 year ago)
Author:
JoeCoder
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/demo1/main.d

    r42 r43  
    6262    disp.bottomRight = Vec2f(1, 1); 
    6363    disp.setVisibility(true); 
    64      
    65     Surface first = new Surface(disp); 
    66     first.texture = camera.getTexture(); 
    67     first.topLeft = Vec2f(0,0); 
    68     first.bottomRight = Vec2f(.75, .75); 
    69     first.setVisibility(true); 
    70      
    71     Surface second = new Surface(disp); 
    72     second.texture = camera.getTexture(); 
    73     second.topLeft = Vec2f(.25,.25); 
    74     second.bottomRight = Vec2f(1,1); 
    75     second.setVisibility(true); 
     64    disp.texture = camera.getTexture(); 
     65 
    7666     
    7767    void onMousedown(Surface self, byte buttons, Vec2i coordinates){ 
    78         self.raise(); 
    7968        Input.button[1].up = false; 
    8069        Input.setGrabMouse(!Input.getGrabMouse()); 
     
    8675    } 
    8776     
    88     first.onMousedown = &onMousedown; 
    89     second.onMousedown = &onMousedown;   
    90     first.onResize = &onResize; 
     77    disp.onMousedown = &onMousedown; 
     78    disp.onResize = &onResize; 
    9179     
    9280    // Music 
  • trunk/src/yage/core/array.d

    r32 r43  
    1919import std.stdio; 
    2020 
    21 /** 
    22  *  
    23  */ 
     21/// Return the maximum value of an array. 
     22T amax(T)(T[] array) 
     23{   T m = array[0]; 
     24    foreach (T a; array) 
     25        if (a>m) 
     26            m=a;     
     27    return m; 
     28
     29 
     30/// Return the minimum value of an array. 
     31T amin(T)(T[] array) 
     32{   T m = array[0]; 
     33    foreach (T a; array) 
     34        if (a<m) 
     35            m=a;     
     36    return m; 
     37
     38 
     39/** 
     40 * Is the array ordered? 
     41 * Params: 
     42 * increasing = Check for ordering by small to big. 
     43 * getKey = a function to get a key.  
     44 * Example: 
     45 * -------------------------------- 
     46 * Timer[] array; 
     47 * // ... fill array with new Timer() ... 
     48 * array.ordered(true, (Timer a) { return a.get(); }); // should return true 
     49 * --------------------------------  
     50 */  
     51bool ordered(T)(T[] array, bool increasing=true) 
     52{   return ordered(array, increasing, (T a) { return a; }); 
     53
     54 
     55/// Ditto 
     56bool ordered(T, K)(T[] array, bool increasing=true, K delegate(T elem) getKey=null) 
     57{   if (array.length <= 1) 
     58        return true; 
     59     
     60    if (increasing) 
     61    {   for (int i=0; i<array.length-1; i++) 
     62            if (getKey(array[i]) > getKey(array[i+1])) 
     63                return false; 
     64    } else 
     65    {   for (int i=0; i<array.length-1; i++) 
     66            if (getKey(array[i]) < getKey(array[i+1])) 
     67                return false;        
     68    }                
     69    return true; 
     70
     71unittest 
     72{   assert(ordered([-1, 0, 1, 2, 2, 5]) == true); 
     73    assert(ordered([-1, 0, 1, 2, 1, 5]) == false); 
     74    assert(ordered([5, 3, 3, 3, 2, -1], false) == true); 
     75
    2476 
    2577/** 
     
    64116 * // ... fill array with new Timer() ... 
    65117 * array.radixSort((Timer a) { return a.get(); }); 
    66  * -------------------------------- */ 
     118 * --------------------------------  
     119 */ 
    67120void radixSort(T)(inout T[] array) 
    68121{   radixSort(array, (T a) { return a; }); 
     
    97150    {   elem[i].key2 = getKey(array[i]); 
    98151        elem[i].data = array[i]; 
     152        writefln(elem[i].key2); 
    99153    } 
    100154 
  • trunk/src/yage/gui/style.d

    r38 r43  
    1515struct Style 
    1616{ 
    17     enum Units {PX, PERCENT}; 
     17    enum Unit {PX, PERCENT}; 
    1818 
    1919    Material backgroundMaterial; 
     
    2121 
    2222    float[4] borderWidth; 
    23     byte[4]  borderWidthUnits; 
    24     float[4] borderRadius; // used for rounded corners. 
    25     byte[4]  borderRadiusUnits; 
    26     Vec4f[4] borderColor;     
     23    Unit[4]  borderWidthUnits; 
     24    float[4] borderRadius;          // used for rounded corners. 
     25    Unit[4]  borderRadiusUnits; 
     26    Vec4f[4] borderColor; 
     27    Material borderMaterial;        // Overrides radius and color if set 
     28    bool[4]  borderMaterialStretch;  // top, right, bottom, left 
    2729 
    2830    Material cursor; 
    29     byte display; // block, none, anything else? 
     31    bool visible = false;; 
    3032    byte position; 
    31     byte visibility; 
    3233 
    3334    //Font  fontFamily; 
     
    3637    float fontWeight; 
    3738 
    38     float[4] marginWidth
    39     byte[4] marginUnits; 
     39    float[4] margin
     40    Unit[4] marginUnits; 
    4041 
    41     float[4] paddingWidth
    42     byte[4] paddingUnits; 
     42    float[4] padding
     43    Unit[4] paddingUnits; 
    4344 
    44     Vec4f dimension; // top, right, bottom, left 
     45    float[4] dimension;        // top, right, bottom, left 
    4546    byte[4] dimensinUnits; 
    46     byte  overflow; 
     47    float height; 
     48    Unit  heightUnits; 
     49    float width; 
     50    Unit  widthUnits; 
    4751    int   zIndex; 
    48     float height; 
    49     byte  heightUnits; 
    50     float width; 
    51     byte  widthUnits; 
    5252 
    5353    Vec4f color; 
  • trunk/src/yage/gui/surface.d

    r40 r43  
     1/** 
     2 * Copyright:  (c) 2005-2007 Eric Poggel 
     3 * Authors:    Joe Pusderis (deformative0@gmail.com) 
     4 * License:    <a href="lgpl.txt">LGPL</a>  
     5 */ 
     6 
    17module yage.gui.surface; 
    28 
    3 import yage.resource.texture; 
    4 import yage.core.vector; 
    5 import yage.system.device; 
     9import std.stdio; 
    610import derelict.opengl.gl; 
    711import derelict.sdl.sdl; 
     12import yage.core.all; 
     13import yage.system.device; 
     14import yage.system.constant; 
     15import yage.resource.texture; 
    816import yage.gui.style; 
    9 import yage.system.constant; 
    10  
    11 import std.stdio; 
    12  
     17 
     18 
     19/**  
     20 * A surface will be similar to an HTML DOM element, including having text inside it,  
     21 * margin, padding, a border, and a background texture, including textures from a camera.  
     22 * Surfaces will exist in a hierarchical structure, with each having a parent and an array of children.  
     23 * The children will be positioned relative to the borders of their parent. */ 
    1324class Surface{ 
     25    static final Style defaultStyle; 
     26    Style style; 
     27     
    1428    //Style style;  //move style into a higher level clas, perhaps make a geometry struct isntead 
    1529    GPUTexture texture;  //Change from GPUTexture to Texture or Material 
     
    3347     
    3448    bool visible; 
     49 
    3550 
    3651    //add root position and stuff 
     
    167182                glEnd(); 
    168183            } 
    169             foreach(sub; subs)sub.draw(); 
     184             
     185            // Sort subs 
     186            if (!subs.ordered(true, (Surface s){return s.style.zIndex;} )) 
     187                subs.radixSort((Surface s){return s.style.zIndex;} );            
     188             
     189            foreach(sub; subs) 
     190                sub.draw(); 
    170191        } 
    171192    } 
  • trunk/src/yage/system/device.d

    r40 r43  
    88 
    99import std.stdio; 
    10  
    1110import std.string; 
    1211import derelict.openal.al;