Jump to content

screen center


cassius
 Share

Recommended Posts

I need more help on this if possible. I used context->GetHeight(); etc but now the dialog ( image) is showing in the lower right side of the screen

 

if (title_on)

{

int w = context->GetWidth();

int h = context->GetHeight();

context->SetBlendMode(Blend::Solid);

context->DrawImage(title, w/2, h/2);

}

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

if (title_on)

{

 

 

context->SetBlendMode(Blend::Solid);

 

context->DrawImage(title, 0, 0, context->GetWidth()/2, context->GetHeight() / 2);

 

}

 

This displays image top left of screen which is better but I want it in the middle.

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

You have to take into account the width/height of the image as well if you are trying to center it.

 

so essentially (psuedocode):

context_w = Context:GetWidth()

context_h = Context:GetHeight()

image_w = Texture:GetWidth()

image_h = Texture:GetHeight()

Context:DrawImage( image, (context_w - image_w) / 2 , (context_h - image_h) / 2, image_w, image_h )

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

if (title_on)

{

 

 

context->SetBlendMode(Blend::Solid);

 

context->DrawImage(title, 0, 0, context->GetWidth()/2, context->GetHeight() / 2);

 

}

 

This displays image top left of screen which is better but I want it in the middle.

 

It's in the top left corner because you are telling it to draw "title" at position 0,0 and its size is half the screen width and half the screen height.

For top of the centre of screen - title,W/2,0

For middle of screen - title, w/2,h/2

Rember that this is where the image will start to draw from so you may need to factor an offset so that the size of the image is accounted for.

If you check out Aggrors project Saturn health bar he explains it well.

Hope this helps.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...