Larry
New Member
Posts: 40
|
Post by Larry on Feb 13, 2020 0:59:55 GMT -5
Hey, am trying a sample program to see how it will work.
'INKEY.BAS - how to use the Inkey$ variable nomainwin WindowWidth = 1090 WindowHeight = 660 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
open "Inkey$ example" for graphics as #graph print #graph, "when characterInput [fetch]" print #graph, "setfocus" wait
[fetch] 'a character was typed! key$ = Inkey$
a$="|"+key$
print #graph, a$
wait
This is from the LB help file, but modified just a bit. What I am actually trying to do is to turn a graphics window into a textedit control by using the print command to print whatever is typed by the user to the graphics window. The only difference would be that it would need to do only a screen full of text, and then when I save that data, it would use the bmpsave command to save it to disk as a bmp. This way whatever font I am using even if it is not the English alphabet, it will show up as a picture in the given font. This way anyone looking at it cannot tell it is in English even if the font is constructed script. Or, I could use a regular texteditor control, and save and edit like normal, then when I was ready, do a bmp save, and the text would be saved into 1 or more bmp's depending on the size of the document. I certainly hope there is a way to mak my idea a reality.
|
|
|
Post by tsh73 on Feb 13, 2020 3:01:15 GMT -5
Play with this. It shows keys and codes which pass to your program. Note some keys generate two character codes, some generate 2 events (Enter key), and some even three (ESC key) And some has codes below 32 (space) - unprintable, as Backspace and TAB And some keys generate event for key press and key release (Shift, Ctrl)
EDIT you can get current position with "posxy" and put cursor back with "place". Alas it doesn't advance X as you print string, so probably only way is to gather string and print it from X=0 (like I did).
Note - if you see in this program on a screen Hello there then a$ actually contains Hello+chr$(13)+there 'INKEY.BAS - how to use the Inkey$ variable nomainwin WindowWidth = 1090 WindowHeight = 660 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
TEXTEDITOR #graph.log, 600,0,400,600 open "Inkey$ example" for graphics as #graph print #graph, "when characterInput [fetch]" print #graph, "setfocus" print #graph, "||" 'new line after initial position what is top left 0,0 #graph, "posxy x currY" 'so we get currY 'notice currY wait
[fetch] 'a character was typed! key$ = Inkey$ keyIsSpecial=len(key$)>1 'like this codes$="" for i = 1 to len(key$) codes$=codes$+" "+str$(asc(mid$(key$, i, 1))) next #graph.log "Got key:>";key$;"< with code(s)";codes$ 'actually you should do different things for Enter key, may be Backspace key if not(keyIsSpecial) then a$=a$+key$ 'construct a line #graph, "place 0 ";currY 'overprint whole line print #graph, "|"+a$ end if ' print a$
wait
|
|
|
Post by Rod on Feb 13, 2020 7:56:36 GMT -5
This is an incomplete old project of mine. It was going to be an editor with built in context sensitive help always on display. But turning a graphicbox into a texteditor is no trivial task. This uses a fixed width font which greatly eases the positioning issues. It uses a hidden graphicbox to take the keyboard input and a display graphicbox to show the drawn text.
Sticking with a texteditor and exporting the completed text to a bmp is the way I would go.
But you may see something in the code that is useful.
nomainwin ' find how much whitespace the windows scheme is taking ' Anatoly's tip WindowWidth = 200 WindowHeight = 200 menu #1, "&File", "E&xit", [quit] open "Ajusting..." for graphics_nsb as #1 #1 "home ; down ; posxy x y" ThemeWidth=200-2*x : ThemeHeight=200-2*y Border=2 close #1
WindowWidth = 1200+ThemeWidth-4 WindowHeight = 600+ThemeHeight UpperLeftX = (DisplayWidth-WindowWidth)/2 UpperLeftY = (DisplayHeight-WindowHeight)/2 graphicbox #1.key, 10, 10, 0, 0 graphicbox #1.code, 199,0,700,600+Border
menu #1, "&File", "E&xit", [quit] menu #1, "edit" menu #1, "&Help", "&About", [about] open "Full graphic view" for window as #1 #1 "trapclose [quit]"
chrWidth=7 chrHeight=15 leftmargin=chrWidth topmargin=chrHeight toplinenumber=1 'top of page line number page=38 linenumber=1 editline=1 lastlinenumber=linenumber caretX=0 maxchr=80 dim code$(5000)
for linenumber= 1 to 50 code$(linenumber)="This is line number ";str$(linenumber) next
lastlinenumber=linenumber linenumber=1
#1.code "down ; color black ; fill white ; font courier_new 9" #1.code "backcolor buttonface" #1.code "vertscrollbar on ; horizscrollbar on"
gosub [printall] gosub [printit] goto [blink]
[got] 'a character was typed! Turn off Keyboard. #1.key "when characterInput" #1.code "when leftButtonDown" timer 0 'Turn off timers. key$ = Inkey$ 'Inkey has Key from hidden Graphic Box. if asc(key$)=3 then notice "copy" if len(key$)=1 then select case 'case asc(key$)=_VK_RETURN ' gosub [enter] case asc(key$)=3 'CTRL+C
notice "copy" case asc(key$)=22 'CTRL+V 'gosub [unselect] 'call InsertText copy$, curx, cury 'curx=curx+len(copy$) notice "paste" case asc(key$)>=32 or asc(key$)<=126 gosub [addchar] end select else select case asc(right$(key$,1)) case _VK_SHIFT shift=1 case _VK_RETURN gosub [enter] case _VK_LEFT gosub [left] case _VK_RIGHT gosub [right] case _VK_UP gosub [up] case _VK_DOWN gosub [down] case _VK_PRIOR gosub [pageup] case _VK_NEXT gosub [pagedown] case _VK_HOME gosub[home] case _VK_BACK gosub [back] case _VK_END gosub [end] case _VK_DELETE gosub [delete] end select end if blink=1 goto [blink]
[addchar] if len(code$(editline))<maxchr then code$(editline)=left$(code$(editline),caretX/chrWidth)+key$+right$(code$(editline),len(code$(editline))-caretX/chrWidth) caretX=caretX+chrWidth end if gosub [printit] return
[up] gosub [printit] editline=editline-1 if editline<1 then editline=1 if caretX>=len(code$(editline))*chrWidth then caretX=len(code$(editline))*chrWidth if editline<toplinenumber then toplinenumber=toplinenumber-10 if toplinenumber<1 then toplinenumber=1 gosub [printall] end if gosub [printit] return
[down] gosub [printit] editline=editline+1 if editline>lastlinenumber then editline=lastlinenumber if caretX>=len(code$(editline))*chrWidth then caretX=len(code$(editline))*chrWidth if editline>toplinenumber+page then toplinenumber=toplinenumber+10 if toplinenumber>lastlinenumber then toplinenumber=lastlinenumber-10 gosub [printall] end if gosub [printit] return
[pageup] gosub [printit] editline=editline-page if editline<1 then editline=1 if caretX>=len(code$(editline))*chrWidth then caretX=len(code$(editline))*chrWidth if editline<toplinenumber then toplinenumber=toplinenumber-page if toplinenumber<1 then toplinenumber=1 gosub [printall] end if gosub [printit] return
[pagedown] gosub [printit] editline=editline+page if editline>lastlinenumber then editline=lastlinenumber if caretX>=len(code$(editline))*chrWidth then caretX=len(code$(editline))*chrWidth if editline>toplinenumber+page then toplinenumber=toplinenumber+page if toplinenumber>lastlinenumber then toplinenumber=lastlinenumber-page gosub [printall] end if gosub [printit] return
[left] gosub [printit] if caretX=0 then if editline=1 then caretX=0 else editline=editline-1 caretX=len(code$(editline))*chrWidth end if else caretX=caretX-chrWidth end if gosub [printit] return
[right] gosub [printit] if caretX>=len(code$(editline))*chrWidth then editline=editline+(editline<lastlinenumber) caretX=0 else caretX=caretX+chrWidth end if blink=0 gosub [printit] return
[home] caretX=0 gosub [printit] return
[end] caretX=len(code$(editline))*chrWidth gosub [printit] return
[delete] if code$(editline)="" then lastlinenumber=lastlinenumber-(lastlinenumber>1) for linenumber=editline to lastlinenumber code$(linenumber)=code$(linenumber+1) next code$(lastlinenumber+1)="" gosub [printall] else code$(editline)=left$(code$(editline),caretX/chrWidth)+right$(code$(editline),len(code$(editline))-caretX/chrWidth-1) gosub [printit] end if return
[back] if caretX=0 then if code$(editline)="" then lastlinenumber=lastlinenumber-(lastlinenumber>1) for linenumber=editline to lastlinenumber code$(linenumber)=code$(linenumber+1) next code$(lastlinenumber+1)="" end if if editline=1 and caretX=0 then editline=editline-(editline>1) caretX=0 else editline=editline-(editline>1) caretX=len(code$(editline))*chrWidth end if gosub [printall] else code$(editline)=left$(code$(editline),caretX/chrWidth-1)+right$(code$(editline),len(code$(editline))-caretX/chrWidth) caretX=caretX-chrWidth gosub [printit] end if return
[enter] l$=left$(code$(editline),caretX/chrWidth) r$=right$(code$(editline),len(code$(editline))-caretX/chrWidth) code$(editline)=l$ lastlinenumber=lastlinenumber+1 editline=editline+1 for linenumber=lastlinenumber to editline step -1 code$(linenumber)=code$(linenumber-1) next code$(editline)=r$ caretX=0 gosub [printall] return
[printit] #1.code "place ";leftmargin;" ";(editline-toplinenumber)*chrHeight+topmargin select case case copystartline = 0 or editline < copystartline or editline > copyendline #1.code "\";code$(editline);" "; case editline = copystartline and copystartline = copyendline l$=left$(code$(editline),copystartcaret/chrWidth) r$=right$(code$(editline),len(code$(editline))-copyendcaret/chrWidth) m$=mid$(code$(editline),len(l$)+1,len(code$(editline))-len(l$)-len(r$)) #1.code "\";l$ #1.code "backcolor blue ; color white" #1.code "place ";leftmargin+len(l$)*chrWidth;" ";(editline-toplinenumber)*chrHeight+topmargin #1.code "\";m$ #1.code "backcolor buttonface ; color black" #1.code "place ";leftmargin+len(l$+m$)*chrWidth;" ";(editline-toplinenumber)*chrHeight+topmargin #1.code "\";r$ case editline = copystartline l$=left$(code$(editline),copystartcaret/chrWidth) r$=right$(code$(editline),len(code$(editline))-copystartcaret/chrWidth) #1.code "\";l$ #1.code "backcolor blue ; color white" #1.code "place ";leftmargin+len(l$)*chrWidth;" ";(editline-toplinenumber)*chrHeight+topmargin #1.code "\";r$ #1.code "backcolor buttonface ; color black"
case editline = copyendline l$=left$(code$(editline),copyendcaret/chrWidth) r$=right$(code$(editline),len(code$(editline))-copyendcaret/chrWidth) #1.code "backcolor blue ; color white" #1.code "\";l$ #1.code "backcolor buttonface ; color black" #1.code "place ";leftmargin+len(l$)*chrWidth;" ";(editline-toplinenumber)*chrHeight+topmargin #1.code "\";r$ case else #1.code "backcolor blue ; color white" #1.code "\";code$(editline);" "; #1.code "backcolor buttonface ; color black" end select return
[printall] #1.code "cls ; fill buttonface" oldeditline=editline for editline=toplinenumber to toplinenumber+page gosub [printit] next editline=oldeditline return
[blink] if blink then #1.code "place ";leftmargin+caretX;" ";(editline-toplinenumber)*chrHeight+topmargin;" ; go 10" blink=0 else gosub [printit] blink=1 end if #1.key "setfocus" #1.key "when characterInput [got]" #1.code "when leftButtonDown [mousedown]" timer 500, [blink] wait
[mousedown] timer 0 #1.key "when characterInput" #1.code "when leftButtonDown" #1.code "when leftButtonUp [mouseup]" mY=MouseY mX=MouseX editline=toplinenumber+int(mY/chrHeight) if editline>lastlinenumber then editline=lastlinenumber caretX=0 else caretX=int(mX/chrWidth)*chrWidth-leftmargin If len(code$(editline))*chrWidth < caretX then caretX=len(code$(editline))*chrWidth end if copystartline=editline copystartcaret=caretX wait
[mouseup] mY=MouseY mX=MouseX editline=toplinenumber+int(mY/chrHeight) if editline>lastlinenumber then editline=lastlinenumber caretX=0 else caretX=int(mX/chrWidth)*chrWidth-leftmargin If len(code$(editline))*chrWidth < caretX then caretX=len(code$(editline))*chrWidth end if if editline < copystartline or (copystartline=editline and copystartcaret>caretX) then copyendline=copystartline copyendcaret=copystartcaret copystartline=editline copystartcaret=caretX else copyendline=editline copyendcaret=caretX end if
if copystartline=copyendline and copystartcaret=copyendcaret then copystartline=0 copyendline=0 copystartcaret=0 copyendcaret=0 end if gosub [printall] goto [blink]
[quit] close #1 end
|
|
Larry
New Member
Posts: 40
|
Post by Larry on May 2, 2020 11:49:20 GMT -5
Thanks for all of your help Rod, you've given me a lot to think about. You see I have a font for a script to write in Dalota, a spoken language I'm designing, and it will also write English. The script works a lot like Hebrtew in that the vowel symbols go above the consonant that they come after.
o en An example is: Hl
The n, is my representation of the umbrella shaped symbol that goes over my double vowels or consonants. With the letters being stacked as many as two vowels above a consonant, it makes for a very complex situation which is why I decided to go the graphics window route.
|
|