| 1 | /* |
|---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
|---|
| 3 | |
|---|
| 4 | Copyright (C) 2004 orx |
|---|
| 5 | |
|---|
| 6 | This program is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the terms of the GNU General Public License as published by |
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
|---|
| 9 | any later version. |
|---|
| 10 | |
|---|
| 11 | ### File Specific: |
|---|
| 12 | main-programmer: Benjamin Grauer |
|---|
| 13 | co-programmer: ... |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI |
|---|
| 17 | |
|---|
| 18 | #include "glgui_image.h" |
|---|
| 19 | |
|---|
| 20 | #include "debug.h" |
|---|
| 21 | |
|---|
| 22 | namespace OrxGui |
|---|
| 23 | { |
|---|
| 24 | ObjectListDefinition(GLGuiImage); |
|---|
| 25 | /** |
|---|
| 26 | * standard constructor |
|---|
| 27 | */ |
|---|
| 28 | GLGuiImage::GLGuiImage () |
|---|
| 29 | { |
|---|
| 30 | this->init(); |
|---|
| 31 | |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | /** |
|---|
| 36 | * standard deconstructor |
|---|
| 37 | */ |
|---|
| 38 | GLGuiImage::~GLGuiImage() |
|---|
| 39 | { |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | /** |
|---|
| 43 | * initializes the GUI-element |
|---|
| 44 | */ |
|---|
| 45 | void GLGuiImage::init() |
|---|
| 46 | { |
|---|
| 47 | this->registerObject(this, GLGuiImage::_objectList); |
|---|
| 48 | |
|---|
| 49 | this->setForegroundColor(Color(1,1,1,1)); |
|---|
| 50 | this->_imageMaterial.setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|---|
| 51 | |
|---|
| 52 | this->resize(); |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | void GLGuiImage::loadImageFromTexture(const Texture& texture) |
|---|
| 57 | { |
|---|
| 58 | this->_imageMaterial.setDiffuseMap(texture); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | void GLGuiImage::loadImageFromFile(const std::string& fileName) |
|---|
| 62 | { |
|---|
| 63 | this->_imageMaterial.setDiffuseMap(fileName); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | void GLGuiImage::loadImageFromSDLSurface(SDL_Surface* surface) |
|---|
| 67 | { |
|---|
| 68 | this->_imageMaterial.setDiffuseMap(Texture(surface)); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | void GLGuiImage::loadImageFromDisplayList(GLuint texture) |
|---|
| 72 | { |
|---|
| 73 | PRINTF(2)("SORRY NOT IMPLEMENTED\n"); |
|---|
| 74 | // this->_imageMaterial.setTexture(texture); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | void GLGuiImage::updateFrontColor() |
|---|
| 78 | { |
|---|
| 79 | this->_imageMaterial.setDiffuseColor(foregroundColor()); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | void GLGuiImage::resize() |
|---|
| 83 | { |
|---|
| 84 | this->_imagePlane.setTopLeft(borderLeft(), borderTop()); |
|---|
| 85 | this->_imagePlane.setSize(this->getSizeX2D() - (borderLeft() + borderRight()), this->getSizeY2D() - (borderTop() + borderBottom()) ); |
|---|
| 86 | GLGuiWidget::resize(); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | /** |
|---|
| 91 | * @brief draws the GLGuiImage |
|---|
| 92 | */ |
|---|
| 93 | void GLGuiImage::draw() const |
|---|
| 94 | { |
|---|
| 95 | this->beginDraw(); |
|---|
| 96 | GLGuiWidget::draw(); |
|---|
| 97 | |
|---|
| 98 | this->_imageMaterial.select(); |
|---|
| 99 | this->drawRect(this->_imagePlane); |
|---|
| 100 | this->endDraw(); |
|---|
| 101 | } |
|---|
| 102 | } |
|---|