Mercurial > projects > myrrdin
diff import/myrrdin/consumers/view.d @ 8:156a95e4c018
final package structure now, i hope
author | fred@reichbier.de |
---|---|
date | Sat, 19 Jul 2008 17:26:41 +0200 |
parents | import/myrrdin/viewconsumer.d@806b3781f4e4 |
children | 79b534bbda65 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/import/myrrdin/consumers/view.d Sat Jul 19 17:26:41 2008 +0200 @@ -0,0 +1,75 @@ +/* + myrrdin, a 2d tile engine + Copyright (c) 2008 Friedrich Weber + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the Software), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +module myrrdin.consumers.view; + +import dsfml.window.all; +import dsfml.system.all; +import dsfml.graphics.all; + +import myrrdin.consumers.consumer; +import myrrdin.renderer; +import tango.io.Stdout; + +/* That is a consumer which sets and manipulates the render window view */ +class ViewConsumer : Consumer { + protected View view; + + this(Renderer renderer) { + super(renderer); + // set the initial view + this.view = renderer.app.getView(); + this.view.setFromRect(new FloatRect(0, 0, renderer.app.getWidth(), renderer.app.getHeight())); + this.update_view(); + } + + protected void update_view() { + this.renderer.app.setView(this.view); + } + + void move_view(float x=0, float y=0) { + this.view.move(x, y); + } +} + +class InteractiveViewConsumer : ViewConsumer { + this(Renderer renderer) { + super(renderer); + } + + bool handle_event(Event evt) { + if (evt.Type == Event.EventType.KEYPRESSED) { + float x=0, y=0; + if(evt.Key.Code == KeyCode.LEFT) x -= 2; + if(evt.Key.Code == KeyCode.RIGHT) x += 2; + if(evt.Key.Code == KeyCode.UP) y -= 2; + if(evt.Key.Code == KeyCode.DOWN) y += 2; + if(x != 0 || y != 0) { + Stdout.formatln("{} fps", 1.0 / this.renderer.app.getFrameTime()); + this.move_view(x, y); + return true; + } + } + return false; + } +}