00001 #ifdef WIN32
00002 #include <windows.h>
00003 #endif
00004 #include <GL/gl.h>
00005 #include "skinner.h"
00006 #include "globals.h"
00007
00008 #ifndef min
00009 #define min(a, b) ((a) < (b) ? (a) : (b))
00010 #endif
00011 glictSkinner::glictSkinner() {
00012 topleft = 0;
00013 topright = 0;
00014 bottomleft = 0;
00015 bottomright = 0;
00016
00017 top = 0;
00018 left = 0;
00019 right = 0;
00020 bottom = 0;
00021
00022 center = 0;
00023
00024
00025 topleftf = NULL;
00026 toprightf = NULL;
00027 bottomleftf = NULL;
00028 bottomrightf = NULL;
00029
00030 topf = NULL;
00031 leftf = NULL;
00032 rightf = NULL;
00033 bottomf = NULL;
00034
00035 centerf = NULL;
00036 }
00037
00038 glictSkinner::~glictSkinner() {
00039 }
00040
00041 void glictSkinner::Paint(glictSize *size) {
00042 static int x1, y1, x2, y2;
00043
00044 #ifndef NO_GL
00045 glEnable(GL_TEXTURE_2D);
00046 glColor4f(1., 1., 1., 1.);
00047 #endif
00048 static glictColor col (1, 1, 1, 1);
00049
00050
00051 if (topleft || topleftf) {
00052 x1 = y1 = 0;
00053 x2 = toplefts.w+1; y2 = toplefts.h+1;
00054 if (topleftf)
00055 topleftf(this, topleftp);
00056 #ifndef NO_GL
00057 else
00058 glBindTexture(GL_TEXTURE_2D, topleft);
00059 #endif
00060 glictGlobals.PaintRect(x1, x2, y1, y2, col);
00061 }
00062
00063 if (topright || toprightf) {
00064 x1 = size->w - toprights.w -1; y1 = 0;
00065 x2 = size->w; y2 = toprights.h + 1;
00066 if (toprightf)
00067 toprightf(this, toprightp);
00068 #ifndef NO_GL
00069 else
00070 glBindTexture(GL_TEXTURE_2D, topright);
00071 #endif
00072 glictGlobals.PaintRect(x1, x2, y1, y2, col);
00073 }
00074
00075 if (bottomleft || bottomleftf) {
00076 x1 = 0; y1 = size->h - bottomlefts.h - 1;
00077 x2 = bottomlefts.w + 1; y2 = size->h;
00078 if (bottomleftf)
00079 bottomleftf(this, bottomleftp);
00080 #ifndef NO_GL
00081 else
00082 glBindTexture(GL_TEXTURE_2D, bottomleft);
00083 #endif
00084 glictGlobals.PaintRect(x1, x2, y1, y2, col);
00085 }
00086
00087 if (bottomright || bottomrightf) {
00088 x1 = size->w - bottomrights.w - 1; y1 = size->h - bottomrights.h - 1;
00089 x2 = size->w; y2 = size->h;
00090 if (bottomrightf)
00091 bottomrightf(this, bottomrightp);
00092 #ifndef NO_GL
00093 else
00094 glBindTexture(GL_TEXTURE_2D, bottomright);
00095 #endif
00096 glictGlobals.PaintRect(x1, x2, y1, y2, col);
00097 }
00098
00099
00100
00101 if (top || topf) {
00102 if (topf)
00103 topf(this, topp);
00104 #ifndef NO_GL
00105 else
00106 glBindTexture(GL_TEXTURE_2D, top);
00107 #endif
00108
00109 for (int pos = (topleft || topleftf) ? toplefts.w : 0; pos < size->w - ((topright || toprightf) ? toprights.w : 0); pos+=tops.w) {
00110 x1 = pos; y1 = 0;
00111 x2 = min(size->w - ((topright || toprightf) ? toprights.w : 0) , pos + tops.w) + 1; y2 = tops.h + 1;
00112 glictGlobals.PaintRect(x1, x2, y1, y2, col);
00113 }
00114 }
00115
00116 if (bottom || bottomf) {
00117 if (bottomf)
00118 bottomf(this, bottomp);
00119 #ifndef NO_GL
00120 else
00121 glBindTexture(GL_TEXTURE_2D, bottom);
00122 #endif
00123
00124 for (int pos = (bottomleft || bottomleftf) ? bottomlefts.w : 0; pos < size->w - ((bottomright || bottomrightf) ? bottomrights.w : 0); pos+=bottoms.w) {
00125 x1 = pos; y1 = size->h - bottoms.h - 1;
00126 x2 = min(size->w - ((bottomleft || bottomleftf) ? bottomlefts.w : 0), pos + bottoms.w) + 1; y2 = size->h;
00127 glictGlobals.PaintRect(x1, x2, y1, y2, col);
00128 }
00129 }
00130
00131
00132
00133 if (left || leftf) {
00134 if (leftf)
00135 leftf(this, leftp);
00136 #ifndef NO_GL
00137 else
00138 glBindTexture(GL_TEXTURE_2D, left);
00139 #endif
00140 for (int pos = (topleft || topleftf) ? toplefts.h : 0; pos < size->h - ((bottomleft || bottomleftf) ? bottomlefts.w : 0); pos+=lefts.h) {
00141 x1 = 0; y1 = pos;
00142 x2 = lefts.w; y2 = min(size->h - ((bottomleft || bottomleftf) ? bottomlefts.h : 0), pos + lefts.h);
00143 glictGlobals.PaintRect(x1, x2, y1, y2, col);
00144 }
00145 }
00146
00147
00148 if (right || rightf) {
00149 if (rightf)
00150 rightf(this, rightp);
00151 #ifndef NO_GL
00152 else
00153 glBindTexture(GL_TEXTURE_2D, right);
00154 #endif
00155 for (int pos = (topright || toprightf) ? toprights.h : 0; pos < size->h - ((bottomright || bottomrightf) ? bottomrights.w : 0); pos+=rights.h) {
00156 x1 = size->w - rights.w; y1 = pos;
00157 x2 = size->w; y2 = min(size->h - ((bottomright || bottomrightf) ? bottomrights.w : 0), pos + rights.h);
00158 glictGlobals.PaintRect(x1, x2, y1, y2, col);
00159 }
00160 }
00161
00162
00163 if (center || centerf) {
00164 if (centerf)
00165 centerf(this, centerp);
00166 #ifndef NO_GL
00167 else
00168 glBindTexture(GL_TEXTURE_2D, center);
00169 #endif
00170 for (int pos = (left || leftf) ? lefts.w : 0; pos < size->w - ((right || rightf) ? rights.w : 0); pos+=centers.w) {
00171 for (int pos2 = (top || topf) ? tops.h : 0; pos2 < size->h - ((bottom || bottomf) ? bottoms.h : 0); pos2+=centers.h) {
00172
00173
00174 y1 = pos2;
00175 y2 = min(size->h - ((bottom || bottomf) ? bottoms.h : 0), pos2 + centers.h);
00176
00177 x1 = pos;
00178 x2 = min(size->w - ((right || rightf) ? rights.w : 0), pos + centers.w);
00179
00180 glictGlobals.PaintRect(x1, x2, y1, y2, col);
00181 }
00182 }
00183 }
00184
00185
00186 #ifndef NO_GL
00187 glDisable(GL_TEXTURE_2D);
00188 #endif
00189
00190 }
00191
00192 void glictSkinner::SetTL(GLuint textureid, glictSize *size ) {
00193 this->topleftf = NULL;
00194 this->topleft = textureid;
00195 if (size) this->toplefts = *size;
00196 }
00197 void glictSkinner::SetTL(glictBindCallback bindf, void* param, glictSize *size) {
00198 this->topleftf = bindf;
00199 this->topleftp = param;
00200 if (size) this->toplefts = *size;
00201 }
00202 void glictSkinner::SetTR(GLuint textureid, glictSize *size ) {
00203 this->toprightf = NULL;
00204 this->topright = textureid;
00205 if (size) this->toprights = *size;
00206 }
00207 void glictSkinner::SetTR(glictBindCallback bindf, void* param, glictSize *size) {
00208 this->toprightf = bindf;
00209 this->toprightp = param;
00210 if (size) this->toprights = *size;
00211 }
00212 void glictSkinner::SetBL(GLuint textureid, glictSize *size ) {
00213 this->bottomleftf = NULL;
00214 this->bottomleft = textureid;
00215 if (size) this->bottomlefts = *size;
00216 }
00217 void glictSkinner::SetBL(glictBindCallback bindf, void* param, glictSize *size) {
00218 this->bottomleftf = bindf;
00219 this->bottomleftp = param;
00220 if (size) this->bottomlefts = *size;
00221 }
00222 void glictSkinner::SetBR(GLuint textureid, glictSize *size ) {
00223 this->bottomrightf = NULL;
00224 this->bottomright = textureid;
00225 if (size) this->bottomrights = *size;
00226 }
00227 void glictSkinner::SetBR(glictBindCallback bindf, void* param, glictSize *size) {
00228 this->bottomrightf = bindf;
00229 this->bottomrightp = param;
00230 if (size) this->bottomrights = *size;
00231 }
00232 void glictSkinner::SetTop(GLuint textureid, glictSize *size ) {
00233 this->topf = NULL;
00234 this->top = textureid;
00235 if (size) this->tops = *size;
00236 }
00237 void glictSkinner::SetTop(glictBindCallback bindf, void* param, glictSize *size) {
00238 this->topf = bindf;
00239 this->topp = param;
00240 if (size) this->tops = *size;
00241 }
00242 void glictSkinner::SetBottom(GLuint textureid, glictSize *size ) {
00243 this->bottomf = NULL;
00244 this->bottom = textureid;
00245 if (size) this->bottoms = *size;
00246 }
00247 void glictSkinner::SetBottom(glictBindCallback bindf, void* param, glictSize *size) {
00248 this->bottomf = bindf;
00249 this->bottomp = param;
00250 if (size) this->bottoms = *size;
00251 }
00252 void glictSkinner::SetLeft(GLuint textureid, glictSize *size ) {
00253 this->leftf = NULL;
00254 this->left = textureid;
00255 if (size) this->lefts = *size;
00256 }
00257 void glictSkinner::SetLeft(glictBindCallback bindf, void* param, glictSize *size) {
00258 this->leftf = bindf;
00259 this->leftp = param;
00260 if (size) this->lefts = *size;
00261 }
00262 void glictSkinner::SetRight(GLuint textureid, glictSize *size ) {
00263 this->rightf = NULL;
00264 this->right = textureid;
00265 if (size) this->rights = *size;
00266 }
00267 void glictSkinner::SetRight(glictBindCallback bindf, void* param, glictSize *size) {
00268 this->rightf = bindf;
00269 this->rightp = param;
00270 if (size) this->rights = *size;
00271 }
00272
00273 void glictSkinner::SetCenter(GLuint textureid, glictSize *size ) {
00274 this->centerf = NULL;
00275 this->center = textureid;
00276 if (size) this->centers = *size;
00277 }
00278 void glictSkinner::SetCenter(glictBindCallback bindf, void* param, glictSize *size) {
00279 this->centerf = bindf;
00280 this->centerp = param;
00281 if (size) this->centers = *size;
00282 }
00283
00284 glictSize *glictSkinner::GetLeftSize() {
00285 return &(this->lefts);
00286 }
00287 glictSize *glictSkinner::GetTopSize() {
00288 return &(this->tops);
00289 }
00290 glictSize *glictSkinner::GetRightSize() {
00291 return &(this->rights);
00292 }
00293 glictSize *glictSkinner::GetBottomSize() {
00294 return &(this->bottoms);
00295 }