Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - Text display without window

Text display without window

Discuss PocketC for CE (including Desktop Edition)

Postby mikeajones on Fri May 04, 2001 7:12 am

I have had to come up with my own way to read a text file and display it without a window so that I could use different color backrounds for a PADD simulator. The method I used goes something like this. I open the file, read each byte and place it into the string "ttttttttttttttttttttttttttttttttt", progressively replacing each t with the read bytes, then placing the string into an array. Once the file is read it places each string from the array on the screen one after another, simulating a text window. It works fine but the problem is that I cant figure out how to make the the text wrap, so words cut off at the end of the line. I guess I could find some way of doing it but I'm new to this. If this makes sense to anyone and you have a better idea of how to display text without windows, let me know.
mikeajones
 
Posts: 6
Joined: Thu Apr 26, 2001 9:16 pm
Location: USA

Postby guy on Fri May 04, 2001 7:45 am

Use the textw() function to get the width of the string in pixels to see if it will fit. If it is too large then use the ratio of actual size to size remaining to work out roughly how many of the characters in the string will fit. Use textw again for complete accuracy, adding or removing one or more characters.

Then display the first part.

Repeat for the remainder of the string until the tail end of the string fits on a line.

Repeat for all of the strings.

If you want to make the text continuous, rather than breaking it at the end of each input string, then don't display the final tail end of the line, add it to the beginning of the next line, and then start displaying again.

Why do you need to start with a string of "t"s and replace characters. Can't you just append them to an empty string?

The fastest way to read a text file line by line is to read a block larger than the longest line that you expect. Then call strchr to find the CR or LF. Chop the string off at that point, then use the fseek function to position the input pointer back to just after the CRLF.

Doing the read a byte at a time is likely to be really slow.



Guy


Edited by - guy on 05/04/2001 02:46:37
Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum
guy
 
Posts: 879
Joined: Thu Dec 07, 2000 8:58 am
Location: United Kingdom

Postby mikeajones on Sat May 05, 2001 8:29 am

Actually, Thats the way I was doing it, reading only the amount to be displayed. Another thing that was strange was when I tried to use an empty string for the text it wouldn't work. I assumed it was because I was replacing characters for which there were none to begin with. The tttttttttt's may seem different but they do work. I think I tried the textw function before and forgot about it, but my original concern was cutting off words in the middle. It actually looks alright the way it is but its confusing to read broken off words, un-hyphenated. I was thinking use the textw to fit the line, then see if the last byte in the line is a character, if it is then see if the next one is and if so, go back to the last space and cut off. Sound good?
mikeajones
 
Posts: 6
Joined: Thu Apr 26, 2001 9:16 pm
Location: USA

Postby Justinespinosa on Sun May 06, 2001 8:40 am

First, i assume you don't use the Tahoma font because every chrartcher haven't got the same width, wich is unusable for a textmode screen in PocketC. Find a font in which every char as the same width.
Then, the best way i think is to do like this:

<pre id=code><font face=courier size=2 id=code>
int CurrentLine;

print(string txt){
string temp1,temp2,rest;
int w,charw,charh;

rest = txt;
charw = textw( (char)1 );
charh = texth( (char)1 );

do{
w = textw(rest)
if(w > screenx() ){
temp1 = strleft( rest, screenx()/charw );
temp2 = strleft( temp1, strlen(temp1) - strrchr(temp1," ") ) ;
rest = strright(rest, (w - screenx())/charw );
}else{
temp2 = rest;
}
text(0,CurrentLine*charh ,temp2);
CurrentLine ++;
}while (w > screenx() )
}
</font id=code></pre id=code>

This code hasen't been tested. But it should work. And you can check it if need an idea to do your word wrap

J.Espinosa

OUTS Softwares
J.Espinosa

OUTS Softwares
Justinespinosa
 
Posts: 156
Joined: Wed Dec 06, 2000 2:30 pm
Location: Switzerland


Return to PocketC for CE

Who is online

Users browsing this forum: No registered users and 1 guest

cron