|
This thread is locked; no one can reply to it. |
1
2
|
Patch to add window constraint functions |
jmasterx
Member #11,410
October 2009
|
I have made a patch for the latest 5.1 svn that adds: void al_set_window_constraints(ALLEGRO_DISPLAY *display, int min_w, int min_h, int max_w, int max_h) and void al_get_window_constraints(ALLEGRO_DISPLAY *display, int *min_w, int *min_h, int *max_w, int *max_h ) to Windows, OSX, and X. It seems to be working fine on Windows. I have not tested it on OSX or Linux / X. Hopefully this can make it to the SVN I was unable to attach it through a.cc so I have uploaded it here: Edit: Edit2: Edit3 Edit4 Agui GUI API -> https://github.com/jmasterx/Agui |
torhu
Member #2,727
September 2002
|
pastebin.com would be a good place to upload something like this. |
Trent Gamblin
Member #261
April 2000
|
Do you have an example I can use to test it on OSX?
|
jmasterx
Member #11,410
October 2009
|
I tested it on Windows by modifying ex_resize: 1#include "allegro5/allegro.h"
2#include <allegro5/allegro_primitives.h>
3
4#include "common.c"
5
6static void redraw(void)
7{
8 ALLEGRO_COLOR black, white;
9 int w, h;
10
11 white = al_map_rgba_f(1, 1, 1, 1);
12 black = al_map_rgba_f(0, 0, 0, 1);
13
14 al_clear_to_color(white);
15 w = 100;
16 h = 100;
17 al_draw_line(0, h, w / 2, 0, black, 0);
18 al_draw_line(w / 2, 0, w, h, black, 0);
19 al_draw_line(w / 4, h / 2, 3 * w / 4, h / 2, black, 0);
20 al_flip_display();
21}
22
23int main(void)
24{
25 ALLEGRO_DISPLAY *display;
26 ALLEGRO_TIMER *timer;
27 ALLEGRO_EVENT_QUEUE *events;
28 ALLEGRO_EVENT event;
29 int rs = 100;
30 bool resize = false;
31
32 /* Initialize Allegro and create an event queue. */
33 if (!al_init()) {
34 abort_example("Could not init Allegro.\n");
35 return 1;
36 }
37 al_init_primitives_addon();
38 events = al_create_event_queue();
39
40 /* Setup a display driver and register events from it. */
41 al_set_new_display_flags(ALLEGRO_RESIZABLE);
42 display = al_create_display(640, 480);
43 if (!display) {
44 abort_example("Could not create display.\n");
45 return 1;
46 }
47 al_set_window_constraints(display,640,0,0,600);
48 al_register_event_source(events, al_get_display_event_source(display));
49
50 timer = al_create_timer(0.1);
51 al_start_timer(timer);
52
53 /* Setup a keyboard driver and register events from it. */
54 al_install_keyboard();
55 al_register_event_source(events, al_get_keyboard_event_source());
56 al_register_event_source(events, al_get_timer_event_source(timer));
57
58 /* Display a pulsating window until a key or the closebutton is pressed. */
59 redraw();
60 while (true) {
61 if (true) {
62 int s;
63 rs += 10;
64 if (rs == 300)
65 rs = 100;
66 s = rs;
67 if (s > 200)
68 s = 400 - s;
69 //al_resize_display(display, s, s);
70 redraw();
71 resize = false;
72 }
73 al_wait_for_event(events, &event);
74 if (event.type == ALLEGRO_EVENT_TIMER) {
75 resize = true;
76 }
77 else if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
78 break;
79 }
80 else if (event.type == ALLEGRO_EVENT_KEY_DOWN) {
81 break;
82 }
83 else if (event.type == ALLEGRO_EVENT_DISPLAY_RESIZE) {
84 al_acknowledge_resize(display);
85
86 }
87 }
88
89 return 0;
90}
91
92/* vim: set sts=4 sw=4 et: */
That way it is minimum restricted on the x axis and maximum restricted on the y, zero means no restriction. Now that I think about it, it may be nessesary to call al_resize_display(display, display->w, display->h) after to sync up the backbuffer. If you need to make changes to the patch to get OSX to work just let me know ad Ill edit the first post. Agui GUI API -> https://github.com/jmasterx/Agui |
Trent Gamblin
Member #261
April 2000
|
The patch has no effect on OSX. One thing that should be done here if you're going to fix this is to make these display options set with al_set_new_display_option. I don't think we need another function, that's what display options are for... someone correct me if I'm wrong.
|
jmasterx
Member #11,410
October 2009
|
I just went with what Matthew had suggested. It is possible that for certain scenarios that the user may want to change this after the display is created. I'll boot into OSX and try some things to see if I can get it working. Agui GUI API -> https://github.com/jmasterx/Agui |
Trent Gamblin
Member #261
April 2000
|
jmasterx said: I just went with what Matthew had suggested. It is possible that for certain scenarios that the user may want to change this after the display is created. Yeah, that is true.. so it's probably best as you have it.
|
jmasterx
Member #11,410
October 2009
|
FIXED IT . I forgot to actually assign the min and max values to the display -_-'. Edit: Unfortunately, I do not have Linux native installed. I only have it in a VM and I cannot seem to get an Allegro window created in the VM so I cannot test it for Linux. If someone could try it and report back It'd be appreciated. Agui GUI API -> https://github.com/jmasterx/Agui |
Trent Gamblin
Member #261
April 2000
|
I was checking to make sure the actual size of the window was exactly 640x600 and I got this image (attached). If you look at it closely you can see there are 3 pixels in each bottom corner that are transparent. Any idea why that would be?
|
jmasterx
Member #11,410
October 2009
|
I really do not know why that would happen. What did you use to capture the image? I'll try to reproduce it here. In the mean time, it seems that the OSX window does not sem to apply the constraints when al_resize_display is called, so I will try to address this. Edit: I do not know if this fixes your 3 pixel issue but it might since I fixed al_resize_display to work with constraints on osx. I guess I'll install Linux native on my PC and get the Linux version working properly so it can be committed today and I can forget about it and check it off my todo list. Agui GUI API -> https://github.com/jmasterx/Agui |
Matthew Leverton
Supreme Loser
January 1999
|
Trent Gamblin said: I don't think we need another function, that's what display options are for... someone correct me if I'm wrong. There's always a bit of a struggle between those who favor of monolithic options and those who favor explicit functions. I generally prefer explicit functions, so of course I suggested an explicit function. I think display options should be limited to those things that affect the creation of the display (or are very unlikely to ever be needed.) That is, here are a list of properties that I require or want, and let me know if you can create the display. It shouldn't be about minimizing the number of functions for the sake of minimizing functions. Constraints, IMO, do not fall under either of those restrictions and therefore do deserve a dedicated function. jmasterx said: In the mean time, it seems that the OSX window does not sem to apply the constraints when al_resize_display is called, so I will try to address this. So is al_resize_display() meant to be constrained? I don't know that it really needs to be, if it's not something that's easily supported. The main benefit of constraints is for abstract resizing from the user. |
jmasterx
Member #11,410
October 2009
|
It was easier to support constraining for al_resize_display. I just got done proper Linux support. With this new revision, all 3 platforms seem to show consistent results which means it should be pretty much ready for the svn, I've tested on all 3 platforms. Here it is: Agui GUI API -> https://github.com/jmasterx/Agui |
Peter Wang
Member #23
April 2000
|
al_set_window_constraints and al_get_window_constraints should return a boolean indicating success. Add documentation and fix the coding style please. It's not that hard. I still would like a constrain-aspect-ratio display flag. This might be a good time to add it.
|
jmasterx
Member #11,410
October 2009
|
How is failure determined? I did not think it was possible for it to fail? Agui GUI API -> https://github.com/jmasterx/Agui |
Matthew Leverton
Supreme Loser
January 1999
|
It might return false on full screen or on certain mobile devices, or if you send invalid parameters like -42 or a positive value that's too small. |
jmasterx
Member #11,410
October 2009
|
Then why doesn't al_set_window_position return success? You cannot move a window in fullscreen nor can you move it to a ridiculous place like -2000,-2000. Agui GUI API -> https://github.com/jmasterx/Agui |
Peter Wang
Member #23
April 2000
|
It should, too. Not everything was scrutinised as it might have been when 5.0 was developed.
|
jmasterx
Member #11,410
October 2009
|
So then I should return false on unsupported platforms, if any of the values are < 0 and return false if the fullscreen flag is set? Are there any other ways it can fail? For the documentation I'll add more comments. I'm not sure how to address coding style. What needs to change? Would you rather: if(something) { x = something; } else { x = something_else; } over if(something) x = something; else x = something_else; Do you think this functionality will make it into 5.05? I and I'm sure others would find it useful to add to their current projects. Agui GUI API -> https://github.com/jmasterx/Agui |
Peter Wang
Member #23
April 2000
|
Max might be smaller than min? Maybe some platforms have other restrictions, e.g. must be multiple of four. Documentation means adding text to docs/src/refman/display.txt For code style, just look at the code around you: K&R with 3 space indents (no hard tabs in new code), and no cuddled else. Space after if, while, for, etc. keywords. I prefer lines wrapped at 80 chars; this is mandatory for code which is copied into documentation (e.g. prototypes after Function: headers). Capitalise and punctuate comments. For your example: if (something) { x = something; } else { x = something_else; }
|
SiegeLord
Member #7,827
October 2006
|
jmasterx said: For the documentation I'll add more comments. Comments are not documentation. You need to document the functions in docs/src/refman/display.txt Quote: I'm not sure how to address coding style. I've noted three things. You used tabs instead of spaces (Allegro source uses 3 spaces per indentation level). You've used C++ comments in C files (// instead of /* */) Also, use attached braces, like so: if (blah) { } instead of if (blah) { }
"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
jmasterx
Member #11,410
October 2009
|
Alright, I'll see if I can address those issues. I've gotten too used to auto formatting by the IDE. I've never coded in pure C, so this is a new experience for me. Edit: It should be good for the svn now. Here is the link: Edit2: Thanks Agui GUI API -> https://github.com/jmasterx/Agui |
SiegeLord
Member #7,827
October 2006
|
Well, the patch still has hard tabs in quite a few places. Surely your IDE has an option to show whitespace? The actual reason is probably the people are a bit busy . "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Trent Gamblin
Member #261
April 2000
|
We need a new example for this. You can start with ex_resize2. Hook it up in cmake. Still need to know why those pixels are missing too. But yeah, it's just people being busy.
|
jmasterx
Member #11,410
October 2009
|
Alright, tonight or tomorrow I'll try to address those issues. Agui GUI API -> https://github.com/jmasterx/Agui |
torhu
Member #2,727
September 2002
|
MSVC has an untabify command on the Edit->Advanced menu. And you can press Ctrl-Shift-8 to show whitespace. |
|
1
2
|