00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00060
00061
00062
00063
00064
00065 if (IsHidden()) return;
00066
00067
00068 PaintThis(surf, lerp_factor, scaled);
00069
00070
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
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
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
00111 surf->Blit(tex, 0, src, width, 1, 0, i);
00112 }
00113 }
00114
00115
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
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 }