-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move letters off the grid to make text more readable #656
base: release
Are you sure you want to change the base?
Changes from all commits
17bf3da
ec26905
c216b11
d5f44b9
35f25e0
81850ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1283,12 +1283,22 @@ enum dungeonLayers { | |
NUMBER_TERRAIN_LAYERS | ||
}; | ||
|
||
typedef struct CellTextInfo { | ||
/// 0 : Normal terminal output | ||
/// 1 : Left-aligned text [startColumn must be set] | ||
/// 2 : Middle-aligned text [startColumn and endColumn must be set] | ||
int8_t mode; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: what about an enum? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, that would be a good idea, I was being lazy. I'll fix this after I rebase the PR to fix the conflicts. |
||
int8_t firstColumn; // first column (x coordinate) of text (inclusive) | ||
int8_t lastColumn; // last column (x coordinate) of text (inclusive) | ||
} CellTextInfo; | ||
|
||
// keeps track of graphics so we only redraw if the cell has changed: | ||
typedef struct cellDisplayBuffer { | ||
enum displayGlyph character; | ||
char foreColorComponents[3]; | ||
char backColorComponents[3]; | ||
char opacity; | ||
CellTextInfo textInfo; | ||
} cellDisplayBuffer; | ||
|
||
typedef struct screenDisplayBuffer { | ||
|
@@ -2884,7 +2894,8 @@ extern "C" { | |
void plotChar(enum displayGlyph inputChar, | ||
short xLoc, short yLoc, | ||
short backRed, short backGreen, short backBlue, | ||
short foreRed, short foreGreen, short foreBlue); | ||
short foreRed, short foreGreen, short foreBlue, | ||
CellTextInfo textInfo); | ||
|
||
typedef struct PauseBehavior { | ||
/// If `interuptForMouseMove` is true, then the pause function will return `true` | ||
|
@@ -2931,7 +2942,7 @@ extern "C" { | |
short x, short y, short width, | ||
boolean includeButtons); | ||
void funkyFade(screenDisplayBuffer *displayBuf, const color *colorStart, const color *colorEnd, short stepCount, short x, short y, boolean invert); | ||
void displayCenteredAlert(char *message); | ||
void displayCenteredAlert(const char *message); | ||
void flashMessage(char *message, short x, short y, int time, const color *fColor, const color *bColor); | ||
void flashTemporaryAlert(char *message, int time); | ||
void highlightScreenCell(short x, short y, const color *highlightColor, short strength); | ||
|
@@ -2956,7 +2967,9 @@ extern "C" { | |
void hiliteCell(short x, short y, const color *hiliteColor, short hiliteStrength, boolean distinctColors); | ||
void colorMultiplierFromDungeonLight(short x, short y, color *editColor); | ||
void plotCharWithColor(enum displayGlyph inputChar, windowpos loc, const color *cellForeColor, const color *cellBackColor); | ||
void plotCharWithColorAndTextInfo(enum displayGlyph inputChar, windowpos loc, const color *cellForeColor, const color *cellBackColor, CellTextInfo textInfo); | ||
void plotCharToBuffer(enum displayGlyph inputChar, windowpos loc, const color *foreColor, const color *backColor, screenDisplayBuffer *dbuf); | ||
void plotCharToBufferWithTextInfo(enum displayGlyph inputChar, windowpos loc, const color *foreColor, const color *backColor, CellTextInfo textInfo, screenDisplayBuffer *dbuf); | ||
void plotForegroundChar(enum displayGlyph inputChar, short x, short y, const color *foreColor, boolean affectedByLighting); | ||
void commitDraws(void); | ||
void dumpLevelToScreen(void); | ||
|
@@ -2978,7 +2991,11 @@ extern "C" { | |
void flashForeground(short *x, short *y, const color **flashColor, short *flashStrength, short count, short frames); | ||
void flashCell(const color *theColor, short frames, short x, short y); | ||
void colorFlash(const color *theColor, unsigned long reqTerrainFlags, unsigned long reqTileFlags, short frames, short maxRadius, short x, short y); | ||
// Prints the specified formatted string to the screen, starting at the coordinates (x, y). | ||
void printString(const char *theString, short x, short y, const color *foreColor, const color* backColor, screenDisplayBuffer *dbuf); | ||
void printStringWithTextMode(const char *theString, short x, short y, const color *foreColor, const color* backColor, int textMode, screenDisplayBuffer *dbuf); | ||
// The same as `printString`, but centers the text when performing letter spacing adjustments. | ||
void printStringCentered(const char *theString, short x, short y, const color *foreColor, const color* backColor, screenDisplayBuffer *dbuf); | ||
short wrapText(char *to, const char *sourceText, short width); | ||
short printStringWithWrapping(const char *theString, short x, short y, short width, const color *foreColor, | ||
const color *backColor, screenDisplayBuffer *dbuf); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ typedef struct ScreenTile { | |
short foreRed, foreGreen, foreBlue; // foreground color (0..100) | ||
short backRed, backGreen, backBlue; // background color (0..100) | ||
short charIndex; // index of the glyph to draw | ||
CellTextInfo textInfo; | ||
short needsRefresh; // true if the tile has changed since the last screen refresh, else false | ||
} ScreenTile; | ||
|
||
|
@@ -589,7 +590,8 @@ static void createTextures(SDL_Renderer *renderer, int outputWidth, int outputHe | |
/// | ||
void updateTile(int row, int column, short charIndex, | ||
short foreRed, short foreGreen, short foreBlue, | ||
short backRed, short backGreen, short backBlue) | ||
short backRed, short backGreen, short backBlue, | ||
CellTextInfo textInfo) | ||
{ | ||
screenTiles[row][column] = (ScreenTile){ | ||
.foreRed = foreRed, | ||
|
@@ -599,6 +601,7 @@ void updateTile(int row, int column, short charIndex, | |
.backGreen = backGreen, | ||
.backBlue = backBlue, | ||
.charIndex = charIndex, | ||
.textInfo = textInfo, | ||
.needsRefresh = 1 | ||
}; | ||
} | ||
|
@@ -692,8 +695,11 @@ void updateScreen() { | |
continue; // this tile uses another texture and gets painted at another step | ||
} | ||
|
||
int tileRow = tile->charIndex / 16; | ||
int tileColumn = tile->charIndex % 16; | ||
int textMode = tile->textInfo.mode; | ||
int charIndex = tile->charIndex; | ||
|
||
int tileRow = charIndex / 16; | ||
int tileColumn = charIndex % 16; | ||
|
||
if (tileEmpty[tileRow][tileColumn] | ||
&& !(tileRow == 21 && tileColumn == 1)) { // wall top (procedural) | ||
|
@@ -712,6 +718,32 @@ void updateScreen() { | |
dest.x = x * outputWidth / COLS; | ||
dest.y = y * outputHeight / ROWS; | ||
|
||
if (textMode == 1) { | ||
// If it's text, then we want to compress the letters | ||
// so the spacing between consecutive letters is more | ||
// natural and readable. | ||
dest.x -= outputWidth * (x - tile->textInfo.firstColumn) / 5 / COLS; | ||
} | ||
if (textMode == 2) { | ||
int offsetForLetter = outputWidth * (x - tile->textInfo.firstColumn) / 5 / COLS; | ||
int offsetForEnd = outputWidth * (tile->textInfo.lastColumn - tile->textInfo.firstColumn) / 5 / COLS; | ||
// `offsetForLetter` is zero for the first letter, and increases for each | ||
// subsequent letter in the line. | ||
dest.x -= offsetForLetter; | ||
// `offsetForEnd` is a constant for all text in the same contiguous span. | ||
// By adding half its value back, we shift the text over so that the first | ||
// letter and the last letter in the span are shifted equally for kerning, | ||
// so that spacing on both sides is uniform. | ||
dest.x += offsetForEnd / 2; | ||
} | ||
|
||
// int diff = abs(tile->foreRed - tile->backRed) + abs(tile->foreGreen - tile->backGreen) + abs(tile->foreBlue - tile->backBlue); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// if (diff < 100) { | ||
// tile->foreRed = 100; | ||
// tile->foreGreen = 100; | ||
// tile->foreBlue = 100; | ||
// } | ||
|
||
// blend the foreground | ||
if (SDL_SetTextureColorMod(Textures[step], | ||
round(2.55 * tile->foreRed), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.