Text Editor
Blitz3D Forums/Blitz3D Beginners Area/Text Editor
| ||
Hiya! Any ideas / snippets on how to do a text type writter please Ladies And Gents. I've tried using ScreenText$=Input$(), but this wont allow for other keys to be pressed like ESC, TAB, Function Keys etc and / or the mouse to function. It's going to have an Edit / Preview mode aswell. If you could help that would be tremendous!! And many many thanks in advance, Mikey F :) |
| ||
http://www.blitzbasic.com/codearcs/codearcs.php?cat=5 |
| ||
thanks for the link to the code archives mate, allready looked in there. And not much help, but thanks anyway buddy. What I'd like to know how to do, is make a program like notepad / wordpad using Blitz2D commands. Where I can type and using the mouse insert / paste and copy etc, text. And have this stored into a single string$ like for example. Text$. If anyone could help, it would be magic! Cheers and many many thanks :) -Mikey F :) |
| ||
Do you have any code you can show what you have tried so far, then perhaps someone could help you adjust this into something that works. |
| ||
I felt imbarrassed to post my feeble attempt, and managed to hunt it down. :lol:;Text Editor Const xres=800,yres=600 Graphics xres,yres SetBuffer BackBuffer() Global Limit=70 Global EditText$,Show$ Global Key Global posx,posy While Not KeyHit(1) Cls Do_Ya_Thing() Flip Wend Function Do_Ya_Thing() Key=GetKey() If Key>31 And Key<128 EditText$ = EditText$ + Chr$(key) ;posx=posx+8 End If If Key=13 EditText$=EditText$ +Chr$(key) posx=0 posy=posy+8 End If ;Draw Border Rect 50,50,Limit*8,400,0 End Function Thanks for your time and help, -Mikey F :) |
| ||
I take it that a text editor is impossible with Blitz then. It's a shame that. O well. Thanks for your time :) |
| ||
It's not impossible, it'd just take a lot more code than that. You have to remember a LOT of information, to do the most basic operations. For instance, because B3D has no built-in text multi-line handling capability, imagine the problems you'd run into when you wanted to do a click,drag,select. You have to know all the text that is on those lines, at those positions on the screen. You can't read the text off the screen - you'd have to see: a) how many pixels down the screen the inital mouse click is b) stringheight of each line c) calculate based on stringheight which line of text is being clicked on, vertically d) figure out which line that is, over the course of the file - if the top of the file is off the top of the screen then it's going to be offset by the number of lines up to the one displayed at the top e) once you know what line of text that is, find the horizontal pixel click location f) do a stringwidth check for every combination of letters in the line until it is equal or more than the location you've clicked on the screen g) remember this location of starting the text select, based not on pixel location, but on text row and column from the text data for the entire document stored in memory. h) and NOW - you've got to start handling the dragging to select....... So far I've covered less than half of the operation. That is one of the most basic operations you'd need in a text editor - but programming it manually without multi-line editboxes.. insanely time-consuming. To do a single-line edit box even, is quite consuming, just for entering in names, etc. It has to handle key presses, backspaces (find the stringwidth of the previous character, remove that character from the string, AND move the cursor back that far), make sure they don't type too far or backspace too far, handle extended ascii characters, error checking to make sure people don't crash the program by it trying to "TYPE" out an F8 or whatever when they press it, support arrow-keys moving the cursor, support pressing TAB, etc etc etc. Don't give up, just make sure you're programming within your limits. Start with a simple routine like you've got above. Figure out what you want to do with it next, and work that into it. Find any bugs in the new additions and fix them. Rinse, repeat, ad nauseum. +BlackD |
| ||
To help you though (after reading the above post) ;) here is an example single-line text box. It utilises all the "legal" character inputs, both enter keys, and backspaces, and will work with any sized font.Graphics 800,600 font=LoadFont("arial",17) SetFont font SetBuffer BackBuffer() Inputx = 14 ;Spot to start drawing text - for calculation inputtxt$="" ;The empty string we're using exitloop=0 While exitloop=0 ;use this rather than keyhit(28) as you ;also need To detect KeyHit(156) for ;numpad ENTER Cls Color 155,155,255 Text 5,10,">" Color 200,200,200 Text 14,10,inputtxt$ Rect inputx,12,8,13 a=GetKey() If a > 31 And a < 126 And a <> 96 And inputx < 780 Then ;make sure it's a legal character, ;and that it's within the screen limit inputtxt$=inputtxt$+(Chr$(a)) inputx=inputx+StringWidth(Chr$(a)) End If If KeyHit(28) Or KeyHit(156) Then exitloop = 1 ;check for ENTER If KeyDown(14) Then ;do backspace stuff :) If inputx > 14 Then lastchar$=Right$(Inputtxt$,1) inputtxt$=Left$(inputtxt$,(Len(inputtxt$)-1)) inputx=inputx-StringWidth(lastchar$) If KeyDown(14) Then Delay 80 ;checks if backspace is still being held, to delay ;deleting the next character a bit - obviously if ;you're using animation etc elsewhere, you don't ;want a delay statement so would need to do this ;another way End If End If Flip Wend Cls Color 255,255,255 Text 0,0,"You typed : "+inputtxt$ Flip WaitKey() End +BlackD |
| ||
Thank you ever so much matey for all of that top advice!! Cheers and take care, Mikey F :) |
| ||
Are you sure the codearchives aren't of use? I thought this was a very nice example (includes mouse-clicks as well): http://www.blitzbasic.com/codearcs/codearcs.php?code=895 |
| ||
@Mikey F Mikey, I assume you are using Blitz3D? Why not purchase the BlitzPlus, which has support for Windows, Gadgets, Requestors and stuff like that? Perhaps that (BlitzPlus) with those features would make life easier for you? Just an idea |
| ||
Thanks for all the top advice and help pointers! Really appreciate it all! And will look into the possibilities, Thanks ever so much, Mikey F :) |