Mercurial > projects > myrrdin
diff import/myrrdin/viewconsumer.d @ 5:f4b89014ad39
added moving figure stuff + animated sprites. not usable atm.
author | fred@reichbier.de |
---|---|
date | Sat, 19 Jul 2008 14:33:08 +0200 |
parents | src/viewconsumer.d@292df259cc85 |
children | 510541745cd1 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/import/myrrdin/viewconsumer.d Sat Jul 19 14:33:08 2008 +0200 @@ -0,0 +1,69 @@ +/* + This file is part of myrrdin. + + myrrdin is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + myrrdin is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with myrrdin. If not, see <http://www.gnu.org/licenses/>. +*/ + +module viewconsumer; + +import dsfml.window.all; +import dsfml.system.all; +import dsfml.graphics.all; + +import consumer; +import 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; + } +}