PBEdit - a Canvas-based Texteditor

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: PBEdit - a Canvas-based Texteditor

Post by davido »

Brilliant!
Thank you for sharing. :D
DE AA EB
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PBEdit - a Canvas-based Texteditor

Post by mk-soft »

Super :D :D :D

Unfortunately 'WindowVectorOutout()' does not work with macOS (Catalina) anymore.
Solution for Style_LoadFont is to create a dummy image.

Line 3428

Code: Select all

Procedure Style_LoadFont(*te.TE_STRUCT, *font.TE_FONT, fontName.s, fontSize, fontStyle = 0)
		ProcedureReturnIf((*te = #Null) Or (*font = #Null))
		
		Protected c, minTextWidth, image
		
		If IsFont(*font\nr)
			FreeFont(*font\nr)
		EndIf
		
		fontStyle | #PB_Font_HighQuality
		CompilerSelect #PB_Compiler_OS
		  CompilerCase #PB_OS_Windows
		    *font\nr						= LoadFont(#PB_Any, fontName, fontSize / DesktopResolutionY() * 1.0, fontStyle)
		  CompilerCase #PB_OS_MacOS
		    *font\nr						= LoadFont(#PB_Any, fontName, fontSize / DesktopResolutionY() * 1.2, fontStyle)
		  CompilerCase #PB_OS_Linux
		    *font\nr						= LoadFont(#PB_Any, fontName, fontSize / DesktopResolutionY() * 1.0, fontStyle)
		CompilerEndSelect
		
		If IsFont(*font\nr)
			
			*font\style					= fontStyle
			*font\id					= FontID(*font\nr)
			*font\name					= fontName
			*font\size					= fontSize
			
			image = CreateImage(#PB_Any, 32, 32)
			If StartVectorDrawing(ImageVectorOutput(image))
				VectorFont(*font\id)
				
				minTextWidth			= VectorTextWidth(" ")
				*font\height			= VectorTextHeight(" ")
				*te\lineHeight			= *font\height
				
				For c = 0 To 255
					*font\width(c)		= Max(minTextWidth, VectorTextWidth(Chr(c)))
				Next
				*font\width(#TAB)			= minTextWidth
				
				StopVectorDrawing()
			EndIf
			FreeImage(image)
			ProcedureReturn #True
		EndIf
		
		ProcedureReturn #False
	EndProcedure
	
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Mr.L
Enthusiast
Enthusiast
Posts: 104
Joined: Sun Oct 09, 2011 7:39 am

Re: PBEdit - a Canvas-based Texteditor

Post by Mr.L »

Thanks for the kind replies!
I already uploaded a new version with multilanguage support.
J. Baker wrote:At idle, it uses 12% CPU and 64 MB of memory. I have an Intel 1.4 Ghz dual core CPU. Not bad. ;)
I think thats strage - 12% at Idle state is quite high, isn't it?
STARGÅTE wrote:How long did you worked on this version?
I have worked quite a long time. Many weeks. Mainly because I didn't plan thoroughly in the beginning. So I had to rewrite large parts of the code over and over again.
When i started I didn't even knew about multicursor editing :lol:
oreopa wrote:Column selection mode like UltraEdit would be a nice addition.
Did you try pressing down the "Alt"-key while selecting code with the mouse. Is that what you mean by "column selection"?
User_Russian wrote:The editor only supports English characters and numbers.
That might be true. Unfortunately I have no clue what to do about it :oops:
infratec wrote:I think horizontal and vertical split are swapped
In the new version they are swapped. I thought horizontal splitting means split the "x-axis" but it could also mean that a horizontal split is made on the y-axis...
Mesa wrote:With windows XP 32, there is something wrong with the pop-up menu.
sorry, I didn't think about the XP users.
The adjustments for the Menutitles can be made in the new "language.cfg" file
mk-soft wrote:Unfortunately 'WindowVectorOutout()' does not work with macOS (Catalina) anymore.
Thanks for the reply. Yes, a dummy image is a nice solution. Also the "multi-OS" part for the fontsize.
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: PBEdit - a Canvas-based Texteditor

Post by J. Baker »

Mr.L wrote:I think thats strage - 12% at Idle state is quite high, isn't it?
It's most likely the blinking cursor having to redraw itself. Otherwise it would be much lower, if not zero percent. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
oreopa
Enthusiast
Enthusiast
Posts: 281
Joined: Sat Jun 24, 2006 3:29 am
Location: Edinburgh, Scotland.

Re: PBEdit - a Canvas-based Texteditor

Post by oreopa »

Mr.L wrote:
oreopa wrote:Column selection mode like UltraEdit would be a nice addition.
Did you try pressing down the "Alt"-key while selecting code with the mouse. Is that what you mean by "column selection"?
It kind of is, and it kind of isn't. :) I know thats not very helpful. It works nicely in tables that are regularly formatted, but in data with shorter lines, or lines with no data at all, it doesn't - its kind of a visual thing, but also a slightly different functionality thing as well. I think the simplest way to describe it is that top left and bottom right of the selection define a box which is the selection, and the cursor(s) are placed there (right side) and data typed or deleted happens there... even in lines with nothing but a <cr>... the selection is uniformly rectangular... i dunno if thats an accurate description... it's kinda hard to explain the subtle difference... phew...

It's not a big deal really. It's a very nice editor indeed.

EDIT: Redraw takes a paltry 0.45% on my ancient 1st gen i5... and (mega-huge) pasting is surprisingly fast...
Proud supporter of PB! * Musician * C64/6502 Freak
Mr.L
Enthusiast
Enthusiast
Posts: 104
Joined: Sun Oct 09, 2011 7:39 am

Re: PBEdit - a Canvas-based Texteditor

Post by Mr.L »

@oreopa:
ah, now i see what you mean. But it would be tough to implement that feature into my editor, i guess.
Right now, in my editor the selection is directly connected to the textlines and you cannot select anything that "is not there".
So, i will keep that feature in mind and maybe one day i come up with a solution :wink:
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: PBEdit - a Canvas-based Texteditor

Post by davido »

@Mr.L ,

I have two questions:

1. Is there a pure text mode that ignores 'keywords'?
2. Can the background and text colours be changed?
DE AA EB
Mr.L
Enthusiast
Enthusiast
Posts: 104
Joined: Sun Oct 09, 2011 7:39 am

Re: PBEdit - a Canvas-based Texteditor

Post by Mr.L »

davido wrote: 1. Is there a pure text mode that ignores 'keywords'?
2. Can the background and text colours be changed?
yes, if you comment the line (near the end of the code)

Code: Select all

PBEdit_LoadStyle(0, "PB_Style.xml")
keywords, folding and indentation will be ignored.

inside the procedure "_PBEdit_::Editor_New"
you can find the line:

Code: Select all

*te\colors\currentBackground = RGBA( 30,  30,  25, 255)
that's the background color

the default textcolor is defined in the procedure "_PBEdit_::Style_SetDefaultStyle"

Code: Select all

Protected defaultColor = RGBA(155,220,255,255)
Maybe it's better to put all the editor color settings into a seperate file.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: PBEdit - a Canvas-based Texteditor

Post by davido »

@Mr.L ,

That was quick!
Thank you. :D
DE AA EB
User avatar
oreopa
Enthusiast
Enthusiast
Posts: 281
Joined: Sat Jun 24, 2006 3:29 am
Location: Edinburgh, Scotland.

Re: PBEdit - a Canvas-based Texteditor

Post by oreopa »

Mr.L wrote:@oreopa:
ah, now i see what you mean. But it would be tough to implement that feature into my editor, i guess.
Right now, in my editor the selection is directly connected to the textlines and you cannot select anything that "is not there".
So, i will keep that feature in mind and maybe one day i come up with a solution :wink:
Yes. I guessed that. I guess one would need to pad the "offending" lines out with tabs/spaces on the fly somehow.

Thx again, really is a work of art.
Proud supporter of PB! * Musician * C64/6502 Freak
Mr.L
Enthusiast
Enthusiast
Posts: 104
Joined: Sun Oct 09, 2011 7:39 am

Re: PBEdit - a Canvas-based Texteditor

Post by Mr.L »

A new version is online (1.0.2)

Download

added: Settings file "PBEdit.xml"
all editor settings and colors can be changed inside this file.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: PBEdit - a Canvas-based Texteditor

Post by falsam »

Whoooo! I love it. Congratulations for this code

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
Mesa
Enthusiast
Enthusiast
Posts: 345
Joined: Fri Feb 24, 2012 10:19 am

Re: PBEdit - a Canvas-based Texteditor

Post by Mesa »

You can download the french translation, here:
http://frazier.wood.free.fr/pb/language_FR.cfg

M.
Mr.L
Enthusiast
Enthusiast
Posts: 104
Joined: Sun Oct 09, 2011 7:39 am

Re: PBEdit - a Canvas-based Texteditor

Post by Mr.L »

thank you, Mesa!
I've uploaded a new version (1.0.5 - see first post) that includes your translation!
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: PBEdit - a Canvas-based Texteditor

Post by Saki »

Hi,
the flickering of the text below, when the mouse is moved, or other, can be removed completely with a trick.

Code: Select all

		Case #PB_Event_Gadget
		  lineNr$="lineNr: " + Str(PBEdit_GetCurrentLineNr(0)) +
		          "  Column: " + Str(PBEdit_GetCurrentColumnNr(0)) +
		          "  (Char: " + Str(PBEdit_GetCurrentCharNr(0)) + ")"
		  If lineNr$<>old_lineNr$
		    StatusBarText(0, 0, lineNr$)
		    old_lineNr$=lineNr$ 
		  EndIf
		  
		  selection$="Selection [" + 
		             Str(PBEdit_GetFirstSelectedLineNr(0)) + ", " + 
		             Str(PBEdit_GetFirstSelectedCharNr(0)) + "] [" + 
		             Str(PBEdit_GetLastSelectedLineNr(0)) + ", " + 
		             Str(PBEdit_GetLastSelectedCharNr(0)) + "]"
		  If selection$<>old_selection$
		    StatusBarText(0, 1, selection$)
		    old_selection$=selection$
		  EndIf
		  
		  If ListSize(*te\cursor())<>old_cursors_changed
		    StatusBarText(0, 2, "Cursors: " + Str(ListSize(*te\cursor())))
		    old_cursors_changed=ListSize(*te\cursor())
		  EndIf
Best Regards Saki
地球上の平和
Post Reply