DecoratorDefender.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #include "DecoratorDefender.h"
  28. #include <Rocket/Core/Element.h>
  29. #include <Rocket/Core/Texture.h>
  30. #include <Rocket/Core/Math.h>
  31. #include <ShellOpenGL.h>
  32. DecoratorDefender::~DecoratorDefender()
  33. {
  34. }
  35. bool DecoratorDefender::Initialise(const Rocket::Core::String& image_source, const Rocket::Core::String& image_path)
  36. {
  37. image_index = LoadTexture(image_source, image_path);
  38. if (image_index == -1)
  39. {
  40. return false;
  41. }
  42. return true;
  43. }
  44. /// Called on a decorator to generate any required per-element data for a newly decorated element.
  45. Rocket::Core::DecoratorDataHandle DecoratorDefender::GenerateElementData(Rocket::Core::Element* ROCKET_UNUSED(element))
  46. {
  47. return NULL;
  48. }
  49. // Called to release element data generated by this decorator.
  50. void DecoratorDefender::ReleaseElementData(Rocket::Core::DecoratorDataHandle ROCKET_UNUSED(element_data))
  51. {
  52. }
  53. // Called to render the decorator on an element.
  54. void DecoratorDefender::RenderElement(Rocket::Core::Element* element, Rocket::Core::DecoratorDataHandle ROCKET_UNUSED(element_data))
  55. {
  56. Rocket::Core::Vector2f position = element->GetAbsoluteOffset(Rocket::Core::Box::PADDING);
  57. Rocket::Core::Vector2f size = element->GetBox().GetSize(Rocket::Core::Box::PADDING);
  58. glEnable(GL_TEXTURE_2D);
  59. glBindTexture(GL_TEXTURE_2D, (GLuint) GetTexture(image_index)->GetHandle(element->GetRenderInterface()));
  60. Rocket::Core::Colourb colour = element->GetProperty< Rocket::Core::Colourb >("color");
  61. glColor4ubv(colour);
  62. glBegin(GL_QUADS);
  63. glVertex2f(position.x, position.y);
  64. glTexCoord2f(0, 1);
  65. glVertex2f(position.x, position.y + size.y);
  66. glTexCoord2f(1, 1);
  67. glVertex2f(position.x + size.x, position.y + size.y);
  68. glTexCoord2f(1, 0);
  69. glVertex2f(position.x + size.x, position.y);
  70. glTexCoord2f(0, 0);
  71. glEnd();
  72. glColor4ub(255, 255, 255, 255);
  73. }