[sword-svn] r123 - trunk/src/SwordReader_GUI
dtrotzjr at www.crosswire.org
dtrotzjr at www.crosswire.org
Wed Apr 23 20:35:01 MST 2008
Author: dtrotzjr
Date: 2008-04-23 20:35:00 -0700 (Wed, 23 Apr 2008)
New Revision: 123
Modified:
trunk/src/SwordReader_GUI/SRNumberChooser.cpp
trunk/src/SwordReader_GUI/SRNumberChooser.h
Log:
Number chooser bug fixes.
Modified: trunk/src/SwordReader_GUI/SRNumberChooser.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRNumberChooser.cpp 2008-04-23 03:26:54 UTC (rev 122)
+++ trunk/src/SwordReader_GUI/SRNumberChooser.cpp 2008-04-24 03:35:00 UTC (rev 123)
@@ -12,7 +12,7 @@
,m_nSelectedNumber(0)
,m_nStartAt(1)
{
- m_nEndNumber = 0xAA; // REMOVE ME!!!!!!
+ m_nEndNumber = 120; // REMOVE ME!!!!!!
m_wcsClassName = "SRNumberChooser";
m_wcsWindowName = "Number Chooser";
m_wcsPrompt = "Choose a number:";
@@ -65,14 +65,26 @@
{
RECT clientRect;
::GetClientRect(m_hWnd,&clientRect);
- return ( ((clientRect.bottom - BUTTON_PADDING_HEIGHT) - clientRect.top)/(BUTTON_PADDING_HEIGHT + BUTTON_HEIGHT) ) - 1;
+ // 2 less rows due to the Prompt and the More Prev buttons.
+ return ( ((clientRect.bottom - BUTTON_PADDING_HEIGHT) - clientRect.top)/(BUTTON_PADDING_HEIGHT + BUTTON_HEIGHT) ) - 2;
}
INT SRNumberChooser::GetMaxNumbersPerScreen()
{
- return GetMaxCols() * GetMaxRows();
+ INT nMaxNumbers = GetMaxCols() * GetMaxRows();
+ if(m_nEndNumber <= nMaxNumbers + GetMaxCols())
+ nMaxNumbers += GetMaxCols(); // We can fit another row since there is no More button.
+ return nMaxNumbers;
}
+// Tries to center the buttons by calculating a left edge
+INT SRNumberChooser::GetLeftEdge()
+{
+ RECT clientRect;
+ GetClientRect(m_hWnd, &clientRect);
+ return ((clientRect.right - clientRect.left)/2) -
+ ((GetMaxCols()*BUTTON_WIDTH_NUMBER + (GetMaxCols() - 1)*BUTTON_PADDING_WIDTH)/2 );
+}
BOOL SRNumberChooser::OnPaint() {
TCHAR buttonText[4];
RECT buttonRect;
@@ -90,12 +102,21 @@
HBRUSH brushBG = CreateSolidBrush((COLORREF)BUTTON_BACKGROUND);
GetClientRect(m_hWnd, &clientRect);
FillRect(hdc, &clientRect, (HBRUSH)GetStockObject(WHITE_BRUSH));
- SetBkColor(hdc, BUTTON_BACKGROUND);
- // Init the first button's bounds
+
+ // Draw the prompt.
buttonRect.top = BUTTON_PADDING_HEIGHT;
+ buttonRect.left = GetLeftEdge();
+ buttonRect.right = clientRect.right - GetLeftEdge();
buttonRect.bottom = buttonRect.top + BUTTON_HEIGHT;
- buttonRect.left = BUTTON_PADDING_WIDTH;
+ DrawText(hdc, m_wcsPrompt.w_str(), -1, &buttonRect, DT_CENTER | DT_VCENTER);
+
+ // Init the first button's bounds
+ buttonRect.top = 2*BUTTON_PADDING_HEIGHT + BUTTON_HEIGHT;
+ buttonRect.bottom = buttonRect.top + BUTTON_HEIGHT;
+ buttonRect.left = GetLeftEdge();
buttonRect.right = buttonRect.left + BUTTON_WIDTH_NUMBER;
+
+ SetBkColor(hdc, BUTTON_BACKGROUND);
for(nRow = 0; nRow < nMaxRows; nRow++){
for(nCol = 0; nCol < nMaxCols; nCol++){
@@ -110,43 +131,71 @@
buttonRect.right = buttonRect.left + BUTTON_WIDTH_NUMBER;
}
- if(nCurrent == m_nEndNumber)
- break;
// Move the bounds down and all the way back to the left.
- buttonRect.left = BUTTON_PADDING_WIDTH;
+ buttonRect.left = GetLeftEdge();
buttonRect.right = buttonRect.left + BUTTON_WIDTH_NUMBER;
buttonRect.top += BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT;
buttonRect.bottom = buttonRect.top + BUTTON_HEIGHT;
+ if(nCurrent == m_nEndNumber)
+ break;
}
+
// If we didn't reach the end we need to draw the More button...
if(nCurrent < m_nEndNumber){
- buttonRect.left = (clientRect.right - clientRect.left)/2 - BUTTON_WIDTH_MORE/2;
+ buttonRect.left = clientRect.right - (BUTTON_WIDTH_MORE + GetLeftEdge());
buttonRect.right = buttonRect.left + BUTTON_WIDTH_MORE;
+ buttonRect.top = clientRect.bottom - (BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT);
+ buttonRect.bottom = clientRect.bottom - BUTTON_PADDING_HEIGHT;
+
FillRect(hdc, &buttonRect, brushBG);
- DrawText(hdc, L"More...", -1, &buttonRect, DT_CENTER | DT_VCENTER);
+ DrawText(hdc, L"More >>", -1, &buttonRect, DT_CENTER | DT_VCENTER);
}
+ // We are not on the first page of numbers we need to draw a Prev button...
+ if(m_nStartAt != 1){
+ buttonRect.left = GetLeftEdge();
+ buttonRect.right = buttonRect.left + BUTTON_WIDTH_MORE;
+ buttonRect.top = clientRect.bottom - (BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT);
+ buttonRect.bottom = clientRect.bottom - BUTTON_PADDING_HEIGHT;
+
+ FillRect(hdc, &buttonRect, brushBG);
+ DrawText(hdc, L"<< Prev", -1, &buttonRect, DT_CENTER | DT_VCENTER);
+ }
//Clean up.
DeleteObject(brushBG);
EndPaint(m_hWnd,&ps);
return TRUE;
}
-
+/* Return:
+ * > 0 - the number found.
+ * 0 - More button pressed.
+ * -1 - Prev button pressed.
+ * -2 - White space tapped. Ignore
+ */
INT SRNumberChooser::NumberAt(int x, int y)
{
RECT clientRect;
INT nCols = (x - BUTTON_PADDING_WIDTH) / (BUTTON_WIDTH_NUMBER + BUTTON_PADDING_WIDTH);
- INT nRows = (y - BUTTON_PADDING_HEIGHT)/ (BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT);
+ INT nRows = (y - BUTTON_PADDING_HEIGHT)/ (BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT) - 1;
+ GetClientRect(m_hWnd, &clientRect);
// I ignore the minimal amount of white space between the buttons.
INT nNumber = m_nStartAt + (nRows * GetMaxCols()) + nCols;
- if(nNumber < m_nStartAt + GetMaxNumbersPerScreen()){
- GetClientRect(m_hWnd, &clientRect);
- if((x > ((clientRect.right - clientRect.left)/2 - BUTTON_WIDTH_MORE/2)) &&
- (x < ((clientRect.right - clientRect.left)/2 - BUTTON_WIDTH_MORE/2) + BUTTON_WIDTH_MORE)){
+
+ if(y < BUTTON_HEIGHT + 2*BUTTON_PADDING_HEIGHT)
+ return -2; // Tapped the title area.
+
+ // Check if the tap was on a button...
+ if(y > clientRect.bottom - (BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT) ){
+ if(x > BUTTON_PADDING_WIDTH && x < BUTTON_PADDING_WIDTH + BUTTON_WIDTH_MORE){
+ return -1;
+ }else if( (x > (GetMaxCols()*(BUTTON_WIDTH_NUMBER+BUTTON_PADDING_WIDTH) - BUTTON_WIDTH_MORE)) &&
+ (x < (GetMaxCols()*(BUTTON_WIDTH_NUMBER+BUTTON_PADDING_WIDTH))) ){
return 0;
- }
+ }else
+ return -2;
}
- if( (nNumber > m_nEndNumber) || (nNumber >= (m_nStartAt + GetMaxNumbersPerScreen())) )
- return -1;
+ if(nNumber > m_nEndNumber || nNumber >= m_nStartAt + GetMaxNumbersPerScreen())
+ return -2;
+
return nNumber;
}
@@ -157,9 +206,12 @@
if(found == 0 && (m_nStartAt + GetMaxNumbersPerScreen() <= m_nEndNumber) ){
m_nStartAt += GetMaxNumbersPerScreen();
RefreshWindow();
- }else if(found < 0){
+ }else if(found == -1 && m_nStartAt != 1){
+ m_nStartAt -= GetMaxNumbersPerScreen();
+ RefreshWindow();
+ }else if(found == -2){
return TRUE;
- }else{
+ }else if(found != 0 && found != -1){
_itow(found, buf, 10);
MessageBox(m_hWnd, buf, L"Found", MB_OK);
}
Modified: trunk/src/SwordReader_GUI/SRNumberChooser.h
===================================================================
--- trunk/src/SwordReader_GUI/SRNumberChooser.h 2008-04-23 03:26:54 UTC (rev 122)
+++ trunk/src/SwordReader_GUI/SRNumberChooser.h 2008-04-24 03:35:00 UTC (rev 123)
@@ -18,6 +18,7 @@
BOOL Create(SRWnd *pParentWnd, RECT bounds);
BOOL OnLButtonUp(WORD fwKeys, INT xPos, INT yPos);
protected:
+ INT GetLeftEdge();
// signals that the user has tapped somewhere.
// returns: the number that the user has tapped. -1 if no number
INT NumberAt(int x, int y);
More information about the sword-cvs
mailing list