1 /* 2 * DSFML - The Simple and Fast Multimedia Library for D 3 * 4 * Copyright (c) 2013 - 2017 Jeremy DeHaan (dehaan.jeremiah@gmail.com) 5 * 6 * This software is provided 'as-is', without any express or implied warranty. 7 * In no event will the authors be held liable for any damages arising from the 8 * use of this software. 9 * 10 * Permission is granted to anyone to use this software for any purpose, 11 * including commercial applications, and to alter it and redistribute it 12 * freely, subject to the following restrictions: 13 * 14 * 1. The origin of this software must not be misrepresented; you must not claim 15 * that you wrote the original software. If you use this software in a product, 16 * an acknowledgment in the product documentation would be appreciated but is 17 * not required. 18 * 19 * 2. Altered source versions must be plainly marked as such, and must not be 20 * misrepresented as being the original software. 21 * 22 * 3. This notice may not be removed or altered from any source distribution 23 */ 24 25 /** 26 * $(U Drawable) is a very simple base interface that allows objects of derived 27 * classes to be drawn to a RenderTarget. 28 * 29 * All you have to do in your derived class is to override the draw virtual 30 * function. 31 * 32 * Note that inheriting from $(DRAWABLE_LINK) is not mandatory, but it allows 33 * this nice syntax `window.draw(object)` rather than `object.draw(window)`, 34 * which is more consistent with other DSFML classes. 35 * 36 * Example: 37 * --- 38 * class MyDrawable : Drawable 39 * { 40 * public: 41 * 42 * this() 43 * { 44 * m_sprite = Sprite(); 45 * m_texture = Texture(); 46 * m_vertices = VertexArray(); 47 * 48 * // additional setup 49 * } 50 * ... 51 * 52 * void draw(RenderTarget target, RenderStates states) const 53 * { 54 * // You can draw other high-level objects 55 * target.draw(m_sprite, states); 56 * 57 * // ... or use the low-level API 58 * states.texture = m_texture; 59 * target.draw(m_vertices, states); 60 * 61 * // ... or draw with OpenGL directly 62 * glBegin(GL_QUADS); 63 * ... 64 * glEnd(); 65 * } 66 * 67 * private: 68 * Sprite m_sprite; 69 * Texture m_texture; 70 * VertexArray m_vertices; 71 * } 72 * --- 73 * 74 * See_Also: 75 * $(RENDERTARGET_LINK) 76 */ 77 module dsfml.graphics.drawable; 78 79 import dsfml.graphics.rendertarget; 80 import dsfml.graphics.renderstates; 81 82 /** 83 * Interface for objects that can be drawn to a render target. 84 */ 85 interface Drawable 86 { 87 /** 88 * Draw the object to a render target. 89 * 90 * Params: 91 * renderTarget = Render target to draw to 92 * renderStates = Current render states 93 */ 94 void draw(RenderTarget renderTarget, RenderStates renderStates); 95 }