forked from ComputerNerd/Retro-Graphics-Toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallback_tiles.cpp
205 lines (182 loc) · 8.07 KB
/
callback_tiles.cpp
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
This file is part of Retro Graphics Toolkit
Retro Graphics Toolkit 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 3 of the License, or any later version.
Retro Graphics Toolkit 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 Retro Graphics Toolkit. If not, see <http://www.gnu.org/licenses/>.
Copyright Sega16 (or whatever you wish to call me) (2012-2017)
*/
#include <FL/fl_ask.H>
#include "class_global.h"
#include "tilemap.h"
#include "undo.h"
#include "classpalettebar.h"
#include "gui.h"
void tilesnewfilppedCB(Fl_Widget*, void*) {
pushTilemapAll(false);
pushTileappendGroupPrepare();
uint32_t amt = currentProject->tileC->amount();
uint32_t*hflip = (uint32_t*)malloc(amt * sizeof(uint32_t));
uint32_t*vflip = (uint32_t*)malloc(amt * sizeof(uint32_t));
uint32_t*hvflip = (uint32_t*)malloc(amt * sizeof(uint32_t));
memset(hflip, 0, amt * sizeof(uint32_t));
memset(vflip, 0, amt * sizeof(uint32_t));
memset(hvflip, 0, amt * sizeof(uint32_t));
uint32_t acum = 0;
uint8_t * tileTemp = (uint8_t *)alloca(currentProject->tileC->tileSize);
uint8_t * tcTemp = (uint8_t *)alloca(currentProject->tileC->tcSize);
for (uint32_t y = 0; y < currentProject->tms->maps[currentProject->curPlane].mapSizeHA; ++y) {
for (uint32_t x = 0; x < currentProject->tms->maps[currentProject->curPlane].mapSizeW; ++x) {
bool hf = currentProject->tms->maps[currentProject->curPlane].get_hflip(x, y), vf = currentProject->tms->maps[currentProject->curPlane].get_vflip(x, y);
uint32_t t = currentProject->tms->maps[currentProject->curPlane].get_tile(x, y);
if (hf && vf) {
if (!(hvflip[t])) {
currentProject->tileC->hflip_tile(t, tileTemp);
currentProject->tileC->hflip_truecolor(t, (uint32_t*)tcTemp);
currentProject->tileC->vflip_tile_ptr(tileTemp, tileTemp);
currentProject->tileC->vflip_truecolor_ptr(tcTemp, tcTemp);
hvflip[t] = amt + acum;
addTileappendGroup(tileTemp, tcTemp);
currentProject->tileC->appendTile();
memcpy(currentProject->tileC->tDat.data() + ((amt + acum)*currentProject->tileC->tileSize), tileTemp, currentProject->tileC->tileSize);
memcpy(currentProject->tileC->truetDat.data() + ((amt + acum)*currentProject->tileC->tcSize), tcTemp, currentProject->tileC->tcSize);
++acum;
}
currentProject->tms->maps[currentProject->curPlane].set_tile(x, y, hvflip[t]);
currentProject->tms->maps[currentProject->curPlane].set_hflip(x, y, false);
currentProject->tms->maps[currentProject->curPlane].set_vflip(x, y, false);
} else if (hf) {
if (!(hflip[t])) {
currentProject->tileC->hflip_tile(t, tileTemp);
currentProject->tileC->hflip_truecolor(t, (uint32_t*)tcTemp);
hflip[t] = amt + acum;
addTileappendGroup(tileTemp, tcTemp);
currentProject->tileC->appendTile();
memcpy(currentProject->tileC->tDat.data() + ((amt + acum)*currentProject->tileC->tileSize), tileTemp, currentProject->tileC->tileSize);
memcpy(currentProject->tileC->truetDat.data() + ((amt + acum)*currentProject->tileC->tcSize), tcTemp, currentProject->tileC->tcSize);
++acum;
}
currentProject->tms->maps[currentProject->curPlane].set_tile(x, y, hflip[t]);
currentProject->tms->maps[currentProject->curPlane].set_hflip(x, y, false);
} else if (vf) {
if (!(vflip[t])) {
currentProject->tileC->vflip_tile(t, tileTemp);
currentProject->tileC->vflip_truecolor(t, tcTemp);
vflip[t] = amt + acum;
addTileappendGroup(tileTemp, tcTemp);
currentProject->tileC->appendTile();
memcpy(currentProject->tileC->tDat.data() + ((amt + acum)*currentProject->tileC->tileSize), tileTemp, currentProject->tileC->tileSize);
memcpy(currentProject->tileC->truetDat.data() + ((amt + acum)*currentProject->tileC->tcSize), tcTemp, currentProject->tileC->tcSize);
++acum;
}
currentProject->tms->maps[currentProject->curPlane].set_tile(x, y, vflip[t]);
currentProject->tms->maps[currentProject->curPlane].set_vflip(x, y, false);
}
}
}
free(hflip);
free(vflip);
free(hvflip);
updateTileSelectAmt();
}
void insertTileCB(Fl_Widget*, void*) {
pushTilenew(window->getCurrentTileCurrentTab() + 1);
currentProject->tileC->insertTile(window->getCurrentTileCurrentTab() + 1);
updateTileSelectAmt();
window->redraw();
}
void delete_tile_at_location(Fl_Widget*, void*) {
/* this function will delete the tile that the user has selected */
pushTile(window->getCurrentTileCurrentTab(), tTypeDelete);
currentProject->tileC->remove_tile_at(window->getCurrentTileCurrentTab());
window->redraw();
}
void new_tile(Fl_Widget*, void*) {
pushTileAppend();
currentProject->tileC->appendTile();
//set the new maximum for slider
updateTileSelectAmt();
//redraw so the user knows that there is another tile
window->redraw();
}
void update_truecolor(Fl_Widget* o, void* v) {
Fl_Slider* s = (Fl_Slider*)o;
truecolor_temp[intptr_t(v)] = s->value();
window->redraw();
}
void blank_tile(Fl_Widget*, void*) {
//this will fill the current tile with zeros
pushTile(window->getCurrentTileCurrentTab(), tTypeBoth);
currentProject->tileC->blank_tile(window->getCurrentTileCurrentTab());
window->damage(FL_DAMAGE_USER1);
}
void update_offset_tile_edit(Fl_Widget*, void*) {
tile_zoom_edit = window->tile_size->value();
tile_edit_offset_x = 16 + (tile_zoom_edit * 8);
window->redraw();
}
void set_tile_current(Fl_Widget* o, void*) {
Fl_Slider* s = (Fl_Slider*)o;
palBar.updateColorSelectionTile(s->value(), 1);
window->redraw();
}
void set_tile_currentTP(Fl_Widget* o, void*) {
Fl_Slider* s = (Fl_Slider*)o;
if (tileEditModePlace_G) {
pushTilemapEdit(selTileE_G[0], selTileE_G[1]);
currentProject->tms->maps[currentProject->curPlane].set_tile(selTileE_G[0], selTileE_G[1], s->value());
}
palBar.updateColorSelectionTile(s->value(), 2);
window->redraw();
}
void update_all_tiles(Fl_Widget*, void*) {
unsigned sel_pal;
if (mode_editor == tile_place)
sel_pal = palBar.selRow[2];
else
sel_pal = palBar.selRow[1];
if (currentProject->tileC->amount() >= 63)
putchar('\n');
pushTilesAll(tTypeTile);
for (uint32_t x = 0; x < currentProject->tileC->amount(); ++x) {
currentProject->tileC->truecolor_to_tile(sel_pal, x, mode_editor == spriteEditor);
if ((!(x & 63)) && x)
printf("Progress: %f\r", ((float)x / (float)currentProject->tileC->amount()) * 100.0f);
}
window->redraw();
}
void remove_duplicate_tiles(Fl_Widget*, void*) {
currentProject->tileC->remove_duplicate_tiles(false);
}
void remove_duplicate_truecolor(Fl_Widget*, void*) {
currentProject->tileC->remove_duplicate_tiles(true);
}
void fill_tile(Fl_Widget* o, void*) {
//fills tile with currently selected color
if (mode_editor == tile_place) {
pushTile(window->getCurrentTileCurrentTab(), tTypeTile);
unsigned color;
color = palBar.selBox[2];
for (unsigned y = 0; y < currentProject->tileC->height(); ++y) {
for (unsigned x = 0; x < currentProject->tileC->width(); ++x)
currentProject->tileC->setPixel(window->getCurrentTileCurrentTab(), x, y, color);
}
}
else if (mode_editor == tile_edit) {
pushTile(window->getCurrentTileCurrentTab(), tTypeBoth);
for (uint32_t x = window->getCurrentTileCurrentTab() * currentProject->tileC->tcSize; x < (window->getCurrentTileCurrentTab() * currentProject->tileC->tcSize) + currentProject->tileC->tcSize; x += 4) {
currentProject->tileC->truetDat[x] = truecolor_temp[0]; //red
currentProject->tileC->truetDat[x + 1] = truecolor_temp[1]; //green
currentProject->tileC->truetDat[x + 2] = truecolor_temp[2]; //blue
currentProject->tileC->truetDat[x + 3] = truecolor_temp[3]; //alpha
}
currentProject->tileC->truecolor_to_tile(palBar.selRow[1], window->getCurrentTileCurrentTab(), false);
} else
fl_alert("To prevent accidental modification be in the Tile editor or Tile map editor to use this");
window->damage(FL_DAMAGE_USER1);
}