1 /* 2 * This source file is part of libRocket, the HTML/CSS Interface Middleware 3 * 4 * For the latest information, see http://www.librocket.com 5 * 6 * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a copy 9 * of this software and associated documentation files (the "Software"), to deal 10 * in the Software without restriction, including without limitation the rights 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 * copies of the Software, and to permit persons to whom the Software is 13 * furnished to do so, subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be included in 16 * all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 * THE SOFTWARE. 25 * 26 */ 27 28 #ifndef ROCKETINVADERSDECORATORSTARFIELD_H 29 #define ROCKETINVADERSDECORATORSTARFIELD_H 30 31 #include <Rocket/Core/Decorator.h> 32 #include <vector> 33 34 class DecoratorStarfield : public Rocket::Core::Decorator 35 { 36 public: 37 virtual ~DecoratorStarfield(); 38 39 bool Initialise(int num_layers, const Rocket::Core::Colourb& top_colour, const Rocket::Core::Colourb& bottom_colour, float top_speed, float bottom_speed, int top_density, int bottom_density); 40 41 /// Called on a decorator to generate any required per-element data for a newly decorated element. 42 /// @param[in] element The newly decorated element. 43 /// @return A handle to a decorator-defined data handle, or NULL if none is needed for the element. 44 virtual Rocket::Core::DecoratorDataHandle GenerateElementData(Rocket::Core::Element* element); 45 /// Called to release element data generated by this decorator. 46 /// @param[in] element_data The element data handle to release. 47 virtual void ReleaseElementData(Rocket::Core::DecoratorDataHandle element_data); 48 49 /// Called to render the decorator on an element. 50 /// @param[in] element The element to render the decorator on. 51 /// @param[in] element_data The handle to the data generated by the decorator for the element. 52 virtual void RenderElement(Rocket::Core::Element* element, Rocket::Core::DecoratorDataHandle element_data); 53 54 private: 55 int num_layers; 56 Rocket::Core::Colourb top_colour; 57 Rocket::Core::Colourb bottom_colour; 58 float top_speed; 59 float bottom_speed; 60 int top_density; 61 int bottom_density; 62 63 struct StarLayer 64 { 65 typedef std::vector< Rocket::Core::Vector2f > StarList; 66 StarList stars; 67 Rocket::Core::Colourb colour; 68 float speed; 69 }; 70 71 struct StarField 72 { 73 void Update(); 74 float last_update; 75 Rocket::Core::Vector2f dimensions; 76 77 typedef std::vector< StarLayer > StarLayerList; 78 StarLayerList star_layers; 79 }; 80 }; 81 82 #endif 83