From d3f142632bf7751b902324c6afe6e970b4616649 Mon Sep 17 00:00:00 2001 From: ghaushe Date: Sat, 11 Jan 2003 19:49:43 +0000 Subject: [PATCH] Added support for Gradiated fonts (as in 'FUEL', 'CREW') - added option to use Gradiated font for Ship-name (as in PC version) Changed cmd-line options for PC settings: now '--pcopt=font,menu,scan' git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@541 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/ChangeLog | 2 + sc2/TODO | 3 + sc2/src/options.c | 1 + sc2/src/options.h | 2 + sc2/src/sc2code/libs/gfxlib.h | 2 + sc2/src/sc2code/libs/graphics/font.c | 39 +++++++++- .../sc2code/libs/graphics/sdl/3do_getbody.c | 78 +++++++++++++++++++ sc2/src/sc2code/sis.c | 9 ++- sc2/src/starcon2.c | 33 +++++--- 9 files changed, 156 insertions(+), 13 deletions(-) diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 934a8f940..6336f7f81 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,6 @@ Changes towards version 0.2: +- Changed PC cmd-line options: now -a font,menu,scan -PhracturedBlue +- Added gradiated font support (for ship name), and PC-font option -PBlue - Minor fixes to PCMenu by fOSSiL, Nic, PhracturedBlue - Updated mingw support with better directions, and easier build -PBlue - PCMenus now suports 'settings', and menu font is correct -PhracturedBlue diff --git a/sc2/TODO b/sc2/TODO index 320cbc348..df9682fef 100644 --- a/sc2/TODO +++ b/sc2/TODO @@ -90,6 +90,9 @@ Implementation bugs (low priority): nearest neighbor. - PC Menu still has some issues - Still using 3DO menu hierarchy, so menu text isn't identical to PC +-PC Font issues: + - Update 'CREW' and 'FUEL' fonts to be identical to PC + - Correct Lander text font color to be the same as PC Stuff still to do (large): - add some way to configure your keys diff --git a/sc2/src/options.c b/sc2/src/options.c index f0437b66a..273640fee 100644 --- a/sc2/src/options.c +++ b/sc2/src/options.c @@ -33,6 +33,7 @@ char *configDir, *saveDir, *meleeDir; BOOLEAN optSubtitles = TRUE; BOOLEAN optPCscan = FALSE; BOOLEAN optPCmenu = FALSE; +BOOLEAN optPCfonts = FALSE; void prepareConfigDir (void) { diff --git a/sc2/src/options.h b/sc2/src/options.h index 3987ee6fb..b58022206 100644 --- a/sc2/src/options.h +++ b/sc2/src/options.h @@ -39,6 +39,8 @@ extern BOOLEAN optPCscan; extern BOOLEAN optPCmenu; +extern BOOLEAN optPCfonts; + extern char *configDir; extern char *meleeDir; extern char *saveDir; diff --git a/sc2/src/sc2code/libs/gfxlib.h b/sc2/src/sc2code/libs/gfxlib.h index 982be8894..6e335e322 100644 --- a/sc2/src/sc2code/libs/gfxlib.h +++ b/sc2/src/sc2code/libs/gfxlib.h @@ -47,6 +47,7 @@ typedef COLOR *PCOLOR; #define COLOR_32k(c) (UWORD)((COLOR)(c)>>8) #define COLOR_256(c) LOBYTE((COLOR)c) #define MAKE_RGB15(r,g,b) (UWORD)(((r)<<10)|((g)<<5)|(b)) +#define BUILD_COLOR_RGBA(r,g,b,a) (DWORD)(((r)<<24)|((g)<<16)|((b)<<8)|(a)) typedef BYTE CREATE_FLAGS; #define WANT_MASK (CREATE_FLAGS)(1 << 0) @@ -329,6 +330,7 @@ extern DWORD LoadFontFile (PVOID pStr); extern DWORD LoadGraphicInstance (DWORD res); extern DWORD LoadGraphic (DWORD res); extern DRAWABLE LoadDisplayPixmap (PRECT area, FRAME frame); +extern void SetContextGradientFont (DWORD from, DWORD to); extern FONT SetContextFont (FONT Font); extern BOOLEAN DestroyFont (FONT_REF FontRef); extern FONT CaptureFont (FONT_REF FontRef); diff --git a/sc2/src/sc2code/libs/graphics/font.c b/sc2/src/sc2code/libs/graphics/font.c index 3924483e6..40364b57f 100644 --- a/sc2/src/sc2code/libs/graphics/font.c +++ b/sc2/src/sc2code/libs/graphics/font.c @@ -18,7 +18,27 @@ #include "gfxintrn.h" +extern FRAME Build_Gradiated_Font (FRAME FramePtr, DWORD from, DWORD to); + static BYTE char_delta_array[MAX_DELTAS]; +static struct { + BOOLEAN Use; + DWORD from; + DWORD to; +} FontGrad = {0,0,0}; + +void SetContextGradientFont (DWORD from, DWORD to) +{ + if (from == to) + FontGrad.Use = 0; + else + { + FontGrad.Use = 1; + FontGrad.from = from; + FontGrad.to = to; + } +} + FONT SetContextFont (FONT Font) @@ -200,7 +220,10 @@ _text_blt (PRECT pClipRect, PRIMITIVEPTR PrimPtr) TEXTPTR TextPtr; PRIMITIVE locPrim; - SetPrimType (&locPrim, STAMPFILL_PRIM); + if (FontGrad.Use) + SetPrimType (&locPrim, STAMP_PRIM); + else + SetPrimType (&locPrim, STAMPFILL_PRIM); SetPrimColor (&locPrim, _get_context_fg_color ()); TextPtr = &PrimPtr->Object.Text; @@ -233,7 +256,19 @@ _text_blt (PRECT pClipRect, PRIMITIVEPTR PrimPtr) r.extent.height = GetFrameHeight (locPrim.Object.Stamp.frame); _save_stamp.origin = r.corner; if (BoxIntersect (&r, pClipRect, &r)) - DrawGraphicsFunc (&r, &locPrim); + { + if (FontGrad.Use) + { + FRAME origFrame = locPrim.Object.Stamp.frame; + locPrim.Object.Stamp.frame = Build_Gradiated_Font( + locPrim.Object.Stamp.frame, FontGrad.from, FontGrad.to); + DrawGraphicsFunc (&r, &locPrim); + DestroyDrawable (ReleaseDrawable (locPrim.Object.Stamp.frame)); + locPrim.Object.Stamp.frame = origFrame; + } + else + DrawGraphicsFunc (&r, &locPrim); + } locPrim.Object.Stamp.origin.x += GetFrameWidth (locPrim.Object.Stamp.frame); #if 0 diff --git a/sc2/src/sc2code/libs/graphics/sdl/3do_getbody.c b/sc2/src/sc2code/libs/graphics/sdl/3do_getbody.c index 04da30f48..8dbb189b9 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/3do_getbody.c +++ b/sc2/src/sc2code/libs/graphics/sdl/3do_getbody.c @@ -298,6 +298,84 @@ Uint32 **getpixelarray(FRAMEPTR FramePtr, int width, int height) map[y] = NULL; return (map); +} + +FRAMEPTR Build_Gradiated_Font (FRAMEPTR FramePtr, Uint32 from, Uint32 to) +{ + UBYTE type; + FRAMEPTR NewFrame; + int x, y; + int width, height; + Uint32 color, clear; + BYTE from_r, from_g, from_b, from_a; + BYTE to_r, to_g, to_b, to_a; + int clrstep_r, clrstep_g, clrstep_b, clrstep_a; + TFB_Image *tfbImg, *tfbOrigImg; + SDL_Surface *img, *OrigImg; + PutPixelFn putpix; + GetPixelFn getpix; + + width = GetFrameWidth (FramePtr); + height = GetFrameHeight (FramePtr); + type = (UBYTE)TYPE_GET (GetFrameParentDrawable (FramePtr) + ->FlagsAndIndex) >> FTYPE_SHIFT; + NewFrame = CaptureDrawable ( + CreateDrawable (type, (SIZE)width, (SIZE)height, 1)); + tfbOrigImg = (TFB_Image *)((BYTE *)(FramePtr) + FramePtr->DataOffs); + OrigImg = tfbOrigImg->NormalImg; + SDL_LockSurface (OrigImg); + + tfbImg = (TFB_Image *)((BYTE *)(NewFrame) + NewFrame->DataOffs); + img = tfbImg->NormalImg; + SDL_LockSurface (img); + + putpix = putpixel_for (img); + getpix = getpixel_for (OrigImg); + + from_r = (from >> 24); + from_g = (from >> 16) & 0xFF; + from_b = (from >> 8) & 0xFF; + from_a = from & 0xFF; + + to_r = (to >> 24); + to_g = (to >> 16) & 0xFF; + to_b = (to >> 8) & 0xFF; + to_a = to & 0xFF; + + clrstep_r = (to_r - from_r) / (height - 5); + clrstep_g = (to_g - from_g) / (height - 5); + clrstep_b = (to_b - from_b) / (height - 5); + clrstep_a = (to_a - from_a) / (height - 5); + clear = SDL_MapRGBA (img->format, 0, 0, 0, 0); + + for (y = 0; y < 2; y++) + for (x = 0; x < width; x++) + putpix (img, x, y, clear); + + width--; + for (; y < height - 1; y++) + { + color = SDL_MapRGBA (img->format, from_r, from_g, from_b, from_a); + from_r += clrstep_r; + from_g += clrstep_g; + from_b += clrstep_b; + from_a += clrstep_a; + for (x = 0; x < width; x++) + if (getpix (OrigImg, x, y) == 1) + putpix (img, x, y, color); + else + putpix (img, x, y, clear); + putpix (img, x, y, clear); + } + + width++; + for (x = 0; x < width; x++) + putpix (img, x, y, clear); + SDL_UnlockSurface (img); + SDL_UnlockSurface (OrigImg); + SetFrameHotSpot (NewFrame, GetFrameHotSpot (FramePtr)); + return (NewFrame); + } // Generate a pixel (in the correct format to be applied to FramePtr) from the // r,g,b,a values supplied diff --git a/sc2/src/sc2code/sis.c b/sc2/src/sc2code/sis.c index 6efe7463e..15e91836d 100644 --- a/sc2/src/sc2code/sis.c +++ b/sc2/src/sc2code/sis.c @@ -378,8 +378,15 @@ DrawFlagshipName (BOOLEAN InStatusArea) t.baseline.y = r.corner.y + (SHIP_NAME_HEIGHT - InStatusArea); t.align = ALIGN_CENTER; t.CharCount = (COUNT)~0; - SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0x14, 0x0A, 0x00), 0x0C)); + if (optPCfonts) + SetContextGradientFont( + BUILD_COLOR_RGBA (0xF7, 0x2C, 0x00, 0xFF), + BUILD_COLOR_RGBA (0xF7, 0xBA, 0x00, 0xFF)); + else + SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0x14, 0x0A, 0x00), 0x0C)); DrawText (&t); + if (optPCfonts) + SetContextGradientFont(0, 0); SetContextForeGroundColor (OldColor); SetContextFont (OldFont); diff --git a/sc2/src/starcon2.c b/sc2/src/starcon2.c index 84f908232..5eef75811 100644 --- a/sc2/src/starcon2.c +++ b/sc2/src/starcon2.c @@ -87,8 +87,7 @@ main (int argc, char *argv[]) {"pcmusic", 0, NULL, 'm'}, {"audioquality", 1, NULL, 'q'}, {"nosubtitles", 0, NULL, 'u'}, - {"pcscan", 0, NULL, 'a'}, - {"pcmenu", 0, NULL, 'b'}, + {"pcopt", 1, NULL, 'a'}, {0, 0, 0, 0} }; @@ -102,7 +101,7 @@ main (int argc, char *argv[]) strcpy (contentdir, "content"); #endif - while ((c = getopt_long(argc, argv, "r:d:foc:spn:?hM:S:T:emq:uab", long_options, &option_index)) != -1) + while ((c = getopt_long(argc, argv, "r:d:foc:spn:?hM:S:T:emq:ua:", long_options, &option_index)) != -1) { switch (c) { case 'r': @@ -187,10 +186,21 @@ main (int argc, char *argv[]) optSubtitles = FALSE; break; case 'a': - optPCscan = TRUE; - break; - case 'b': - optPCmenu = TRUE; + { + char *thisopt, *optptr = optarg; + while (thisopt = strtok (optptr, ",")) + { + optptr= NULL; + if (!strcmp (thisopt, "m") || !strcmp (thisopt, "menu")) + optPCmenu = TRUE; + else if (!strcmp (thisopt, "s") || !strcmp (thisopt, "scan")) + optPCscan = TRUE; + else if (!strcmp (thisopt, "f") || !strcmp (thisopt, "font")) + optPCfonts = TRUE; + else + printf ("\nUnknown PC option: %s\n", thisopt); + } + } break; default: printf ("\nOption %s not found!\n", long_options[option_index].name); @@ -211,9 +221,12 @@ main (int argc, char *argv[]) printf(" -e, --3domusic (default)\n"); printf(" -m, --pcmusic\n"); printf(" -q, --audioquality=QUALITY (high, medium or low, default medium)\n"); - printf(" -u, --nosubtitles\n"); - printf(" -a --pcscan\n"); - printf(" -b --pcmenu\n"); + printf(" -u, --nosubtitles\n"); + printf(" -a --pcopt=font,menu,scan\n"); + printf(" options are comma seperated (no spaces)\n"); + printf(" font (or 'f') : use PC fonts\n"); + printf(" menu (or 'm') : use text menus\n"); + printf(" scan (or 's') : use text for coarse-scan (not hierogliphics)\n"); return 0; break; }