More text drawing and graphics updates.

This commit is contained in:
Steve 2018-12-07 14:49:08 +00:00
parent 40c4557704
commit a851ea6c01
20 changed files with 198 additions and 136 deletions

View File

@ -68,8 +68,6 @@ void initBattle(void)
initStars();
initBackground();
initEffects();
initHud();

View File

@ -65,7 +65,6 @@ extern void drawOptions(void);
extern void drawStars(void);
extern void drawWidgets(char *groupName);
extern Widget *getWidget(const char *name, const char *group);
extern void initBackground(void);
extern void initBullets(void);
extern void initChallengeHome(void);
extern void initCredits(void);

View File

@ -292,6 +292,8 @@ void drawBullets(void)
int i;
Bullet *b;
setAtlasColor(255, 255, 255, 255);
for (i = 0, b = bulletsToDraw[i] ; b != NULL ; b = bulletsToDraw[++i])
{
blitRotated(b->texture, b->x - battle.camera.x, b->y - battle.camera.y, b->angle);

View File

@ -47,6 +47,7 @@ extern void playBattleSound(int id, int x, int y);
extern void playSound(int id);
extern char *readFile(char *filename);
extern void *resize(void *array, int oldSize, int newSize);
extern void setAtlasColor(int r, int g, int b, int a);
extern App app;
extern Battle battle;

View File

@ -95,9 +95,20 @@ static void calculateMessageBoxHeight(MessageBox *msg)
{
app.textWidth = MSG_BOX_TEXT_WIDTH;
msg->height = getWrappedTextHeight(msg->body, (msg->type == MB_PANDORAN) ? 0 : 18);
if (msg->type == MB_PANDORAN)
{
useFont("khosrau");
}
else
{
useFont("roboto");
}
msg->height = getWrappedTextHeight(msg->body, 18);
app.textWidth = 0;
useFont("roboto");
}
int showingMessageBoxes(void)
@ -142,10 +153,21 @@ void drawMessageBox(void)
app.textWidth = MSG_BOX_TEXT_WIDTH;
drawText(r.x + 10, r.y + 30, (msg->type == MB_PANDORAN) ? 0 : 18, TA_LEFT, (msg->type != MB_IMPORTANT) ? colors.white : colors.red, msg->body);
if (msg->type == MB_PANDORAN)
{
useFont("khosrau");
}
else
{
useFont("roboto");
}
drawText(r.x + 10, r.y + 30, 18, TA_LEFT, (msg->type != MB_IMPORTANT) ? colors.white : colors.red, msg->body);
app.textWidth = 0;
}
useFont("roboto");
}
static void nextMessage(void)

View File

@ -20,11 +20,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../common.h"
#define MSG_BOX_TEXT_WIDTH 565
#define MSG_BOX_TEXT_WIDTH 600
extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...);
extern int getWrappedTextHeight(char *text, int size);
extern void playSound(int sound);
extern void useFont(char *name);
extern App app;
extern Battle battle;

View File

@ -115,8 +115,6 @@ void initChallengeHome(void)
show = SHOW_CHALLENGES;
initBackground();
start = getWidget("start", "challenges");
start->action = startChallengeMission;

View File

@ -52,7 +52,6 @@ extern char *getChallengeDescription(Challenge *c);
extern char *getPlanetTextureName(int n);
extern SDL_Texture *getTexture(char *filename);
extern Widget *getWidget(const char *name, const char *group);
extern void initBackground(void);
extern void initBattle(void);
extern void initFighterDatabaseDisplay(void);
extern void initOptions(void (*returnFromOptions)(void));

View File

@ -129,8 +129,6 @@ void initGalacticMap(void)
/* clear the pulses */
destroyGalacticMap();
initBackground();
getWidget("close", "starSystem")->action = resume;
startMissionButton = getWidget("startMission", "starSystem");
startMissionButton->action = startMission;
@ -302,12 +300,14 @@ static void scrollGalaxy(void)
camera.x -= app.mouse.dx * 1.5;
camera.y -= app.mouse.dy * 1.5;
ssx = -(app.mouse.dx / 3);
ssy = -(app.mouse.dy / 3);
ssx = -app.mouse.dx;
ssx /= 3;
ssy = -app.mouse.dy;
ssy /= 3;
camera.x = MAX(cameraMin.x, MIN(camera.x, cameraMax.x));
camera.y = MAX(cameraMin.y, MIN(camera.y, cameraMax.y));
}
if (lastX == camera.x)
{
@ -318,6 +318,7 @@ static void scrollGalaxy(void)
{
ssy = 0;
}
}
}
static void doStarSystemView(void)
@ -698,7 +699,7 @@ static void drawStarSystemDetail(void)
drawText(525, 160, 18, TA_LEFT, colors.lightGrey, CRAFT_TEXT, game.currentMission->craft);
drawText(525, 185, 18, TA_LEFT, colors.lightGrey, SQUADRON_TEXT, game.currentMission->squadron);
app.textWidth = 550;
app.textWidth = 525;
drawText(525, 230, 22, TA_LEFT, colors.white, game.currentMission->description);

View File

@ -53,7 +53,6 @@ extern AtlasImage *getAtlasImage(char *filename);
extern StarSystem *getStarSystem(char *name);
extern SDL_Texture *getTexture(char *filename);
extern Widget *getWidget(const char *name, const char *group);
extern void initBackground(void);
extern void initBattle(void);
extern void initFighterDatabaseDisplay(void);
extern void initOptions(void (*returnFromOptions)(void));

View File

@ -72,8 +72,6 @@ void initTitle(void)
earth.x = rand() % SCREEN_WIDTH;
earth.y = -(128 + (rand() % 128));
initBackground();
initEffects();
initFighters();

View File

@ -49,7 +49,6 @@ extern void endSectionTransition(void);
extern AtlasImage *getAtlasImage(const char *filename);
extern SDL_Texture *getTexture(const char *filename);
extern Widget *getWidget(const char *name, const char *group);
extern void initBackground(void);
extern void initChallengeHome(void);
extern void initCredits(void);
extern void initEffects(void);

View File

@ -179,16 +179,17 @@ void drawTrophies(void)
}
else
{
blitScaled(trophyIcons[TROPHY_UNEARNED], x, y, 64, 64, 0);
if (!t->hidden)
{
setAtlasColor(255, 255, 255, 128);
blitScaled(trophyIcons[t->value], x, y, 64, 64, 0);
drawText(x + 85, y - 10, 20, TA_LEFT, colors.lightGrey, t->title);
drawText(x + 85, y + 20, 18, TA_LEFT, colors.darkGrey, t->description);
drawText(x + 85, y + 48, 18, TA_LEFT, colors.darkGrey, "-");
}
else
{
blitScaled(trophyIcons[TROPHY_UNEARNED], x, y, 64, 64, 0);
drawText(x + 85, y + 20, 20, TA_LEFT, colors.darkGrey, HIDDEN_TEXT);
}
}

View File

@ -20,9 +20,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "draw.h"
static void initColor(SDL_Color *c, int r, int g, int b);
static PointF backgroundPoint[4];
void initBackground(void)
void initGraphics(void)
{
backgroundPoint[0].x = -SCREEN_WIDTH / 2;
backgroundPoint[0].y = -SCREEN_HEIGHT / 2;
@ -35,6 +37,27 @@ void initBackground(void)
backgroundPoint[3].x = SCREEN_WIDTH / 2;
backgroundPoint[3].y = SCREEN_HEIGHT / 2;
initColor(&colors.red, 255, 0, 0);
initColor(&colors.orange, 255, 128, 0);
initColor(&colors.yellow, 255, 255, 0);
initColor(&colors.green, 0, 255, 0);
initColor(&colors.blue, 0, 0, 255);
initColor(&colors.cyan, 0, 255, 255);
initColor(&colors.purple, 255, 0, 255);
initColor(&colors.white, 255, 255, 255);
initColor(&colors.black, 0, 0, 0);
initColor(&colors.lightGrey, 192, 192, 192);
initColor(&colors.darkGrey, 128, 128, 128);
}
static void initColor(SDL_Color *c, int r, int g, int b)
{
memset(c, 0, sizeof(SDL_Color));
c->r = r;
c->g = g;
c->b = b;
c->a = 255;
}
void prepareScene(void)

View File

@ -23,7 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void loadConfig(void);
static void loadConfigFile(char *filename);
void saveConfig(void);
static void initColor(SDL_Color *c, int r, int g, int b);
static void showLoadingStep(float step, float maxSteps);
void init18N(int argc, char *argv[])
@ -124,6 +123,7 @@ void initGameSystem(void)
{
int i, numInitFuns;
void (*initFuncs[]) (void) = {
initGraphics,
initFonts,
initResources,
initSounds,
@ -137,31 +137,18 @@ void initGameSystem(void)
initChallenges,
initStats,
initModalDialog,
initBackground,
initStars,
initControls,
initTrophies,
initFighterDatabase
};
numInitFuns = sizeof(initFuncs) / sizeof(void*);
initColor(&colors.red, 255, 0, 0);
initColor(&colors.orange, 255, 128, 0);
initColor(&colors.yellow, 255, 255, 0);
initColor(&colors.green, 0, 255, 0);
initColor(&colors.blue, 0, 0, 255);
initColor(&colors.cyan, 0, 255, 255);
initColor(&colors.purple, 255, 0, 255);
initColor(&colors.white, 255, 255, 255);
initColor(&colors.black, 0, 0, 0);
initColor(&colors.lightGrey, 192, 192, 192);
initColor(&colors.darkGrey, 128, 128, 128);
initAtlas();
initInput();
numInitFuns = sizeof(initFuncs) / sizeof(void*);
for (i = 0 ; i < numInitFuns ; i++)
{
showLoadingStep(i + 1, numInitFuns);
@ -201,16 +188,6 @@ static void showLoadingStep(float step, float maxSteps)
SDL_Delay(1);
}
static void initColor(SDL_Color *c, int r, int g, int b)
{
memset(c, 0, sizeof(SDL_Color));
c->r = r;
c->g = g;
c->b = b;
c->a = 255;
}
static void loadConfig(void)
{
char *configFilename;

View File

@ -50,13 +50,13 @@ extern int getJSONValue(cJSON *node, char *name, int defValue);
extern char *getLookupName(char *prefix, long num);
extern char *getSaveFilePath(char *filename);
extern void initAtlas(void);
extern void initBackground(void);
extern void initBulletDefs(void);
extern void initChallenges(void);
extern void initControls(void);
extern void initFighterDatabase(void);
extern void initFonts(void);
extern void initGame(void);
extern void initGraphics(void);
extern void initInput(void);
extern void initModalDialog(void);
extern void initResources(void);
@ -77,4 +77,3 @@ extern void setLanguage(char *applicationName, char *languageCode);
extern int writeFile(char *filename, char *data);
extern App app;
extern Colors colors;

View File

@ -115,6 +115,8 @@ void drawMouse(void)
app.mouse.x = x * app.scaleX;
app.mouse.y = y * app.scaleY;
setAtlasColor(255, 255, 255, 255);
blit(mousePointer, app.mouse.x, app.mouse.y, 1);
}

View File

@ -23,5 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern void blit(AtlasImage *atlasImage, int x, int y, int centered);
extern AtlasImage *getAtlasImage(char *filename);
extern void musicSetPlaying(int playing);
extern void setAtlasColor(int r, int g, int b, int a);
extern App app;

View File

@ -22,8 +22,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void initFont(char *name, char *filename);
static void drawWord(char *word, int *x, int *y, int startX);
static void applyWordWrap(char *word, int *x, int *y, int startX);
void calcTextDimensions(char *text, int size, int *w, int *h);
static void drawTextLines(int x, int y, int size, int align, SDL_Color color);
static void drawTextLine(int x, int y, int size, int align, SDL_Color color, const char *line);
void calcTextDimensions(const char *text, int size, int *w, int *h);
void useFont(char *name);
static SDL_Color white = {255, 255, 255, 255};
@ -110,8 +111,6 @@ static void initFont(char *name, char *filename)
void drawText(int x, int y, int size, int align, SDL_Color color, const char *format, ...)
{
int i, startX, n, w, h;
char word[128];
va_list args;
if (activeFont)
@ -125,15 +124,75 @@ void drawText(int x, int y, int size, int align, SDL_Color color, const char *fo
vsprintf(drawTextBuffer, format, args);
va_end(args);
if (app.textWidth == 0)
{
drawTextLine(x, y, size, align, color, drawTextBuffer);
}
else
{
drawTextLines(x, y, size, align, color);
}
}
}
static void drawTextLines(int x, int y, int size, int align, SDL_Color color)
{
char line[MAX_LINE_LENGTH], token[MAX_WORD_LENGTH];
int i, n, w, h, currentWidth, len;
memset(&line, '\0', sizeof(line));
memset(&token, '\0', sizeof(token));
len = strlen(drawTextBuffer);
n = currentWidth = 0;
for (i = 0 ; i < len ; i++)
{
token[n++] = drawTextBuffer[i];
if (drawTextBuffer[i] == ' ' || i == len - 1)
{
calcTextDimensions(token, size, &w, &h);
if (currentWidth + w > app.textWidth)
{
drawTextLine(x, y, size, align, color, line);
currentWidth = 0;
y += h;
memset(&line, '\0', sizeof(line));
}
strcat(line, token);
n = 0;
memset(&token, '\0', sizeof(token));
currentWidth += w;
}
}
drawTextLine(x, y, size, align, color, line);
}
static void drawTextLine(int x, int y, int size, int align, SDL_Color color, const char *line)
{
int i, startX, n, w, h;
char word[MAX_WORD_LENGTH];
scale = size / (FONT_SIZE * 1.0f);
startX = x;
memset(word, 0, 128);
memset(word, 0, MAX_WORD_LENGTH);
n = 0;
calcTextDimensions(drawTextBuffer, size, &w, &h);
calcTextDimensions(line, size, &w, &h);
if (align == TA_RIGHT)
{
@ -144,22 +203,21 @@ void drawText(int x, int y, int size, int align, SDL_Color color, const char *fo
x -= (w / 2);
}
for (i = 0 ; i < strlen(drawTextBuffer) ; i++)
for (i = 0 ; i < strlen(line) ; i++)
{
word[n++] = drawTextBuffer[i];
word[n++] = line[i];
if (drawTextBuffer[i] == ' ')
if (line[i] == ' ')
{
drawWord(word, &x, &y, startX);
memset(word, 0, 128);
memset(word, 0, MAX_WORD_LENGTH);
n = 0;
}
}
drawWord(word, &x, &y, startX);
}
}
static void drawWord(char *word, int *x, int *y, int startX)
@ -167,11 +225,6 @@ static void drawWord(char *word, int *x, int *y, int startX)
int i, c;
SDL_Rect dest;
if (app.textWidth > 0)
{
applyWordWrap(word, x, y, startX);
}
for (i = 0 ; i < strlen(word) ; i++)
{
c = word[i];
@ -187,29 +240,6 @@ static void drawWord(char *word, int *x, int *y, int startX)
}
}
static void applyWordWrap(char *word, int *x, int *y, int startX)
{
int i, w, c;
w = 0;
for (i = 0 ; i < strlen(word) ; i++)
{
c = word[i];
w += activeFont->glyphs[c].rect.w * scale;
if (w + *x - startX > app.textWidth)
{
*x = startX;
*y += activeFont->glyphs[c].rect.h * scale;
return;
}
}
}
void useFont(char *name)
{
Font *f;
@ -224,7 +254,7 @@ void useFont(char *name)
}
}
void calcTextDimensions(char *text, int size, int *w, int *h)
void calcTextDimensions(const char *text, int size, int *w, int *h)
{
int i, c;
float scale;
@ -245,28 +275,39 @@ void calcTextDimensions(char *text, int size, int *w, int *h)
int getWrappedTextHeight(char *text, int size)
{
int x, y, w, h, i, c;
float scale;
char word[MAX_WORD_LENGTH];
int i, y, n, w, h, currentWidth, len;
scale = size / (FONT_SIZE * 1.0f);
STRNCPY(drawTextBuffer, text, MAX_LINE_LENGTH);
x = y = 0;
n = 0;
y = 0;
h = 0;
currentWidth = 0;
len = strlen(drawTextBuffer);
memset(word, 0, MAX_WORD_LENGTH);
for (i = 0 ; i < strlen(text) ; i++)
for (i = 0 ; i < len ; i++)
{
c = text[i];
word[n++] = drawTextBuffer[i];
w = activeFont->glyphs[c].rect.w * scale;
h = activeFont->glyphs[c].rect.h * scale;
if (x + w > app.textWidth)
if (drawTextBuffer[i] == ' ' || i == len - 1)
{
x = 0;
calcTextDimensions(word, size, &w, &h);
if (currentWidth + w > app.textWidth)
{
currentWidth = 0;
y += h;
}
x += w;
currentWidth += w;
memset(word, 0, MAX_WORD_LENGTH);
n = 0;
}
}
return y;
return y + h;
}

View File

@ -28,6 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define FONT_SIZE 32
#define FONT_TEXTURE_SIZE 1024
#define MAX_WORD_LENGTH 128
extern char *getFileLocation(char *filename);
extern SDL_Texture *toTexture(SDL_Surface *surface, int destroySurface);