fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Window / Foreground / OSGImageForeground.cpp
blob7fdb24752e21b9aa8bd74f5bea8e2220786d010f
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright(C) 2000-2005 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
48 #include "OSGGL.h"
50 #include "OSGFieldContainer.h"
51 #include "OSGNode.h"
52 #include "OSGAction.h"
53 #include "OSGViewport.h"
54 #include "OSGCamera.h"
55 #include "OSGWindow.h"
56 #include "OSGImage.h"
58 #include "OSGImageForeground.h"
60 OSG_USING_NAMESPACE
62 // Documentation for this class is emited in the
63 // OSGImageForegroundBase.cpp file.
64 // To modify it, please change the .fcd file (OSGImageForeground.fcd) and
65 // regenerate the base file.
67 /***************************************************************************\
68 * Class methods *
69 \***************************************************************************/
71 /*-------------------------------------------------------------------------*\
72 - private -
73 \*-------------------------------------------------------------------------*/
75 void ImageForeground::initMethod(InitPhase ePhase)
77 Inherited::initMethod(ePhase);
80 /***************************************************************************\
81 * Instance methods *
82 \***************************************************************************/
84 /*------------- constructors & destructors --------------------------------*/
86 ImageForeground::ImageForeground(void) :
87 Inherited()
91 ImageForeground::ImageForeground(const ImageForeground &source) :
92 Inherited(source)
96 ImageForeground::~ImageForeground(void)
100 void ImageForeground::changed(ConstFieldMaskArg whichField,
101 UInt32 origin,
102 BitVector details)
104 Inherited::changed(whichField, origin, details);
107 /*------------------------------- dump ----------------------------------*/
109 void ImageForeground::dump( UInt32 OSG_CHECK_ARG(uiIndent),
110 const BitVector OSG_CHECK_ARG(bvFlags)) const
112 SLOG << "Dump ImageForeground NI" << std::endl;
116 void ImageForeground::draw(DrawEnv * pEnv)
118 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
119 if(getActive() == false)
120 return;
122 UInt16 i;
124 for(i = 0; i < getMFPositions()->size(); i++)
126 if(getImages(i) != NULL)
127 break;
130 if(i == getMFPositions()->size()) // all images == NULL?
131 return;
133 glPushAttrib(GL_POLYGON_BIT | GL_DEPTH_BUFFER_BIT |
134 GL_LIGHTING_BIT);
136 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
138 glDisable(GL_DEPTH_TEST);
140 glDisable(GL_COLOR_MATERIAL);
142 glDisable(GL_TEXTURE_2D);
144 glMatrixMode(GL_MODELVIEW);
145 glPushMatrix();
146 glLoadIdentity();
148 glMatrixMode(GL_PROJECTION);
149 glPushMatrix();
150 glLoadIdentity();
151 glOrtho(0, 1, 0, 1, 0, 1);
153 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
154 glEnable(GL_BLEND);
156 float vpWidth = 1.0, vpHeight = 1.0;
158 // for absolute pixel position
159 vpWidth = 1.0 / pEnv->getPixelWidth ();
160 vpHeight = 1.0 / pEnv->getPixelHeight();
162 for(i = 0; i < getMFPositions()->size(); i++)
164 Image *img = getImages(i);
166 if(img == NULL)
167 continue;
169 Pnt2f p = getPositions(i);
171 if(p[0] >= 1.0 || p[1] >= 1.0)
173 glRasterPos2f(p[0] * vpWidth, p[1] * vpHeight); // absolute
174 // position
176 else
178 glRasterPos2f(p[0], p[1]); // relative position
181 if(i < this->getMFScales()->size())
183 glPixelZoom(this->getScales(i)[0],
184 this->getScales(i)[1]);
187 glDrawPixels(img->getWidth(),
188 img->getHeight(),
189 img->getPixelFormat(),
190 GL_UNSIGNED_BYTE,
191 img->getData());
193 glPixelZoom(1.f, 1.f);
195 glDisable(GL_BLEND);
198 glPopMatrix();
199 glMatrixMode(GL_MODELVIEW);
200 glPopMatrix();
202 glPopAttrib();
203 #endif
206 void ImageForeground::subImage(Image *image)
208 MFImagesType::const_iterator imgIt = getMFImages()->find(image);
210 if(imgIt != getMFImages()->end())
212 MFImagesType::difference_type iIdx =
213 std::distance(getMFImages()->begin(), imgIt);
215 editMFImages ()->erase(iIdx);
216 editMFPositions()->erase(iIdx);