Programming 2D Games

The official forum for "Programming 2D Games" the book by: Charles Kelly

It is currently Sun Oct 22, 2017 9:47 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Moveable dialog boxes
PostPosted: Mon Jun 19, 2017 9:34 pm 
Offline

Joined: Wed Mar 22, 2017 10:33 pm
Posts: 14
Hi. Right now i am working on dialog boxes. I think its a shame that you cannot move them, so i decided to try to code this into the dialog box. So, in the update for dialog box, i added this:

if (input->getMouseX()*screenRatioX >= topBar.left &&//if moving
input->getMouseX()*screenRatioX <= topBar.right &&
input->getMouseY()*screenRatioY >= topBar.top &&
input->getMouseY()*screenRatioY <= topBar.bottom)

{
visible = true;

x = x+input->getMouseRawX();
y = y+input->getMouseRawY();
prepareVerts();
print(text);
input->clear(inputNS::MOUSE);


}
topBar is a rect that i made by myself, which goes on the top and is as wide as border+margin. so, i am trying to make it easier to adjust the dialog window, but it is very buggy . When i try to move the dialog by clicking and dragging, the mouse will stop being over the topBar and therefore stop setting X and Y for the dialog box. What is wrong? I will provide the files and the exe if you want . Thanks. AND, the text does not move with the dialog box. Whats up wtih that?


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 20, 2017 6:14 pm 
Offline

Joined: Wed Mar 22, 2017 10:33 pm
Posts: 14
I still need help with the moveable bit, but i did fix the textRect acting up and the text not moving. Here is the updated version:

if (input->getMouseX()*screenRatioX >= topBar.left &&//if moving
input->getMouseX()*screenRatioX <= topBar.right &&
input->getMouseY()*screenRatioY >= topBar.top &&
input->getMouseY()*screenRatioY <= topBar.bottom)

{
visible = true;

x = x+input->getMouseRawX();
y = y+input->getMouseRawY();
prepareVerts();
textRect.left = (long)(x + messageDialogNS::MARGIN);
textRect.right = (long)(x + messageDialogNS::WIDTH - messageDialogNS::MARGIN);
textRect.top = (long)(y + messageDialogNS::MARGIN + messageDialogNS::BORDER);
textRect.bottom = (long)(y + messageDialogNS::HEIGHT - messageDialogNS::MARGIN);
dxFont.print(text, textRect, DT_CENTER | DT_WORDBREAK | DT_CALCRECT);
height = textRect.bottom - (int)y + messageDialogNS::BORDER + messageDialogNS::MARGIN;
// print(text);
input->clear(inputNS::MOUSE);


}


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 20, 2017 6:18 pm 
Offline
Site Admin
User avatar

Joined: Sat Jan 28, 2012 4:36 pm
Posts: 542
I'm working on Win2D text display for my next book at the moment. Movable text boxes are next on the list. May be a day or two before I can get to it.

_________________
Professor Kelly


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 26, 2017 8:45 pm 
Offline
Site Admin
User avatar

Joined: Sat Jan 28, 2012 4:36 pm
Posts: 542
Here is my code for a moveable dialog box. I may have changed multiple files as I was working on this. Now that I think about it I'm not sure which version of the game engine I started with so you should do a careful comparison of the files to make sure everything is correct.
http://www.programming2dgames.com/chapter9/messageDialogMoveable.zip

The WinMerge application is handy for comparing source files.

_________________
Professor Kelly


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group