PDA

View Full Version : Possible implementation RTF_AppendText



catventure
21-09-2006, 18:30
Hi,

I cannot seem to get the rtf_appendtext command to work in the richedit smaple program 0002...



rtf_appendtext(hDlg,%ID_EDITOR,"some text",%sf_rtf)


I don't know why. Curious, it was working fine last night but in new preview it throws up a script run time error - missing parentheses...

Can't get it or rtf_settext to work period.

Any ideas?

Thanks,
catventure

Petr Schreiber
21-09-2006, 18:47
Hi catventure,

I was getting this error too. But if you look at the help file, the correct syntax is:


rtf_appendtext (hDlg, %ID_EDITOR, "some text" )


... the last equate is not needed. New version probably introduced abbreviated syntax.

Bye,
Petr

catventure
21-09-2006, 18:54
Hi Psch,

Will check that, but think I tried it before - maybe that it only appends the text as standard text format and not in rich text format....?

catventure

Petr Schreiber
21-09-2006, 19:01
Hi catventure,

you are right. Just text works, not the RTF "source".
One way could be to use some function, which would send the formatting messages separately.

You could for example send this UBB code like text:


"And in the room was ugly monster"


... The function could parse the text, and when it would find "[ b ]" it would send


RTF_SetEffect(hDlg, %ID_Editor, RTF_GetEffect(hDlg, %ID_Editor) OR %CFE_BOLD)


then reset it on "[/b]" and so on...

I'll try to write such a helper function and post it here.

Bye,
Petr

Petr Schreiber
21-09-2006, 19:34
Hi,

so this is my first attempt. It sends rich text to the control, you must send ubb like coded string in.
Caution!: Only tags for bold, italics, underscore and strike are currently supported!



function RTF_AppendUBB( hDlg as dword, ctrlID as long, ubbText as string)
local r1, r2 as long, ubbToken as string
local tText as string
tText = ubbText

' Reset formating
rtf_seteffect( hDlg, ctrlid, 0)

do

r1 = instr(tText, "[")

if r1 = 0 then
if len(tText) then RTF_AppendText( hDlg, ctrlID, tText)
exit do
end if

r2 = instr(tText, "]")

RTF_AppendText( hDlg, ctrlID, MID$( tText, 1, r1-1 ))
ubbToken = UCASE$(trim$(mid$( tText, r1, r2-r1+1)))
select case ubbToken
case ""
RTF_SetEffect(hDlg, ctrlID, RTF_GetEffect(hDlg, ctrlID) OR %CFE_BOLD)

case ""
RTF_SetEffect(hDlg, ctrlID, RTF_GetEffect(hDlg, ctrlID) AND NOT %CFE_BOLD)

case ""
RTF_SetEffect(hDlg, ctrlID, RTF_GetEffect(hDlg, ctrlID) OR %CFE_ITALIC)

case ""
RTF_SetEffect(hDlg, ctrlID, RTF_GetEffect(hDlg, ctrlID) AND NOT %CFE_ITALIC)

case ""
RTF_SetEffect(hDlg, ctrlID, RTF_GetEffect(hDlg, ctrlID) OR %CFE_UNDERLINE)

case ""
RTF_SetEffect(hDlg, ctrlID, RTF_GetEffect(hDlg, ctrlID) AND NOT %CFE_UNDERLINE)

case ""
RTF_SetEffect(hDlg, ctrlID, RTF_GetEffect(hDlg, ctrlID) OR %CFE_STRIKEOUT)

case ""
RTF_SetEffect(hDlg, ctrlID, RTF_GetEffect(hDlg, ctrlID) AND NOT %CFE_STRIKEOUT)

end select

tText = STRDELETE$( tText, 1, r2)
if len(tText) = 0 then exit do

loop

' Reset formating
rtf_seteffect( hDlg, ctrlid, 0)

end function


Usage
Call something like this to make it work:


RTF_AppendUBB( hDlg, %ID_EDITOR, "And in the room was ugly monster")

catventure
21-09-2006, 20:07
Hi Psch,

It seems you were right about the new syntax after all!
I changed my code and its now working OK. Certainly the rich text is being carried forward by RTF_APPENDTEXT now in TAB's readonly richedit control - so maybe the shortened syntax is now correct and functioning OK? Maybe Eros will confirm.

As to your code snippet example I will indeed be implementing something along those lines and I will examine your code carefully. But please do not trouble yourself on this for now. Everything seems OK now. Thanks for your valued help on this.

I thought something wrong when trying to use RTF_APPEND TEXT correctly in the sample 2 richedit example when the text did not appear at the start of the control in the Courier 12 default, that is all.

Bye
catventure

catventure
21-09-2006, 22:34
Hi Psch,

The code you made I have copied to look at as I'm thinking of using such embedded control commands as and , and .....etc
It seems a good way of doing it using rtf_geteffect and rtf_seteffect to effect changes within outputted text to the richedit. I'll study it more offline. I'm amazed you came up with the example so fast!

Best wishes,
catventure

ErosOlmi
21-09-2006, 22:46
Petr,

I like so much your idea that I would like to embed your function inside RTF_AppendText function.
What do you think? catventure, are you OK with UBB codes?

Ciao
Eros

ErosOlmi
22-09-2006, 00:04
Ok, I could not wait :D
I've already added it and new version updated in download area.

Have a look at "RichEdit_002.tBasic" example under Control menu :)

For the moment supported BB codes are: bold, italic, underline, strikeout
I will see if I can add: font, sont size, beep, wait, color, ...

Ciao
Eros

ErosOlmi
22-09-2006, 00:16
And another one: sound.
Something like UBB code: wav, midi, ...
Catventure, imagine how many possibilities are open with sounds in TAB? More atmosphere for the user: :-[ :) :D :o
When a character enter a room or move or look at something, a sound, in many cases can make a lot of difference.

I do not know if this is against text adventure games rules but it would be nice.

What do you think?

catventure
22-09-2006, 00:33
Hi Eros,

I've just read this and it is exciting, yes!
Psch idea good.
I just came in so will get new preview to check out.
Thanks again.
But adding fontname,fontsize and other stuff into code seems like fantastic news!

catventure

catventure
22-09-2006, 01:18
Woohoo YES!

What can I say? The extension to the rtf_appendtext is the biz!!! :) :)
I'm knocked over by how easy you've made it with the UBB codes (great idea, psch)
Eros, you're right I can see it would be ideal for adventure text in richedit.
Special request - please can we make it work with fg, bg colors too?????
Maybe and and
Absolutely fantastic guys!
Well, anyway I'm off to have a play with it now :)

catventure

catventure
22-09-2006, 02:33
Hi,

I am astounded to report that with just one line of code in Thinbasic Adventure Builder I have successfully added the extended RTF_AppendText function and TAB can now use the existing new rtf formatting through the code embedding in text of UBB's. All thanks to Eros and Psch help.
What a great day it's been!!! :)

This is a really marvellous feature now.

I hope you do not think me nit-picking when I tell you that I have
performed a test of the codes using the word "test" and apply each code (bold,italic,underline and strikeout) to EACH LETTER of the word "test" like so:


Test 1
=====

"test" ------- This is how it should look but in the richedit only the first code (bold) was applied.... the others were ignored..

If I put AT LEAST ONE space between each set of square brackets then all the codes are correctly formatted when the text is appended eg:

Test 2
======

"t e s t" ------ This is OK in richedit.

Ideally and by far the best option, would be to make it behave so that Test 1 worked; that way a word could be printed as normal but still have each of its letters formatted; if even or ever required, that is... ( and maybe later individual colored letters of words...)

Don't get me wrong. I'm over the moon with it as it is :) Still it would be nice if it could pass Test 1 ;)

catventure.

ErosOlmi
22-09-2006, 07:15
catventure, why to worry? no problem at all.
If there are problems, we are here to try to solve them :D

This night I've added this functionality in one minutes thanks to Psch generosity. I was expecting there would be some problems.
I will fix it as soon as possible, just give me few hours because I'm on the road today for some time.
In the meantime, please play with it and report any other possible bugs. We want it working fine. If you are happy, we are happy ;)
Test 1 will work as expected and even better !!

This weekend I will have more time to add new UBB codes support. Psch idea was really brilliant (as usual :) ) also because so simple and elegant.

I will let you know.

Ciao and thanks for your support here.
Eros

Petr Schreiber
22-09-2006, 09:42
Hi,

I'm glad you found the UBB pseudocode usable. Nothing brilliant on this idea from my side, just say thanks to the UBB inventor ( does he still live :D ? ).

Bye,
Petr

catventure
05-10-2006, 17:47
Hi,

Although I have been able to easily include left, right and center aligned text in my adventure richedit control using the new RTF_SETALIGN without problem (and also fg and bg colours) I would like to request if this too could also be added to RTF_APPENDTEXT as UBB code eg:


I am left aligned


I am right aligned


i am centered

The above uses the set/unset LEFT RIGHT CENTER forum tags enclosed in brackets

............I don't know if marquee would be possible at all..........

It would certainly be easier/faster than my current routine and make for simpler construction of formatted adventure game text.
I really like the RTF_APPENDTEXT and can't wait for it to be given even more extended power :)

Regards,
catventure

ErosOlmi
05-10-2006, 23:02
catventure,

I've updated current thinBasic 1.0.11.0 with latest UBB requests: left, center, right. Marquee not possible, sorry :)
Remember: LEFT, CENTER and RIGHT have no corresponding /LEFT, /CENTER and /RIGHT because they work at paragraph level. To change align, just add a new $CRLF and a new align tag.

I think I've also fixed enter problem. Let me know about this, please.

Eros

catventure
06-10-2006, 01:09
Hi Eros,

Nice job with the 'align' UBB codes which works well.

The 'enter' problem: Eros, it is a whole lot better now, but just *occasionally* it gets a little sluggish - by that I mean not always responding to first keypress...
But yes..definitely fixed better :)

You might want to check out RTF_SETBGCOLOR. It seems to have stopped working.. See: Samplescripts/UI/richedit_002.tbasic

Thanks,
catventure.