![]() |
|
Resize window |
AleX-G Squadron
Member #13,593
October 2011
![]() |
I am having problem catching the ALLEGRO_MESSAGEBOX_YES_NO return value. Here is the code i have made. 1int resize = ALLEGRO_MESSAGEBOX_YES_NO;
2
3 int box = al_show_native_message_box(display, "Change display", "Are you sure?",
4 "Do you want to change your display to 600x600?", "Of course|No", resize);
5
6 if(resize == 1)
7 {
8 al_resize_display(display, 600, 600);
9 }
www.anothergames.com |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
int resize; resize = al_show_native_message_box(display, "Change display", "Are you sure?", "Do you want to change your display to 600x600?", "Of course|No", ALLEGRO_MESSAGEBOX_YES_NO); if(resize == 1) { al_resize_display(display, 600, 600); }
They all watch too much MSNBC... they get ideas. |
AleX-G Squadron
Member #13,593
October 2011
![]() |
I tried it but i get this error on visual studio 2012 {"name":"606487","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/4\/0409376e1c55faeb0c7fcd20ac88a3b6.png","w":441,"h":319,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/4\/0409376e1c55faeb0c7fcd20ac88a3b6"} www.anothergames.com |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
Your 'display' pointer is bad, but you didn't get this error before because ALLEGRO_MESSAGEBOX_YES_NO isn't equal to 1, so the al_resize_display() was never called. They all watch too much MSNBC... they get ideas. |
AleX-G Squadron
Member #13,593
October 2011
![]() |
This is my display pointer. Is it bad? Even if i change its parameters to It will show an error on the first parameter www.anothergames.com |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
AleX-G Squadron said: This is my display pointer. Is it bad? ALLEGRO_DISPLAY *display = NULL; It shouldn't be NULL after you've successfully created a display with it. [EDIT] You need to create a display to resize it. 1#include <allegro5/allegro.h>
2#include <allegro5/allegro_native_dialog.h>
3
4int main(int argc, char **argv)
5{
6 ALLEGRO_DISPLAY *display = NULL;
7 ALLEGRO_DISPLAY_MODE desktop;
8
9 ALLEGRO_EVENT_QUEUE *queue;
10 ALLEGRO_TIMER *timer;
11 ALLEGRO_EVENT event;
12 ALLEGRO_PATH *path;
13 int window_width = 100;
14 int window_height = 100;
15 int resize;
16 int quit = 0;
17
18 if(!al_init())
19 {
20 al_show_native_message_box(display, "Error", "Failed to initialize Allegro", "", NULL, 0);
21 return 1;
22 }
23
24 //If user runs it from somewhere else...
25 path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
26 al_change_directory(al_path_cstr(path,ALLEGRO_NATIVE_PATH_SEP));
27
28 al_install_keyboard();
29 al_get_display_mode(0, &desktop);
30 al_set_new_window_position((desktop.width-window_width)/2,(desktop.height-window_height)/2);
31
32 display = al_create_display(window_width,window_height);
33 if(!display)
34 {
35 al_show_native_message_box(display, "Error", "Unable to set display mode", "", NULL, 0);
36 return -1;
37 }
38
39 al_set_target_backbuffer(display);
40
41 al_install_mouse();
42
43 timer = al_create_timer(1. / 60.);
44
45 queue = al_create_event_queue();
46 al_register_event_source(queue,al_get_keyboard_event_source());
47 al_register_event_source(queue,al_get_display_event_source(display));
48 al_register_event_source(queue,al_get_timer_event_source(timer));
49 al_register_event_source(queue, al_get_mouse_event_source());
50 al_hide_mouse_cursor(display);
51
52 resize = al_show_native_message_box(display, "Change display", "Are you sure?",
53 "Do you want to change your display to 600x600?", "Of course|No", ALLEGRO_MESSAGEBOX_YES_NO);
54
55 if(resize == 1)
56 {
57 window_width = 600;
58 window_height = 600;
59 al_set_new_window_position((desktop.width-window_width)/2,(desktop.height-window_height)/2); //doesn't work here???!!
60 al_resize_display(display, window_width,window_height);
61 }
62 al_start_timer(timer);
63
64 while(quit == 0)
65 {
66 al_wait_for_event(queue, &event);
67 switch(event.type)
68 {
69 case ALLEGRO_EVENT_DISPLAY_CLOSE:
70 quit = 1;
71
72 case ALLEGRO_EVENT_KEY_DOWN:
73 if(event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
74 quit = 1;
75 break;
76
77 case ALLEGRO_EVENT_TIMER:
78 if(al_is_event_queue_empty(queue))
79 {
80 al_flip_display();
81 }
82 break;
83 }
84 }
85
86 al_destroy_display(display);
87 display = 0;
88
89 return 0;
90}
They all watch too much MSNBC... they get ideas. |
AleX-G Squadron
Member #13,593
October 2011
![]() |
I got it to work, but i get a weird thing in the display Edit: I didnt get this error with your code {"name":"606488","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/e\/ee68b60bdb4ade90c9d5119dd2d2d1b9.png","w":301,"h":394,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/e\/ee68b60bdb4ade90c9d5119dd2d2d1b9"} www.anothergames.com |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
I edited my previous post just when you were posting. Save your code to something else temporarily and try what I posted. It worked OK for me except the window always went to lower right corner of desktop, whether the al_set_new_window_position() was above the resize or not. They all watch too much MSNBC... they get ideas. |
AleX-G Squadron
Member #13,593
October 2011
![]() |
Very weird errors indeed. I will try to find what is the problem with the programs. Also, when executing your code, it shows in the center of my screen, so it works perfect! Still, i cannot understand why i get that white think EDIT: i got it to work, but i used 2 times the al_flip_display(); Here is my code 1#include <allegro5\allegro.h>
2#include <allegro5\allegro_native_dialog.h>
3
4int main (void)
5{
6 al_init();
7
8 ALLEGRO_DISPLAY *window = al_create_display(200, 300);
9
10 al_flip_display(); // First time!
11
12 int resize = al_show_native_message_box(window, "Change display", "Are you sure?",
13 "Do you want to change your display to 600x600?", "Of course|No", ALLEGRO_MESSAGEBOX_YES_NO);
14
15 if(resize == 1)
16 {
17 al_resize_display(window, 600, 600);
18 al_flip_display(); // Second time!
19 }
20
21 al_rest(3.0);
22
23 al_destroy_display(window);
24}
Actually, i was thinking if the user, can specify himself the resolution using a text box, or maybe two. Is it possible? www.anothergames.com |
|