Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I want to get back into coding...FB starter's help please?
#11
Hey Zack, WB!

Im Dark_Prevail, if you were wondering
Reply
#12
Hey Zack! WB!!!
I'm Whitetiger0990, if you were wondering.
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#13
Quote:
Zack Wrote:First, why doesn't the old QBASIC trick for detecting arrow keys work? I mean the old IF k$=CHR$(0) + CHR$(77) THEN rightArrowPress=1 thing. I tried it, it didn't work.
http://www.freebasic.net/forum/viewtopic.php?t=1807

Quote:Secondly...when I draw in the program, if I move the mouse cursor too fast across the canvas, instead of drawing a smooth line, it draws a broken line. Now I suspect it's because the mouse cursor moves past the spot where you want to draw before the code registers that it was ever there. But I might be wrong. In either case, I don't know how to fix it. Can anyone help?
You'll have to draw a line from point to point. Which in your case means drawing a 3-pixel thick line from point to point.
That link didn't really explain much to me...either that or I just didn't understand it. Perhaps I should rephrase: how do I detect arrow keypresses in FB?
On the second topic: I suspected that. But I'm not sure how to engineer it. I'll have to experiment. Thanks.

Hey dp, what's new? Big Grin
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#14
http://www.freebasic.net/wiki/wikka.php?...keypginkey

I thought it was explained quite well.
stylin:
Reply
#15
I guess I needed it in fewer words.
I see now. Replace CHR$(0) with CHR$(255). Thank you!
Now I still have to engineer the line-drawing thing. Any tips? I can't seem to wrap my head around it. I'm thinking that somehow I need to make the program "remember" if in the last loop iteration the mouse button was pressed, and if so draw a line from the last dot to the new position.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#16
Quote:.....
First, why doesn't the old QBASIC trick for detecting arrow keys work? I mean the old IF k$=CHR$(0) + CHR$(77) THEN rightArrowPress=1 thing. I tried it, it didn't work....l.
Ooops, another FB gotcha.
As you know, Arrow keys and others like Home, Page-Up, etc. are extended characters. In QB when you do an INKEY$ of an extended character, you get 2 characters in, the first of which is CHR$(0) to identify the second character as extended. In FB, you get a CHR$(255) first. No big deal once you know.

Welcome back, Zack!
*****
Reply
#17
Hey, Moneo!
Yeah I figured that out with stylin's help. Thanks.

And re the other bug. Fixed! I take the old x and y coords before I got the new ones, and then I draw a line from the oldX and oldY to the newX and newY. Thanks stylin!
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#18
The fixed code, if you're interested:
Code:
'CANVAZZ.BAS
'Written by Zack (VE3VYZ)
'Rudimentary sketching app.
'To draw, hold down the left mouse button and drag the mouse while inside the white canvas.
'Use the mouse wheel or left/right arrow keys to change colour.
'Click the Quit button to exit.

screen 19

'the quit button
line (702,20)-(785,58),2,b
line (707,25)-(780,53),2,b
paint (704,23),2,2
locate 3,92
print "Quit"

'the canvas area
line (80,100)-(720,550),2,b
line (79,99)-(721,551),2,b
line (78,98)-(722,552),2,b
paint (110,135),15,2

c=1 'default colour (blue)

'the in-app loop
do
k$=inkey$
'code to change colour, if desired. (left/right arrow keys)
if k$=chr$(255) + chr$(75) then c=c-1
if k$=chr$(255) + chr$(77) then c=c+1

'before the mouse status is updated, we need to store the previous iteration's values
oldwheelstatus=wheelstatus
oldx=x
oldy=y

getmouse x,y,wheelstatus,buttons   'get the mouse coords, wheel and button status
if oldwheelstatus <> wheelstatus then c=wheelstatus 'if wheel turned, change colour

'if you click while inside the canvas...
if buttons=1 then
    if ((x>80) and (x<720)) and ((y>100) and (y<550)) then
        line (oldx,oldy)-(x,y),c
    end if
end if
'if you click the quit button, end program:
if ((x > 707) and (x < 780)) and ((y > 25) and (y < 53)) and (buttons=1) then end

'if mouse is inside canvas, print x,y mouse coords, colour number and sample
locate 1,1
if ((x>81) and (x<719)) and ((y>101) and (y<549)) then
    print "X:";x-82;"       "
    print "Y:";y-102;"       "
    print "CLR:";c;"   "
    line (2,48)-(43,78),c,bf 'the box that shows the current colour
end if

'clear old mouse coords, colour number and sample in case cursor is moved out of canvas
if ((x<80) OR (x>720)) OR ((y<100) OR (y>550)) then
    line (0,0)-(300,80),0,bf
end if
loop
Next project: add line, box and circle capability. I might do a total rewrite and work it around lib with bitmap loading/saving, etc.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#19
Quote:Next project: add line, box and circle capability. I might do a total rewrite and work it around lib with bitmap loading/saving, etc.
A lib.. kind of like.. the standard FB lib? Tongue
Bload "mybmpfile.bmp"
Bsave "mybmpfile.bmp"

Just make sure to use the .bmp extension, and to bload into a properly dimensioned surface (array)
Reply
#20
Is there a reason for the CHR$(255) instead of CHR$(0), or just laziness?
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)