Changeset 49
- Timestamp:
- 07/15/07 21:02:51 (1 year ago)
- Files:
-
- trunk/src/demo1/main.d (modified) (2 diffs)
- trunk/src/demo1/ship.d (modified) (1 diff)
- trunk/src/demo2/gameobj.d (modified) (1 diff)
- trunk/src/demo2/main.d (modified) (8 diffs)
- trunk/src/demo2/ship.d (modified) (2 diffs)
- trunk/src/yage/gui/style.d (modified) (1 diff)
- trunk/src/yage/gui/surface.d (modified) (3 diffs)
- trunk/src/yage/system/input.d (modified) (5 diffs)
- trunk/src/yage/util/flyer.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/demo1/main.d
r47 r49 7 7 */ 8 8 9 module demo 1.main;9 module demo2.main; 10 10 11 11 import std.string; … … 66 66 67 67 void onMousedown(Surface self, byte buttons, Vec2i coordinates){ 68 Input.button[1].up = false; 69 Input.setGrabMouse(!Input.getGrabMouse()); 68 self.grabMouse(!Input.getGrabMouse()); 70 69 } 71 70 trunk/src/demo1/ship.d
r34 r49 99 99 { 100 100 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)); 103 103 } 104 104 trunk/src/demo2/gameobj.d
r43 r49 7 7 */ 8 8 9 module demo 1.gameobj;9 module demo2.gameobj; 10 10 11 11 import std.math; trunk/src/demo2/main.d
r48 r49 7 7 */ 8 8 9 module demo 1.main;9 module demo2.main; 10 10 11 11 import std.string; … … 17 17 import derelict.opengl.glext; 18 18 19 import demo 1.ship;19 import demo2.ship; 20 20 21 21 // Current program entry point. This may change in the future. … … 65 65 66 66 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()); 70 68 } 71 69 72 70 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); 77 73 } 78 74 … … 102 98 103 99 Surface clear = new Surface(bg); 104 clear.setTexture(inactive );100 clear.setTexture(inactive2); 105 101 clear.topLeft = Vec2f(.65,0); 106 102 clear.bottomRight = Vec2f(1, .25); … … 114 110 115 111 Surface clear2 = new Surface(clear); 116 clear2.setTexture(inactive );112 clear2.setTexture(inactive2); 117 113 clear2.topLeft = Vec2f(.65,0); 118 114 clear2.bottomRight = Vec2f(1, .25); … … 126 122 127 123 Surface clear3 = new Surface(bg); 128 clear3.setTexture(inactive );124 clear3.setTexture(inactive2); 129 125 clear3.topLeft = Vec2f(.65,0); 130 126 clear3.bottomRight = Vec2f(1, .25); … … 136 132 clear3.onMouseenter = &onMouseenter; 137 133 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; 138 158 139 159 // Music … … 166 186 167 187 // Add to the scene's update loop 168 Input.getMouseDelta();188 //Input.getMouseDelta(); 169 189 void update(BaseNode self) 170 190 { // check for exit 171 191 if (Input.keydown[SDLK_ESCAPE]) 172 192 Input.exit=true; 173 174 // Toggle mouse grab175 // if (Input.button[1].up)176 // { Input.button[1].up = false;177 // Input.setGrabMouse(!Input.getGrabMouse());178 // }179 193 ship.getSpring().update(1/60.0f); 180 194 } 181 195 scene.onUpdate(&update); 182 183 Device.resizeWindow(800, 600); 184 //disp.recalculateTexture(); 196 197 bg.recalculate(); 185 198 186 199 // Rendering / Input Loop trunk/src/demo2/ship.d
r43 r49 7 7 */ 8 8 9 module demo 1.ship;9 module demo2.ship; 10 10 11 11 import std.stdio; 12 12 import yage.all; 13 import demo 1.gameobj;13 import demo2.gameobj; 14 14 15 15 class Ship : GameObject … … 99 99 { 100 100 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)); 103 103 } 104 104 trunk/src/yage/gui/style.d
r43 r49 44 44 45 45 float[4] dimension; // top, right, bottom, left 46 byte[4] dimensi nUnits;46 byte[4] dimensionUnits; 47 47 float height; 48 48 Unit heightUnits; trunk/src/yage/gui/surface.d
r48 r49 177 177 178 178 void startDrag(){ 179 Input.setSurfaceLock(this);179 lock(); 180 180 } 181 181 182 182 void drag(Vec2i add){ 183 locationAdd.x -= add.x;184 locationAdd.y -= add.y;183 locationAdd.x += add.x; 184 locationAdd.y += add.y; 185 185 186 186 … … 233 233 recalculate(false); 234 234 after: 235 Input.unlockSurface();235 unlock(); 236 236 } 237 237 … … 497 497 if(onFocus) onFocus(this); 498 498 } 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 } 499 527 500 528 bool isSub(Surface surf){ trunk/src/yage/system/input.d
r48 r49 18 18 class Input 19 19 { 20 private static bool resetmouse = true; // Used to disable large mouse jumps21 20 22 21 static bool[1024] keyup; /// The key was down and has been released. … … 99 98 break; 100 99 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 104 109 } 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 } 113 114 114 115 auto surface = getSurface(); … … 130 131 //Needs to be changed so that check is run once 131 132 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)); 133 134 134 135 break; … … 156 157 } 157 158 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 attaching161 * 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 }else168 { SDL_WM_GrabInput(SDL_GRAB_OFF);169 SDL_ShowCursor(true);170 }171 grabbed = _grabbed;172 }173 174 159 static bool getGrabMouse() 175 160 { return grabbed; 176 }177 178 static void setSurfaceLock(Surface lock){179 surfaceLock = lock;180 }181 static void unlockSurface(){182 surfaceLock = null;183 161 } 184 162 … … 187 165 return findSurface(mousex, mousey); 188 166 } 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 } 189 178 } trunk/src/yage/util/flyer.d
r32 r49 102 102 accelerate(speed, 0, 0); 103 103 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 // } 108 108 } 109 109
