Display Mode removes window controls
AceBlkwell

All,

I'll try to be brief and if you need code I can send the files. There is too much going on to single out a single section.

In short, I wrote a simple "concentration" match game. Mainly to use a mouse which I've never written for. As ideas came to me I added and patched onto the original game. Once running fair my grandson asked if I could go full screen. You may remember that post. I managed to include a choice of screen sizes and have the blocks / cards change proportionally so I didn't have to rewrite a bunch of size cards.

Things went well. I made it so you could choose a screen size, with largest being 1600 x 900. At this size I still have the window title bar. Still my grandson pointed out it wasn't full screen. (1900x1080) So I decided for a trial I'd work with FULLSCREEN. The program goes full screen however the content doesn't. I need the width and height to use in calculating the proportional drawing of the cards. I also use it to calculate mouse position in relation to the cards.

In any case I tried working with DISPLAY_MODE. It will give me the number of screen modes along with their height x width. I minus 2 from max count of screen modes and use that H x W. It works fine. Not quite tall enough to cover screen but close.

I said all of this to ask, if I'm just setting display size in the same manner as with 320x200 / 640x480/ 800x600 etc, then why does the window control disappear like with full screen? I grab the screen modes. Use the largest height and width. Calculate like normal and set the screen to the height and width as before. I just don't have a window bar now. Was just curious.

Thanks

OK I thought maybe the function for choosing screen size might help. How I use the numbers later really doesn't matter. Here is where the screen size is set.

#SelectExpand
1/**********************INCLUDES ***********************/ 2#include <cstdio> 3#include <cstdlib> 4#include <iostream> 5#include <string> 6#include <allegro5/allegro5.h> 7#include <allegro5/allegro_font.h> 8#include <allegro5/allegro_ttf.h> 9#include <allegro5/allegro_image.h> 10#include <allegro5/allegro_primitives.h> 11#include <allcolor_A5.h> 12 13/********************* DEFINES ******/ 14 15 16/********************* STRUCTS ******/ 17 18 19/********************* FUNCTION DECLARE ******/ 20 21/********************* EXTERNALS ******/ 22extern ALLEGRO_EVENT_QUEUE* queue; 23extern ALLEGRO_DISPLAY* disp; 24extern ALLEGRO_BITMAP* buffer; 25extern ALLEGRO_FONT* font; 26extern ALLEGRO_FONT* scr_font; 27extern ALLEGRO_FONT* err_font; 28extern ALLEGRO_EVENT event; 29extern int nDispWD; 30extern int nDispHT; 31 32ALLEGRO_DISPLAY_MODE mode; 33 34/********************* PROGRAM FUNCTIONS *****/ 35 36void scr_size() 37{ 38 39 int modes_count = 0; 40 int nEntry = 0; 41 bool bQuit = false; 42 43 modes_count = al_get_num_display_modes(); 44 45 al_get_display_mode(modes_count-2, &mode); 46 al_clear_to_color(COLOR::BLACK); 47 al_draw_textf(font, COLOR::BR_CYAN, 10, 20, 0, "Choose screen size."); 48 al_draw_textf(font, COLOR::BR_RED, 10, 50, 0, " 1) 320 x 200"); 49 al_draw_textf(font, COLOR::BR_RED, 10, 80, 0, " 2) 640 x 480 "); 50 al_draw_textf(font, COLOR::BR_RED, 10, 110, 0, " 3) 800 x 640 "); 51 al_draw_textf(font, COLOR::BR_RED, 10, 140, 0, " 4) 1200 x 800 "); 52 al_draw_textf(font, COLOR::BR_RED, 10, 170, 0, " 5) 1600 x 900 "); 53 al_draw_textf(font, COLOR::BR_RED, 10, 200, 0, " 6) Fullscreen "); 54 55 al_flip_display(); 56 57while (!bQuit ) 58 { 59 al_wait_for_event(queue, &event); 60 61 if(event.type == ALLEGRO_EVENT_KEY_DOWN) 62 { 63 if(event.keyboard.keycode >= ALLEGRO_KEY_1 && event.keyboard.keycode <= ALLEGRO_KEY_6 ) 64 { // Loop for keyboard choice A ~ X 65 nEntry = event.keyboard.keycode-27; 66 bQuit = true; 67 } // end if for screen choice 68 } // end Key Down 69 } // end While 70switch(nEntry) // Setting up screen sizes - resolutions for a_init() 71 { 72 case 1: 73 nDispWD = 320; 74 nDispHT = 240; 75 break; 76 case 2: 77 nDispWD = 640; 78 nDispHT = 480; 79 break; 80 case 3: 81 nDispWD = 800; 82 nDispHT = 600; 83 break; 84 case 4: 85 nDispWD = 1200; 86 nDispHT = 800; 87 break; 88 case 5: 89 nDispWD = 1600; 90 nDispHT = 900; 91 break; 92 case 6: 93 nDispWD = mode.width; 94 nDispHT = mode.height; 95 break; 96 } //end switch 97 98 al_destroy_display(disp); 99 disp = al_create_display(nDispWD,nDispHT); 100 al_register_event_source(queue, al_get_display_event_source(disp)); 101 102 103 return; 104 105}// end screen size function

DanielH

You need to set the flags for fullscreen vs windowed when creating a new display.
al_set_new_display_flags()

AceBlkwell

Thanks Daniel I think I see the reason behind what you are saying. I was just playing around and shaving 80 to 100 off the 1080 (largest screen height picked up by DISPLAY_MODE) and seen the title bar is there, it's just not visible at 1080. The upper left hand corner of the window viewing area starts at 0,0, not the window itself.

I'm guessing the if you don't specify windowed as you indicated, the screen height and width, must represent the area within the window and not include the window attributes themselves. I only use the X in the title block but it would probably be the same with scroll bars and menus if you used them.

Just thinking out loud. Thanks Again.

DanielH

Yes, if you make it too big, the title bar will go off screen.

torhu

You can use ALLEGRO_FULLSCREEN_WINDOW as the graphics mode, and just scale the graphics to match that.

I use this code to scale my drawing so that it fills the screen without changing the aspect ratio:

#SelectExpand
1static void set_up_scaling() 2{ 3 ALLEGRO_TRANSFORM trans; 4 int display_w, display_h; 5 ALLEGRO_BITMAP *old; 6 7 old = al_get_target_bitmap(); 8 al_set_target_backbuffer(display); 9 10 al_identity_transform(&trans); 11 al_reset_clipping_rectangle(); 12 13 display_w = al_get_display_width(display); 14 display_h = al_get_display_height(display); 15 16 if (display_w != GFX_WIDTH || display_h != GFX_HEIGHT) { 17 int scaled_w, scaled_h, view_x, view_y; 18 float factor; 19 20 factor = MIN((float)display_w / GFX_WIDTH, (float)display_h / GFX_HEIGHT); 21 scaled_w = GFX_WIDTH * factor; 22 scaled_h = GFX_HEIGHT * factor; 23 view_x = (display_w - scaled_w) / 2; 24 view_y = (display_h - scaled_h) / 2; 25 26 al_clear_to_color(letterbox_color); 27 28 al_scale_transform(&trans, factor, factor); 29 al_translate_transform(&trans, view_x, view_y); 30 al_set_clipping_rectangle(view_x, view_y, scaled_w, scaled_h); 31 32 /* Logging */ 33 logfile("Display is %dx%d", display_w, display_h); 34 logfile("Scaling to %dx%d", scaled_w, scaled_h); 35 logfile("Image top left: x=%d, y=%d ", view_x, view_y); 36 LOGSKIP(); 37 } 38 39 al_use_transform(&trans); 40 al_set_target_bitmap(old); 41}

AceBlkwell

Thanks torhu,

My original attempts with FULLSCREEN (and WINDOW) did change the program screen as expected. However, the program itself didn't scale to match.

If I set the screen size to a specific / numeric size I could get the program to scale proportionally. The issue came with the mouse position in relation to the cards/blocks on screen. When the mouse button was pressed to flip the card, the card was no longer in the original location or size. I figured out a way to scale the mouse by put in an offset based on screen size.

I think your solution will make that a lot easier. I'll read up on transforming I haven't used it before. Or clipping for that matter. Thanks again.

torhu

The issue came with the mouse position in relation to the cards/blocks on screen. When the mouse button was pressed to flip the card, the card was no longer in the original location or size. I figured out a way to scale the mouse by put in an offset based on screen size.

I haven't tried using mouse input with this way of scaling, but I assume it would just be something like this:

ALLEGRO_TRANSFORM inverse_trans;
float unscaled_x, unscaled_y;

al_copy_transform(&inverse_trans, &drawing_trans);
al_invert_transform(&inverse_trans);
al_transform_coordinates(&inverse_trans, &unscaled_x, &unscaled_y);

APPEND:
Need to set x and y to the coordinates from the mouse event first, of course.

AceBlkwell

Thanks torhu,

Again, I really need to investigate TRANSFORM. I'm going to look it over today.

Meanwhile here is the short of what I am doing. The opening screen is set at 640x480. It has Play & Quit buttons. For simplicity sake, lets say upper left of Play is 50,50 and lower right is 100,100. The Quit button is at 50,120 by 100,170.

When the screen is set to a different size, say 800x600, and I do a al_draw_scaled_bitmap, the buttons are no longer at those coordinates. When the mouse button is pressed, & I look to see if it's between 50,50 x 100,100, nothing happens.

What I do is (ht_percentage = screen height / buffer height) & the same for width. The ht_percentage and wd_percentage are multiplied by the original 50,50 x 100,100. This give me the new location of the buttons. I do this as well for the card locations in the game.

I'm sure there is a better way of doing this but I couldn't find it.

Thanks again for the insight.

Edgar Reynaldo

Ace, the gist of what you are doing is applying world transformations.

When you place your button at 50,50 that is world space. When you make your display larger than normal, that is screen space. You need a way to translate from screen space to world space and back.

In this case all you had to do was scale and unscale the mouse for the button coordinates.

I hope this makes it a little clearer.

AceBlkwell

That is clearer Edgar, and sounds a lot simpler. I'll look into it. I do scale the buffer, make sense there would be an option to do this for the mouse.

Edgar Reynaldo

You just create a transform to move from world to screen coordinates. Then you invert that transform and apply it to your mouse coordinates to get their position on the world.

Thread #618882. Printed from Allegro.cc