00001 #include "lugre_prefix.h"
00002 #include "lugre_BorderColourClipPaneOverlay.h"
00003 #include <OgreOverlayElementFactory.h>
00004 #include <OgreOverlayManager.h>
00005 #include <OgreMaterialManager.h>
00006
00007 using namespace Ogre;
00008
00009 namespace Lugre {
00010
00011 String cBorderColourClipPaneOverlay::msTypeName = "BorderColourClipPane";
00012
00013
00014
00015
00016
00017
00018
00019
00021 class BorderColourClipPaneOverlayElementFactory: public OverlayElementFactory { public:
00023 OverlayElement* createOverlayElement(const String& instanceName) {
00024 return new cBorderColourClipPaneOverlay(instanceName);
00025 }
00027 const String& getTypeName(void) const {
00028 return cBorderColourClipPaneOverlay::msTypeName;
00029 }
00030 };
00031
00032 void cBorderColourClipPaneOverlay::RegisterFactory () {
00033 OverlayManager::getSingleton().addOverlayElementFactory(new BorderColourClipPaneOverlayElementFactory());
00034 }
00035
00036
00037
00038
00039
00040
00041
00042
00043 cBorderColourClipPaneOverlay::cBorderColourClipPaneOverlay(const Ogre::String& name)
00044 : cColourClipPaneOverlay(name), mpBorderMaterial(0), mBorderRenderable(0), mpRobRenderOpBorder(&mRenderOpBorder) {
00045 mBorder.left = 0;
00046 mBorder.top = 0;
00047 mBorder.right = 0;
00048 mBorder.bottom = 0;
00049 }
00050
00051 cBorderColourClipPaneOverlay::~cBorderColourClipPaneOverlay() {
00052 delete mRenderOpBorder.vertexData; mRenderOpBorder.vertexData = 0;
00053 delete mRenderOpBorder.indexData; mRenderOpBorder.indexData = 0;
00054 delete mBorderRenderable; mBorderRenderable = 0;
00055 }
00056
00058 void cBorderColourClipPaneOverlay::initialise(void) {
00059 bool init = !mInitialised;
00060 cColourClipPaneOverlay::initialise();
00061
00062 if (init) {
00063
00064 mBorderRenderable = new CCPBorderRenderable(this);
00065
00066 mInitialised = true;
00067 }
00068 }
00069
00070 void cBorderColourClipPaneOverlay::_updateRenderQueue(RenderQueue* queue)
00071 {
00072
00073
00074 if (mVisible)
00075 {
00076
00077 queue->addRenderable(mBorderRenderable, RENDER_QUEUE_OVERLAY, mZOrder);
00078
00079
00080
00081 cColourClipPaneOverlay::_updateRenderQueue(queue);
00082 }
00083 }
00084
00085 void cBorderColourClipPaneOverlay::setBorderMaterialName(const String& name) {
00086 mBorderMaterialName = name;
00087 mpBorderMaterial = MaterialManager::getSingleton().getByName(name);
00088 if (mpBorderMaterial.isNull())
00089 OGRE_EXCEPT( Exception::ERR_ITEM_NOT_FOUND, "Could not find material " + name,
00090 "cBorderColourClipPaneOverlay::setBorderMaterialName" );
00091 mpBorderMaterial->load();
00092
00093 mpBorderMaterial->setLightingEnabled(false);
00094 mpBorderMaterial->setDepthCheckEnabled(false);
00095 }
00096
00097
00098
00100 void cBorderColourClipPaneOverlay::SetTexCoords (const Ogre::Real fU1,const Ogre::Real fV1,const Ogre::Real fU2,const Ogre::Real fV2) {
00101 SetTexCoords(kBCCPOPart_LT,fU1,fV1,fU1,fV1);
00102 SetTexCoords(kBCCPOPart_LB,fU1,fV2,fU1,fV2);
00103 SetTexCoords(kBCCPOPart_RT,fU2,fV1,fU2,fV1);
00104 SetTexCoords(kBCCPOPart_RB,fU2,fV2,fU2,fV2);
00105 SetTexCoords(kBCCPOPart_L,fU1,fV1,fU1,fV2);
00106 SetTexCoords(kBCCPOPart_R,fU2,fV1,fU2,fV2);
00107 SetTexCoords(kBCCPOPart_T,fU1,fV1,fU2,fV1);
00108 SetTexCoords(kBCCPOPart_B,fU1,fV2,fU2,fV2);
00109 SetTexCoords(kBCCPOPart_M,fU1,fV1,fU2,fV2);
00110 }
00111
00112 void cBorderColourClipPaneOverlay::setColour (const Ogre::ColourValue& col) {
00113 SetColours(col,col,col,col);
00114 }
00115
00116 void cBorderColourClipPaneOverlay::SetColours (const Ogre::ColourValue colLT,const Ogre::ColourValue colRT,const Ogre::ColourValue colLB,const Ogre::ColourValue colRB) {
00117 SetColours(kBCCPOPart_LT,colLT,colLT,colLT,colLT);
00118 SetColours(kBCCPOPart_RT,colRT,colRT,colRT,colRT);
00119 SetColours(kBCCPOPart_LB,colLB,colLB,colLB,colLB);
00120 SetColours(kBCCPOPart_RB,colRB,colRB,colRB,colRB);
00121 SetColours(kBCCPOPart_L,colLT,colLT,colLB,colLB);
00122 SetColours(kBCCPOPart_R,colRT,colRT,colRB,colRB);
00123 SetColours(kBCCPOPart_T,colLT,colRT,colLT,colRT);
00124 SetColours(kBCCPOPart_B,colLB,colRB,colLB,colRB);
00125 SetColours(kBCCPOPart_M,colLT,colRT,colLB,colRB);
00126 }
00127
00128
00129 void cBorderColourClipPaneOverlay::SetTexCoords (const int iPart,const Ogre::Real fU1,const Ogre::Real fV1,const Ogre::Real fU2,const Ogre::Real fV2) {
00130
00131 mFormParts[iPart].SetUV(fU1,fV1,fU2,fV2);
00132 mGeomPositionsOutOfDate = true;
00133 }
00134
00135 void cBorderColourClipPaneOverlay::SetColours (const int iPart,const Ogre::ColourValue colLT,const Ogre::ColourValue colRT,const Ogre::ColourValue colLB,const Ogre::ColourValue colRB) {
00136 mFormParts[iPart].lt.col = colLT;
00137 mFormParts[iPart].rt.col = colRT;
00138 mFormParts[iPart].lb.col = colLB;
00139 mFormParts[iPart].rb.col = colRB;
00140 mGeomPositionsOutOfDate = true;
00141 }
00142
00143
00145 void cBorderColourClipPaneOverlay::SetBorder (const Ogre::Real l,const Ogre::Real t,const Ogre::Real r,const Ogre::Real b) {
00146 mBorder.left = l;
00147 mBorder.top = t;
00148 mBorder.right = r;
00149 mBorder.bottom = b;
00150 }
00151
00153 const String& cBorderColourClipPaneOverlay::getTypeName(void) const {
00154 return msTypeName;
00155 }
00156
00157
00159 void cBorderColourClipPaneOverlay::updatePositionGeometry(void) {
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 Real l = _getDerivedLeft();
00176 Real t = _getDerivedTop();
00177 Real r = l+mWidth;
00178 Real b = t+mHeight;
00179 Real l2,r2,t2,b2;
00180 if (mMetricsMode != GMM_RELATIVE) {
00181
00182 l2 = l + mBorder.left*mPixelScaleX;
00183 r2 = r - mBorder.right*mPixelScaleX;
00184 t2 = t + mBorder.top*mPixelScaleY;
00185 b2 = b - mBorder.bottom*mPixelScaleY;
00186 } else {
00187 l2 = l + mBorder.left;
00188 r2 = r - mBorder.right;
00189 t2 = t + mBorder.top;
00190 b2 = b - mBorder.bottom;
00191 }
00192
00193 mFormParts[kBCCPOPart_LT].SetLTRB(l,t,l2,t2);
00194 mFormParts[kBCCPOPart_LB].SetLTRB(l,b2,l2,b);
00195 mFormParts[kBCCPOPart_RB].SetLTRB(r2,b2,r,b);
00196 mFormParts[kBCCPOPart_RT].SetLTRB(r2,t,r,t2);
00197 mFormParts[kBCCPOPart_L].SetLTRB(l,t2,l2,b2);
00198 mFormParts[kBCCPOPart_R].SetLTRB(r2,t2,r,b2);
00199 mFormParts[kBCCPOPart_T].SetLTRB(l2,t,r2,t2);
00200 mFormParts[kBCCPOPart_B].SetLTRB(l2,b2,r2,b);
00201 mFormParts[kBCCPOPart_M].SetLTRB(l2,t2,r2,b2);
00202
00203 int i;
00204 VertexRect clipped[9];
00205 if (mbClipInitialized) {
00206
00207 Ogre::Rectangle clippingRegion = mClip;
00208 if (mMetricsMode != GMM_RELATIVE) {
00209 clippingRegion.left *= mPixelScaleX;
00210 clippingRegion.right *= mPixelScaleX;
00211 clippingRegion.top *= mPixelScaleY;
00212 clippingRegion.bottom *= mPixelScaleY;
00213 }
00214
00215
00216 for (i=0;i<9;++i) clipped[i] = mFormParts[i].Intersect(clippingRegion);
00217 } else {
00218
00219 for (i=0;i<9;++i) clipped[i] = mFormParts[i];
00220 }
00221
00222
00223
00224 Real maxz = GetMaxZ();
00225
00226
00227 #if 0
00228 0-----2
00229 | /|
00230 | / |
00231 |/ |
00232 1-----3
00233 #endif
00234 Begin(4,0,false,false,Ogre::RenderOperation::OT_TRIANGLE_STRIP);
00235
00236
00237 clipped[kBCCPOPart_M].DrawStrip(this,maxz);
00238 End();
00239
00240 mpRobRenderOpBorder.Begin(6*8,0,false,false,Ogre::RenderOperation::OT_TRIANGLE_LIST);
00241 for (i=0;i<9;++i) if (i != kBCCPOPart_M) clipped[i].DrawList(&mpRobRenderOpBorder,maxz);
00242 mpRobRenderOpBorder.End();
00243 }
00244
00245
00246
00247
00248
00249
00250 #if 0
00251 struct Vertex {
00252 Ogre::Real x,y;
00253 Ogre::Real u,v;
00254 Ogre::ColourValue col;
00255
00256 Vertex();
00257 Vertex(const Ogre::Real x,const Ogre::Real y,const Ogre::Real u,const Ogre::Real v,const Ogre::ColourValue& col);
00258 friend Vertex Interpolate (const Vertex& a,const Vertex& b,const float t);
00259 };
00260
00261 struct VertexRect {
00262 Vertex lt,lb,rt,rb;
00263
00264 VertexRect ();
00265 VertexRect (const Vertex& lt,const Vertex& lb,const Vertex& rt,const Vertex& rb);
00266 void SetLTWH (const Ogre::Real l,const Ogre::Real t,const Ogre::Real w,const Ogre::Real h);
00267 void SetCol (const Ogre::ColourValue& col);
00268 void SetUV (const Ogre::Real u1,const Ogre::Real v1,const Ogre::Real u2,const Ogre::Real v2);
00269 Vertex Pick (const Ogre::Real x,const Ogre::Real y);
00270 VertexRect Intersect (const Ogre::Rectangle& clippingRegion);
00271 };
00272 #endif
00273
00274 };