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(); initStars();
initBackground();
initEffects(); initEffects();
initHud(); initHud();

View File

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

View File

@ -291,6 +291,8 @@ void drawBullets(void)
{ {
int i; int i;
Bullet *b; Bullet *b;
setAtlasColor(255, 255, 255, 255);
for (i = 0, b = bulletsToDraw[i] ; b != NULL ; b = bulletsToDraw[++i]) for (i = 0, b = bulletsToDraw[i] ; b != NULL ; b = bulletsToDraw[++i])
{ {

View File

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

View File

@ -95,9 +95,20 @@ static void calculateMessageBoxHeight(MessageBox *msg)
{ {
app.textWidth = MSG_BOX_TEXT_WIDTH; 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; app.textWidth = 0;
useFont("roboto");
} }
int showingMessageBoxes(void) int showingMessageBoxes(void)
@ -142,10 +153,21 @@ void drawMessageBox(void)
app.textWidth = MSG_BOX_TEXT_WIDTH; 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; app.textWidth = 0;
} }
useFont("roboto");
} }
static void nextMessage(void) 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" #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 void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...);
extern int getWrappedTextHeight(char *text, int size); extern int getWrappedTextHeight(char *text, int size);
extern void playSound(int sound); extern void playSound(int sound);
extern void useFont(char *name);
extern App app; extern App app;
extern Battle battle; extern Battle battle;

View File

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

View File

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

View File

@ -129,8 +129,6 @@ void initGalacticMap(void)
/* clear the pulses */ /* clear the pulses */
destroyGalacticMap(); destroyGalacticMap();
initBackground();
getWidget("close", "starSystem")->action = resume; getWidget("close", "starSystem")->action = resume;
startMissionButton = getWidget("startMission", "starSystem"); startMissionButton = getWidget("startMission", "starSystem");
startMissionButton->action = startMission; startMissionButton->action = startMission;
@ -302,21 +300,24 @@ static void scrollGalaxy(void)
camera.x -= app.mouse.dx * 1.5; camera.x -= app.mouse.dx * 1.5;
camera.y -= app.mouse.dy * 1.5; camera.y -= app.mouse.dy * 1.5;
ssx = -(app.mouse.dx / 3); ssx = -app.mouse.dx;
ssy = -(app.mouse.dy / 3); ssx /= 3;
ssy = -app.mouse.dy;
ssy /= 3;
camera.x = MAX(cameraMin.x, MIN(camera.x, cameraMax.x)); camera.x = MAX(cameraMin.x, MIN(camera.x, cameraMax.x));
camera.y = MAX(cameraMin.y, MIN(camera.y, cameraMax.y)); camera.y = MAX(cameraMin.y, MIN(camera.y, cameraMax.y));
}
if (lastX == camera.x)
{
ssx = 0;
}
if (lastX == camera.x) if (lastY == camera.y)
{ {
ssx = 0; ssy = 0;
} }
if (lastY == camera.y)
{
ssy = 0;
} }
} }
@ -698,7 +699,7 @@ static void drawStarSystemDetail(void)
drawText(525, 160, 18, TA_LEFT, colors.lightGrey, CRAFT_TEXT, game.currentMission->craft); 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); 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); 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 StarSystem *getStarSystem(char *name);
extern SDL_Texture *getTexture(char *filename); extern SDL_Texture *getTexture(char *filename);
extern Widget *getWidget(const char *name, const char *group); extern Widget *getWidget(const char *name, const char *group);
extern void initBackground(void);
extern void initBattle(void); extern void initBattle(void);
extern void initFighterDatabaseDisplay(void); extern void initFighterDatabaseDisplay(void);
extern void initOptions(void (*returnFromOptions)(void)); extern void initOptions(void (*returnFromOptions)(void));

View File

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

View File

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

View File

@ -179,16 +179,17 @@ void drawTrophies(void)
} }
else else
{ {
blitScaled(trophyIcons[TROPHY_UNEARNED], x, y, 64, 64, 0);
if (!t->hidden) 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 - 10, 20, TA_LEFT, colors.lightGrey, t->title);
drawText(x + 85, y + 20, 18, TA_LEFT, colors.darkGrey, t->description); drawText(x + 85, y + 20, 18, TA_LEFT, colors.darkGrey, t->description);
drawText(x + 85, y + 48, 18, TA_LEFT, colors.darkGrey, "-"); drawText(x + 85, y + 48, 18, TA_LEFT, colors.darkGrey, "-");
} }
else else
{ {
blitScaled(trophyIcons[TROPHY_UNEARNED], x, y, 64, 64, 0);
drawText(x + 85, y + 20, 20, TA_LEFT, colors.darkGrey, HIDDEN_TEXT); 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" #include "draw.h"
static void initColor(SDL_Color *c, int r, int g, int b);
static PointF backgroundPoint[4]; static PointF backgroundPoint[4];
void initBackground(void) void initGraphics(void)
{ {
backgroundPoint[0].x = -SCREEN_WIDTH / 2; backgroundPoint[0].x = -SCREEN_WIDTH / 2;
backgroundPoint[0].y = -SCREEN_HEIGHT / 2; backgroundPoint[0].y = -SCREEN_HEIGHT / 2;
@ -35,6 +37,27 @@ void initBackground(void)
backgroundPoint[3].x = SCREEN_WIDTH / 2; backgroundPoint[3].x = SCREEN_WIDTH / 2;
backgroundPoint[3].y = SCREEN_HEIGHT / 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) 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 loadConfig(void);
static void loadConfigFile(char *filename); static void loadConfigFile(char *filename);
void saveConfig(void); void saveConfig(void);
static void initColor(SDL_Color *c, int r, int g, int b);
static void showLoadingStep(float step, float maxSteps); static void showLoadingStep(float step, float maxSteps);
void init18N(int argc, char *argv[]) void init18N(int argc, char *argv[])
@ -124,6 +123,7 @@ void initGameSystem(void)
{ {
int i, numInitFuns; int i, numInitFuns;
void (*initFuncs[]) (void) = { void (*initFuncs[]) (void) = {
initGraphics,
initFonts, initFonts,
initResources, initResources,
initSounds, initSounds,
@ -137,30 +137,17 @@ void initGameSystem(void)
initChallenges, initChallenges,
initStats, initStats,
initModalDialog, initModalDialog,
initBackground,
initStars, initStars,
initControls, initControls,
initTrophies, initTrophies,
initFighterDatabase 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(); initAtlas();
initInput(); initInput();
numInitFuns = sizeof(initFuncs) / sizeof(void*);
for (i = 0 ; i < numInitFuns ; i++) for (i = 0 ; i < numInitFuns ; i++)
{ {
@ -201,16 +188,6 @@ static void showLoadingStep(float step, float maxSteps)
SDL_Delay(1); 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) static void loadConfig(void)
{ {
char *configFilename; 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 *getLookupName(char *prefix, long num);
extern char *getSaveFilePath(char *filename); extern char *getSaveFilePath(char *filename);
extern void initAtlas(void); extern void initAtlas(void);
extern void initBackground(void);
extern void initBulletDefs(void); extern void initBulletDefs(void);
extern void initChallenges(void); extern void initChallenges(void);
extern void initControls(void); extern void initControls(void);
extern void initFighterDatabase(void); extern void initFighterDatabase(void);
extern void initFonts(void); extern void initFonts(void);
extern void initGame(void); extern void initGame(void);
extern void initGraphics(void);
extern void initInput(void); extern void initInput(void);
extern void initModalDialog(void); extern void initModalDialog(void);
extern void initResources(void); extern void initResources(void);
@ -77,4 +77,3 @@ extern void setLanguage(char *applicationName, char *languageCode);
extern int writeFile(char *filename, char *data); extern int writeFile(char *filename, char *data);
extern App app; extern App app;
extern Colors colors;

View File

@ -114,6 +114,8 @@ void drawMouse(void)
app.mouse.x = x * app.scaleX; app.mouse.x = x * app.scaleX;
app.mouse.y = y * app.scaleY; app.mouse.y = y * app.scaleY;
setAtlasColor(255, 255, 255, 255);
blit(mousePointer, app.mouse.x, app.mouse.y, 1); 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 void blit(AtlasImage *atlasImage, int x, int y, int centered);
extern AtlasImage *getAtlasImage(char *filename); extern AtlasImage *getAtlasImage(char *filename);
extern void musicSetPlaying(int playing); extern void musicSetPlaying(int playing);
extern void setAtlasColor(int r, int g, int b, int a);
extern App app; 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 initFont(char *name, char *filename);
static void drawWord(char *word, int *x, int *y, int startX); static void drawWord(char *word, int *x, int *y, int startX);
static void applyWordWrap(char *word, int *x, int *y, int startX); static void drawTextLines(int x, int y, int size, int align, SDL_Color color);
void calcTextDimensions(char *text, int size, int *w, int *h); 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); void useFont(char *name);
static SDL_Color white = {255, 255, 255, 255}; 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, ...) 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; va_list args;
if (activeFont) if (activeFont)
@ -125,53 +124,107 @@ void drawText(int x, int y, int size, int align, SDL_Color color, const char *fo
vsprintf(drawTextBuffer, format, args); vsprintf(drawTextBuffer, format, args);
va_end(args); va_end(args);
scale = size / (FONT_SIZE * 1.0f); if (app.textWidth == 0)
startX = x;
memset(word, 0, 128);
n = 0;
calcTextDimensions(drawTextBuffer, size, &w, &h);
if (align == TA_RIGHT)
{ {
x -= w; drawTextLine(x, y, size, align, color, drawTextBuffer);
} }
else if (align == TA_CENTER) else
{ {
x -= (w / 2); drawTextLines(x, y, size, align, color);
} }
for (i = 0 ; i < strlen(drawTextBuffer) ; i++)
{
word[n++] = drawTextBuffer[i];
if (drawTextBuffer[i] == ' ')
{
drawWord(word, &x, &y, startX);
memset(word, 0, 128);
n = 0;
}
}
drawWord(word, &x, &y, startX);
} }
} }
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, MAX_WORD_LENGTH);
n = 0;
calcTextDimensions(line, size, &w, &h);
if (align == TA_RIGHT)
{
x -= w;
}
else if (align == TA_CENTER)
{
x -= (w / 2);
}
for (i = 0 ; i < strlen(line) ; i++)
{
word[n++] = line[i];
if (line[i] == ' ')
{
drawWord(word, &x, &y, startX);
memset(word, 0, MAX_WORD_LENGTH);
n = 0;
}
}
drawWord(word, &x, &y, startX);
}
static void drawWord(char *word, int *x, int *y, int startX) static void drawWord(char *word, int *x, int *y, int startX)
{ {
int i, c; int i, c;
SDL_Rect dest; SDL_Rect dest;
if (app.textWidth > 0)
{
applyWordWrap(word, x, y, startX);
}
for (i = 0 ; i < strlen(word) ; i++) for (i = 0 ; i < strlen(word) ; i++)
{ {
c = 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) void useFont(char *name)
{ {
Font *f; 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; int i, c;
float scale; float scale;
@ -245,28 +275,39 @@ void calcTextDimensions(char *text, int size, int *w, int *h)
int getWrappedTextHeight(char *text, int size) int getWrappedTextHeight(char *text, int size)
{ {
int x, y, w, h, i, c; char word[MAX_WORD_LENGTH];
float scale; 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; if (drawTextBuffer[i] == ' ' || i == len - 1)
h = activeFont->glyphs[c].rect.h * scale;
if (x + w > app.textWidth)
{ {
x = 0; calcTextDimensions(word, size, &w, &h);
y += h;
}
x += w; if (currentWidth + w > app.textWidth)
{
currentWidth = 0;
y += h;
}
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_SIZE 32
#define FONT_TEXTURE_SIZE 1024 #define FONT_TEXTURE_SIZE 1024
#define MAX_WORD_LENGTH 128
extern char *getFileLocation(char *filename); extern char *getFileLocation(char *filename);
extern SDL_Texture *toTexture(SDL_Surface *surface, int destroySurface); extern SDL_Texture *toTexture(SDL_Surface *surface, int destroySurface);