Changeset 976

Show
Ignore:
Timestamp:
07/04/08 08:20:58 (2 months ago)
Author:
takkaria
Message:

Fix remaining items in #107, and some others (largely graphics-related): (Rowan Beentje)

  • Graphics are now enabled in all terms when switched on
  • Tile cache is now invalidated correctly on tile size changes
  • Bugfix to ensure the background tile is included in cache resets
  • Reverse the term size check to prevent rounding errors from incorrectly missing small resizes
  • Clean up some memory leaks, mostly introduced by me in previous patches
  • Fix incorrect order of recent items menu instantiation, fixing lack of submenu on first load without a pref file.
  • Fixed some wacky minimum size enforcement
  • Fixed window positioning following a close/open to prevent the window being positioned behind the menubar
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/Makefile.std

    r834 r976  
    4949# Basic compiler stuff 
    5050CC = gcc 
    51 CFLAGS = -Wall -O2 -Wno-unused-parameter 
     51CFLAGS = -O2 -W -Wall -Wno-unused-parameter 
    5252 
    5353 
  • trunk/src/main-crb.c

    r961 r976  
    255255 
    256256static bool CheckEvents(int wait); 
    257 static OSStatus RevalidateGraphics(term_data *td, EventRef inEvent); 
     257static OSStatus RevalidateGraphics(term_data *td, bool reset_tilesize); 
    258258static char *locate_lib(char *buf, size_t size); 
    259259static void graphics_aux(int op); 
     
    781781        { 
    782782 
    783                 /* Enforce minimal size */ 
     783                /* Enforce minimal size for the main game window */ 
    784784                if (td->cols < 80) td->cols = 80; 
    785785                if (td->rows < 24) td->rows = 24; 
    786786 
    787787        } 
    788  
    789         /* Information windows can be much smaller */ 
    790788        else 
    791789        { 
    792                 if (td->cols < 5) td->cols = 10; 
    793                 if (td->rows < 10) td->rows = 5; 
     790 
     791                /* Information windows can be much smaller */ 
     792                if (td->cols < 10) td->cols = 10; 
     793                if (td->rows < 5) td->rows = 5; 
    794794        } 
    795795 
     
    798798        if (td->rows > 255) td->rows = 255; 
    799799 
     800        /* Minimal tile size */ 
    800801        bool dirty = false; 
    801         /* Minimal tile size */ 
    802802        if (td->tile_wid < td->font_wid) { 
    803803                td->tile_wid = td->font_wid; 
     
    857857                td->t->always_pict = TRUE; 
    858858        } 
    859         else if (use_graphics && (td == &data[0])
     859        else if (use_graphics
    860860        { 
    861861                /* Use higher pict whenever possible */ 
     
    11911191{ 
    11921192        if(frame.tile_images) { 
    1193                 for(int i = frame.rows*frame.cols; --i > 0; ) { 
     1193                for(int i = frame.rows*frame.cols; --i >= 0; ) { 
    11941194                        if(frame.tile_images[i]) CGImageRelease(frame.tile_images[i]); 
    11951195                        frame.tile_images[i] = 0; 
     
    14441444        GetWindowBounds((WindowRef)td->w, kWindowTitleBarRgn, &tmpR); 
    14451445        int trueTop = td->r.top - (tmpR.bottom-tmpR.top); 
    1446         MoveWindow((WindowRef)td->w, td->r.left, trueTop, FALSE); 
     1446 
     1447        /* Enforce a minimum y position to avoid windows positioned vertically off screen */ 
     1448        if (trueTop < GetMBarHeight()) trueTop = GetMBarHeight(); 
     1449         
     1450        MoveWindowStructure((WindowRef)td->w, td->r.left, trueTop); 
    14471451         
    14481452 
     
    21032107                        FSRefMakePath(&fsRef, (UInt8 *)prefpath, 1024); 
    21042108                        mac_warning(format("Preference file has changed.  If you have display problems, delete %s/%s.plist and restart.", prefpath, bundlename)); 
     2109                        CFRelease(bundleid); 
    21052110                } 
    21062111        } 
     
    21732178        if (recentItemsLoaded != NULL) 
    21742179        { 
     2180                CFRelease(recentItemsArrayRef); 
    21752181                recentItemsArrayRef = CFArrayCreateMutableCopy(kCFAllocatorDefault, 0, recentItemsLoaded); 
     2182                CFRelease(recentItemsLoaded); 
    21762183                redrawRecentItemsMenu(); 
    21772184        } 
     
    22982305        HIViewFindByID(HIViewGetRoot(aboutDialog), aboutDialogName, &aboutDialogViewRef); 
    22992306        HIViewSetText(aboutDialogViewRef, cfstr_applicationName); 
     2307        CFRelease(cfstr_applicationName); 
    23002308         
    23012309        /* Set the application copyright as set up in variable.c */ 
     
    23042312                                                                                strlen(copyright), kCFStringEncodingASCII, false); 
    23052313        HIViewSetText(aboutDialogViewRef, cfstr_applicationCopyright); 
     2314        CFRelease(cfstr_applicationCopyright); 
    23062315 
    23072316        /* Use a small font for the copyright text */ 
     
    24952504                        AppendMenuItemTextWithCFString(m, cfstr, 0, j, NULL); 
    24962505                        SetMenuItemRefCon(m, i-MIN_FONT+1, i); 
     2506                        CFRelease(cfstr); 
    24972507                } 
    24982508        } 
     
    26362646                        CFStringRef cfstr = CFStringCreateWithCharacters(kCFAllocatorDefault, recentFileName.unicode, recentFileName.length); 
    26372647                        AppendMenuItemTextWithCFString(MyGetMenuHandle(kOpenRecentMenu), cfstr, 0, i, NULL); 
     2648                        CFRelease(cfstr); 
    26382649                } 
    26392650                AppendMenuItemTextWithCFString(MyGetMenuHandle(kOpenRecentMenu), CFSTR("-"), kMenuItemAttrSeparator, -1, NULL); 
     
    27602771        for(int i = 0; i < N_ELEMENTS(data); i++) { 
    27612772                if(data[i].mapped) 
    2762                         RevalidateGraphics(&data[i], 0); 
     2773                        RevalidateGraphics(&data[i], FALSE); 
    27632774        } 
    27642775 
     
    29702981 
    29712982        /* Ignore drag effects, other than for moving the mouse origin */ 
    2972         if(td->rows == y/ td->tile_hgt && td->cols ==x/td->tile_wid
     2983        if(td->rows * td->tile_hgt == y && td->cols * td->tile_wid == x
    29732984                return noErr; 
    29742985 
     
    30553066                reset_visuals(TRUE); 
    30563067        } 
    3057         RevalidateGraphics(&data[0], 0); 
     3068        RevalidateGraphics(&data[0], FALSE); 
    30583069        Term_key_push(KTRL('R')); 
    30593070} 
     
    30823093        } 
    30833094 
    3084         RevalidateGraphics(td, inEvent); 
     3095        RevalidateGraphics(td, FALSE); 
    30853096 
    30863097        return noErr; 
     
    31663177} 
    31673178 
    3168 static OSStatus RevalidateGraphics(term_data *td, EventRef inEvent) 
    3169 
    3170         if(!td) return noErr; 
    3171  
    3172         HICommand command; 
    3173         command.commandID = 0; 
    3174         command.menu.menuRef = 0; 
    3175         if(inEvent) { 
    3176                 GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, 
    3177                                                         NULL, sizeof(command), NULL, &command); 
    3178         } 
    3179  
    3180         // Only rescale graphics when absolutely necessary. 
    3181         if(command.commandID != kTileWidMenu && command.commandID != kTileHgtMenu) 
    3182         { 
    3183                 // Reset tilesize to default when graphics change. 
     3179static OSStatus RevalidateGraphics(term_data *td, bool reset_tilesize) 
     3180
     3181        if (!td) return noErr; 
     3182 
     3183        /* 
     3184         * Reset the tilesize on graphics changes; term_data_check_font recalculates 
     3185         * this after it's been reset.  However, only reset the tilesize for default, 
     3186         * font, and toggle events (not startup - 'Play' 'Band' - or manual changes) 
     3187        */ 
     3188        if (reset_tilesize) 
     3189        { 
    31843190                td->tile_wid = td->tile_hgt = 0; 
    31853191        } 
     3192 
     3193        /* Clear the graphics tile cache. */ 
     3194        graphics_tiles_nuke(); 
    31863195 
    31873196        /* Sanity check for rows, columns, tilesize. */ 
    31883197        term_data_check_font(td); 
    31893198        term_data_check_size(td); 
     3199         
    31903200        /* Window size changes */ 
    31913201        term_data_resize(td); 
     
    32463256                        *toggle_defs[i].var = !(*toggle_defs[i].var); 
    32473257                        if(toggle_defs[i].refresh == true) { 
    3248                                 RevalidateGraphics(&data[0], inEvent); 
    3249                                 graphics_tiles_nuke(); 
     3258                                RevalidateGraphics(&data[0], TRUE); 
    32503259                                // Force redraw. 
    32513260                                Term_key_push(KTRL('R')); 
     
    33053314        td->font_id = fontID; 
    33063315        td->font_size = size; 
    3307         RevalidateGraphics(td, 0); 
     3316        RevalidateGraphics(td, TRUE); 
    33083317} 
    33093318 
     
    38323841        SetCursor(*(GetCursor(watchCursor))); 
    38333842 
     3843        /* Prepare the menubar */ 
     3844        init_menubar(); 
     3845 
    38343846        /* Ensure that the recent items array is always an array and start with an empty menu */ 
    38353847        recentItemsArrayRef = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); 
    38363848        redrawRecentItemsMenu(); 
    3837  
    3838         /* Prepare the menubar */ 
    3839         init_menubar(); 
    38403849 
    38413850        /* Initialize */