Changeset 49

Show
Ignore:
Timestamp:
07/15/07 21:02:51 (1 year ago)
Author:
Deformative
Message:

Bug fixes, mostly in system.input

Files:

Legend:

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

    r47 r49  
    77 */ 
    88 
    9 module demo1.main; 
     9module demo2.main; 
    1010 
    1111import std.string; 
     
    6666     
    6767    void onMousedown(Surface self, byte buttons, Vec2i coordinates){ 
    68         Input.button[1].up = false; 
    69         Input.setGrabMouse(!Input.getGrabMouse()); 
     68        self.grabMouse(!Input.getGrabMouse()); 
    7069    } 
    7170     
  • trunk/src/demo1/ship.d

    r34 r49  
    9999        { 
    100100            Vec2f m = Input.getMouseDelta(); 
    101             angularAccelerate(Vec3f(0, -m.x/16.0, 0)); 
    102             pitch.angularAccelerate(Vec3f(m.y/24.0, 0, 0)); 
     101            angularAccelerate(Vec3f(0, m.x/16.0, 0)); 
     102            pitch.angularAccelerate(Vec3f(-m.y/24.0, 0, 0)); 
    103103        } 
    104104 
  • trunk/src/demo2/gameobj.d

    r43 r49  
    77 */ 
    88 
    9 module demo1.gameobj; 
     9module demo2.gameobj; 
    1010 
    1111import std.math; 
  • trunk/src/demo2/main.d

    r48 r49  
    77 */ 
    88 
    9 module demo1.main; 
     9module demo2.main; 
    1010 
    1111import std.string; 
     
    1717import derelict.opengl.glext; 
    1818 
    19 import demo1.ship; 
     19import demo2.ship; 
    2020 
    2121// Current program entry point.  This may change in the future. 
     
    6565         
    6666    void onMousedown(Surface self, byte buttons, Vec2i coordinates){ 
    67         self.raise(); 
    68         Input.button[1].up = false; 
    69         Input.setGrabMouse(!Input.getGrabMouse()); 
     67        self.grabMouse(!Input.getGrabMouse()); 
    7068    } 
    7169     
    7270    void onResize(Surface self){ 
    73         int xres = self.position2.x - self.position1.x; 
    74         int yres = self.position2.y - self.position1.y; 
    75         camera.setResolution(xres, yres); 
    76         writefln("Camera resolution changed to ", xres, " x ", yres); 
     71        camera.setResolution(self.size.x, self.size.y); 
     72        writefln("Camera resolution changed to ", self.size.x, " x ", self.size.y); 
    7773    } 
    7874     
     
    10298     
    10399    Surface clear = new Surface(bg); 
    104     clear.setTexture(inactive); 
     100    clear.setTexture(inactive2); 
    105101    clear.topLeft = Vec2f(.65,0); 
    106102    clear.bottomRight = Vec2f(1, .25); 
     
    114110     
    115111    Surface clear2 = new Surface(clear); 
    116     clear2.setTexture(inactive); 
     112    clear2.setTexture(inactive2); 
    117113    clear2.topLeft = Vec2f(.65,0); 
    118114    clear2.bottomRight = Vec2f(1, .25); 
     
    126122 
    127123    Surface clear3 = new Surface(bg); 
    128     clear3.setTexture(inactive); 
     124    clear3.setTexture(inactive2); 
    129125    clear3.topLeft = Vec2f(.65,0); 
    130126    clear3.bottomRight = Vec2f(1, .25); 
     
    136132    clear3.onMouseenter = &onMouseenter; 
    137133    clear3.onMouseleave = &onMouseleave; 
     134 
     135    Surface clear4 = new Surface(bg); 
     136    clear4.setTexture(inactive2); 
     137    clear4.topLeft = Vec2f(.4,0); 
     138    clear4.bottomRight = Vec2f(1, .25); 
     139    clear4.fill = stretched; 
     140    clear4.setVisibility(true); 
     141    clear4.onMousedown = &onMousedown2; 
     142    clear4.onMousemove = &onMousemove; 
     143    clear4.onMouseup = &onMouseup2; 
     144    clear4.onMouseenter = &onMouseenter; 
     145    clear4.onMouseleave = &onMouseleave; 
     146 
     147    Surface clear5 = new Surface(bg); 
     148    clear5.setTexture(inactive); 
     149    clear5.topLeft = Vec2f(.65,0); 
     150    clear5.bottomRight = Vec2f(1, .4); 
     151    clear5.fill = stretched; 
     152    clear5.setVisibility(true); 
     153    clear5.onMousedown = &onMousedown2; 
     154    clear5.onMousemove = &onMousemove; 
     155    clear5.onMouseup = &onMouseup2; 
     156    clear5.onMouseenter = &onMouseenter; 
     157    clear5.onMouseleave = &onMouseleave; 
    138158     
    139159    // Music 
     
    166186 
    167187    // Add to the scene's update loop 
    168     Input.getMouseDelta(); 
     188    //Input.getMouseDelta(); 
    169189    void update(BaseNode self) 
    170190    {   // check for exit 
    171191        if (Input.keydown[SDLK_ESCAPE]) 
    172192            Input.exit=true; 
    173  
    174         // Toggle mouse grab 
    175 //      if (Input.button[1].up) 
    176 //      {   Input.button[1].up = false; 
    177 //          Input.setGrabMouse(!Input.getGrabMouse()); 
    178 //      } 
    179193        ship.getSpring().update(1/60.0f); 
    180194    } 
    181195    scene.onUpdate(&update); 
    182  
    183     Device.resizeWindow(800, 600); 
    184     //disp.recalculateTexture(); 
     196     
     197    bg.recalculate(); 
    185198     
    186199    // Rendering / Input Loop 
  • trunk/src/demo2/ship.d

    r43 r49  
    77 */ 
    88 
    9 module demo1.ship; 
     9module demo2.ship; 
    1010 
    1111import std.stdio; 
    1212import yage.all; 
    13 import demo1.gameobj; 
     13import demo2.gameobj; 
    1414 
    1515class Ship : GameObject 
     
    9999        { 
    100100            Vec2f m = Input.getMouseDelta(); 
    101             angularAccelerate(Vec3f(0, -m.x/16.0, 0)); 
    102             pitch.angularAccelerate(Vec3f(m.y/24.0, 0, 0)); 
     101            angularAccelerate(Vec3f(0, m.x/16.0, 0)); 
     102            pitch.angularAccelerate(Vec3f(-m.y/24.0, 0, 0)); 
    103103        } 
    104104 
  • trunk/src/yage/gui/style.d

    r43 r49  
    4444 
    4545    float[4] dimension;         // top, right, bottom, left 
    46     byte[4] dimensinUnits; 
     46    byte[4] dimensionUnits; 
    4747    float height; 
    4848    Unit  heightUnits; 
  • trunk/src/yage/gui/surface.d

    r48 r49  
    177177     
    178178    void startDrag(){ 
    179         Input.setSurfaceLock(this); 
     179        lock(); 
    180180    } 
    181181     
    182182    void drag(Vec2i add){ 
    183         locationAdd.x -= add.x; 
    184         locationAdd.y -= add.y; 
     183        locationAdd.x += add.x; 
     184        locationAdd.y += add.y; 
    185185         
    186186         
     
    233233        recalculate(false); 
    234234        after: 
    235         Input.unlockSurface(); 
     235        unlock(); 
    236236    } 
    237237     
     
    497497        if(onFocus) onFocus(this); 
    498498    } 
     499     
     500    //Perhaps change to setLock(bool) 
     501    //Events will be forwarded to this 
     502    void lock(){ 
     503        Input.surfaceLock = this; 
     504    } 
     505     
     506    void unlock(){ 
     507        Input.surfaceLock = null; 
     508    } 
     509     
     510    /** If enabled, the mousecursor will be hidden and grabbed by the application. 
     511     *  This also allows for mouse position changes to be registered in a relative fashion, 
     512     *  i.e. even when the mouse is at the edge of the screen.  This is ideal for attaching 
     513     *  the mouse to the look direction of a first or third-person camera. */ 
     514    void grabMouse(bool grab){ 
     515        if (grab){ 
     516            lock(); 
     517            SDL_WM_GrabInput(SDL_GRAB_ON); 
     518            SDL_ShowCursor(false); 
     519        } 
     520        else{ 
     521            unlock(); 
     522            SDL_WM_GrabInput(SDL_GRAB_OFF); 
     523            SDL_ShowCursor(true); 
     524        } 
     525        Input.grabbed = grab; 
     526    } 
    499527         
    500528    bool isSub(Surface surf){ 
  • trunk/src/yage/system/input.d

    r48 r49  
    1818class Input 
    1919{ 
    20     private static bool resetmouse = true;  // Used to disable large mouse jumps 
    2120 
    2221    static bool[1024] keyup;        /// The key was down and has been released. 
     
    9998                    break; 
    10099                case SDL_MOUSEMOTION: 
    101                     if (resetmouse) 
    102                     {   resetmouse = false; 
    103                         event.motion.xrel = event.motion.yrel = 0; 
     100                     
     101                    mousedx = event.motion.xrel;    // these seem to behave differently on linux 
     102                    mousedy = event.motion.yrel;    // than on win32.  Testing should be done. 
     103                     
     104                    if(grabbed){ 
     105                        if(event.motion.x != mousex || event.motion.y != mousey) 
     106                            SDL_WarpMouse(mousex, mousey); 
     107                        else break; 
     108                         
    104109                    } 
    105                     mousedx += event.motion.xrel;   // these seem to behave differently on linux 
    106                     mousedy += event.motion.yrel;   // than on win32.  Testing should be done. 
    107                      
    108                     xdiff = mousex - event.motion.x; 
    109                     ydiff = mousey - event.motion.y; 
    110                      
    111                     mousex = event.motion.x; 
    112                     mousey = event.motion.y; 
     110                    else{ 
     111                        mousex = event.motion.x; 
     112                        mousey = event.motion.y; 
     113                    } 
    113114                     
    114115                    auto surface = getSurface(); 
     
    130131                    //Needs to be changed so that check is run once 
    131132                    if(surface !is null) 
    132                         surface.mousemove(event.button.button, Vec2i(xdiff,ydiff)); 
     133                        surface.mousemove(event.button.button, Vec2i(event.motion.xrel, event.motion.yrel)); 
    133134                     
    134135                    break; 
     
    156157    } 
    157158 
    158     /** If enabled, the mousecursor will be hidden and grabbed by the application. 
    159      *  This also allows for mouse position changes to be registered in a relative fashion, 
    160      *  i.e. even when the mouse is at the edge of the screen.  This is ideal for attaching 
    161      *  the mouse to the look direction of a first or third-person camera. */ 
    162     static void setGrabMouse(bool _grabbed) 
    163     {   if (_grabbed) 
    164         {   SDL_WM_GrabInput(SDL_GRAB_ON); 
    165             SDL_ShowCursor(false); 
    166             resetmouse = true; 
    167         }else 
    168         {   SDL_WM_GrabInput(SDL_GRAB_OFF); 
    169             SDL_ShowCursor(true); 
    170         } 
    171         grabbed = _grabbed; 
    172     } 
    173  
    174159    static bool getGrabMouse() 
    175160    {   return grabbed; 
    176     } 
    177      
    178     static void setSurfaceLock(Surface lock){ 
    179         surfaceLock = lock; 
    180     } 
    181     static void unlockSurface(){ 
    182         surfaceLock = null; 
    183161    } 
    184162     
     
    187165        return findSurface(mousex, mousey); 
    188166    } 
     167     
     168    void unlock(){ 
     169        Input.surfaceLock = null; 
     170    } 
     171     
     172    void ungrab(){ 
     173        Input.unlock(); 
     174        SDL_WM_GrabInput(SDL_GRAB_OFF); 
     175        SDL_ShowCursor(true); 
     176        grabbed = false; 
     177    } 
    189178} 
  • trunk/src/yage/util/flyer.d

    r32 r49  
    102102            accelerate(speed, 0, 0); 
    103103 
    104       if (Input.getGrabMouse()) 
    105       {   Vec2f movement = Input.getMouseDelta(); 
    106           angularAccelerate(-movement.x/12.0, movement.y/16.0); 
    107       } 
     104//        if (Input.getGrabMouse()) 
     105//        {   Vec2f movement = Input.getMouseDelta(); 
     106//            angularAccelerate(-movement.x/12.0, movement.y/16.0); 
     107//        } 
    108108    } 
    109109