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 / Line Creation

Author
Message
vorconan
17
Years of Service
User Offline
Joined: 4th Nov 2006
Location: Wales
Posted: 11th May 2007 00:31 Edited at: 11th May 2007 00:32
Hi,

I'm creating an art program (my first major program) except I have immediately run into a problem, I have 2 tools working, but my line tool isn't, I'm afraid to say.

Here is the code



I assumed that when the mouse was first clicked it would store the positions in variables which would be used as x1 and y1.Then the second mouse click would use the current mouse position as the x2 and y2 co-ordinates. But with this code, the line always starts at the position 0,0. It ends in the current mouse position fine, just that starting problem.

Any help would be greatly appreciated, thanks.

Edit - The mousex()>30 is only there because I have a toolbar on the left side of the screen.
Soldier X1
18
Years of Service
User Offline
Joined: 10th Oct 2005
Location:
Posted: 11th May 2007 00:36 Edited at: 11th May 2007 00:37
Looks to me like you are assigning values to functions...

should be...


Let me know if that helped.
vorconan
17
Years of Service
User Offline
Joined: 4th Nov 2006
Location: Wales
Posted: 11th May 2007 00:40
Thanks for the effort but unfortunately the line doesn't even appear now.
Soldier X1
18
Years of Service
User Offline
Joined: 10th Oct 2005
Location:
Posted: 11th May 2007 00:58 Edited at: 11th May 2007 01:03
Perhaps the problem is that you aren't getting two different mouse clicks... I say loop it and then after you have two mouse clicks then have the code that draws the line.

Ya see what happend first is that omxp and omyp is zero so that is why it started at 0,0... now with the modified code I gave you are now just getting like a dot because omxp and the other is the same as mousex() and y so you need to get a second mouse click and it should work.
Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 11th May 2007 01:17
Try something like this...



This is untested code, i'll try it out once arrived at home, and update accordingly.
The main problem might be that omxp and omyp are local variables, so they lose the value after exiting the function. The second reason is that it enters the second "if mouseclick()" as the program continues on without waiting for another instruction, such as the click of the mouse.

If you need a better explanaition of it, just ask. Hope it helps...

Further on my stuff at...
vorconan
17
Years of Service
User Offline
Joined: 4th Nov 2006
Location: Wales
Posted: 11th May 2007 01:29
No, it didn't work. Thanks for the try though. I really don't see how this isn't working, just wondering as well Zergei, why do you suggest that omxp and omyp have to be global variables? They are called within the function, I don't seem to grasp the idea. Thanks again.
Soldier X1
18
Years of Service
User Offline
Joined: 10th Oct 2005
Location:
Posted: 11th May 2007 02:05 Edited at: 11th May 2007 02:06
I haven't tested this but try it anyway...

Let me know if that works.
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 11th May 2007 02:35
@ vorconan

Try this code, I have tested it and it works:



The error checking for only drawing a line if oxmp>30 does not work correctly all the time and will need some revision.

The program will draw lines between two points that you click with the mouse. If you rem out the last three lines of the linetool function, the program will draw from the end point of the last line you drew.

Good luck on your project.

LB
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 11th May 2007 02:36


TDK_Man

Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 11th May 2007 03:02 Edited at: 11th May 2007 05:55
Sorry about that, i just copied your code and forgot to correct one part of it.



Some of the other ones code seem possible, however they all sugest to stop the program from continuing on.
Again, once i reach home, i'll open dbpro and test it, as i already done a line drawing program.

Further on my stuff at...
aluseus GOD
17
Years of Service
User Offline
Joined: 19th Mar 2007
Location: I\'m here. Now I\'m there. I keep moving
Posted: 11th May 2007 04:23
In case you want to know why your code didn't work, its because it will only make a line from a mouseclick if you are all ready pressing the mouse, which creates a dot line.

I will Learn to rule 2d. Someday...
Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 11th May 2007 06:00
Ok, this is the code i just tested, and it works fine, thought it can be better, at least its a start.



Further on my stuff at...
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 11th May 2007 07:46
I know the routine I posted wasn't a function, but it was only to demonstrate the method. It could very easily have been converted.

It also has the advantage that it's called only once, is self contained - and probably a little faster.

But, you have either not noticed I posted it or have chosen to completely ignore it.

TDK_Man

Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 11th May 2007 13:49
Quote: "But, you have either not noticed I posted it or have chosen to completely ignore it."


The 2nd one. Sorry, it was 2 am and i had to be quick on what i read.
But what i see as a problem there, is that it is self contained, thus if i'd needed to work outside of it on everyloop, say to refresh something else, it would be bothersome. It can be worked around, thought.

Further on my stuff at...
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 11th May 2007 15:35
:/ you'd just call it every loop...

vorconan
17
Years of Service
User Offline
Joined: 4th Nov 2006
Location: Wales
Posted: 11th May 2007 18:23 Edited at: 11th May 2007 18:47
Thanks everybody, I didn't expect such a large response.

@Zergei - Can I ask why you put drawing as boolean at the beginning?

@TDK - That was helpful code man, thanks alot.

@LBFM - Thanks for that code too, that last extra you put in will help.

I'm going to try these different methods out and see which one will run the best. Thanks a lot everyone.

Edit - Just tested Zergei's Method, nice one. The only problem I found is that the first line you draw starts by the top left, not 0,0, more like 0,30. I'll try and fix it.

Edit 2 - TDK, just tested the code, it's a brilliant line dragging code, I think I may go with it. The only problems I've found, are that the toolbar disappears every time I try to draw a line, then comes back again. And if I clear the screen while using a different tool, then use the linetool again, the lines reappear that I made before, bit weird, despite all that, good code man.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 11th May 2007 20:55 Edited at: 11th May 2007 21:00
Quote: "The only problems I've found, are that the toolbar disappears every time I try to draw a line, then comes back again."


That's only down to where you grab the background image. Just move it to a point after where the toolbar is visible so it gets grabbed too.

The down side is that doing this you could draw over the toolbar, so it might be better to hide it and put it back after drawing.

You also get full screen drawing that way - as an added bonus!

The trick is to have one image that always contains the background image - use a variable to do this:

BackGroundImg = 1000

Then, in every drawing routine, as soon as you have put something on the screen, use:

Get Image BackGroundImg,0,0,ScrnWidth,ScrnHeight

In every routine where you are using 'rubber-band' drawing tools - like the circle or the line example I posted, you would use:

Paste Image BackGroundImg,0,0

Copying this image at any time gives you the ability to add an Undo function by simply pasting the backup image and grabbing it as the new background image.

TDK_Man

vorconan
17
Years of Service
User Offline
Joined: 4th Nov 2006
Location: Wales
Posted: 11th May 2007 21:01
The full screen drawing is good thanks.
Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 12th May 2007 02:30
Again here's an updated version. This time i was awake enough to know what i was writing...



Quote: ":/ you'd just call it every loop..."


If that went on me, well, yes. But thats not what i was arguing on the otherones code. My point was that the program only stood in the line sequence without exiting and doing something else in the meantime(is meantime it written like this?).


Quote: "
@Zergei - Can I ask why you put drawing as boolean at the beginning?"


Reason is that i wanted that variable to distinguish when on is on drawing mode and when not. As only 2 states will it represent, i decided to make it a boolean.

Quote: "The only problem I found is that the first line you draw starts by the top left, not 0,0, more like 0,30. I'll try and fix it."


That was due to the "if" statement i left from your codes left over. Trying to fix something on your own will lead you to great understanding of things. Keep up that spirit and the good work of course.

Quote: "TDK, just tested the code, it's a brilliant line dragging code,"


It sure is, thats why i tried to best mine.

@TDK - Have you came up whith another method than just the "get image" and "paste image". I've been thinking of memblocks, and other things, but thought i might just ask.

Further on my stuff at...
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th May 2007 03:43
No, I've never looked at doing it with memblocks - I just wanted to keep the above example as short and simple to follow as possible.

I've also done it exactly the same way in the past, but only grabbing the screen below the line itself which is a tiny bit faster. If you are trying to grab that extra little but of speed out of it then grabbing the whole screen could be considered slow.

TDK_Man

Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 12th May 2007 06:09 Edited at: 12th May 2007 06:18
Yet another update. Taking into consideration what TDK said, this version is a bit faster than the previous one (when doing small lines, not whith screenwide lines), as it grabs a smaller portion of the screen.



Quote: "I've also done it exactly the same way in the past, but only grabbing the screen below the line itself which is a tiny bit faster. If you are trying to grab that extra little but of speed out of it then grabbing the whole screen could be considered slow."


I got that idea some time ago, but didn't try it out as i was thinking on doing it whith memblocks. Also, the fact that with big lines it will be the same quite discouraged me of doing so, and thinking of another alternative.

Further on my stuff at...
vorconan
17
Years of Service
User Offline
Joined: 4th Nov 2006
Location: Wales
Posted: 12th May 2007 11:09 Edited at: 12th May 2007 11:11
@Zergei

That's incredible, thanks so much. I'm learning a lot from you and TDK's codes, thanks again. This project is definetely going ahead now that the line tool is working. I hope this thread will be useful to others aswell.

Thanks

Login to post a reply

Server time is: 2024-09-26 22:44:03
Your offset time is: 2024-09-26 22:44:03