Changeset 48

Show
Ignore:
Timestamp:
07/13/07 17:30:32 (1 year ago)
Author:
Deformative
Message:

Added mousenter and leave

Files:

Legend:

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

    r46 r48  
    5959     
    6060    Surface bg = new Surface(null); 
    61     bg.topLeft = Vec2f(.05,.05); 
    62     bg.bottomRight = Vec2f(.95, .95); 
    63     bg.setTexture(new GPUTexture("test2.png")); 
    64     bg.fill = stretched; 
     61    bg.setTexture(camera.getTexture()); 
     62    bg.topLeft = Vec2f(0,0); 
     63    bg.bottomRight = Vec2f(1, 1); 
    6564    bg.setVisibility(true); 
    66      
    67     Surface disp = new Surface(bg); 
    68     disp.topLeft = Vec2f(.1,.1); 
    69     disp.bottomRight = Vec2f(.9, .9); 
    70     disp.setTexture(new GPUTexture("test/bc-dark.png")); 
    71     //disp.fill = stretched; 
    72     disp.setVisibility(true); 
    73  
    74     Surface first = new Surface(disp); 
    75     first.setTexture(new GPUTexture("test.png")); 
    76     first.fill = stretched; 
    77     first.topLeft = Vec2f(.8, .8); 
    78     first.bottomRight = Vec2f(.95, .95); 
    79     first.setVisibility(true); 
    80      
    81     Surface third = new Surface(disp); 
    82     third.setTexture(new GPUTexture("box.png")); 
    83     third.fill = stretched; 
    84     third.topLeft = Vec2f(.8, .05); 
    85     third.bottomRight = Vec2f(.95, .2); 
    86     third.setVisibility(true); 
    87      
    88     Surface fourth = new Surface(disp); 
    89     fourth.setTexture(new GPUTexture("test/button2.png")); 
    90     fourth.fill = stretched; 
    91     fourth.topLeft = Vec2f(.05, .8); 
    92     fourth.bottomRight = Vec2f(.2, .95); 
    93     fourth.setVisibility(true); 
    94      
    95     Surface fifth = new Surface(disp); 
    96     fifth.setTexture(new GPUTexture("test/radio1.png")); 
    97     fifth.fill = stretched; 
    98     fifth.topLeft = Vec2f(.05, .05); 
    99     fifth.bottomRight = Vec2f(.2, .2); 
    100     fifth.setVisibility(true); 
    101      
    102     Surface second = new Surface(disp); 
    103     second.setTexture(camera.getTexture()); 
    104     second.topLeft = Vec2f(.2,.2); 
    105     second.bottomRight = Vec2f(.8, .8); 
    106     second.setVisibility(true); 
    107      
    108     Surface clear = new Surface(second); 
    109     clear.setTexture(new GPUTexture("test/clear.png")); 
    110     clear.topLeft = Vec2f(.1,.1); 
    111     clear.bottomRight = Vec2f(.9, .9); 
    112     clear.fill = stretched; 
    113     clear.setVisibility(true); 
    114      
     65         
    11566    void onMousedown(Surface self, byte buttons, Vec2i coordinates){ 
    11667        self.raise(); 
     
    12677    } 
    12778     
     79    bg.onMousedown = &onMousedown;   
     80    bg.onResize = &onResize; 
     81     
     82    GPUTexture active = new GPUTexture("test/clear.png"); 
     83    GPUTexture inactive = new GPUTexture("test/clearInactive.png"); 
     84    GPUTexture inactive2 = new GPUTexture("test/clearInactive2.png"); 
     85     
    12886    void onMousedown2(Surface self, byte buttons, Vec2i coordinates){ 
    12987        self.raise(); 
     
    13694        if(buttons == 1) self.drag(coordinates); 
    13795    } 
    138      
    139     second.onMousedown = &onMousedown;   
    140     second.onResize = &onResize; 
     96    void onMouseenter(Surface self, byte buttons, Vec2i coordinates){ 
     97        self.setTexture(active); 
     98    } 
     99    void onMouseleave(Surface self, byte buttons, Vec2i coordinates){ 
     100        self.setTexture(inactive2); 
     101    } 
     102     
     103    Surface clear = new Surface(bg); 
     104    clear.setTexture(inactive); 
     105    clear.topLeft = Vec2f(.65,0); 
     106    clear.bottomRight = Vec2f(1, .25); 
     107    clear.fill = stretched; 
     108    clear.setVisibility(true); 
    141109    clear.onMousedown = &onMousedown2; 
    142110    clear.onMousemove = &onMousemove; 
    143111    clear.onMouseup = &onMouseup2; 
    144     first.onMousedown = &onMousedown2; 
    145     first.onMousemove = &onMousemove; 
    146     first.onMouseup = &onMouseup2; 
    147      
    148     bg.onMousedown = &onMousedown2; 
    149     bg.onMousemove = &onMousemove; 
    150     bg.onMouseup = &onMouseup2; 
     112    clear.onMouseenter = &onMouseenter; 
     113    clear.onMouseleave = &onMouseleave; 
     114     
     115    Surface clear2 = new Surface(clear); 
     116    clear2.setTexture(inactive); 
     117    clear2.topLeft = Vec2f(.65,0); 
     118    clear2.bottomRight = Vec2f(1, .25); 
     119    clear2.fill = stretched; 
     120    clear2.setVisibility(true); 
     121    clear2.onMousedown = &onMousedown2; 
     122    clear2.onMousemove = &onMousemove; 
     123    clear2.onMouseup = &onMouseup2; 
     124    clear2.onMouseenter = &onMouseenter; 
     125    clear2.onMouseleave = &onMouseleave; 
     126 
     127    Surface clear3 = new Surface(bg); 
     128    clear3.setTexture(inactive); 
     129    clear3.topLeft = Vec2f(.65,0); 
     130    clear3.bottomRight = Vec2f(1, .25); 
     131    clear3.fill = stretched; 
     132    clear3.setVisibility(true); 
     133    clear3.onMousedown = &onMousedown2; 
     134    clear3.onMousemove = &onMousemove; 
     135    clear3.onMouseup = &onMouseup2; 
     136    clear3.onMouseenter = &onMouseenter; 
     137    clear3.onMouseleave = &onMouseleave; 
    151138     
    152139    // Music 
  • trunk/src/yage/gui/surface.d

    r46 r48  
    5959     
    6060    bool visible; 
     61    bool mouseIn; 
    6162     
    6263    byte fill = traditional; 
     
    9394    } 
    9495 
    95     void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onMouseout; 
    96  
    97     void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onMouseover; 
    98  
     96    void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onMouseleave; 
     97    void mouseleave(Surface next, byte buttons, Vec2i coordinates){ 
     98        if(mouseIn == true){ 
     99            if(isSub(next)) 
     100                return; 
     101            else{ 
     102                mouseIn = false; 
     103                if(onMouseleave) 
     104                    onMouseleave(this, buttons, coordinates); 
     105             
     106                if(next !is parent && parent !is null) 
     107                    parent.mouseleave(next, buttons, coordinates); 
     108            } 
     109        } 
     110    } 
     111     
     112    void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onMouseenter; 
     113    void mouseenter(byte buttons, Vec2i coordinates){ 
     114        if(mouseIn == false){ 
     115            if(parent !is null) parent.mouseenter(buttons, coordinates); 
     116             
     117            mouseIn = true; 
     118            if(onMouseenter) onMouseenter(this, buttons, coordinates); 
     119        } 
     120    } 
     121     
    99122    void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onMouseup; //Done 
    100123    void mouseup(byte buttons, Vec2i coordinates){  
     
    473496        } 
    474497        if(onFocus) onFocus(this); 
    475     }    
     498    } 
     499         
     500    bool isSub(Surface surf){ 
     501        foreach(sub; subs){ 
     502            if (sub == surf) return true; 
     503        } 
     504        return false; 
     505    } 
    476506} 
    477507 
  • trunk/src/yage/node/camera.d

    r36 r48  
    171171        if (xres > max) xres = max; 
    172172        if (yres > max) yres = max; 
     173 
     174        aspect = cast(float)width / cast(float)height; 
    173175    } 
    174176 
  • trunk/src/yage/system/input.d

    r46 r48  
    4545 
    4646    static Surface surfaceLock; 
     47    static Surface currentSurface; 
    4748 
    4849    /** This function fills the above fields with the current intput data. 
     
    8182                    button[event.button.button].ydown = mousey; 
    8283 
    83                     auto surface = currentSurface(); 
     84                    auto surface = getSurface(); 
    8485 
    8586                    if(surface !is null) surface.mousedown(event.button.button, Vec2i(mousex,mousey)); 
     
    9293                    button[event.button.button].yup = mousey; 
    9394 
    94                     auto surface = currentSurface(); 
     95                    auto surface = getSurface(); 
    9596 
    9697                    if(surface !is null) surface.mouseup(event.button.button, Vec2i(mousex,mousey)); 
     
    111112                    mousey = event.motion.y; 
    112113                     
    113                     auto surface = currentSurface(); 
     114                    auto surface = getSurface(); 
    114115 
    115                     if(surface !is null) surface.mousemove(event.button.button, Vec2i(xdiff,ydiff)); 
     116                    //if the surface that the mouse is in has changed 
     117                    if(currentSurface !is surface){ 
     118                        //If the old surface is not device 
     119                        if(currentSurface !is null) 
     120                            //Tell it that the mouse left 
     121                            currentSurface.mouseleave(surface, event.button.button, Vec2i(mousex,mousey)); 
     122                        //If the new surface is not device 
     123                        if(surface !is null) 
     124                            //Tell it that the mosue entered 
     125                            surface.mouseenter(event.button.button, Vec2i(mousex,mousey)); 
     126                         
     127                        //The new current surface 
     128                        currentSurface = surface; 
     129                    } 
     130                    //Needs to be changed so that check is run once 
     131                    if(surface !is null) 
     132                        surface.mousemove(event.button.button, Vec2i(xdiff,ydiff)); 
     133                     
    116134                    break; 
    117135 
     
    165183    } 
    166184     
    167     static Surface currentSurface(){ 
     185    static Surface getSurface(){ 
    168186        if(surfaceLock) return surfaceLock; 
    169187        return findSurface(mousex, mousey);