#define kVK_Escape 0x35
#define kVK_ANSI_KeypadEnter 0x4C
-static NSSize const AngbandScaleIdentity = {1.0, 1.0};
static NSString * const AngbandDirectoryNameLib = @"lib";
static NSString * const AngbandDirectoryNameBase = @"Hengband";
/* The max number of glyphs we support. Currently this only affects
- * updateGlyphInfo() for the calculation of the tile size (the glyphArray and
- * glyphWidths members of AngbandContext are only used in updateGlyphInfo()).
- * The rendering in drawWChar will work for glyphs not in updateGlyphInfo()'s
+ * updateGlyphInfo() for the calculation of the tile size, fontAscender,
+ * fontDescender, ncol_pre, and ncol_post (the glyphArray and glyphWidths
+ * members of AngbandContext are only used in updateGlyphInfo()). The
+ * rendering in drawWChar will work for glyphs not in updateGlyphInfo()'s
* set, and that is used for rendering Japanese characters.
*/
#define GLYPH_COUNT 256
* defaults */
- (void)resizeTerminalWithContentRect: (NSRect)contentRect saveToDefaults: (BOOL)saveToDefaults;
+/* Change the minimum size for the window associated with the context. */
+- (void)setMinimumWindowSize;
+
/* Called from the view to indicate that it is starting or ending live resize */
- (void)viewWillStartLiveResize:(AngbandView *)view;
- (void)viewDidEndLiveResize:(AngbandView *)view;
}
/*
- * Record the ascender and descender. Adjust both by 0.5 pixel to leave
- * space for antialiasing/subpixel positioning.
+ * Record the ascender and descender. Some fonts, for instance DIN
+ * Condensed and Rockwell in 10.14, the ascent on '@' exceeds that
+ * reported by [screenFont ascender]. Get the overall bounding box
+ * for the glyphs and use that instead of the ascender and descender
+ * values if the bounding box result extends farther from the baseline.
*/
- fontAscender = [screenFont ascender] + 0.5;
- fontDescender = [screenFont descender] - 0.5;
+ CGRect bounds = CTFontGetBoundingRectsForGlyphs((CTFontRef) screenFont, kCTFontHorizontalOrientation, glyphArray, NULL, GLYPH_COUNT);
+ fontAscender = [screenFont ascender];
+ if (fontAscender < bounds.origin.y + bounds.size.height) {
+ fontAscender = bounds.origin.y + bounds.size.height;
+ }
+ fontDescender = [screenFont descender];
+ if (fontDescender > bounds.origin.y) {
+ fontDescender = bounds.origin.y;
+ }
/*
- * Record the tile size. Add one to the median advance to leave space
- * for antialiasing/subpixel positioning. Round both values up to
- * have tile boundaries match pixel boundaries.
+ * Record the tile size. Round both values up to have tile boundaries
+ * match pixel boundaries.
*/
- tileSize.width = ceil(medianAdvance + 1.);
+ tileSize.width = ceil(medianAdvance);
tileSize.height = ceil(fontAscender - fontDescender);
/*
textMatrix = CGAffineTransformScale( textMatrix, 1.0, -1.0 );
CGContextSetTextMatrix(ctx, textMatrix);
- CGContextShowGlyphsWithAdvances(ctx, &glyph, &CGSizeZero, 1);
+ CGContextShowGlyphsAtPositions(ctx, &glyph, &CGPointZero, 1);
/* Restore the text matrix if we messed with the compression ratio */
if (compressionRatio != 1.)
/* Adjust terminal to fit window with new font; save the new columns
* and rows since they could be changed */
NSRect contentRect = [self->primaryWindow contentRectForFrameRect: [self->primaryWindow frame]];
+
+ [self setMinimumWindowSize];
+ NSSize size = self->primaryWindow.contentMinSize;
+ BOOL windowNeedsResizing = NO;
+ if (contentRect.size.width < size.width) {
+ contentRect.size.width = size.width;
+ windowNeedsResizing = YES;
+ }
+ if (contentRect.size.height < size.height) {
+ contentRect.size.height = size.height;
+ windowNeedsResizing = YES;
+ }
+ if (windowNeedsResizing) {
+ size.width = contentRect.size.width;
+ size.height = contentRect.size.height;
+ [self->primaryWindow setContentSize:size];
+ }
[self resizeTerminalWithContentRect: contentRect saveToDefaults: YES];
}
Term_activate( old );
}
+- (void)setMinimumWindowSize
+{
+ NSSize minsize;
+
+ if ([self terminalIndex] == 0) {
+ minsize.width = 80;
+ minsize.height = 24;
+ } else {
+ minsize.width = 1;
+ minsize.height = 1;
+ }
+ minsize.width =
+ minsize.width * self->tileSize.width + self->borderSize.width * 2.0;
+ minsize.height =
+ minsize.height * self->tileSize.height + self->borderSize.height * 2.0;
+ [[self makePrimaryWindow] setContentMinSize:minsize];
+}
+
- (void)saveWindowVisibleToDefaults: (BOOL)windowVisible
{
int termIndex = [self terminalIndex];
{
NSUserDefaults *angbandDefs = [NSUserDefaults angbandDefaults];
[angbandDefs setObject:savefileString forKey:@"SaveFile"];
- [angbandDefs synchronize];
+ [angbandDefs synchronize];
}
}
/* Get the window */
NSWindow *window = [context makePrimaryWindow];
- NSString *title;
-
/* Set its title and, for auxiliary terms, tentative size */
- if (termIdx == 0)
- {
- title = [NSString stringWithCString:angband_term_name[0]
+ NSString *title = [NSString stringWithCString:angband_term_name[termIdx]
#ifdef JP
- encoding:NSJapaneseEUCStringEncoding
+ encoding:NSJapaneseEUCStringEncoding
#else
- encoding:NSMacOSRomanStringEncoding
+ encoding:NSMacOSRomanStringEncoding
#endif
- ];
- [window setTitle:title];
-
- /* Set minimum size (80x24) */
- NSSize minsize;
- minsize.width = 80 * context->tileSize.width + context->borderSize.width * 2.0;
- minsize.height = 24 * context->tileSize.height + context->borderSize.height * 2.0;
- [window setContentMinSize:minsize];
- }
- else
- {
- title = [NSString stringWithCString:angband_term_name[termIdx]
-#ifdef JP
- encoding:NSJapaneseEUCStringEncoding
-#else
- encoding:NSMacOSRomanStringEncoding
-#endif
- ];
- [window setTitle:title];
- /* Set minimum size (1x1) */
- NSSize minsize;
- minsize.width = context->tileSize.width + context->borderSize.width * 2.0;
- minsize.height = context->tileSize.height + context->borderSize.height * 2.0;
- [window setContentMinSize:minsize];
- }
-
+ ];
+ [window setTitle:title];
+ [context setMinimumWindowSize];
/* If this is the first term, and we support full screen (Mac OS X Lion or
* later), then allow it to go full screen (sweet). Allow other terms to be
prc->cell_changes[jx].a;
sourceRect.size.width = graf_width;
sourceRect.size.height = graf_height;
- terrainRect.origin.x = graf_width *
+ terrainRect.origin.x = graf_width *
prc->cell_changes[jx].tcol;
terrainRect.origin.y = graf_height *
prc->cell_changes[jx].trow;
pict_image,
sourceRect,
destinationRect,
- NSCompositeSourceOver);
+ NSCompositeSourceOver);
} else {
draw_image_tile(
nsContext,
[angbandContext setNeedsDisplayInBaseRect:rect];
}
- [angbandContext unlockFocus];
+ [angbandContext unlockFocus];
}
{
[angbandContext lockFocus];
[[NSColor blackColor] set];
- NSRect imageRect = {NSZeroPoint, [angbandContext imageSize]};
+ NSRect imageRect = {NSZeroPoint, [angbandContext imageSize]};
NSRectFillUsingOperation(imageRect, NSCompositeCopy);
[angbandContext unlockFocus];
[angbandContext setNeedsDisplay:YES];
game_in_progress = TRUE;
/* Wait for a keypress */
- pause_line(23);
+ pause_line(Term->hgt - 1);
}
}
}
else
{
+ /*
+ * Another window is only usable after Term_init_cocoa() has
+ * been called for it. For Angband if window_flag[i] is nonzero
+ * then that has happened for window i. For Hengband, that is
+ * not the case so also test angband_term[i]->data.
+ */
NSInteger subwindowNumber = tag - AngbandWindowMenuItemTagBase;
- return (window_flag[subwindowNumber] > 0);
+ return (angband_term[subwindowNumber]->data != 0
+ && window_flag[subwindowNumber] > 0);
}
return NO;
NSMenu *windowsMenu = [[NSApplication sharedApplication] windowsMenu];
[windowsMenu addItem: [NSMenuItem separatorItem]];
- NSMenuItem *angbandItem = [[NSMenuItem alloc] initWithTitle: @"Hengband" action: @selector(selectWindow:) keyEquivalent: @"0"];
+ NSString *title1 = [NSString stringWithCString:angband_term_name[0]
+#ifdef JP
+ encoding:NSJapaneseEUCStringEncoding
+#else
+ encoding:NSMacOSRomanStringEncoding
+#endif
+ ];
+ NSMenuItem *angbandItem = [[NSMenuItem alloc] initWithTitle:title1 action: @selector(selectWindow:) keyEquivalent: @"0"];
[angbandItem setTarget: self];
[angbandItem setTag: AngbandWindowMenuItemTagBase];
[windowsMenu addItem: angbandItem];
/* Add items for the additional term windows */
for( NSInteger i = 1; i < ANGBAND_TERM_MAX; i++ )
{
- NSString *title = [NSString stringWithFormat: @"Term %ld", (long)i];
+ NSString *title = [NSString stringWithCString:angband_term_name[i]
+#ifdef JP
+ encoding:NSJapaneseEUCStringEncoding
+#else
+ encoding:NSMacOSRomanStringEncoding
+#endif
+ ];
NSString *keyEquivalent = [NSString stringWithFormat: @"%ld", (long)i];
NSMenuItem *windowItem = [[NSMenuItem alloc] initWithTitle: title action: @selector(selectWindow:) keyEquivalent: keyEquivalent];
[windowItem setTarget: self];
int main(int argc, char* argv[])
{
- NSApplicationMain(argc, (void*)argv);
+ NSApplicationMain(argc, (void*)argv);
return (0);
}