|
Post by crob1974 on Jul 30, 2018 9:25:21 GMT
Hi, I have written a small program using Just Basic and wondered if anyone could help. I would like it to function as follows:
- The lines move (vertically and horizontally) following the mouse a bit like a cross hair but permanently fixed to the top, bottom, left and right of the screen.
At the moment it keeps re-drawing the lines. I have tried flush, cls & discard (now removed from code) but don't really understand their properties.
Any help with the refresh would be appreciated, I would like the lines to move with the mouse rather than duplicate.
Thank you.
' Mouse moves line (+)
nomainwin open "Click left or right" for graphics_nsb_fs as #w print #w, "trapclose [Quit]" print #w, "When mouseMove [mm]" wait
[mm] mx1$ = "";MouseX my1$ = "";MouseY print #w, "home" print #w, "down" print #w, "color black" print #w, "line "; mx1$; " ";0000; " ";mx1$; " ";0768 print #w, "line "; 0000; " ";my1$; " ";1366; " ";my1$ wait
[Quit] close #w end
|
|
|
Post by tsh73 on Jul 30, 2018 13:08:07 GMT
Just use CLS
' Mouse moves line (+)
nomainwin open "Click left or right" for graphics_nsb_fs as #w print #w, "trapclose [Quit]" 'set it first print #w, "down" print #w, "color black" print #w, "When mouseMove [mm]" wait
[mm] mx1$ = "";MouseX my1$ = "";MouseY print #w,"cls" 'clear 'and redraw print #w, "line "; mx1$; " ";0000; " ";mx1$; " ";0768 print #w, "line "; 0000; " ";my1$; " ";1366; " ";my1$ wait
[Quit] close #w end
|
|
|
Post by crob1974 on Jul 30, 2018 14:09:51 GMT
tsh73: Thank you that worked great....
Quick question, if I was to put an image on the screen then have the cross hair moving over the image would the 'cls' command clear the image?
If so how would I get around that ?
|
|
|
Post by tsh73 on Jul 30, 2018 20:32:43 GMT
attempt #1
draw a BG flush it as named segment on each mouseMove, redraw that segment (clearing old cross) - flickers like mad on my machine. YMMV.
nomainwin
open "untitled" for graphics_nsb_fs as #w 'full screen #w "trapclose [quit]" #w "down; home" #w "posxy cx cy" 'after home it gives center 'print cx, cy 'so 2*cx, 2*cy is drawing area
'get a bitmap fname$="sprites\bg1.bmp" call GetBmpDimensions fname$, bmpWidth, bmpHeight 'print bmpWidth, bmpHeight loadbmp "bg", fname$
'tile for y = 1 to 2*cy step bmpHeight for x = 1 to 2*cx step bmpWidth #w "drawbmp bg ";x;" ";y next next
#w "flush BG"
#w "When mouseMove [mm]" #w "color black"
wait
[mm] mx1 = MouseX my1 = MouseY print #w, "redraw BG" print #w, "line "; mx1; " ";0; " ";mx1; " ";cy*2 print #w, "line "; 0; " ";my1; " ";cx*2; " ";my1 wait
[quit] close #w end
'Custom function from FreeForm GUI editor (shiped with JB, check it out ' menu Run | FreeForm GUI editor
sub GetBmpDimensions fileName$, byref width, byref height open fileName$ for input as #gbd temp$ = input$(#gbd, 24) close #gbd width = asc(mid$(temp$, 19, 1))+asc(mid$(temp$, 20, 1))*256 height = asc(mid$(temp$, 23, 1))+asc(mid$(temp$, 24, 1))*256 end sub
|
|
|
Post by tsh73 on Jul 30, 2018 20:36:29 GMT
Attempt#2 RULE XOR works like a charm (don't forget to set RULE NORMAL then start drawing something)
nomainwin
open "untitled" for graphics_nsb_fs as #w 'full screen #w "trapclose [quit]" #w "down; home" #w "posxy cx cy" 'after home it gives center 'print cx, cy 'so 2*cx, 2*cy is drawing area
'get a bitmap fname$="sprites\bg1.bmp" call GetBmpDimensions fname$, bmpWidth, bmpHeight 'print bmpWidth, bmpHeight loadbmp "bg", fname$
'tile for y = 1 to 2*cy step bmpHeight for x = 1 to 2*cx step bmpWidth #w "drawbmp bg ";x;" ";y next next
#w "flush"
#w "When mouseMove [mm]" #w "color black" #w "rule xor"
wait
[mm] 'second draw on same coords clears it. So this one is clear print #w, "line "; mx1; " ";0; " ";mx1; " ";cy*2 print #w, "line "; 0; " ";my1; " ";cx*2; " ";my1 'new coords mx1 = MouseX my1 = MouseY 'draw at new coords print #w, "line "; mx1; " ";0; " ";mx1; " ";cy*2 print #w, "line "; 0; " ";my1; " ";cx*2; " ";my1
wait
[quit] close #w end
'Custom function from FreeForm GUI editor (shiped with JB, check it out ' menu Run | FreeForm GUI editor
sub GetBmpDimensions fileName$, byref width, byref height open fileName$ for input as #gbd temp$ = input$(#gbd, 24) close #gbd width = asc(mid$(temp$, 19, 1))+asc(mid$(temp$, 20, 1))*256 height = asc(mid$(temp$, 23, 1))+asc(mid$(temp$, 24, 1))*256 end sub
|
|
|
Post by crob1974 on Jul 30, 2018 21:40:18 GMT
Thank you this is going to help me a lot.
|
|
|
Post by B+ on Jul 31, 2018 13:20:48 GMT
Why not use the image as a background?
'Cross Hairs Over Image Test.txt for JB 2.0 bplus 2018-07-31 'recurring lightning.txt for JB (B+=MGA) 2017-08-21
global H$, XMAX, YMAX H$ = "gr" XMAX = 800 YMAX = 600
nomainwin
WindowWidth = XMAX + 8 WindowHeight = YMAX + 32 UpperLeftX = (1200 - XMAX) / 2 UpperLeftY = (700 - YMAX) / 2 ttl$ = "Cross Hairs Over Image Test ";space$(65);"move mouse" open ttl$ for graphics_nsb_nf as #gr #gr "setfocus" #gr "trapclose quit" #gr "When mouseMove [mm]" #gr "when leftButtonUp lButtonUp" #gr "when characterInput charIn" #gr "down" #gr "fill black" #gr "size 1" 'or 2?
'draw an image to use for background call drawLandscape #gr "getbmp land 0 0 ";XMAX;" ";YMAX #gr "background land"
[mm] 'redraw background then mouse cross hairs #gr "drawsprites" #gr "color 0 0 0" mx1$ = "";MouseX my1$ = "";MouseY #gr "line "; mx1$; " ";0000; " ";mx1$; " ";YMAX #gr "line "; 0000; " ";my1$; " ";XMAX; " ";my1$ wait
function rand(lo, hi) rand = int((hi - lo + 1) * rnd(0)) + lo end function
sub drawLandscape 'the sky call hue 180, 200, 220 call fbox 0, 0, XMAX, YMAX
'the land startH = YMAX - 200 rr = 70 : gg = 70 : bb = 90 for mountain = 1 to 6 Xright = 0 y = startH while Xright < XMAX ' upDown = local up / down over range, change along Y ' range = how far up / down, along X upDown = (rnd(1)*.8 - .35) * (mountain *.5) range = Xright + rand(15, 25) * 2.5/mountain for x = Xright -1 to range y = y + upDown call hue rr, gg, bb call aline x, y, x, YMAX next Xright = range wend rr = rand(rr - 15, rr) : gg = rand(gg - 15, gg) : bb = rand(bb - 25, bb) if rr < 0 then rr = 0 if gg < 0 then gg = 0 if bb < 0 then bb = 0 startH = startH + rand(5, 20) next end sub
sub aline x0, y0, x1, y1 #gr "line ";x0;" ";y0;" ";x1+1;" ";y1+1 'add 1 to end point end sub
sub hue r, g, b 'fore and back #gr "color ";r;" ";g;" ";b #gr "backcolor ";r;" ";g;" ";b end sub
sub fbox x0, y0, x1, y1 #gr "place ";x0;" ";y0 #gr "boxfilled ";x1+1;" ";y1+1 end sub
sub lButtonUp H$, mx, my 'must have handle and mouse x,y call quit H$ '<=== H$ global window handle end sub
sub charIn H$, c$ call quit H$ end sub
sub quit H$ close #H$ '<=== this needs Global H$ = "gr" end 'Thanks Facundo, close graphic wo error end sub
|
|