1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
// ----------------------------------------------------------
//
// Copyright (C) 2002 Brad Wasson <bard@systemtoolbox.com>
//
// This file is part of 3ddesktop.
//
// 3ddesktop is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
//
// 3ddesktop is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with 3ddesktop; see the file COPYING. If not, write to
// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
//
#ifndef _FACESET_HPP
#define _FACESET_HPP
#include "3ddesk.h"
#include "util.h"
#include "config.hpp"
using namespace std;
#include <vector>
// container class for a set of faces
class FaceSet {
private:
int number_of_faces;
int cols;
int rows;
vector <Face *> faces;
public:
FaceSet (int r, int c) {
cols = c;
rows = r;
number_of_faces = rows * cols;
for (int i = 0; i < number_of_faces; i++) {
Face *f = new Face();
if (f == NULL) {
msgout (ERROR, "Out of memory: faceset constructor\n");
end_program(-1);
}
faces.push_back(f);
}
//load_digit_textures();
};
void reconfigure (int r, int c) {
int old_num = number_of_faces;
int old_cols = cols;
cols = c;
rows = r;
number_of_faces = rows * cols;
if (old_num > number_of_faces) {
// deleting faces
for (int i = 0; i < old_num - number_of_faces; i++) {
msgout (DEBUG, "uuuu deleted %d\n", i + number_of_faces);
delete faces[i + number_of_faces];
}
faces.erase (faces.begin() + number_of_faces, faces.end());
reset_face_textures();
} else if (old_num < number_of_faces) {
// adding faces
for (int i = 0; i < number_of_faces - old_num; i++) {
msgout (DEBUG, "uuuu new face %d\n", i + old_num);
Face *f = new Face();
if (f == NULL) {
msgout (ERROR, "Out of memory: faceset constructor\n");
end_program(-1);
}
faces.push_back(f);
//faces[i + old_num] = f; this is a no-no!
}
if (cols != old_cols && rows > 1) // if columns changed must start new
reset_face_textures();
} else {
// same cols and rows - do nothing
}
};
void reset_face_textures() {
for(int i = 0; i < number_of_faces; i++) {
faces[i]->set_texture_id ((uint)-1);
}
};
void render_all () {
int i;
for (i = 0; i < number_of_faces; i++)
faces[i]->render();
};
uint get_texture_id (int i) {
if (i >= number_of_faces) {
msgout (ERROR, "BUG: FaceSet::get_texture_id i >= n\n");
return (uint)-1;
}
return faces[i]->get_texture_id();
};
void load_texture_data (int i, int size, unsigned char *data) {
if (i >= number_of_faces) {
msgout (ERROR, "BUG: FaceSet::load_texture_data i >= n\n");
return;
}
faces[i]->load_texture_data(size, data);
};
void set_list (int i, uint l) {
if (i >= number_of_faces) {
msgout (ERROR, "BUG: FaceSet::set_list i >= n\n");
return;
}
faces[i]->set_list (l);
};
void set_active (int i) {
if (i >= number_of_faces) {
msgout (ERROR, "BUG: FaceSet::set_active i >= n\n");
return;
}
faces[i]->set_active ();
};
void set_face (int i, Point tl, Point tr, Point bl, Point br) {
if (i >= number_of_faces) {
msgout (ERROR, "BUG: FaceSet::set_face i >= n\n");
return;
}
faces[i]->set_corners(tl, tr, bl, br);
};
void set_transparency (float t) {
for (int i = 0; i < number_of_faces; i++)
faces[i]->set_transparency(t);
};
};
#endif // _FACESET_HPP
|