Changeset 45

Show
Ignore:
Timestamp:
07/12/07 19:58:02 (1 year ago)
Author:
Deformative
Message:

Added stretch and boundries

Files:

Legend:

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

    r43 r45  
    5757    CameraNode camera = new CameraNode(ship.getCameraSpot()); 
    5858    camera.setView(2, 20000, 60, 0, 1); // wide angle view 
    59  
    60     Surface disp = new Surface(null); 
    61     disp.topLeft = Vec2f(0,0); 
    62     disp.bottomRight = Vec2f(1, 1); 
     59     
     60    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; 
     65    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; 
    6372    disp.setVisibility(true); 
    64      
     73 
    6574    Surface first = new Surface(disp); 
    66     first.texture = camera.getTexture(); 
    67     first.topLeft = Vec2f(0,0); 
    68     first.bottomRight = Vec2f(.75, .75); 
     75    first.setTexture(new GPUTexture("test.png")); 
     76    first.fill = stretched; 
     77    first.topLeft = Vec2f(.8, .8); 
     78    first.bottomRight = Vec2f(.95, .95); 
    6979    first.setVisibility(true); 
    7080     
     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     
    71102    Surface second = new Surface(disp); 
    72     second.texture = camera.getTexture(); 
    73     second.topLeft = Vec2f(.25,.25); 
    74     second.bottomRight = Vec2f(1,1); 
     103    second.setTexture(camera.getTexture()); 
     104    second.topLeft = Vec2f(.2,.2); 
     105    second.bottomRight = Vec2f(.8, .8); 
    75106    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); 
    76114     
    77115    void onMousedown(Surface self, byte buttons, Vec2i coordinates){ 
     
    81119    } 
    82120     
    83     void onResize(Surface self, Vec2i difference){ 
    84         camera.setResolution(self.size.x, self.size.y); 
    85         writefln("Resolution changed to ", self.size.x, " x ", self.size.y); 
    86     } 
    87      
    88     first.onMousedown = &onMousedown; 
     121    void onResize(Surface self){ 
     122        int xres = self.position2.x - self.position1.x; 
     123        int yres = self.position2.y - self.position1.y; 
     124        camera.setResolution(xres, yres); 
     125        writefln("Camera resolution changed to ", xres, " x ", yres); 
     126    } 
     127     
     128    void onMousedown2(Surface self, byte buttons, Vec2i coordinates){ 
     129        self.raise(); 
     130        Input.setSurfaceLock(self); 
     131    } 
     132    void onMouseup2(Surface self, byte buttons, Vec2i coordinates){ 
     133        Input.unlockSurface(); 
     134    } 
     135    void onMousemove(Surface self, byte buttons, Vec2i coordinates){ 
     136        if(buttons == 1) self.moveAdd(coordinates); 
     137    } 
     138     
    89139    second.onMousedown = &onMousedown;   
    90     first.onResize = &onResize; 
     140    second.onResize = &onResize; 
     141    clear.onMousedown = &onMousedown2; 
     142    clear.onMousemove = &onMousemove; 
     143    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; 
    91151     
    92152    // Music 
     
    151211        Input.processInput(); 
    152212        camera.toTexture(); 
    153         disp.render(); 
     213        bg.render(); 
    154214         
    155215         
  • trunk/src/yage/gui/surface.d

    r43 r45  
    1313import yage.system.device; 
    1414import yage.system.constant; 
     15import yage.system.input; 
    1516import yage.resource.texture; 
    1617import yage.gui.style; 
    1718 
     19 
     20//move to constants 
     21enum{ 
     22    traditional, //default 
     23    stretched, 
     24    tiled 
     25} 
     26 
     27float third = 1.0/3.0; 
    1828 
    1929/**  
     
    2333 * The children will be positioned relative to the borders of their parent. */ 
    2434class Surface{ 
    25     static final Style defaultStyle; 
    26     Style style; 
    27      
    28     //Style style;  //move style into a higher level clas, perhaps make a geometry struct isntead 
    29     GPUTexture texture;  //Change from GPUTexture to Texture or Material 
    30      
    31     //Linked list would be faster for raising a window. 
    32     Surface[] subs;//Perhaps this should be changed into a linked list... 
     35    //Not sure that a Surface should have a style... I think surface should be a lower abstraction, for only geometry, rendering, and input. 
     36    //static final Style defaultStyle; //Default style should be more fitting as something that is global. 
     37    //Style style; 
     38     
     39    //Change from GPUTexture to Texture or Material 
     40    private GPUTexture texture; 
     41     
     42    Surface[] subs; 
    3343    //Not sure if I should have a reference to Parent or not, but for now, I will. 
    3444    Surface parent; 
    3545     
    36     Vec2f portion; //used for the texture only 
    37      
    38     Vec2f topLeft; 
     46    Vec2f topLeft;//rid self of these 
    3947    Vec2f bottomRight; 
    4048     
    41     //these are used for rendering, not calculation 
     49    //these are used for rendering, not for user 
    4250    Vec2i position1; 
    4351    Vec2i position2; 
    4452     
    45      
    46     Vec2i size; 
     53    Vec2i location; 
     54     
     55    //used for the texture 
     56    Vec2f portion; 
    4757     
    4858    bool visible; 
    49  
    50  
    51     //add root position and stuff 
     59     
     60    byte fill = traditional; 
    5261     
    5362    //Not sure how to impelement gluUnProject 
    5463     
     64    //Perhaps add some of these for global events. 
    5565    void delegate(typeof(this) self) onBlur; 
    56     void blur(){ if(onBlur)onBlur(this);} 
    57  
     66     
     67    //dunno how 
    5868    void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onClick; 
    5969 
     70    //dunno how 
    6071    void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onDblclick; 
    6172 
    62     void delegate(typeof(this) self) onFocus; 
     73    void delegate(typeof(this) self) onFocus; //Done -- See Raise, no fall through 
    6374 
    6475    void delegate(typeof(this) self, byte key, byte modifiers) onKeydown; 
     
    6879    void delegate(typeof(this) self, byte key, byte modifiers) onKeyup; 
    6980 
    70     void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onMousedown; 
    71     void mousedown(byte buttons, Vec2i coordinates){ if(onMousedown)onMousedown(this, buttons, coordinates);} 
    72  
    73     void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onMousemove; 
    74     void mousemove(byte buttons, Vec2i coordinates){ if(onMousemove)onMousemove(this, buttons, coordinates);} 
     81    void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onMousedown; //Done 
     82    void mousedown(byte buttons, Vec2i coordinates){  
     83        if(onMousedown)onMousedown(this, buttons, coordinates); 
     84        else if(parent !is null) parent.mousedown(buttons, coordinates); 
     85    } 
     86 
     87    void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onMousemove; //Done 
     88    void mousemove(byte buttons, Vec2i coordinates){ 
     89        if(onMousemove)onMousemove(this, buttons, coordinates); 
     90        else if(parent !is null) parent.mousemove(buttons, coordinates); 
     91    } 
    7592 
    7693    void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onMouseout; 
     
    7895    void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onMouseover; 
    7996 
    80     void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onMouseup; 
    81     void mouseup(byte buttons, Vec2i coordinates){ if(onMouseup)onMouseup(this, buttons, coordinates);} 
    82  
    83     void delegate(typeof(this) self, Vec2i difference) onResize; 
     97    void delegate(typeof(this) self, byte buttons, Vec2i coordinates) onMouseup; //Done 
     98    void mouseup(byte buttons, Vec2i coordinates){  
     99        if(onMouseup)onMouseup(this, buttons, coordinates); 
     100        else if(parent !is null) parent.mouseup(buttons, coordinates); 
     101    } 
     102 
     103    void delegate(typeof(this) self) onResize; //Done -- See recalculate, no fall through 
    84104     
    85105     
     
    88108        if(parent is null){ 
    89109            Device.subs ~= this; 
    90             recalculate(Device.getHeight(), Device.getWidth()); 
     110            this.recalculate(); 
    91111        } 
    92112        else{ 
    93113            parent.subs ~= this; 
    94             recalculate(parent.size.x, parent.size.y); 
     114            this.recalculate(); 
    95115        } 
    96116    } 
     
    101121    } 
    102122     
    103     void recalculate(int width, int height){ //not done 
    104         position1.x = cast(int)(topLeft.x * cast(float)width); 
    105         position1.y = cast(int)(topLeft.y * cast(float)height); 
    106          
    107         position2.x = cast(int)(bottomRight.x * cast(float)width); 
    108         position2.y = cast(int)(bottomRight.y * cast(float)height); 
    109          
    110         Vec2i temp = size; 
    111          
    112         size.x = position2.x - position1.x; 
    113         size.y = position2.y - position1.y; 
    114          
    115         if(onResize)onResize(this, Vec2i(temp.x - size.x, temp.y - size.y)); 
     123    //MAYBE I SHOULD PUT RECALCUALTE INTO A DELEGATE SO THAT THE USER COULD PICK ANYTHING! 
     124    void recalculate(Vec2i parent1, Vec2i parent2){ //not done 
     125        Vec2i parentSize = Vec2i(parent2.x - parent1.x, parent2.y - parent1.y); 
     126         
     127        Vec2i tempPosition1; 
     128        Vec2i tempPosition2; 
     129         
     130        tempPosition1.x = cast(int)(topLeft.x * cast(float)parentSize.x) + parent1.x + location.x; 
     131        tempPosition1.y = cast(int)(topLeft.y * cast(float)parentSize.y) + parent1.y + location.y; 
     132        tempPosition2.x = parent2.x - cast(int)((1.0 - bottomRight.x) * cast(float)parentSize.x) + location.x; 
     133        tempPosition2.y = parent2.y - cast(int)((1.0 - bottomRight.y) * cast(float)parentSize.y) + location.y; 
     134         
     135        //All of the below is for not going out of boundry 
     136        if(parent is null) goto setx; 
     137        bool xfailed; 
     138        if(tempPosition1.x < parent.position1.x){ 
     139            xfailed = true; 
     140            goto afterx; 
     141        } 
     142        if(tempPosition2.x > parent.position2.x){ 
     143            xfailed = true; 
     144            goto afterx; 
     145        } 
     146         
     147        setx: 
     148            position1.x = tempPosition1.x; 
     149            position2.x = tempPosition2.x; 
     150            if(parent is null) goto sety; 
     151             
     152        afterx: 
     153            if(tempPosition1.y < parent.position1.y){ 
     154                if(xfailed) return; //subs are not calculated and the window has not been resized 
     155                else goto aftery; 
     156            } 
     157            if(tempPosition2.y > parent.position2.y){ 
     158                if(xfailed) return; //subs are not calculated and the window has not ben resized 
     159                else goto aftery; 
     160            } 
     161         
     162        sety: 
     163            position1.y = tempPosition1.y; 
     164            position2.y = tempPosition2.y; 
     165         
     166        aftery: 
     167        if(onResize)onResize(this); 
    116168         
    117169        foreach(sub ;this.subs) 
    118             sub.recalculate(size.x, size.y); 
     170            sub.recalculate(position1, position2); 
    119171    } 
    120172     
    121173    void recalculate(){ 
    122         if(parent == null) 
    123             recalculate(Device.width, Device.height); 
     174        if(parent is null) 
     175            recalculate(Vec2i(0,0), Vec2i(Device.width, Device.height)); 
    124176        else 
    125             recalculate(parent.size.x, parent.size.y); 
    126     } 
    127      
    128     void recalculateTexture(){ 
     177            recalculate(parent.position1, parent.position2); 
     178    } 
     179     
     180    void moveAdd(Vec2i add){ 
     181        location.x -= add.x; 
     182        location.y -= add.y; 
     183        recalculate(); 
     184    } 
     185     
     186    //I would like textures to automatically do this so that it doesn't need to happen for every single surface on every single frame 
     187    void recalculateTexture(){  //Dunno if this will be needed when we change to materials 
    129188        portion.x = texture.requested_width/cast(float)texture.getWidth(); 
    130189        portion.y = texture.requested_height/cast(float)texture.getHeight(); 
     
    147206        glDisable(GL_LIGHTING); 
    148207         
     208        glEnable(GL_BLEND); 
     209        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
     210        //glColor4f(1, 1, 1, 1); 
     211         
     212         
    149213        glEnable(GL_TEXTURE_2D); 
    150214         
     
    167231         
    168232                glBegin(GL_QUADS); 
    169  
    170                 glTexCoord2f(0, 0); 
    171                 glVertex2i(position1.x, position2.y); 
    172233                 
    173                 glTexCoord2f(portion.x, 0); 
    174                 glVertex2i(position2.x, position2.y); 
    175                  
    176                 glTexCoord2f(portion.x, portion.y);  
    177                 glVertex2i(position2.x, position1.y); 
    178  
    179                 glTexCoord2f(0, portion.y); 
    180                 glVertex2i(position1.x, position1.y); 
    181  
     234                switch(fill){ 
     235                    case traditional: 
     236                        glTexCoord2f(0, 0); 
     237                        glVertex2i(position1.x, position2.y); 
     238                         
     239                        glTexCoord2f(portion.x, 0); 
     240                        glVertex2i(position2.x, position2.y); 
     241                         
     242                        glTexCoord2f(portion.x, portion.y);  
     243                        glVertex2i(position2.x, position1.y); 
     244         
     245                        glTexCoord2f(0, portion.y); 
     246                        glVertex2i(position1.x, position1.y); 
     247                        break; 
     248                    case stretched: //Move calculations somwhere else! 
     249                        //Not sure about the difference between /3 and *third, but who cares, I used *third 
     250                        float partx = portion.x * third; 
     251                        float party = portion.y * third; 
     252                         
     253                        float partytimes2 = party * 2; 
     254                        float partxtimes2 = partx * 2; 
     255                         
     256                        int w = cast(int)(texture.requested_width * third); 
     257                        int h = cast(int)(texture.requested_height * third); 
     258                         
     259                        int partwidth = position1.x + w; 
     260                        int partheight = position1.y + h; 
     261                         
     262                        int partwidthminus = position2.x - w; 
     263                        int partheightminus = position2.y - h; 
     264                         
     265                        /* 
     266                        * topleft 
     267                        */ 
     268                        glTexCoord2f(0, party); 
     269                        glVertex2i(position1.x, partheight); 
     270                         
     271                        glTexCoord2f(partx, party); 
     272                        glVertex2i(partwidth, partheight); 
     273                         
     274                        glTexCoord2f(partx, 0);  
     275                        glVertex2i(partwidth, position1.y); 
     276         
     277                        glTexCoord2f(0, 0); 
     278                        glVertex2i(position1.x, position1.y); 
     279     
     280                         
     281                        /* 
     282                        * left 
     283                        */ 
     284                        glTexCoord2f(0, partytimes2); 
     285                        glVertex2i(position1.x, partheightminus); 
     286                         
     287                        glTexCoord2f(partx, partytimes2); 
     288                        glVertex2i(partwidth, partheightminus); 
     289                         
     290                        glTexCoord2f(partx, party);  
     291                        glVertex2i(partwidth, partheight); 
     292         
     293                        glTexCoord2f(0, party); 
     294                        glVertex2i(position1.x, partheight); 
     295     
     296     
     297                        /* 
     298                        * bottomleft 
     299                        */ 
     300                        glTexCoord2f(0, portion.y); 
     301                        glVertex2i(position1.x, position2.y); 
     302                         
     303                        glTexCoord2f(partx, portion.y); 
     304                        glVertex2i(partwidth, position2.y); 
     305                         
     306                        glTexCoord2f(partx, partytimes2);  
     307                        glVertex2i(partwidth, partheightminus); 
     308         
     309                        glTexCoord2f(0, partytimes2); 
     310                        glVertex2i(position1.x, partheightminus); 
     311     
     312     
     313                        /* 
     314                        * top 
     315                        */ 
     316                        glTexCoord2f(partx, party); 
     317                        glVertex2i(partwidth, partheight); 
     318                         
     319                        glTexCoord2f(partxtimes2, party); 
     320                        glVertex2i(partwidthminus, partheight); 
     321                         
     322                        glTexCoord2f(partxtimes2, 0);  
     323                        glVertex2i(partwidthminus, position1.y); 
     324         
     325                        glTexCoord2f(partx, 0); 
     326                        glVertex2i(partwidth, position1.y); 
     327     
     328     
     329                        /* 
     330                        * middle 
     331                        */ 
     332                        glTexCoord2f(partx, partytimes2); 
     333                        glVertex2i(partwidth, partheightminus); 
     334                         
     335                        glTexCoord2f(partxtimes2, partytimes2); 
     336                        glVertex2i(partwidthminus, partheightminus); 
     337                         
     338                        glTexCoord2f(partxtimes2, party);  
     339                        glVertex2i(partwidthminus, partheight); 
     340         
     341                        glTexCoord2f(partx, party); 
     342                        glVertex2i(partwidth, partheight); 
     343     
     344     
     345                        /* 
     346                        * bottom 
     347                        */ 
     348                        glTexCoord2f(partx, portion.y); 
     349                        glVertex2i(partwidth, position2.y); 
     350                         
     351                        glTexCoord2f(partxtimes2, portion.y); 
     352                        glVertex2i(partwidthminus, position2.y); 
     353                         
     354                        glTexCoord2f(partxtimes2, partytimes2);  
     355                        glVertex2i(partwidthminus, partheightminus); 
     356         
     357                        glTexCoord2f(partx, partytimes2); 
     358                        glVertex2i(partwidth, partheightminus); 
     359     
     360     
     361                        /* 
     362                        * topright 
     363                        */ 
     364                        glTexCoord2f(partxtimes2, party); 
     365                        glVertex2i(partwidthminus, partheight); 
     366                         
     367                        glTexCoord2f(portion.x, party); 
     368                        glVertex2i(position2.x, partheight); 
     369                         
     370                        glTexCoord2f(portion.x, 0);  
     371                        glVertex2i(position2.x, position1.y); 
     372         
     373                        glTexCoord2f(partxtimes2, 0); 
     374                        glVertex2i(partwidthminus, position1.y); 
     375     
     376     
     377                        /* 
     378                        * right 
     379                        */ 
     380                        glTexCoord2f(partxtimes2, partytimes2); 
     381                        glVertex2i(partwidthminus, partheightminus); 
     382                         
     383                        glTexCoord2f(portion.x, partytimes2); 
     384                        glVertex2i(position2.x, partheightminus); 
     385                         
     386                        glTexCoord2f(portion.x, party);  
     387                        glVertex2i(position2.x, partheight); 
     388         
     389                        glTexCoord2f(partxtimes2, party); 
     390                        glVertex2i(partwidthminus, partheight); 
     391     
     392                        /* 
     393                        * bottomright 
     394                        */ 
     395                        glTexCoord2f(partxtimes2, portion.y); 
     396                        glVertex2i(partwidthminus, position2.y); 
     397                         
     398                        glTexCoord2f(portion.x, portion.y); 
     399                        glVertex2i(position2.x, position2.y); 
     400                         
     401                        glTexCoord2f(portion.x, partytimes2);  
     402                        glVertex2i(position2.x, partheightminus); 
     403         
     404                        glTexCoord2f(partxtimes2, partytimes2); 
     405                        glVertex2i(partwidthminus, partheightminus); 
     406                        break; 
     407                    case tiled: 
     408                         
     409                        break; 
     410                    default: 
     411                        writefln("Not a valid fill type"); 
     412                        //assert(0) 
     413                        break; 
     414                } 
    182415                glEnd(); 
    183416            } 
    184417             
     418            //I am clueless about this, so it's commented 
    185419            // Sort subs 
    186             if (!subs.ordered(true, (Surface s){return s.style.zIndex;} )) 
    187                subs.radixSort((Surface s){return s.style.zIndex;} );            
     420            //if (!subs.ordered(true, (Surface s){return s.style.zIndex;} )) 
     421            // subs.radixSort((Surface s){return s.style.zIndex;} ); 
    188422             
    189423            foreach(sub; subs) 
     
    201435            for(; index < Device.subs.length - 1; index++) 
    202436                Device.subs[index] = Device.subs[index+1]; 
    203             Device.subs[$] = this; 
     437            Device.subs[$-1] = this; 
    204438        } 
    205439        else{ 
     
    209443            parent.subs[$-1] = this; 
    210444        } 
    211     } 
     445        if(onFocus) onFocus(this); 
     446    }    
    212447} 
    213448 
     449//Perhaps put into yage.system.input 
     450//Could be better, a method perhaps... 
    214451Surface findSurface(int x, int y){ 
     452    if(Input.surfaceLock) return Input.surfaceLock; 
    215453    foreach_reverse(sub; Device.subs){ 
    216454        if(sub.position1.x <= x && x <= sub.position2.x && sub.position1.y <= y && y <= sub.position2.y){ 
     
    220458    return null; 
    221459} 
    222  
     460//Could be better, a method perhaps... 
    223461Surface findSurface(Surface surface,int x, int y){ 
    224462    foreach_reverse(sub; surface.subs){ 
     
    234472        if(current == surface) return  index; 
    235473    } 
    236     return 1 << 8; 
     474    return 1 << 8;  //Implement this for not in subs 
    237475} 
  • trunk/src/yage/resource/texture.d

    r39 r45  
    318318 
    319319        } 
     320        if(this.requested_width == 0) this.requested_width = this.getWidth(); 
     321        if(this.requested_height == 0) this.requested_height = this.getHeight(); 
    320322    } 
    321323 
  • trunk/src/yage/system/device.d

    r43 r45  
    1818import derelict.ogg.vorbis; 
    1919import derelict.ogg.vorbisfile; 
    20 import yage.resource.texture; 
     20//import yage.resource.texture; 
    2121import yage.gui.surface; 
    2222import yage.system.log; 
    2323import yage.system.constant; 
    2424import yage.system.input; 
     25import yage.core.vector; 
    2526 
    2627// Enable specular highlights with textures. 
     
    321322        height = _height; 
    322323         
    323         foreach(sub ;this.subs) sub.recalculate(width, height); 
     324        foreach(sub ;this.subs) sub.recalculate(Vec2i(0, 0), Vec2i(width, height)); 
    324325         
    325326        // For some reason, SDL Linux requires a call to SDL_SetVideoMode for a screen resize that's 
  • trunk/src/yage/system/input.d

    r40 r45  
    2626    static int mousex, mousey;      /// The current pixel location of the mouse cursor; (0, 0) is top left. 
    2727    static int mousedx, mousedy;    /// The number of pixels the mouse has moved since the last time input was queried. 
    28  
     28     
     29    //I do not know if this does the same as moused, I was too lazy to mod it for my needs. 
     30    static int xdiff, ydiff; 
     31     
    2932    /// A structure to track various state variables associated with each mouse button. 
    3033    struct Buttons 
     
    4144    static bool exit = false;       /// A termination request has been received. 
    4245 
    43  
     46    static Surface surfaceLock; 
    4447 
    4548    /** This function fills the above fields with the current intput data. 
     
    7982 
    8083                    auto surface = findSurface(mousex, mousey); 
    81                     if(!(surface is null)) surface.mousedown(event.button.button, Vec2i(mousex,mousey)); 
     84                    if(surface !is null) surface.mousedown(event.button.button, Vec2i(mousex,mousey)); 
    8285 
    8386                    break; 
     
    8992 
    9093                    auto surface = findSurface(mousex, mousey); 
    91                     if(!(surface is null)) surface.mouseup(event.button.button, Vec2i(mousex,mousey)); 
     94                    if(surface !is null) surface.mouseup(event.button.button, Vec2i(mousex,mousey)); 
    9295 
    9396                    break; 
     
    99102                    mousedx += event.motion.xrel;   // these seem to behave differently on linux 
    100103                    mousedy += event.motion.yrel;   // than on win32.  Testing should be done. 
     104                     
     105                    xdiff = mousex - event.motion.x; 
     106                    ydiff = mousey - event.motion.y; 
     107                     
    101108                    mousex = event.motion.x; 
    102109                    mousey = event.motion.y; 
    103110                     
    104                     //auto surface = findSurface(mousex, mousey); 
    105                     //if(!(surface is null)) surface.mousemove(event.button.button, Vec2i(mousex,mousey)); 
     111                    auto surface = findSurface(mousex, mousey); 
     112                    if(surface !is null) surface.mousemove(event.button.button, Vec2i(xdiff,ydiff)); 
    106113                    break; 
    107114 
     
    147154    {   return grabbed; 
    148155    } 
     156     
     157    static void setSurfaceLock(Surface lock){ 
     158        surfaceLock = lock; 
     159    } 
     160    static void unlockSurface(){ 
     161        surfaceLock = null; 
     162    } 
    149163}