Center primitive after resize

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:

1int resolution = al_show_native_message_box(window, "Change resolution", "800x600?", 2 "Do you really want to change resolution?", "Of course!|No", 3 4ALLEGRO_MESSAGEBOX_YES_NO); 5 6 if(resolution == 1) 7 { 8 width = width + 300; 9 height = height + 500; 10 al_resize_display(window, height, width); 11 al_flip_display(); 12 }

jmasterx

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

Trent Gamblin

Are you recalculating width, height, x and y after resizing the display?

Yes, i have to, because it doesnt work too.

Trent Gamblin
```    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.

jmasterx

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);
```