Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Custom Window help

Author
Message
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 12th Apr 2011 21:16 Edited at: 12th Apr 2011 21:55
Just trying to make some things for a GUI and though id start by making a window, then make it transparent, then make it move around when clicked on in a certain place, and move round with it till you let go but its that part im having trouble with.
Ive done buttons before and made a mouse click box, but this is stumping me getting the right maths as its not a fixed x, y co-ordinate. Can anyone help?



I tried an offset thing but that didnt work out so went back and tried smoe other stuff so there is alsorts in that above code thats more likely not necessary and lots missing that more likely is.
Images attached.

Edit: Ok i just thought of an easier way to do this so cleaned up the code by a lot and tried it but this too doesnt work. It doesnt seem happy about wether the mouse point is over the menu or not. Really cant fathom why setting the offset sprite at the mousex and y wouldnt work when then moving it, but it doesnt so i cant see whats going on exactly.

Attachments

Login to view attachments
Admiral MH
13
Years of Service
User Offline
Joined: 10th Feb 2011
Location: TX, USA
Posted: 13th Apr 2011 00:37
Here is the code with a few new things added.



Also offsetting sprites will only offset it from its original position. So if you had the code,



The sprite position will be 75.

Hope this helps. If you have any questions just let me know.
Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 14th Apr 2011 08:26
I was browsing DB Code Corner the other day and found this;

http://dbcodecorner.com/showcode.php?snippet=32

Check it out, hopefully it'll give you a good idea on how things can be done. I'm yet to pull it apart myself though.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 14th Apr 2011 15:35 Edited at: 14th Apr 2011 15:35
Thanks for the help guys. Ill take a look at that when i get home. @Burning Feet man - the example you posted does seem to do pretty much what im after if not more. I will maybe expand a mini demo to contain windows with sliding scrollers and that later on but for now this should do.

@Admiral MH - the reason i thought offsetting the sprite would work was somehow i was thinking (well my logic behind it was) whereever the mouse is when you click, thats the sprites offset, then move the window from the sprite offset to where ever the mouse X and Y is until you are not clicking (not holding down). I had good intentions but this is just not the way it is done. Ill have a play with the above code when i get home and see if i have any problems.

Between the help you guys have given i should be able to work out where i went wrong on this.


Thanks again.
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 14th Apr 2011 21:00
@Admiral MH
Just had a play around with that code and it works perfectly, its spot on thank you. Just wondering about what that mouseselectactive is doing exactly. I know it doesnt work without it but cant quite follow what its doing as such. Sorry fro the very simple question but i just cant work out quite why its there, why just mouseclick doesnt work. Thanks.
Admiral MH
13
Years of Service
User Offline
Joined: 10th Feb 2011
Location: TX, USA
Posted: 20th Apr 2011 01:04 Edited at: 20th Apr 2011 01:04
Quote: "Just had a play around with that code and it works perfectly, its spot on thank you. Just wondering about what that mouseselectactive is doing exactly. I know it doesnt work without it but cant quite follow what its doing as such. Sorry fro the very simple question but i just cant work out quite why its there, why just mouseclick doesnt work. Thanks. "


It took me a few minutes to figure out too. Here is what is going on.



The "MouseSelect_Active" variable is so it can get the window offset once. If you just had this "MenuX = MouseX()" then it would place the window at the mouse location. So to find the offset value you have. "MouseSelect_X = MouseX() - Sprite X(1)" What this does is that it takes the position of the mouse, then subtracts the sprites X position. Doing that will give you value to offset when you want to position your window.

You need the "MouseSelect_Active" variable so it can get the value to offset the window only once. If you remove it then it will get a new offset value every loop, and therefore when code is executed "MenuX = MouseX() - MouseSelect_X" then the sprite will remain in the same position.

Here is a example that might be helpful.



Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 20th Apr 2011 01:29
Ahhhh, i see now. Thank you. I am hoping to learn a lot more about windows and GUIs in the not so distant future and this was a nice little excersize for me.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Apr 2011 07:55
My GUI tutorial might help you with other aspects of the development:
http://dbcodecorner.com/?page=tutorials

The Internet: Where men are men, women are men, and children are federal agents
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 20th Apr 2011 09:43
Thanks Phaelax i had been looking at that a short while ago, i didnt realise that was yours. The only thing though is it literally ends with "We can’t have a GUI tutorial without discussing how to create a menu bar!" and thats it. Did you ever get round to finishing that guide off as it looks like a really good guide and i would love to read all of it. I know most of it is complete, certainly enough to give me a head start but i would still love to see it finished.

Thanks.

Login to post a reply

Server time is: 2024-11-24 04:31:06
Your offset time is: 2024-11-24 04:31:06