shithub: puzzles

Download patch

ref: 5b695b8d8bac1dca52a696cfa8207311ca28af47
parent: bcbee006c508f670d194b83fd77359831472e747
author: Simon Tatham <anakin@pobox.com>
date: Mon Jan 24 02:37:50 EST 2005

Status bar support.

[originally from svn r5183]

--- a/osx.m
+++ b/osx.m
@@ -1,10 +1,29 @@
 /*
  * Mac OS X / Cocoa front end to puzzles.
  *
- * TODO:
+ * Actually unfinished things left to do:
  *
- *  - status bar support.
+ *  - proper fatal errors.
  *
+ *  - Find out how to do help, and do some. We have a help file; at
+ *    _worst_ this should involve a new Halibut back end, but I
+ *    think help is HTML round here anyway so perhaps we can work
+ *    with what we already have.
+ * 
+ *  - Can we arrange for a pop-up menu from the Dock icon which
+ *    launches specific games, perhaps?
+ *     + apparently we can; see the NSApplication method
+ * 	 `applicationDockMenu:'. Good good. Do so.
+ *
+ *  - Why are the right and bottom edges of the Pattern grid one
+ *    pixel thinner than they should be?
+ * 
+ * Mac interface issues that possibly could be done better:
+ * 
+ *  - is there a better approach to frontend_default_colour?
+ *
+ *  - do we need any more options in the Window menu?
+ *
  *  - not sure what I should be doing about default window
  *    placement. Centring new windows is a bit feeble, but what's
  *    better? Is there a standard way to tell the OS "here's the
@@ -18,12 +37,6 @@
  *    should simply assign the number keys to UP_LEFT et al?
  *    They're not in use for anything else right now.
  *
- *  - proper fatal errors.
- *
- *  - is there a better approach to frontend_default_colour?
- *
- *  - do we need any more options in the Window menu?
- *
  *  - see if we can do anything to one-button-ise the multi-button
  *    dependent puzzle UIs:
  *     - Pattern is a _little_ unwieldy but not too bad (since
@@ -36,19 +49,6 @@
  * 	 default action. I fear this is why the Flash Net had the
  * 	 UI it did...
  *
- *  - Find out how to do help, and do some. We have a help file; at
- *    _worst_ this should involve a new Halibut back end, but I
- *    think help is HTML round here anyway so perhaps we can work
- *    with what we already have.
- * 
- *  - Can we arrange for a pop-up menu from the Dock icon which
- *    launches specific games, perhaps?
- *     + apparently we can; see the NSApplication method
- * 	 `applicationDockMenu:'. Good good. Do so.
- *
- *  - Why are the right and bottom edges of the Pattern grid one
- *    pixel thinner than they should be?
- * 
  *  - Should we _return_ to a game configuration sheet once an
  *    error is reported by midend_set_config, to allow the user to
  *    correct the one faulty input and keep the other five OK ones?
@@ -98,10 +98,6 @@
     /* FIXME */
     output[0] = output[1] = output[2] = 0.8F;
 }
-void status_bar(frontend *fe, char *text)
-{
-    /* FIXME */
-}
 
 void get_random_seed(void **randseed, int *randseedsize)
 {
@@ -266,6 +262,7 @@
     int cfg_which;
     NSView **cfg_controls;
     int cfg_ncontrols;
+    NSTextField *status;
 }
 - (id)initWithGame:(const game *)g;
 - dealloc;
@@ -273,6 +270,7 @@
 - (void)keyDown:(NSEvent *)ev;
 - (void)activateTimer;
 - (void)deactivateTimer;
+- (void)setStatusLine:(NSString *)text;
 @end
 
 @implementation MyImageView
@@ -349,27 +347,33 @@
 @implementation GameWindow
 - (void)setupContentView
 {
-    NSSize size = {0,0};
+    NSRect frame;
     int w, h;
 
+    if (status) {
+	frame = [status frame];
+	frame.origin.y = frame.size.height;
+    } else
+	frame.origin.y = 0;
+    frame.origin.x = 0;
+
     midend_size(me, &w, &h);
-    size.width = w;
-    size.height = h;
+    frame.size.width = w;
+    frame.size.height = h;
 
-    fe.image = [[NSImage alloc] initWithSize:size];
+    fe.image = [[NSImage alloc] initWithSize:frame.size];
     [fe.image setFlipped:YES];
-    fe.view = [[MyImageView alloc]
-	       initWithFrame:[self contentRectForFrameRect:[self frame]]];
+    fe.view = [[MyImageView alloc] initWithFrame:frame];
     [fe.view setImage:fe.image];
     [fe.view setWindow:self];
 
     midend_redraw(me);
 
-    [self setContentView:fe.view];
+    [[self contentView] addSubview:fe.view];
 }
 - (id)initWithGame:(const game *)g
 {
-    NSRect rect = { {0,0}, {0,0} };
+    NSRect rect = { {0,0}, {0,0} }, rect2;
     int w, h;
 
     ourgame = g;
@@ -388,6 +392,27 @@
     rect.size.width = w;
     rect.size.height = h;
 
+    /*
+     * Create the status bar, which will just be an NSTextField.
+     */
+    if (ourgame->wants_statusbar()) {
+	status = [[NSTextField alloc] initWithFrame:NSMakeRect(0,0,100,50)];
+	[status setEditable:NO];
+	[status setSelectable:NO];
+	[status setBordered:YES];
+	[status setBezeled:YES];
+	[status setBezelStyle:NSTextFieldSquareBezel];
+	[status setDrawsBackground:YES];
+	[[status cell] setTitle:@""];
+	[status sizeToFit];
+	rect2 = [status frame];
+	rect.size.height += rect2.size.height;
+	rect2.size.width = rect.size.width;
+	rect2.origin.x = rect2.origin.y = 0;
+	[status setFrame:rect2];
+    } else
+	status = nil;
+
     self = [super initWithContentRect:rect
 	    styleMask:(NSTitledWindowMask | NSMiniaturizableWindowMask |
 		       NSClosableWindowMask)
@@ -411,6 +436,8 @@
     }
 
     [self setupContentView];
+    if (status)
+	[[self contentView] addSubview:status];
     [self setIgnoresMouseEvents:NO];
 
     [self center];		       /* :-) */
@@ -917,6 +944,11 @@
     [self sheetEndWithStatus:NO];
 }
 
+- (void)setStatusLine:(NSString *)text
+{
+    [[status cell] setTitle:text];
+}
+
 @end
 
 /*
@@ -1045,6 +1077,11 @@
 void activate_timer(frontend *fe)
 {
     [fe->window activateTimer];
+}
+
+void status_bar(frontend *fe, char *text)
+{
+    [fe->window setStatusLine:[NSString stringWithCString:text]];
 }
 
 /* ----------------------------------------------------------------------