PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Soft input panel

I am literally pulling hair outta my head. I read Conan's idea about making our own SIP but i cant for the life of me figure out HOW to do it.

All I have now is I can detect what box is being hit on my simple SIP but I cant put that char in a string. I always get 'cant convert char * to const char' and things like that.

Okay lets say i hit the letter T on the sip, how do i assign char keyhit="T"? and if i hit Y then keyhit="Y"? The only idea is to test each rect using "if" but that would make more than 36 "if" statements.

Then how to save that char in a string? I tried..
char *dname;
strcat(dname[strlen(dname)],keyhit);
and it doesnt give the slightest indication of it working.

All I need is a dialog to popup that asks "what is your name?" and the user can enter text and the value saved to a string called dname after pressing enter. I dont even know how to display what the current value of dname is on the screen..(current value means before pressing enter)

Is there any sample code that can achieve this? I can only learn by example not by theory. I wont know how to pocketfrog if there was no blitsample.

Please please point me in the right direction. Keep in mind I dont know C++, I only know pocketfrog. And not much at that either. =(

Thanks a million in advance for ANY help you can give me!

masCh
Hi,

"T" is a string that has one character and an unseen NULL terminator. 'T' is a single character. So, to assign your char variable you should do this:

char keyhit = 'T';

To build up a string of characters you could do something like this:

Code:
char keyhit;
char dname[16];
int index = 0;

//each time the user taps the screen,
//assign the appropriate character to the next
//available position in the string

keyhit = 'T'; //or whatever other character you want
dname[index] = keyhit;
index++;



Don't forget to check that index doesn't go out of range.

Pam
BurningSheep · 01 Nov 2002, 18:36 UTC — Soft input panel
masCh wrote:
Okay lets say i hit the letter T on the sip, how do i assign char keyhit="T"? and if i hit Y then keyhit="Y"? The only idea is to test each rect using "if" but that would make more than 36 "if" statements.

It would be better to make an array of rects which you can walk through using a for-loop.
What would be even better is borrowing the concept that jojosip uses, check out their website for more info

http://jojosoft.gapidraw.com/

basicly what it comes down to is that they are using an image to map coordinates on the keyboard to their corresponding ascii code. Shouldn't be too difficult with the brand new GetPixel() function :lol:
Conan · 01 Nov 2002, 20:01 UTC — Soft input panel
The GapiDraw version is more complex than mine as I lined up the characters in columns so that QAZ, WSX etc were all lined up vertically instead of offset. This made reading the min-keyboard easier.

My code is tidy enough to release & I comment pretty well but if you want a complete keyboard then trying a convert of the GapiDraw version would be best. Mine does the alphabet, numbers, backspace/DEL and spacebar.

About the reading of the keyboard and assigning the correct values it's actually easier than you think. If you read a Rect you then have an x & y which you can translate with a little maths into a key code. You then look up the required value in a string table and use that to output to screen or wherever.

If anyone wants my code let me know here and I will tidy it up sometime and post to my PF pages.

I've just gone through the process of understanding C++ chars, TCHARs and it's total lack of real string support. Getting string data into a 2D array and out again took an hour to figure as the built-in help is not much good. It's amazing how the most simple basic interpreter can handle strings better than C++ :?:
masCh · 01 Nov 2002, 23:42 UTC — .
I think that might be my problem that there is limited string support. I was actually thinking of doing something like this:
char line[4][10];
char line[0]="qwertyuiop";
char line[1]="asdfghjkl";
and when the user hits the keyboard i find out which rect and do:
char keyhit=line[x][y];
but that didnt work iirc.. some problem with converting const char to char or something. that should work right? i saw in the help files that c++ can support multidimensional arrays.

on another problem.. lets say you wanna popup a dialog that has 2 lines: "what is your name?" and underneath is the user input char array dname variable. how would you do this?
I tried:
display->Blit(100,50,Ddialog);
RECT rcStr,rcStr2;
rcStr.set(0,0,100,50);
rcStr2.set(0,50,100,100);
HDC hDC=Ddialog->GetDC();
DrawText(hDC,TEXT("what is your name"),-1,&rcStr, DT_WORDBREAK);
DrawText(hDC,TEXT(dname),-1,&rcStr2,DT_WORDBREAK);
Ddialog->releaseDC(hDC);

This look right? I got errors on the 2nd parameter of the 2nd DrawText. Thats why I need to know how you would do it so that i can compare.

Thanks for all the input all! appreciate this very much.

p/s if you can post your sip code Conan that would be grand! i want to find out what i'm doing wrong.
BurningSheep · 02 Nov 2002, 02:14 UTC — Soft input panel
Conan wrote:
I've just gone through the process of understanding C++ chars, TCHARs and it's total lack of real string support. Getting string data into a 2D array and out again took an hour to figure as the built-in help is not much good. It's amazing how the most simple basic interpreter can handle strings better than C++ :?:

Total lack? I'm guessing you're exagerating, but anyways there are quite some string functions you can use to make your life a little easier.
Documentation on the other hand... I was coding some stuff earlier today and it took me a half hour before I figured out how to use a function (GetCharacterPlacement), just because of an error in the MSDN library :\

[edit]
BTW, the TEXT() macro is for string literals only, you should use TCHAR * dname instead of char * dname (if you aren't already doing that)
[/edit]
masCh · 03 Nov 2002, 08:14 UTC — thecode
when can we take a look at your sip code, Conan ? I need to see how you display teXt on the screen.

By the way,your html pages chapter 3 and 4 cant be accessed from chapter 2 and 3 respectively, you have to go back to chapter 1 for eg before you can click chapter 4. the problem is with the links, i think you referenced it on your local harddrive
Conan · 03 Nov 2002, 09:47 UTC — Posting my code, fixing my links
I will post the code & let you know here when it's there.

Frontpage is bad a slipping in the odd C:\ path instead of a proper link. I will sort today.

I'm using 2 methods to display text. In the SIP sample I use TTF fonts & windows GDI functions and I'm also using the bitmap font support posted on PF by Gersen (hope that name's correct). With both these methods I'm using wide characters so I'm using TCHAR instead of char, TEXT("HELLO") to make literals and the wide versions of the string functions like wcscpy. I have also been using the int to wide char finctions to display numbers eg: _itow(int_num,tchar_num,10);

For the keyboard I have a big case statement with lots of these lines loading up strings:-
case keychar_1:LoadString(_Module.GetResourceInstance(),key_1,inkeystr,20); break;

Just in case my code does not answer this, what part of displaying text on screen are you most interested in? making up the strings or actual rendering etc
BurningSheep · 03 Nov 2002, 13:52 UTC — Posting my code, fixing my links
Conan wrote:
With both these methods I'm using wide characters so I'm using TCHAR instead of char, TEXT("HELLO") to make literals and the wide versions of the string functions like wcscpy.

TCHARs aren't exactly wide characters, it's compiler dependent; it can either be a normal ANSI character or a UNICODE char (like it is in eVC++). If you want to use wide chars you can use the wchar type, if you really want to use the flexibility of the TCHAR type you should use TCHARs and the TEXT/_T macros; but also the TCHAR string functions. They all start with _tcs instead of str. So to copy a string you would use the _tcscpy() function
masCh · 04 Nov 2002, 15:58 UTC — hmm
I dont understand what you mean by teXt rendering, but I think I am mostly interested in being able to display variables on screen

Mainly I'd just like to be able to ask the user to input something in a teXt boX and be able to display each char as it is being typed with backspace etc working
Conan · 04 Nov 2002, 19:29 UTC — drawing text on screen
By rendering I just meant which way you caused the text to appear on screen. ie: using TTF fonts & GDI functions or using a bitmap with pictures of fonts linked to code to cut out the correct bitmap for the string to be drawn.

I checked out my code today & added extra comments but did not get to test as activesync 3.6 (which I installed as it's needed by smartphone 2002) seems to have stopped downloads to the emulator. Once I know it's working as it was then I'll upload the project files.
Conan · 09 Nov 2002, 17:31 UTC — SIP keyboard project files now available
As requested I have uploaded the code for my simple SIP keyboard as a resource to show how to read the keyboard & display the text to the display.

I had to rip this out of a bigger program so ignore any lines which don't seem to belong if I did not cut them all.

Here is the link to my PocketFrog pages:-
http://www.sundialsoft.freeserve.co.uk/pocket_frog.htm

Hope this helps. It's not great code but it works & looks good.
masCh · 10 Nov 2002, 05:20 UTC — cool
i wont be able to try out your code as i'm outstationed till the end of the week. thanks though i will definitely give it a try and figure out how its done. awesome!
adde · 13 Nov 2002, 14:44 UTC — Strings in C++
I've just gone through the process of understanding C++ chars, TCHARs and it's total lack of real string support. Getting string data into a 2D array and out again took an hour to figure as the built-in help is not much good. It's amazing how the most simple basic interpreter can handle strings better than C++


Conan. Don't blame C++ for faults induced by sucky Windows. I've worked quite a bit with C++, but I've only been working with Windows (CE) programming for a month now. String handeling is a hassle in CE, I give you that, but there are solutions if you know what you want to do.

If you are using ASCII chars, the solution is simply the STL std::string container. It works (almost) exactly as the JAVA String class. You can construct, concatenate, test for equality/inequality and search. For instance:
Code:
std::string str = "Testing";
if (str == "Testing")
str += " concatenation";

STL is fully documented and references can be found on the internet. I recommend using STL containers, like string,vector,list,etc.. instead of writing your own, becuase they are fast, safe and easy to use. They keep track of their own memory allocation/deallocation so you don't have to worry about "writing outside the array".

Ok.. but what good do I have with ASCII chars when coding in WinCE? They are using wchar_t (=widechar) instead of char. Well, it all depends on what you are doing. For instance, if you are reading and writing from a file, you don't need to worry about wide-chars at all. And if you absolutely must use widechars, for displaying info to the user using MessageBox:es for example, you can always convert from char to wchar_t using mbstowcs function defined in stdlib.h (or was it wchar.h) and the back again if you get input from the user as well.

Anyways, there are a bunch of functions to work with and convert back-n-forth between ASCII chars (multibyte chars) and wide-chars. They are located in the stdlib.h and wchar.h libraries.

Also, Thanks to Pam for enlightening me about the use (and usage) of the T char functions. Having a compiler dependant type is very practical for writing compatible code that can run on both CE and PC platforms.

So, to return to Conans quote. Strings in CE is a problem because
1. They use wide-chars and the STL container doesn't support that.
2. There are no iostreams in CE witch makes everything so much harder.

A small example on how to insert and retrieve text from a 2D (character) array can look something like this. Actually, it's not a 2D array, but a single vector storing strings (which is what I think you wanted, right?)
Code:

// Declare and initialize a few STL strings
// (=character container)
std::string str = "string";
std::string str1 = str +"1";
// Declare a STL vector container, containing strings
std::vector<std::string> vect;
// Push the string into the vector (last index)
vect.push_back(str);
vect.push_back(str1);
// Ok, for those who have followed this far, the vector looks like this:
// vect[0] = "string"
// vect[1] = "string1"
// To retrieve the string, you use standard array notification,
for (int i=0; i<vect.size(); i++)
printf("String: %s\n",vect[i]);
// or the special iterator classes that works with ALL the STL containers
std::vector<std::string>::iterator i;
for (i = vect.begin(); i != vect.end(); i++)
printf("String: %s\n",*i);
// What does this mean? Well, i is a vector iterator.
// std::vector.begin() returns an iterator object pointing to the beginning of vector.
// std::vector.end() returns an iterator pointing one position after the last item in the vector.
// i++ just increases the iterator (ie: pointer arithmetic)
// *i dereferences the iterator so that you get the item stored in the vector: in our case a std::string.

EASY!! String handeling in C++ using STL
Conan · 13 Nov 2002, 15:12 UTC — STL Strings etc
Many thanks for the advice & sample. I would prefer to use ascii as my game has so much data loaded from files defining the universe that all those zero bytes are a waste. I will try your suggestions out at the weekend & report back.
adde · 13 Nov 2002, 15:17 UTC — Wide-chars and STL strings
DUH!! don't I feel like an idiot? :oops:

Regarding my last note, forget you ever read the line
Strings in CE is a problem because
1. They use wide-chars and the STL container doesn't support that.


What I didn't know then (but know know since I got curious and looked it up in the STL library reference) is that std::string is just a typedef for std::basic_string<char>. And if you want to use wchar_t, there is a typedef called std::wstring.

So, I can now easily say that string handeling in CE is NOT that much of a problem if you use the STL containers.

Ok, that's nice, but how do I get the wchar/char string out of the container and into a MessageBox for instance??

Easy, you use the std::basic_string<charT>.c_str() function that returns a null-terminated charT*. For example:
Code:
std::wstring wstr = L"I'm a wide-char string!";
::MessageBox(0,wstr.c_str(),L"Info:",MB_OK);

And that's how you do it. Sorry about my "false" info before, but there are times when you want to convert from char to wchar_t and vice-versa so I didn't bother to change it.

Also, a tip for all you C++ coders out there who use other platforms than CE (ie: platforms that has iostreams), the <stringstream> class is very nice. Whith it, you can use strings just as you would use stdout and stdin with cout,cin and cerr. For example:
Code:
ostringstream message;
int i=17;
double d=33.3;
message << "Error: " << i << " is less than " << d;
cerr << message.str() << endl;

Of course, the stringstream has a wide-char equivelant in wstringstream. They are both typedefs of the basic_stringstream class.

Hope this helped (or can help) someone. Shure helped me =)
masCh · 17 Nov 2002, 23:16 UTC — wow
how did you guys become such geniouses at programming? I can just barely make some sense as to what you guys are actually saying. (wchars? tchars? huh?) I couldnt even feel comfortable with just using basic string if that even exists (i used to do a little java) I dont understand the built-in docs because they usually lack sample code and then i'd have no idea as to what they're actually saying =)

Nevertheless, I think this is a great reference for me in trying out c++ and understanding more about this compiler.

Thanks a bunch, guys!
adde · 18 Nov 2002, 02:40 UTC — Stringstream library
Just to clearify: the class std::stringstream is available from the <sstream> library and NOT the <stringstream> library as I wrote earlier (it doesn't even excist). More info is available in the STL reference. Peace out!