Skip to content

Commit eee0dd4

Browse files
create screenDisplayBuffer type for the whole screen (#625)
1 parent 565e479 commit eee0dd4

12 files changed

+293
-287
lines changed

src/brogue/Buttons.c

+18-18
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ short smoothHiliteGradient(const short currentXValue, const short maxXValue) {
3838
// Text is white, but can use color escapes.
3939
// Hovering highlight augments fore and back colors with buttonHoverColor by 20%.
4040
// Pressed darkens the middle color (or turns it the hover color if the button is black).
41-
void drawButton(brogueButton *button, enum buttonDrawStates highlight, cellDisplayBuffer dbuf[COLS][ROWS]) {
41+
void drawButton(brogueButton *button, enum buttonDrawStates highlight, screenDisplayBuffer *dbuf) {
4242
if (!(button->flags & B_DRAW)) {
4343
return;
4444
}
@@ -114,7 +114,7 @@ void drawButton(brogueButton *button, enum buttonDrawStates highlight, cellDispl
114114
plotCharToBuffer(displayCharacter, (windowpos){ button->x + i, button->y }, &fColor, &bColor, dbuf);
115115
if (dbuf) {
116116
// Only buffers can have opacity set.
117-
dbuf[button->x + i][button->y].opacity = opacity;
117+
dbuf->cells[button->x + i][button->y].opacity = opacity;
118118
}
119119
}
120120
}
@@ -160,7 +160,7 @@ void drawButtonsInState(buttonState *state) {
160160
// Draw the buttons to the dbuf:
161161
for (int i=0; i < state->buttonCount; i++) {
162162
if (state->buttons[i].flags & B_DRAW) {
163-
drawButton(&(state->buttons[i]), BUTTON_NORMAL, state->dbuf);
163+
drawButton(&(state->buttons[i]), BUTTON_NORMAL, &state->dbuf);
164164
}
165165
}
166166
}
@@ -182,15 +182,15 @@ void initializeButtonState(buttonState *state,
182182
for (int i=0; i < state->buttonCount; i++) {
183183
state->buttons[i] = buttons[i];
184184
}
185-
copyDisplayBuffer(state->rbuf, displayBuffer);
186-
clearDisplayBuffer(state->dbuf);
185+
copyDisplayBuffer(&state->rbuf, &displayBuffer);
186+
clearDisplayBuffer(&state->dbuf);
187187

188188
drawButtonsInState(state);
189189

190190
// Clear the rbuf so that it resets only those parts of the screen in which buttons are drawn in the first place:
191191
for (int i=0; i<COLS; i++) {
192192
for (int j=0; j<ROWS; j++) {
193-
state->rbuf[i][j].opacity = (state->dbuf[i][j].opacity ? 100 : 0);
193+
state->rbuf.cells[i][j].opacity = (state->dbuf.cells[i][j].opacity ? 100 : 0);
194194
}
195195
}
196196
}
@@ -216,7 +216,7 @@ short processButtonInput(buttonState *state, boolean *canceled, rogueEvent *even
216216

217217
// Revert the button with old focus, if any.
218218
if (state->buttonFocused >= 0) {
219-
drawButton(&(state->buttons[state->buttonFocused]), BUTTON_NORMAL, state->dbuf);
219+
drawButton(&(state->buttons[state->buttonFocused]), BUTTON_NORMAL, &state->dbuf);
220220
state->buttonFocused = -1;
221221
}
222222

@@ -242,11 +242,11 @@ short processButtonInput(buttonState *state, boolean *canceled, rogueEvent *even
242242

243243
if (state->buttonDepressed >= 0) {
244244
if (state->buttonDepressed == state->buttonFocused) {
245-
drawButton(&(state->buttons[state->buttonDepressed]), BUTTON_PRESSED, state->dbuf);
245+
drawButton(&(state->buttons[state->buttonDepressed]), BUTTON_PRESSED, &state->dbuf);
246246
}
247247
} else if (state->buttonFocused >= 0) {
248248
// If no button is depressed, then update the appearance of the button with the new focus, if any.
249-
drawButton(&(state->buttons[state->buttonFocused]), BUTTON_HOVER, state->dbuf);
249+
drawButton(&(state->buttons[state->buttonFocused]), BUTTON_HOVER, &state->dbuf);
250250
}
251251

252252
// Mouseup:
@@ -257,7 +257,7 @@ short processButtonInput(buttonState *state, boolean *canceled, rogueEvent *even
257257
} else {
258258
// Otherwise, no button is depressed. If one was previously depressed, redraw it.
259259
if (state->buttonDepressed >= 0) {
260-
drawButton(&(state->buttons[state->buttonDepressed]), BUTTON_NORMAL, state->dbuf);
260+
drawButton(&(state->buttons[state->buttonDepressed]), BUTTON_NORMAL, &state->dbuf);
261261
} else if (!(x >= state->winX && x < state->winX + state->winWidth
262262
&& y >= state->winY && y < state->winY + state->winHeight)) {
263263
// Clicking outside of a button means canceling.
@@ -268,7 +268,7 @@ short processButtonInput(buttonState *state, boolean *canceled, rogueEvent *even
268268

269269
if (state->buttonFocused >= 0) {
270270
// Buttons don't hover-highlight when one is depressed, so we have to fix that when the mouse is up.
271-
drawButton(&(state->buttons[state->buttonFocused]), BUTTON_HOVER, state->dbuf);
271+
drawButton(&(state->buttons[state->buttonFocused]), BUTTON_HOVER, &state->dbuf);
272272
}
273273
state->buttonDepressed = -1;
274274
}
@@ -287,20 +287,20 @@ short processButtonInput(buttonState *state, boolean *canceled, rogueEvent *even
287287
if (state->buttons[i].flags & B_DRAW) {
288288
// Restore the depressed and focused buttons.
289289
if (state->buttonDepressed >= 0) {
290-
drawButton(&(state->buttons[state->buttonDepressed]), BUTTON_NORMAL, state->dbuf);
290+
drawButton(&(state->buttons[state->buttonDepressed]), BUTTON_NORMAL, &state->dbuf);
291291
}
292292
if (state->buttonFocused >= 0) {
293-
drawButton(&(state->buttons[state->buttonFocused]), BUTTON_NORMAL, state->dbuf);
293+
drawButton(&(state->buttons[state->buttonFocused]), BUTTON_NORMAL, &state->dbuf);
294294
}
295295

296296
// If the button likes to flash when keypressed:
297297
if (state->buttons[i].flags & B_KEYPRESS_HIGHLIGHT) {
298298
// Depress the chosen button.
299-
drawButton(&(state->buttons[i]), BUTTON_PRESSED, state->dbuf);
299+
drawButton(&(state->buttons[i]), BUTTON_PRESSED, &state->dbuf);
300300

301301
// Update the display.
302-
overlayDisplayBuffer(state->rbuf, NULL);
303-
overlayDisplayBuffer(state->dbuf, NULL);
302+
overlayDisplayBuffer(&state->rbuf, NULL);
303+
overlayDisplayBuffer(&state->dbuf, NULL);
304304

305305
if (!rogue.playbackMode || rogue.playbackPaused) {
306306
// Wait for a little; then we're done.
@@ -359,7 +359,7 @@ short buttonInputLoop(brogueButton *buttons,
359359

360360
do {
361361
// Update the display.
362-
overlayDisplayBuffer(state.dbuf, NULL);
362+
overlayDisplayBuffer(&state.dbuf, NULL);
363363

364364
// Get input.
365365
nextBrogueEvent(&theEvent, true, false, false);
@@ -368,7 +368,7 @@ short buttonInputLoop(brogueButton *buttons,
368368
button = processButtonInput(&state, &canceled, &theEvent);
369369

370370
// Revert the display.
371-
overlayDisplayBuffer(state.rbuf, NULL);
371+
overlayDisplayBuffer(&state.rbuf, NULL);
372372

373373
} while (button == -1 && !canceled);
374374

src/brogue/GlobalsBase.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
tcell tmap[DCOLS][DROWS]; // grids with info about the map
3131
pcell pmap[DCOLS][DROWS];
3232
short **scentMap;
33-
cellDisplayBuffer displayBuffer[COLS][ROWS]; // used to optimize plotCharWithColor
33+
screenDisplayBuffer displayBuffer; // used to optimize plotCharWithColor
3434
short terrainRandomValues[DCOLS][DROWS][8];
3535
short **safetyMap; // used to help monsters flee
3636
short **allySafetyMap; // used to help allies flee

src/brogue/GlobalsBase.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static inline pos posNeighborInDirection(pos p, enum directions direction_to_ste
4646
}
4747

4848
extern short **scentMap;
49-
extern cellDisplayBuffer displayBuffer[COLS][ROWS];
49+
extern screenDisplayBuffer displayBuffer;
5050
extern short terrainRandomValues[DCOLS][DROWS][8];
5151
extern short **safetyMap; // used to help monsters flee
5252
extern short **allySafetyMap;

src/brogue/Grid.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,13 @@ void hiliteGrid(short **grid, const color *hiliteColor, short hiliteStrength) {
8888
x = mapToWindowX(i);
8989
y = mapToWindowY(j);
9090

91-
displayBuffer[x][y].backColorComponents[0] = clamp(displayBuffer[x][y].backColorComponents[0] + hCol.red * hiliteStrength / 100, 0, 100);
92-
displayBuffer[x][y].backColorComponents[1] = clamp(displayBuffer[x][y].backColorComponents[1] + hCol.green * hiliteStrength / 100, 0, 100);
93-
displayBuffer[x][y].backColorComponents[2] = clamp(displayBuffer[x][y].backColorComponents[2] + hCol.blue * hiliteStrength / 100, 0, 100);
94-
displayBuffer[x][y].foreColorComponents[0] = clamp(displayBuffer[x][y].foreColorComponents[0] + hCol.red * hiliteStrength / 100, 0, 100);
95-
displayBuffer[x][y].foreColorComponents[1] = clamp(displayBuffer[x][y].foreColorComponents[1] + hCol.green * hiliteStrength / 100, 0, 100);
96-
displayBuffer[x][y].foreColorComponents[2] = clamp(displayBuffer[x][y].foreColorComponents[2] + hCol.blue * hiliteStrength / 100, 0, 100);
91+
cellDisplayBuffer *cell = &displayBuffer.cells[x][y];
92+
cell->backColorComponents[0] = clamp(cell->backColorComponents[0] + hCol.red * hiliteStrength / 100, 0, 100);
93+
cell->backColorComponents[1] = clamp(cell->backColorComponents[1] + hCol.green * hiliteStrength / 100, 0, 100);
94+
cell->backColorComponents[2] = clamp(cell->backColorComponents[2] + hCol.blue * hiliteStrength / 100, 0, 100);
95+
cell->foreColorComponents[0] = clamp(cell->foreColorComponents[0] + hCol.red * hiliteStrength / 100, 0, 100);
96+
cell->foreColorComponents[1] = clamp(cell->foreColorComponents[1] + hCol.green * hiliteStrength / 100, 0, 100);
97+
cell->foreColorComponents[2] = clamp(cell->foreColorComponents[2] + hCol.blue * hiliteStrength / 100, 0, 100);
9798
}
9899
}
99100
}

0 commit comments

Comments
 (0)