Changeset 105

Show
Ignore:
Timestamp:
05/01/07 21:47:51 (2 years ago)
Author:
pmac
Message:

Fix preferences and font manager bugs in main-crb.c
(Graphics fixes will take longer.)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main-crb.c

    r51 r105  
    160160 
    161161 
     162 
    162163 /* 
    163164 * #define ANGBAND_CREATOR four letter code for your variant, if any. 
     
    257258        s16b cols;              // columns in picture. 
    258259 
     260        char font_name[200]; // Name of font for storage. 
    259261        ATSUFontID font_id; 
    260262        float font_size;        // Scaled ATSU font size. 
     
    684686 
    685687        /* ICK */ 
    686                          
     688 
    687689        info->font_size = size; 
    688690        info->font_id = fid; 
     
    805807        td->font_wid = (info->font_wid +.999); 
    806808        td->font_hgt = info->ascent + info->descent; 
     809        strncpy(td->font_name, info->psname, sizeof(td->font_name)); 
    807810 
    808811        /* Set default tile size */ 
     
    20692072 * pointed by key 
    20702073 */ 
    2071 static void save_pref_short(const char *key, short value) 
     2074static void save_preference(const char *key, type_union value) 
    20722075{ 
    20732076        CFStringRef cf_key; 
    2074         CFNumberRef cf_value; 
     2077        CFPropertyListRef cf_value; 
    20752078 
    20762079        /* allocate and initialise the key */ 
     
    20782081 
    20792082        /* allocate and initialise the value */ 
    2080         cf_value = CFNumberCreate(NULL, kCFNumberShortType, &value); 
     2083        if(value.t == T_INT) 
     2084                cf_value = CFNumberCreate(NULL, kCFNumberIntType, &value.u.i); 
     2085 
     2086        else if(value.t == T_STRING) 
     2087                cf_value = CFStringCreateWithCString(NULL, value.u.s, kTextEncodingUS_ASCII); 
     2088 
     2089        else quit(format("Unrecognized save type %d\n", value.t)); 
     2090 
    20812091 
    20822092        if ((cf_key != NULL) && (cf_value != NULL)) 
     
    21022112 * vptr updated appropriately, FALSE otherwise. 
    21032113 */ 
    2104 static bool query_load_pref_short(const char *key, short *vptr
     2114static bool load_preference(const char *key, type_union *vptr, size_t maxlen
    21052115{ 
    21062116        CFStringRef cf_key; 
    2107         CFNumberRef cf_value; 
     2117        CFPropertyListRef cf_value; 
    21082118 
    21092119        /* allocate and initialise the key */ 
     
    21252135        } 
    21262136 
    2127         /* Convert the value to short */ 
    2128         CFNumberGetValue( 
    2129                 cf_value, 
    2130                 kCFNumberShortType, 
    2131                 vptr); 
     2137        /* Convert the value to appropriate type */ 
     2138        if(vptr->t == T_INT) 
     2139                CFNumberGetValue( cf_value, kCFNumberIntType, &vptr->u.i); 
     2140        else if(vptr->t == T_STRING) { 
     2141                CFRange range = { 0, 200}; 
     2142                (void) CFStringGetBytes (cf_value, range, kCGEncodingMacRoman, 0, 0, (UInt8*)vptr->u.s, maxlen, 0); 
     2143        } 
    21322144 
    21332145        /* Free CF data */ 
     
    21392151} 
    21402152 
    2141  
    2142 /* 
    2143  * Update short data pointed by vptr only if preferences 
    2144  * value for key is located. 
    2145  */ 
    2146 static void load_pref_short(const char *key, short *vptr) 
    2147 
    2148         short tmp; 
    2149  
    2150         if (query_load_pref_short(key, &tmp)) *vptr = tmp; 
    2151 
    2152  
     2153/* Convenience wrappers for commonly used type short */ 
     2154static void save_pref_short(const char *key, short value) 
     2155
     2156        type_union u = i2u(value); 
     2157        save_preference(key, u); 
     2158
     2159static bool load_pref_short(const char *key, short *vptr) 
     2160
     2161        bool ret; 
     2162        type_union u = { T_INT }; 
     2163        ret = load_preference(key, &u, 0); 
     2164        if( ret == TRUE ) *vptr = u.u.i; 
     2165        return ret; 
     2166
    21532167 
    21542168/* 
     
    21652179 
    21662180        /* Gfx settings */ 
     2181        /* sound */ 
    21672182        save_pref_short("arg.arg_sound", arg_sound); 
    2168 /* Tile dimensions of the current graphics mode */ 
     2183 
     2184        /* double-width tiles */ 
     2185        save_pref_short("arg.use_bigtile", use_bigtile); 
     2186 
     2187        /* graphics mode */ 
     2188        save_pref_short("graf_mode", graf_mode); 
     2189 
    21692190 
    21702191        /* Windows */ 
     
    21822203                save_pref_short(format("term%d.left", i), td->r.left); 
    21832204                save_pref_short(format("term%d.top", i), td->r.top); 
     2205 
     2206                /* Integer font sizes only */ 
     2207                save_preference(format("term%d.font_size", i), i2u((int)td->font_size)); 
     2208                save_preference(format("term%d.font_name", i), s2u(td->font_name)); 
    21842209        } 
    21852210 
     
    22042229 
    22052230        /* Load version information */ 
    2206         ok &= query_load_pref_short("version.major", &pref_major); 
    2207         ok &= query_load_pref_short("version.minor", &pref_minor); 
    2208         ok &= query_load_pref_short("version.patch", &pref_patch); 
    2209         ok &= query_load_pref_short("version.extra", &pref_extra); 
     2231        ok &= load_pref_short("version.major", &pref_major); 
     2232        ok &= load_pref_short("version.minor", &pref_minor); 
     2233        ok &= load_pref_short("version.patch", &pref_patch); 
     2234        ok &= load_pref_short("version.extra", &pref_extra); 
    22102235 
    22112236        /* Any of the above failed */ 
     
    22562281 
    22572282        /* sound */ 
    2258         if (query_load_pref_short("arg.arg_sound", &pref_tmp)) 
     2283        if (load_pref_short("arg.arg_sound", &pref_tmp)) 
    22592284                arg_sound = pref_tmp; 
    22602285 
    22612286        /* double-width tiles */ 
    2262         if (query_load_pref_short("arg.big_tile", &pref_tmp)) 
    2263         { 
     2287        if (load_pref_short("arg.use_bigtile", &pref_tmp)) 
    22642288                use_bigtile = pref_tmp; 
    2265         } 
     2289 
     2290        if(load_pref_short("graf_mode", &pref_tmp)) 
     2291                graf_mode = pref_tmp; 
    22662292 
    22672293 
     
    22802306                load_pref_short(format("term%d.left", i), &td->r.left); 
    22812307                load_pref_short(format("term%d.top", i), &td->r.top); 
     2308 
     2309                type_union u = {T_INT}; 
     2310                if(load_preference(format("term%d.font_size", i), &u, sizeof(int))) 
     2311                        td->font_size = (float) u.u.i; 
     2312                u = s2u(td->font_name); 
     2313                if(load_preference(format("term%d.font_name", i), &u, sizeof(td->font_name))) { 
     2314                        ATSUFontID fid = 0; 
     2315                        ATSUFindFontFromName(td->font_name, strlen(td->font_name), 
     2316                                                                kFontPostscriptName, kFontMacintoshPlatform, 
     2317                                                                kFontNoScriptCode, kFontNoLanguageCode, &fid); 
     2318                        if(fid) td->font_id = fid; 
     2319                        /* Use the default */ 
     2320                        else strncpy(td->font_name, "Monaco", sizeof(td->font_name)); 
     2321                } 
    22822322        } 
    22832323} 
     
    22912331        /* Default to Monaco font */ 
    22922332        ATSUFontID fid = 0; 
     2333 
    22932334        ATSUFindFontFromName("Monaco", strlen("Monaco"), kFontPostscriptName, 
    22942335                                                        kFontMacintoshPlatform, kFontNoScriptCode, 
    22952336                                                        kFontNoLanguageCode, &fid); 
    22962337 
     2338 
    22972339        if(!fid) 
    22982340                quit("Failed to find font 'Monaco'"); 
     
    23062348        /* Default font */ 
    23072349        td->font_id = fid; 
     2350        strncpy(td->font_name, "Monaco", sizeof(td->font_name)); 
    23082351 
    23092352        /* Default font size - was 12 */ 
     
    27672810        case 'font': 
    27682811          { 
     2812                if(!FPIsFontPanelVisible()) { 
     2813                        WindowRef w = FrontWindow(); 
     2814                        if (w) { 
     2815                                term_data *td = (term_data*) GetWRefCon(w); 
     2816                                SetFontInfoForSelection(kFontSelectionATSUIType, 1, 
     2817                                                                                &td->ginfo->style, NULL); 
     2818                        } 
     2819                } 
    27692820                CFStringRef tags[] = {CFSTR("Show Fonts"), CFSTR("Hide Fonts")}; 
    27702821        FPShowHideFontPanel();  
     
    38383889        validate_menus(); 
    38393890 
     3891        if(graf_mode) graphics_aux(graf_mode); 
     3892 
    38403893        /* Start playing! */ 
    38413894        EventRef newGameEvent = nil;