0 registered members (),
18,008
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Text/string editing
#270100
06/06/09 09:47
06/06/09 09:47
|
Joined: May 2009
Posts: 258 Chicago
Jaeger
OP
Member
|
OP
Member
Joined: May 2009
Posts: 258
Chicago
|
Good ehh... morning? It's 4:30am here, lol...
But, I've got a few questions. First and foremost, is how to edit a text/string like it's done in standard Windows programs. I've been using inkey(string);, however it is more akin to editing text in DOS or on a really old computer. You can't highlight or select text with the mouse, cut, copy, or even paste. I'm sure I could write my own functions to do things like copy and paste, but I don't know how to select text/characters with the mouse to begin with.
I've also got another question, and I guess I'll have to explain what the goal is to ask it. I'm doing a side project to make a decent messenger/chat application. I want to have the text editing functionality like mentioned above, with a few other things. I want it so that when a user sends a message to the server, it is displayed on the screen after the user's name (I can do this part). I want to set a maximum of 2, maybe 3 lines of text per message. After a certain number of characters, it needs to skip to the next line (probably 100-150 characters per line, and max of 200-300 per message). Furthermore, as messages come in, they are displayed in a descending order, one after another. There should be a maximum of visible messages in the window, maybe 50 or so. After that limit is reached, the oldest message is erased to make room for newer ones.
Yes, I know that's a lot of info all at once, heheh. I can handle all of the basic stuff... making windows, buttons, whatever. But I scoured the manual for information on how to do some of these things and came up with nothing. inkey() was about the only thing I can see, and it's not the best choice for what I need to do. It's decent for entering the IP address and username, but I don't feel it will cut it for the actual message box.
Any help is greatly appreciated. I just can't find this stuff in the manual....
Last edited by Jaeger; 06/06/09 09:48.
|
|
|
Re: Text/string editing
[Re: Jaeger]
#270236
06/07/09 07:19
06/07/09 07:19
|
Joined: May 2009
Posts: 258 Chicago
Jaeger
OP
Member
|
OP
Member
Joined: May 2009
Posts: 258
Chicago
|
Guess the lack of response means no one's ever tried this, or knows how, heheh. Maybe you can't do it with Lite-C and standard instructions period? I guess I'll have to finish this with inkey(), and then do an improved version later in C++ or something. Too bad if so... I love how quick and concise Lite-C is... It's really a wonderful language. It's really a side project to test the native A7 networking abilities (which I hear leave much to be desired). Our WWII sim is on hold right now while I'm waiting for the new artwork, so I wanted to do this in the meantime. Well, thanks anyway I guess... I'll post again if I resolve the issues...
|
|
|
Re: Text/string editing
[Re: Jaeger]
#270240
06/07/09 07:28
06/07/09 07:28
|
Joined: Aug 2000
Posts: 1,140 Baunatal, Germany
Tobias

Moderator
|

Moderator
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
|
You need not to permanently ask why you dont get responses, not all people watch the forum 24/7 so it may take a day or two.
For editing text you have the choice to either use inkey, thats a predefined simple editor, or to use inchar, then you can write the editing functions yourself in lite-C. For instance you can check the last key and then delete or insert characters or move a cursor character and so on.
But if you want to edit the text like in a text editor then you need a Windows Editbox. Thats using the Windows API and you can probably get better info on a Windows forum, at least I have not yet used a Windows Editbox. If its MFC you probably need to write a plugin, if its not MFC you can probably still do it in lite-C.
|
|
|
Re: Text/string editing
[Re: Tobias]
#270263
06/07/09 11:02
06/07/09 11:02
|
Joined: May 2009
Posts: 258 Chicago
Jaeger
OP
Member
|
OP
Member
Joined: May 2009
Posts: 258
Chicago
|
You need not to permanently ask why you dont get responses, not all people watch the forum 24/7 so it may take a day or two. What? Lol. I'm not sure what it means to "permanently ask", but I think you've misjudged what I actually meant. I'm not sitting here groaning because no one answered. People normally don't answer questions they don't know the answer to. I've never seen someone use anything like a Windows edit box in a Lite-C program, and I found no questions like mine in the forums. It's not exactly a "common" occurrence. It was about 2 days now, so I assumed no one has tried this before, or at least recently. And so far that appears to be a very reasonable assessment. That seemed like a sort of rude/condescending statement, but maybe I'm mistaken... But thanks for the info anyway. I was thinking I'd have to access Windows API somehow to do this properly. I'm glad to know that I may be able to do it in Lite-C, so I might not have to rewrite the whole thing in C++ (which can get ugly if I work too fast, heheh). I actually think I've got a tutorial on Windows programming for text fields and this sort of thing somewhere on my PC. I'm going to hunt for it. If I can find it, I might be able to "convert" it over to Lite-C. I've adapted C and C++ programs and commands to Lite-C before. I recently did it with an encryption/decryption program that encodes and decodes text with a special key (really cool program :D). I could probably even chop that code down, include it in this app, and use it to encrypt data. But anyway, I'll continue looking into this. If I can get this to work well, I'll definitely share the code and info on it with everyone. I think that could open up a lot of possibilities for Lite-C programming. It would even be cool to see this sort of feature made into a native A7 feature in the future. Thanks again, and if anyone else has info, I'm eager to hear! 
|
|
|
Re: Text/string editing
[Re: Jaeger]
#270280
06/07/09 11:58
06/07/09 11:58
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
Expert
|
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
use str_width() for the line breaks. if you use str_length (which returns the number of characters) and you're working with true type fonts then lines will have different lengths on screen because an m is longer than an l, so 5 lllll will be much shorter than 5 mmmmmm. str_width will let you cut the line where you want it. What you're trying to do will be quite some work. I wrote my chat with a scrolling text struct which consists of Text objects (one per line) so that I can color ever line a different color (in case multiple people chat). The line break is a pain as well, because usually text fields don't break after a set width but after the last word that fully fits into the line. So I'd say use every shortcut you can. The inchar function sounds very interesting though. i have no idea how you'd do the text selecting though...
Good luck. and use str_width.
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: Text/string editing
[Re: ventilator]
#270288
06/07/09 13:14
06/07/09 13:14
|
Joined: May 2009
Posts: 258 Chicago
Jaeger
OP
Member
|
OP
Member
Joined: May 2009
Posts: 258
Chicago
|
Ok, thanks guys. I'm going to see what I can do with it now. "you can't use mfc controls in a directx window." I did not even think about that. Thanks for mentioning. This is going to be pretty tricky then I guess. I have one cool idea though. Maybe I could make a separate, free floating text box inside it's own little window, where the user can type/edit text freely, like in a standard windows program. Then hitting the "Send" button, or pressing enter could pass the string to the main application? That may be more trouble than it's even worth though. Just a thought. I think it could be pretty cool though, especially with a feature to dock/undock it from the main window, drag it around, etc.  I know I COULD do this copy/paste thing, in an extremely complicated way; maybe by getting the mouse_pos vector when the button is clicked, measuring where it is dragged to before it's release, and then determining which characters in TEXT objects should highlight, and so on... But that really seems ridiculous for a small project like this. I'm trying not to make it too outrageous. Plus, I'd probably go and do all of that, then find out there was a very easy way to do it that I overlooked (happens to me often!). I'll also look at the stuff in the SDK and see if anything fits the bill. I think this will be really cool if I can get it done! 
|
|
|
Re: Text/string editing
[Re: Jaeger]
#270319
06/07/09 17:52
06/07/09 17:52
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
Heya, I've created what you've explained so it acn be done. str_width I've not tested yet but it might be able to achieve what you need for limiting string lengths (if it doesn't you'll need to calculate every character length in pixels for the font you're supporting) create a TEXT* for displaying the lines create a function for creating each line for i < txt.strings txt.pstring[0] = str_create("") create a function for writing a new line for i < txt.strings txt.pstring[i+1] = txt.pstring[i] txt.pstring[0] = new_string create a blue bmap for the cursor the height of the text and 1pixel wide create a PANEL* for for placing behind the text where the user will click to type create 2 variables for storing the cursors start_position and selection_position then the cursor position will be all the characters in the string combined width, from the cursor start_position to the selection_position hope this gives you a pointer, and yes it's definately possible though you'll need to add to every other function if!(new_inkey) or something similar i never did find a way to check for capslock tho 
|
|
|
|