I am having some problems centering a primitive after i resize the window using a native dialog box. It will work only if i put 1:1 ratio resolutions such as 300x300 or 500x500, otherwise the primitive object wont be at the center. I want to use a resolution of 800x600 and make the primitive appear at the center. How am i supposed to do that? Here is the logic i am using:
Can you show the code that draws the primitive (a messagebox is not a primitive).
It is a triangle:
al_draw_triangle(x,y-15,x-15,y+15,x+15,y+15,al_map_rgb(0,255,0),2.0);
x is width/2 and y is height/2
Are you recalculating width, height, x and y after resizing the display?
Yes, i have to, because it doesnt work too.
width = width + 300; height = height + 500;
That looks suspicious. Are you starting out with a 500x100 window?
EDIT: Instead of playing detective, just show the whole code.
To draw an isosceles triangle of width W and height H at center cx, cy:
cx = al_get_display_width / 2; cy = al_get_display_height / 2; p1.x = cx; p1.y = cy - (H / 2.0f); p2.x = cx - (W / 2.0f); p2.y = cy + (H / 2.0f); p3.x = cx + (W / 2.0f); p3.y = cy + (H / 2.0f);
I changed some things but the idea is exactly the same
al_resize_display takes the width parameter before the height parameter...