diff --git a/main.c b/main.c index 6404091..7ccc363 100644 --- a/main.c +++ b/main.c @@ -55,10 +55,10 @@ static int global_firstcall; extern int argFull; extern int argARDS; +static GtkWidget *window; int windowWidth; int windowHeight; -static int windowHeightOffset = 0; -static int windowWidthOffset = 0; +static double aspectRatio; extern int tube_doClearPersistent; @@ -95,8 +95,25 @@ static void on_quit_event() static void do_drawing(cairo_t *cr, GtkWidget *widget) { static cairo_surface_t *permanent_surface, *temporary_surface; + static int windowHeightOffset = 0; + static int windowWidthOffset = 0; if (global_firstcall) { + // force aspect ratio by making black stripes at left and right, or top and bottom + gtk_window_get_size(GTK_WINDOW(window), &windowWidth, &windowHeight); + // gtk_window_set_resizable(GTK_WINDOW(window), 0); // do not allow further resizing + + if (windowWidth > (int)((double)windowHeight * aspectRatio + 0.5)) { + windowWidthOffset = (windowWidth - (int)((double)windowHeight * aspectRatio)) / 2; + windowWidth = (int)((double)windowHeight * aspectRatio + 0.5); + } + if (windowHeight > (int)((double)windowWidth / aspectRatio + 0.5) ) { + windowHeightOffset = (windowHeight - (int)((double)windowWidth / aspectRatio)) / 2; + windowHeight = (int)((double)windowWidth / aspectRatio + 0.5); + } + + printf("Window dimensions: %d x %d\n", windowWidth, windowHeight); + permanent_surface = cairo_surface_create_similar(cairo_get_target(cr), CAIRO_CONTENT_COLOR, windowWidth, windowHeight); temporary_surface = cairo_surface_create_similar(cairo_get_target(cr), @@ -175,11 +192,9 @@ static void on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer user_da int main (int argc, char *argv[]) { GtkWidget *darea; - GtkWidget *window; int askWindowWidth; int askWindowHeight; - double aspectRatio; tube_init(argc, argv); @@ -190,13 +205,14 @@ int main (int argc, char *argv[]) else if (argFull) { askWindowWidth = 4096; - askWindowHeight = 3072; + askWindowHeight = 3120; } else { askWindowWidth = 1024; askWindowHeight = 780; } - aspectRatio = (double)askWindowWidth/(double)askWindowHeight; + + aspectRatio = (double)askWindowWidth / (double)askWindowHeight; gtk_init(&argc, &argv); @@ -233,32 +249,27 @@ int main (int argc, char *argv[]) gtk_window_set_keep_above(GTK_WINDOW(window), FALSE); windowWidth = screenWidth; windowHeight = screenHeight; - // force aspect ratio - if (windowWidth > (int)((double)windowHeight * aspectRatio)) { - windowWidthOffset = (windowWidth - (int)((double)windowHeight * aspectRatio)) / 2; - windowWidth = (int)((double)windowHeight * aspectRatio); - } - if (windowHeight > (int)((double)windowWidth / aspectRatio)) { - windowHeightOffset = (windowHeight - (int)((double)windowWidth / aspectRatio)) / 2; - windowHeight = (int)((double)windowWidth / aspectRatio); - } } else { // DISPLAY DECORATED WINDOW - if (argARDS && (askWindowHeight > (screenHeight - 32))) { - askWindowWidth = 540; - askWindowHeight = 707; +#define BORDER 64 // we need to make an educated guess here what the window manager will accept + // otherwise we will have a decorated window with wrong aspect ratio + // if BORDER is too small, we end up with small black stripes at the left and right + // if BORDER is too large, the decorated window will be smaller than possible + // with a reasonable size BORDER, both are acceptable + // ideally, one could force the window manager to use a certain aspect ratio + if (askWindowHeight > (screenHeight - BORDER)) { + askWindowWidth = (int)((double)(screenHeight - BORDER) * aspectRatio); + askWindowHeight = screenHeight - BORDER; } gtk_window_set_decorated(GTK_WINDOW(window), TRUE); gtk_window_set_default_size(GTK_WINDOW(window), askWindowWidth, askWindowHeight); windowWidth = askWindowWidth; windowHeight = askWindowHeight; } + // printf("Requested window dimensions: %d x %d\n", windowWidth, windowHeight); - printf("Window dimensions: %d x %d\n", windowWidth, windowHeight); - - if (TIME_INTERVAL > 0) { // Add timer event // Register the timer and set time in mS. diff --git a/tek4010 b/tek4010 index 168a39e..96843d7 100755 Binary files a/tek4010 and b/tek4010 differ diff --git a/tek4010.c b/tek4010.c index ae18a64..25c43ab 100755 --- a/tek4010.c +++ b/tek4010.c @@ -245,17 +245,11 @@ void tek4010_draw(cairo_t *cr, cairo_t *cr2, int first) refreshCount++; if (first) { - first = 0; - if (argFull) { - efactor = windowHeight / 780.0; - } - else { - efactor = 1.0; - } + first = 0; + efactor = windowWidth / 1024.0; refresh_interval = 30; tube_changeCharacterSize(cr, cr2, 74, 35, (int) (18.0 * efactor)); - printf("Scaling: %0.3f\n", efactor / 4.0); - // printf("Refresh interval: %d\n",refresh_interval); + if (windowWidth != 1024) printf("Scaling: %0.3f\n", efactor / 4.0); } startPaintTime = tube_mSeconds(); // start to measure time for this draw operation @@ -422,7 +416,7 @@ void tek4010_draw(cairo_t *cr, cairo_t *cr2, int first) if (DEBUG) printf("setting yh to %d\n", yh); break; case 2: yl = (ch & 31); - if (argFull) { + if (windowWidth != 1024) { int yb = (xy4014 >> 2) & 3; tube_y0 = (int)(efactor * (double)(((yh+yl) << 2) + yb) / 4.0); } @@ -434,7 +428,7 @@ void tek4010_draw(cairo_t *cr, cairo_t *cr2, int first) if (DEBUG) printf("setting xh to %d\n", xh); break; case 4: xl = (ch & 31); - if (argFull) { + if (windowWidth != 1024) { int xb = xy4014 & 3; tube_x0 = (int)(efactor * (double)(((xh+xl) << 2) + xb) / 4.0); } @@ -461,7 +455,7 @@ void tek4010_draw(cairo_t *cr, cairo_t *cr2, int first) break; if (DEBUG) printf(">>>>>xh=%d\n",xh); case 8: xl = (ch & 31); - if (argFull) { + if (windowWidth != 1024) { int xb = xy4014 & 3; tube_x2 = (int)(efactor * (double)(((xh+xl) << 2) + xb) / 4.0); int yb = (xy4014 >> 2) & 3; diff --git a/tube.c b/tube.c index 7bfc1ba..141b4e6 100755 --- a/tube.c +++ b/tube.c @@ -178,7 +178,7 @@ void tube_init(int argc, char* argv[]) char *argv2[20]; size_t bufsize = 127; int firstArg = 1; - printf("tek4010 version 1.2.1\n"); + printf("tek4010 version 1.2.2\n"); windowName = "Tektronix 4010/4014 emulator"; if ((argc<2) || (argc>19)) { printf("Error:number of arguments\n"); diff --git a/versions.txt b/versions.txt index 70e39c0..e8d9faf 100644 --- a/versions.txt +++ b/versions.txt @@ -1,3 +1,8 @@ +Version 1.2.2 April 16, 2019 +============================ +Bug fixes +- fixed window size and scaling on lower resolution displays + Version 1.2.1 April 15, 2019 ============================ New features