RELEASED: NXC UserInteraction Library
-
- Posts: 16
- Joined: 31 Jan 2012, 19:44
Re: RELEASED: NXC UserInteraction Library
That looks useful, no there is nothing this specific in the library. It could be achieved by using multiple calls to createQuestionDialog but having the code behind do you job looks better, since in this case your answers and actions follow a pattern that can be automated. I will certainly include it in the next release, thanks!
Elendurwen
http://lenkaspace.net
http://lenkaspace.net
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Re: RELEASED: NXC UserInteraction Library
I wrote a "split string" routine so the user doesn't have to figure out where the newline characters have to be placed and modified my "multi-panel" code to use it.
Split String:
Modified multi-panel:
Please feel free to pick these up and use them.
Split String:
Code: Select all
// ====== Split the string at blanks that will give the longest displayable lines.
string splitString(string si)
{
int iStringLength = StrLen(si);
int iLineLength = (100 - (SCREEN_PADDING * 2)) / FONT_WIDTH;
string ci;
string so;
bool bDone = false;
int iStart = 0;
int i, iAbs, iBlank;
so = si;
until (bDone)
{
iBlank = 0; // Assume we won't find a blank.
bDone = ((iStart + iLineLength) >= iStringLength);
if (!bDone)
{
for (i=0; i<iLineLength+1; i++)
{
iAbs = i + iStart;
ci = MidStr(so, iAbs, 1);
if (" " == ci)
iBlank = iAbs;
else
{
if ("#" == ci)
{
iBlank = iAbs;
break;
}
}
}
if (0 == iBlank)
bDone = true;
else
{
so = StrReplace(so, iBlank, "#");
iStart = iBlank + 1;
}
}
}
return so;
}
Code: Select all
//=============== Multipanel display
/**
* Dispaly multiple panels controlled by the NXT arrow keys.
* @param panelItems_[] Array of strings that are the panels.
* exits when user select "Next" on last panel.
*/
void createMultiPanel(string& panelItems_[]) {
// State machine controls which item is displayed.
int iState = 1; // Display first panel.
string sLeft, sRight; // Values for buttons.
until (0 == iState) {
sLeft = "Previous";
if (1 == iState) // If at the first panel.
sLeft = ""; // No "previous" panel to go to.
if (ArrayLen(panelItems_) == iState)
sRight = "Exit";
else
sRight = "Next";
if (0 == createQuestionDialog(splitString(panelItems_[iState-1]),sLeft,sRight))
{
if (1 != iState) // If not at panel 1, move left.
iState--;
}
else
iState = (ArrayLen(panelItems_) == iState) ? 0 : iState+1;
}
}
McSummation aka James
http://www.mcsummation.com/Mindstorms/
http://www.mcsummation.com/Mindstorms/
-
- Posts: 16
- Joined: 31 Jan 2012, 19:44
Re: RELEASED: NXC UserInteraction Library
Hi, thanks a lot was planning on getting down to it this weekend actually but this helps. I wanted to incorporate the split string algorithm in the drawAlignedText function so that all other functions automatically pick it up. Will have a look at your code in details and see what I can do.
I'd like to give you credit in the code, do you have a name / web site you would like me to use?
I'd like to give you credit in the code, do you have a name / web site you would like me to use?
Elendurwen
http://lenkaspace.net
http://lenkaspace.net
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Re: RELEASED: NXC UserInteraction Library
My name is James Summers. My online name, on most forums, is McSummation. My web site doesn't have much on it right now, but I'm getting ready to turn the home page into a "McSummation's Lego Mindstorms" site - http://www.mcsummation.com.
Something else you might think about is - making the top (straight) line an option in the createQuestionDialog routine. A couple of my panels need another line for text.
Feel free to change whatever you need in the stuff I posted. Your coding style is different than mine and your library ought to be consistent.
The "splitstring" scans from left to right for the space. I had originally done the scan from "the last possible character position on the line", scanning left to find a space. However, one screen needed a forced newline in it and that messed up the right-to-left scan. Just to make the code simple, I did the left-to-right. Remember KISS - Keep It Simple Stupid. (Yes, I know there are different versions of this but the result is the same.)
Something else you might think about is - making the top (straight) line an option in the createQuestionDialog routine. A couple of my panels need another line for text.
Feel free to change whatever you need in the stuff I posted. Your coding style is different than mine and your library ought to be consistent.
The "splitstring" scans from left to right for the space. I had originally done the scan from "the last possible character position on the line", scanning left to find a space. However, one screen needed a forced newline in it and that messed up the right-to-left scan. Just to make the code simple, I did the left-to-right. Remember KISS - Keep It Simple Stupid. (Yes, I know there are different versions of this but the result is the same.)
McSummation aka James
http://www.mcsummation.com/Mindstorms/
http://www.mcsummation.com/Mindstorms/
-
- Posts: 16
- Joined: 31 Jan 2012, 19:44
RELEASED: NXC UserInteraction Library Version 1.1
A new and improved version of the UIn library can be downloaded from here: http://lenkaspace.net/lab/legoMindstorm ... ionLibrary
The main changes include addition of automatic text line breaks and a multiple info dialog. Full changes log can be found on http://lenkaspace.net/lab/legoMindstorm ... ionHistory
The main changes include addition of automatic text line breaks and a multiple info dialog. Full changes log can be found on http://lenkaspace.net/lab/legoMindstorm ... ionHistory
Elendurwen
http://lenkaspace.net
http://lenkaspace.net
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Re: RELEASED: NXC UserInteraction Library
I downloaded your library and am testing it. I found the following things:
1) In order to change QUESTION_DIALOG_BOTTOM_LINE_Y, I have to modify your source. Could you make it either:
a) a global variable or
b) "define guard" it in your source?
The second way would let me define it before including your code and my value would be used. This code works properly
2) A typographical error in this line " * @param exitText_ (Optional) String displayed for the left of right arrow when there is no screen to navigate to. Default = "Exit" " of the createMultiInfoDialog procedure. It should be "left or right".
Other than those 2 things (which are minor), it seems to work properly for my code. Thank you very much.
1) In order to change QUESTION_DIALOG_BOTTOM_LINE_Y, I have to modify your source. Could you make it either:
a) a global variable or
b) "define guard" it in your source?
The second way would let me define it before including your code and my value would be used. This code works properly
Code: Select all
#ifndef QUESTION_DIALOG_BOTTOM_LINE_Y
#define QUESTION_DIALOG_BOTTOM_LINE_Y 12 // y position of line separaring question and anwer in the question dialog
#endif
Other than those 2 things (which are minor), it seems to work properly for my code. Thank you very much.
McSummation aka James
http://www.mcsummation.com/Mindstorms/
http://www.mcsummation.com/Mindstorms/
-
- Posts: 16
- Joined: 31 Jan 2012, 19:44
Re: RELEASED: NXC UserInteraction Library
Hi, thanks for testing. I designed those constants for people to change but your way seems to be more logical to use. I will update this forum with a new release soon.
Elendurwen
http://lenkaspace.net
http://lenkaspace.net
-
- Posts: 16
- Joined: 31 Jan 2012, 19:44
RELEASED: NXC UserInteraction Library Version 1.2
There is a new version 1.2 of the UIn library that has the following changes to it: http://lenkaspace.net/lab/legoMindstorm ... ionHistory
You can download the library from http://lenkaspace.net/lab/legoMindstorm ... ionLibrary
You can download the library from http://lenkaspace.net/lab/legoMindstorm ... ionLibrary
Elendurwen
http://lenkaspace.net
http://lenkaspace.net
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Re: RELEASED: NXC UserInteraction Library
Changes look good.
McSummation aka James
http://www.mcsummation.com/Mindstorms/
http://www.mcsummation.com/Mindstorms/
-
- Posts: 16
- Joined: 31 Jan 2012, 19:44
Who is online
Users browsing this forum: No registered users and 4 guests