IonicWind Software

IWBasic => General Questions => Topic started by: Andy on February 03, 2020, 12:10:44 AM

Title: Color text
Post by: Andy on February 03, 2020, 12:10:44 AM
Hi every one,

One area I've never really had a try at is colouring text itself.

Sure you can set the colour of an edit control, etc... but if I had an editor (such as the editor example program) how would I go about changing the colour of individual words in a multi line edit box?

Or would you use a Rich edit control instead?

If so, does any one have any examples of how to do something like this please?

I can get each word, the starting / end positions of each word, but how do I colour it?

Any ideas, please.

Thanks,
Andy.
:)
Title: Re: Color text
Post by: Andy on February 03, 2020, 03:44:04 AM
I found this:

http://www.ionicwind.com/forums/index.php?topic=5480.msg40658#msg40658

But I can't get it to compile in IWB?

In the SUB RemoveCR()

This line is stopping it:

pos = INSTR(pos+1,buffer,chr$(13))

Any one got this working in IWB?

Thanks,
Andy.
Title: Re: Color text
Post by: h3kt0r on February 03, 2020, 04:08:11 AM
This is not possible with an edit control. Your best bet would be to use a RichEdit control, build an
array of keywords then, when a file is loaded into the control, parse each line for the keywords and format them
adequatly (font color and flags).
This can be really slow on any file weighting more than 10Kb (10 seconds and more, related to the file size).
You could however use some tricks to speed up things a bit, like turning off the control update or the events mask.
But you would gain a few seconds at best.
I've seen an ASM routine cutting the loading time by 50%. This sounds really better.
Finally, you could inject RTF color codes while parsing the file into a memory buffer and stream that into the control :
this is the fastest option and works fine even with files weighting hundreds of Kb.
Not so sure with files weighting more than 1Mb.

Or you could roll your own Edit control from scratch using GDI. This would be a huge project...


This is a text editor written by Aleksander Shengalts rolling its own custom edit control : AkelPad (http://akelpad.sourceforge.net/en/index.php)

If you want to take a look at its syntax highlighting, download the plugins pack, activate the "Coder" plugin
then load a C or an HTML source file.
Sometimes, syntax highlighting doesn't works right out of the box.
In that case, open the "Akelpad\Akelfiles\Plugs\Coder" subfolder, find the file named "Cache" and delete it.
Restart the program.
Now the syntax highlighting should work...
Title: Re: Color text
Post by: Andy on February 03, 2020, 04:45:04 AM
Thanks for that,

I have all the IW key words already stored in a pointer array, and my convertkeywords program can match words up with the key words - so that's not a problem.

For me, it might be that keeping a records of every character, font and colour would be a way to do this, but I think there is a limit on the number of controls per window?

Thin it's 255 - is that wright any one?

Ideally, I'd could have say 80,000 little edit boxes, all being able to be set different colours and fonts - is that possible?

Andy.
Title: Re: Color text
Post by: h3kt0r on February 03, 2020, 06:17:03 AM
No. Seriously, you can't do it that way.
I think you have to use GDI to paint each text string on the program's window canvas.
Exactly like in that gutter custom control i've written.

Here is a custom Edit control (http://www.reonis.com/POFFS/edm32.zip) written by Borje Hagsten in PowerBasic, so you can have a look at
the source by yourself and get a general idea on how this is achieved. The syntax is somewhat
different from iwBasic, but it's BASIC language and still understandable.
Title: Re: Color text
Post by: Andy on February 04, 2020, 06:29:17 AM
That's a great example,

But I think I might be onto something here - see screen shot.

Andy.
Title: Re: Color text
Post by: Andy on February 05, 2020, 06:00:47 AM
When I get finished with this of course I will release it, what I've got so far...

See screen shot.

Andy.
Title: Re: Color text
Post by: aurelCB on February 05, 2020, 07:09:52 AM
WOW 
is that scintilla control  ;D
well ..how you create margin ?..i will guess it is richedit control?
Title: Re: Color text
Post by: h3kt0r on February 05, 2020, 07:26:38 AM
looks promising.
Title: Re: Color text
Post by: LarryMc on February 05, 2020, 11:36:41 AM
What you trying to do  Andy, replicate what all I did in the IDE?  ;D  ;D
Title: Re: Color text
Post by: Andy on February 05, 2020, 11:49:12 PM
Larry,

Would never step on your toes  8)

As you all know, I have been writing some additional tools for us all to help us code.

After completing my Find and Replace program, it occurred to me that after making some line replacements that you might actually want to see the whole file on screen.

I can't force our editor to re-load the changed code so thought what about some sort of viewer in a style of our editor.

So this is what I'm trying to do.

Yes I am using Rich Edit controls at the moment, but have several options.

Thanks for the WOW comment - appreciated!

Andy.
Title: Re: Color text
Post by: aurelCB on February 06, 2020, 01:50:50 AM
Well building custom editor control is a nice project and also remove need for something like scintilla 
but i like scintilla and i vased my editor on it.
Interesting custom edit control is Creative basic editor IDE it is written by MFC but if you have ib source code you can figured what is what and can be done even without mfc but require lot of work .
Title: Re: Color text
Post by: Andy on February 06, 2020, 05:31:08 AM
Update...

I have the program able to display the whole file with text correctly indented.

You can move down by pressing <Enter> or the down arrow key, and up with the up arrow key.

You can use Page up & Page down to change the page.

And of course you can edit any line.

Sub routines & windows are listed with line number start / end.

To do...

Auto complete typed words - coming next.
Insert / delete lines.
Save file.

See screen shot.
Thanks for the encouragement every one!
Andy.
Title: Re: Color text
Post by: aurelCB on February 06, 2020, 07:00:08 AM
Andy 
may I ask you is this program based on Joske program?
and do you will post source code?

I would like to try this method in one different compiler, i have few examples somewhere 
but i think that all of them are in C or C#
Title: Re: Color text
Post by: Andy on February 06, 2020, 09:49:09 AM
aurel,

Yes it will be posted when I've finished it - as always with my code.

Joske program? never heard of that - no, I just started from scratch on this one.

If you want a copy of what I've done so far just send me a PM with your email address in it - don't think I've got yours - but it will probably be tomorrow before I can reply with the code.

Andy.
Title: Re: Color text
Post by: billhsln on February 06, 2020, 10:06:39 AM
Wow, very cool.

Bill
Title: Re: Color text
Post by: fasecero on February 06, 2020, 01:00:27 PM
Yep super nice, it would be amazing if user FUNCTION names could have a unique color (dark red, something like that).
Title: Re: Color text
Post by: Andy on February 07, 2020, 12:34:44 AM
Thanks every one for your support - it does help to keep me going - much appreciated!

Good idea fasecero, and I have made it do exactly what you mentioned.

When you look at the attached screen shot, subs...

PageUp
PageDown
ColourText - are all coloured a maroon (deep redish colour)

These sub routines are all user defined local routines in this file.

Note line 127, it is not highlighted because although it is a function (sub routine) it resides in another file (the include file).

Also note that when you click on a line, to the left next to the line number there is a ">" symbol just to remind you which line you clicked on.

The actual screen you use looks much clearer than the screen shot by the way.

Thanks again guys!
Must carry on now...

Andy.
:)
Title: Re: Color text
Post by: aurelCB on February 07, 2020, 05:01:31 AM
QuoteIf you want a copy of what I've done so far just send me a PM with your email address in it - don't think I've got your
Hi Andy..

I will send you ,and i like to try..
when i say Joske i mean Jos de Jong member of CodingMonkeys forum and here is published something similar
tbohon..

by the way my email is public and anyone can send me a email.
Title: Re: Color text
Post by: aurelCB on February 07, 2020, 05:19:10 AM
Oufff i forget that i mae one very primitive in Creative basic long time ago 

http://www.ionicwind.com/forums/index.php?topic=2658.msg22651#msg22651
Title: Re: Color text
Post by: Andy on February 07, 2020, 05:40:41 AM
Email with code sent.

Any questions just ask me - best is in the mornings as I get a little tiered after 2 pm (was up at 5 am).

Andy.
Title: Re: Color text
Post by: aurelCB on February 07, 2020, 08:24:19 AM
Thanks Andy
how i to know when is after 2 pm,i am far away from you ,,i guess  ;D
no problem ..first i need to found sapero windowssdk.inc then i will try to compile..
all fine..
Title: Re: Color text
Post by: aurelCB on February 07, 2020, 08:36:30 AM
Hi Andy and others ..
Becuase i don't have IWB i use last EBasic 1.737
and after i add windowssdk.ink i get whole bunch of errors.
Fixing this errors would take to long i think... ???
Andy your include codetools.inc is a large file 6000 lines of code...wow i am impressed...

So i asking , can i try just subroutine ColourText() to see how how coloring works?
Title: Re: Color text
Post by: aurelCB on February 07, 2020, 10:28:13 AM
I remove some parts and i get almost nothing.
program is very complex according to large amount of string pointers 
and i will give up it is to complex for me  ::)
i will wait for finished program just to see what is this all about ...
thanks..
Title: Re: Color text
Post by: Andy on February 07, 2020, 11:00:02 PM
The include file "codetools.inc" has many different routines & pointers.

This is because I use this file for several different programs.

The are only three sub routines that need to be used here, and they are:

ReadKeyWords()  'Read in IW keywords.
BuildWordSize() 'Build key word indexes.

And:

ChangeWord() ' used for auto complete of words.

All I'm doing is reading in the key words to a pointer array called P (ReadKeyWords).
As there are 1,661 "words" to search, I then use another two pointer arrays to store words into

1. Size
2. Starting letter.

The ChangeWord sub routine gets the range From and To in our word list (pointer P).

Example:

We want to check for the word "cats", now "cats" has 4 characters, and begins with the letter "C".

BuildWordSize() sub routine has already built indexes for words that are 4 characters in length, and begin with "C".

Suppose there are only 2 "words" stored that are 4 characters in length and begin with "C"...

CLIP
CLOP

You see straight away there are only 2 words, so we don't need to check against all words beginning with "C", just these two.

In this example, "cats" is not one of them, so the ChangeWord routine just returns the word "cats".
If our word to search was "Clop", it returns CLOP.

There are many include files etc that I don't fully understand myself, so I know the feeling.

Sometimes we just have to accept them and use them.

This include file has many tools in it, and has taken many many months and long hours to write, it's just a case of accepting it, and using it - it will I think have a lot of time for many on here.

Re ColourText sub routine, I will have a look today and see how I could drop that into my Auto complete tutorial for you all.

Re Pointers, at first (at least for me) they look complex, but really they aren't, but the help file doesn't really describe them very well.

That's why I posted a Pointers tutorial (see attached).

Re Ebasic, yes I had that problem a while ago (started to get a little left behind on code) so upgraded to IWBasic.

Andy.





 



Title: Re: Color text
Post by: aurelCB on February 08, 2020, 12:45:17 AM
Hi Andy
Yes i see many subs used here in your include, i undrstand pointers very well because i use them in my old 
interpreter,,,AurelBasic....and yes routines in someone else includes are not easy to folow.
IWB is not that much different from EB but i recenly using another compiler so i have mix in my head of 
all that basic-s versions ,keep up the good work it is interesting.

Just one small question..as line numbers panel ,it looks to me that you use static control or i have wrong?
thanks
Title: Re: Color text
Post by: aurelCB on February 08, 2020, 01:24:32 AM
I found one interesting article on C board, adding margin looks like in scintilla control
i don't know but maybe i will try
https://cboard.cprogramming.com/windows-programming/99118-line-number-rich-edit-control.html
Title: Re: Color text
Post by: Andy on February 08, 2020, 02:49:02 AM
Yes, the line numbers on the left are statics.

It's easy in this program as you have 30 lines per screen, and I know what page number you are on.

For calculating, I start at page 0

And I use this:

sub PageDown()
 Page ++
 NewLineNo = (Page * 30)
 Down = 80
 for a = 1 to 30
  NewLineNo ++

So NewLineNo in the FOR a / NEXT a loop always has the correct corresponding line number to what text is being displayed.

And Page up goes like this:

sub PageUp()
 Page --
 if Page < 0
 Page = 0
 endif
 NewLineNo = Page * 30
 Down = 80
 for a = 1 to 30
  NewLineNo ++

Just set the the static control text "a" to a string of NewLineNo

setcontroltext(w1,a+500,ltrim$(str$(NewLineNo)))

The static controls are 501 to 531

Andy.
:)
Title: Re: Color text
Post by: aurelCB on February 08, 2020, 04:30:57 AM
Ahh Ok, i understand it now..
But first i will try this C example with margins in another compiler(o2) to see is it worth to spending time on that.
So far i get margins...in the same time i will made same example in EB to check both compilers.
I hope that should work..  ;)
Title: Re: Color text
Post by: Andy on February 08, 2020, 04:42:07 AM
Yes worth checking out before spending lots of time on something.
And thanks for the encouragement!

I have in the mean time got inserting lines working.
It correctly moves the text down and re-colours it, leaving a blank line ready for you to type something.

Here I have added a few new lines.

Screen shot attached.
Andy.
:)
Title: Re: Color text
Post by: aurelCB on February 08, 2020, 08:36:52 AM
It looks very good Andy, i like syntax coloring  ;)
Title: Re: Color text
Post by: Andy on February 09, 2020, 03:19:10 AM
Thanks Aurel!

I have now got insert & delete lines working now, more or less like our editor.

Think a nice function will be to click say a button and insert certain lines such as FOR x / NEXT x etc.

OPENCONSOLE / DO:UNTIL INKEYS <> "" / CLOSECONSOLE would also be nice, I use this a lot when debugging my programs and hate having to keep typing these lines.

But before I do that, auto complete is the next function to work on.

Andy.
 :)
Title: Re: Color text
Post by: billhsln on February 09, 2020, 11:06:44 AM
Instead of a button for FOR x / Next x and other configurations, how about a drop down box that can be modified by the user to add combinations that they would prefer to be loaded by your code?

We have FOR/NEXT, IF/THEN/ELSE/ENDIF, OPENCONSOLE/CLOSECONSOLE/DO:WHILE INKEY$<> "", ETC.

You could have:

IF x THEN y ELSE z

IF x
   y
ELSE
   z
ENDIF

Etc.

I don't know about other people, but I know I think it is a brilliant idea and a great time saver for all of us.

Thanks for all the work you are doing,
Bill


Title: Re: Color text
Post by: aurelCB on February 09, 2020, 12:53:04 PM
Translating that C code for richedit margin i get margin and line numbers but i have 
problem with EN_UPDATE notification and i get one line number more in marging 
this is how look in o2...i really don't know how to tranlate this to IWB.
if someone wish i can post translated function in basic
Title: Re: Color text
Post by: Andy on February 09, 2020, 09:55:45 PM
Bill

Thanks for the drop down box idea, thought I might not be the only one who has to keep typing the same thing time after time.

Thanks, keeps me going.

Andy.
Title: Re: Color text
Post by: Andy on February 10, 2020, 05:55:41 AM
Took on what Bill suggested,

So I've added in (just for now a list view control - will make it a drop down box later) of all pairs of blocks...

That is FOR / NEXT,  DO / UNTIL etc...

Please see the attached screen shot.

Think this could be in a little text file so the user could easily edit it.

My code is always free and available as you all know.

Great ideas, any more any one?

Thanks,
Andy.
:)
Title: Re: Color text
Post by: Andy on February 10, 2020, 07:11:42 AM
So to recap,

With my code tools software, we already have Find & Replace (using words and in string commands).
Copy entire sub routines.
Copy windows & their handlers & the ability to rename the windows and references too.
We can remove sub routines from our code as well.

Now we can put them together with auto complete of key words (again, already done).

So any suggestions will be welcome...

Andy.
:)
Title: Re: Color text
Post by: billhsln on February 10, 2020, 09:43:27 AM
Only one, hopefully, very minor addition.  I prefer all my keywords to be in UPPER case, but many prefer LOWER, so how about a click to switch between upper and lower for the code that gets inserted from the new drop down?

Thanks,
Bill
Title: Re: Color text
Post by: Andy on February 10, 2020, 07:41:21 PM
Bill,

Good suggestion, I am like you on this one.

Like the key words to stand out.

I have a variable called "Ucase" for upper case.
When you set it to 1, all key words are returned as upper case, set it to zero and they are returned in lower case.

Remember my convert key words program? it's all there, just need to pull it all together in this editor now.

Thanks again,
Andy.
Title: Re: Color text
Post by: LarryMc on February 12, 2020, 10:20:44 PM
remember, in the IDE there's the option of Upper case , Lower case, or show them as typed : 1, 0, -1
Title: Re: Color text
Post by: billhsln on February 12, 2020, 10:36:31 PM
Or instead of a click button, how about let the user save it the way they want by editing the file, just in case, but start them out as either upper or lower.

Just another thought.

Bill
Title: Re: Color text
Post by: Andy on February 13, 2020, 01:12:02 AM
Yes great points guys,

My include file has a variable called Ucase.

1 = key words in upper case.
0 = As typed.
-1 = Lower case (just need to add this option in).

Thanks, it does help with suggestions!

Andy.
 :)

Title: Re: Color text - Scroll and search
Post by: Andy on February 13, 2020, 11:18:27 PM
Just a quick update - think you will like this.

Managed now to get live scrolling with line numbers.

You can click on a sub routine / window name and the rich edit is scrolled to the exact line number the window / sub routine starts at.

You can also type in a line number - the line is also automatically scrolled to.

The text colour is coming along nicely.

And with the find / replace / copy sub / remove sub code this should be a very nice program when I have finished it for us all.

Also I can now add in bookmarks, think a description / and sub routine name would be nice as I end up with a lot of bookmarks and can never remember which one refers to what.

See attached screen shot.

Andy.
 :)
Title: Re: Color text
Post by: billhsln on February 14, 2020, 10:29:28 AM
I really like your Subroutine and Window drop downs, also the JUMP.  Great ideas.

Bill
Title: Re: Color text
Post by: LarryMc on February 14, 2020, 09:31:34 PM
Andy
re:bookmarks
in the IDE I let the User bookmark any line and keep all the bookmarks in a scrollable control like you Next to that control I have two controls. One to allow the user to delete the currently selected bookmark and one to delete all bookmarks
Title: Re: Color text
Post by: Andy on February 15, 2020, 04:23:00 AM
Thanks Larry, that is helpful.

I was wondering, some buttons have icons / bitmaps on them - where these royalty free?

Andy.
Title: Re: Color text
Post by: Andy on February 15, 2020, 04:24:50 AM
Bill,

Thanks, glad you like it! there's plenty more we can add in to suite the way we program I'm sure.

Have sent you an email.

Andy.
Title: Re: Color text
Post by: LarryMc on February 15, 2020, 05:43:30 PM
Quote from: Andy on February 15, 2020, 04:23:00 AMI was wondering, some buttons have icons / bitmaps on them - where these royalty free?

yes, I bought them

Title: Re: Color text
Post by: Andy on February 17, 2020, 04:56:50 AM
Thanks Larry for that.

Hecktor, please don't think I am competing with you - you are doing some great work with your editor.
I am doing something a little different just for us who use IW code - looks similar but it's not.

Here is an update for you all.

Added in Find / Replace / Copy / Rename / Remove functions.

External sub routines (not in this file) are highlighted in a coral (orange / red colour).
Internal sub routines (in this file) are in a maroon colour.
You now have page number, current edit line, page starts at line number.

If you click once on a window or sub routine, it jumps to the start line number of the window or sub routine.

If you double click on them, it jumps to the end line number.

Rome wasn't built in a day - but getting on with it.

Please see attached.

Andy.
Title: Re: Color text
Post by: Andy on February 17, 2020, 07:12:16 AM
Hi every one,

Thought a wish list would be good.

So what what you like in an Alternative IW editor program?

Please let me know your ideas.

Please see attached screen shot.

Andy.
Title: Re: Color text - Update
Post by: Andy on March 11, 2020, 05:25:34 AM
Just a little update for you all in case you were wondering.

My colour text additional IWB editor is moving on at good speed thanks to you all regarding my recent questions.

In place now:

Subroutines, windows, bookmarks are all now drop down boxes.

For subs you can jump to the start of the subroutine line as well as jumping to the end of it.
The same applies for windows with the addition that you can also jump to its' handler as well.

Right click on the text allows you to cut, copy, and paste.

Jump to any line by typing the number in.

I'm also adding a "snap shot" button which saves your code safely to another file.
A useful feature when you have something working and don't want to mess it up by making more changes.

As always, this will be posted when finished.

Please see attached screen shot.

Thanks for reading this,
Andy.
Title: Re: Color text
Post by: LarryMc on March 11, 2020, 06:19:24 AM
I don't see hou you open a file or a project ?
Title: Re: Color text
Post by: Andy on March 11, 2020, 07:09:16 AM
Larry,

No you won't yet.

I'm hard setting a file to open at the moment but that is easily done with a couple of buttons.

Already got the code in for that, this is just an example of the program without those buttons.

As said before, Larry I know how much work you have done on the editor - I know because I'm trying to do something similar.

And thanks for all your help.

Andy.

Title: Re: Color text
Post by: LarryMc on March 12, 2020, 07:07:07 AM
Just another thought
If you are going to be working on a project or you going to allow your editor to allow having multiple files open at the same time and moving between them? And maintaining the bookmarks for each and such? If so, I'm just interested in the technique you'll use to do it? It ate my lunch in the IDE. LOL.
Title: Re: Color text
Post by: Andy on March 12, 2020, 07:18:07 AM
Larry,

Not really worked on that up up till now, but it is in the back of my mind and I do have a few thoughts on it.

When I've got them clearer in my mind and tested them a little then of course I'll let you know.

Any one attempting this needs a lot of spare time that's for sure!

Was wondering at the moment just how I could get the code to be compiled - maybe if I crawl a little and ask very nicely you might tell me? lol.

Andy.
Title: Re: Color text
Post by: LarryMc on March 12, 2020, 10:47:46 AM
Quote from: Andy on March 12, 2020, 07:18:07 AMWas wondering at the moment just how I could get the code to be compiled - maybe if I crawl a little and ask very nicely you might tell me?

You would have to get LarryS' approval for that because at that point you would have a competitive IDE of sorts.  You're getting close to the point now where I may feel limited in how I can help you as much as I would like to.

Title: Re: Color text
Post by: Andy on March 12, 2020, 11:18:04 PM
Larry,

Yes, thought that would be the most likely answer - and making a competitive editor was never my goal.

It was just a logical question to ask.

So just to re-iterate what / why i'm attempting this editor.

1. I had not really programmed with rich edit / multi line edit controls before and wanted to see just how it works.

2. I wanted to test just how good (or not so) was colouring of text in a rich edit control.

3. When I use the IWB editor there are some things I would like to do that I simply can't - so I wanted to see if I could make a program do some of these things.

The plan in my mind is to use this additional editor to help code with such things as..

Insert block of code with onr click like SUB / ENDSUB, FOR / NEXT etc.

Not only list sub routines, but also windows (and their handlers).

Have to ability to jump not only to the start of a sub or window, but also jump to the end of any of them as well.
 
Be able to add in my

Find / Replace code
Copy / Rename sub and windows code
Remove sub routines code

Have a one click option (button) where copies of the whole file can be saved as a snapshot.

And simply working out how I and probably others code.

All this is there so that when you want to the file can then be loaded into the IWB editor and carry on.

These are the limits of what I'm trying to do and no more.

As said earlier, it was just a logical question to ask - no more.

Hope that clears everything up.

Only ever good intentions here.

Andy.
Title: Re: Color text
Post by: LarryMc on March 13, 2020, 12:20:41 AM
Never was a question of intentions.
I think it's a demonstration of good programming skills.

And the adding of blocks of code like for window and dialog skeletons and loops etc was something I'd thought about when I added the functionality of the tool menu of the IDE.