March 29, 2024, 07:00:42 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Color text

Started by Andy, February 03, 2020, 12:10:44 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

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.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

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.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

h3kt0r

February 03, 2020, 04:08:11 AM #2 Last Edit: February 03, 2020, 04:43:09 AM by h3kt0r
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

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...

Andy

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.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

h3kt0r

February 03, 2020, 06:17:03 AM #4 Last Edit: February 03, 2020, 06:33:39 AM by h3kt0r
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 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.

Andy

That's a great example,

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

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

When I get finished with this of course I will release it, what I've got so far...

See screen shot.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

aurelCB

WOW 
is that scintilla control  ;D
well ..how you create margin ?..i will guess it is richedit control?

h3kt0r


LarryMc

What you trying to do  Andy, replicate what all I did in the IDE?  ;D  ;D
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

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.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

aurelCB

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 .

Andy

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.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

aurelCB

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#

Andy

February 06, 2020, 09:49:09 AM #14 Last Edit: February 06, 2020, 09:56:53 AM by Andy
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.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

billhsln

When all else fails, get a bigger hammer.

fasecero

Yep super nice, it would be amazing if user FUNCTION names could have a unique color (dark red, something like that).

Andy

February 07, 2020, 12:34:44 AM #17 Last Edit: February 07, 2020, 01:26:31 AM by Andy
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.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

aurelCB

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.

aurelCB

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

Andy

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.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

aurelCB

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..

aurelCB

February 07, 2020, 08:36:30 AM #22 Last Edit: February 07, 2020, 08:50:32 AM by aurelCB
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?

aurelCB

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..

Andy

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.





 



Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.