InverterGump.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2004  The Pentagram Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #include "pent_include.h"
00020 #include "InverterGump.h"
00021 
00022 #include "RenderSurface.h"
00023 #include "Texture.h"
00024 #include "GUIApp.h"
00025 
00026 DEFINE_RUNTIME_CLASSTYPE_CODE(InverterGump,DesktopGump);
00027 
00028 InverterGump::InverterGump(sint32 _x, sint32 _y, sint32 _width, sint32 _height)
00029         : DesktopGump(_x, _y, _width, _height)
00030 {
00031         buffer = 0;
00032 }
00033 
00034 InverterGump::~InverterGump()
00035 {
00036         delete buffer;
00037 }
00038 
00039 static inline int getLine(int index, int n)
00040 {
00041         index = index % (2*n);
00042 
00043         if (index >= n)
00044                 return 2*n - 1 - 2*(index - n);
00045         else
00046                 return 2*index;
00047 }
00048 
00049 static inline int getIndex(int line, int n)
00050 {
00051         if (line % 2 == 0)
00052                 return line / 2;
00053         else
00054                 return 2*n - 1 - (line/2);
00055 }
00056 
00057 void InverterGump::Paint(RenderSurface* surf, sint32 lerp_factor, bool scaled)
00058 {
00059         // Skip the clipping rect/origin setting, since they will already be set
00060         // correctly by our parent.
00061         // (Or maybe I'm just to lazy to figure out the correct coordinates
00062         //  to use to compensate for the flipping... -wjp :-) )
00063 
00064         // Don't paint if hidden
00065         if (IsHidden()) return;
00066 
00067         // Paint This
00068         PaintThis(surf, lerp_factor, scaled);
00069 
00070         // Paint children
00071         PaintChildren(surf, lerp_factor, scaled);
00072 }
00073 
00074 
00075 void InverterGump::PaintChildren(RenderSurface* surf, sint32 lerp_factor, bool scaled)
00076 {
00077         unsigned int state = GUIApp::get_instance()->getInversion();
00078 
00079         if (state == 0) {
00080                 DesktopGump::PaintChildren(surf, lerp_factor, scaled);
00081                 return;
00082         }
00083         else if (state == 0x8000) {
00084                 bool old_flipped = surf->IsFlipped();
00085                 surf->SetFlipped(!old_flipped);
00086 
00087                 DesktopGump::PaintChildren(surf, lerp_factor, scaled);
00088 
00089                 surf->SetFlipped(old_flipped);
00090                 return;
00091         }
00092 
00093         int width = dims.w, height = dims.h;
00094 
00095 
00096         // need a backbuffer
00097         if (!buffer) {
00098                 buffer = RenderSurface::CreateSecondaryRenderSurface(width, height);
00099         }
00100 
00101         DesktopGump::PaintChildren(buffer, lerp_factor, scaled);
00102 
00103         Texture* tex = buffer->GetSurfaceAsTexture();
00104 
00105         // now invert-blit buffer to screen
00106         int t = (state * height) / 0x10000;
00107 
00108         for (int i = 0; i < height; ++i) {
00109                 int src = getLine(getIndex(i, height/2) + t, height/2);
00110 //              pout << src << " -> " << i << std::endl;
00111                 surf->Blit(tex, 0, src, width, 1, 0, i);
00112         }
00113 }
00114 
00115 // Convert a parent relative point to a gump point
00116 void InverterGump::ParentToGump(int &px, int &py, PointRoundDir)
00117 {
00118         px -= x;
00119         px += dims.x;
00120         py -= y;
00121         if (GUIApp::get_instance()->isInverted()) py = dims.h - py - 1;
00122         py += dims.y;
00123 }
00124 
00125 // Convert a gump point to parent relative point
00126 void InverterGump::GumpToParent(int &gx, int &gy, PointRoundDir)
00127 {
00128         gx -= dims.x;
00129         gx += x;
00130         gy -= dims.y;
00131         if (GUIApp::get_instance()->isInverted()) gy = dims.h - gy - 1;
00132         gy += y;
00133 }
00134 
00135 void InverterGump::RenderSurfaceChanged()
00136 {
00137         DesktopGump::RenderSurfaceChanged();
00138         FORGET_OBJECT(buffer);
00139 }

Generated on Fri Jul 27 22:27:20 2007 for pentagram by  doxygen 1.4.7