1 /** 2 * Copyright: Enalye 3 * License: Zlib 4 * Authors: Enalye 5 */ 6 module atelier.render.drawable; 7 8 import bindbc.sdl, bindbc.sdl.image; 9 import atelier.core; 10 11 /// Indicate if something is mirrored. 12 enum Flip { 13 none, 14 horizontal, 15 vertical, 16 both 17 } 18 19 package SDL_RendererFlip getSDLFlip(Flip flip) { 20 final switch (flip) with (Flip) { 21 case both: 22 return cast(SDL_RendererFlip)(SDL_FLIP_HORIZONTAL | SDL_FLIP_VERTICAL); 23 case horizontal: 24 return SDL_FLIP_HORIZONTAL; 25 case vertical: 26 return SDL_FLIP_VERTICAL; 27 case none: 28 return SDL_FLIP_NONE; 29 } 30 } 31 32 /// Blending algorithm \ 33 /// none: Paste everything without transparency \ 34 /// modular: Multiply color value with the destination \ 35 /// additive: Add color value with the destination \ 36 /// alpha: Paste everything with transparency (Default one) 37 enum Blend { 38 none, 39 modular, 40 additive, 41 alpha 42 } 43 44 /// Everything that can be rendered. 45 interface Drawable { 46 @property { 47 /// loaded ? 48 bool isLoaded() const; 49 /// Width in texels. 50 uint width() const; 51 /// Height in texels. 52 uint height() const; 53 54 /// Color added to the renderable. 55 Color color() const; 56 /// Ditto 57 Color color(Color); 58 59 /// Alpha 60 float alpha() const; 61 /// Ditto 62 float alpha(float); 63 64 /// Blending algorithm. 65 Blend blend() const; 66 /// Ditto 67 Blend blend(Blend); 68 } 69 70 /// Render the whole texture here 71 void draw(Vec2f pos, Vec2f anchor) const; 72 73 /// Render a section of the texture here 74 void draw(Vec2f pos, Vec4i srcRect, Vec2f anchor) const; 75 76 /// Render the whole texture here 77 void draw(Vec2f pos, Vec2f size, Vec2f anchor) const; 78 79 /// Render a section of the texture here 80 void draw(Vec2f pos, Vec2f size, Vec4i srcRect, Vec2f anchor) const; 81 82 /// Render a section of the texture here 83 void draw(Vec2f pos, Vec2f size, Vec4i srcRect, float angle, Flip flip, 84 Vec2f anchor = Vec2f.half) const; 85 }