[sword-svn] r152 - trunk/src/SwordReader_GUI

dtrotzjr at www.crosswire.org dtrotzjr at www.crosswire.org
Mon Jul 21 19:01:43 MST 2008


Author: dtrotzjr
Date: 2008-07-21 19:01:42 -0700 (Mon, 21 Jul 2008)
New Revision: 152

Modified:
   trunk/src/SwordReader_GUI/SRBookChooser.cpp
   trunk/src/SwordReader_GUI/SRBookChooser.h
   trunk/src/SwordReader_GUI/SRNumberChooser.cpp
   trunk/src/SwordReader_GUI/SRNumberChooser.h
   trunk/src/SwordReader_GUI/SwordReaderResource.h
Log:
Made button widths in the choosers reflect the width of the currently selected font in the device context. This is the first step towards allowing user selected font sizes on the interface.

Modified: trunk/src/SwordReader_GUI/SRBookChooser.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRBookChooser.cpp	2008-07-20 20:14:56 UTC (rev 151)
+++ trunk/src/SwordReader_GUI/SRBookChooser.cpp	2008-07-22 02:01:42 UTC (rev 152)
@@ -12,8 +12,16 @@
 ,m_wNextMenuID(wNextMenuID)
 ,m_wcsBookNames(wcsBookNames)
 {   
+    RECT rect = {0,0,1,1};
     m_wcsClassName = "SRBookChooser";
     m_wcsWindowName = "Book Chooser";
+    // Calculate the button size. the ZZZ string should be a good representation of the largest string.
+    // Future representations will reflect a preferred font.
+    HDC hdc = ::GetDC(m_hWnd);
+    INT h = ::DrawText(hdc, L"ZZZ", -1, &rect, DT_CALCRECT | DT_SINGLELINE | DT_CENTER | DT_VCENTER);
+    m_nButtonHeight = 2*BUTTON_INTERNAL_PADDING + (rect.bottom - rect.top);
+    m_nButtonWidth = 2*BUTTON_INTERNAL_PADDING + (rect.right - rect.left);
+    ::ReleaseDC(m_hWnd, hdc);
 }
 
 BOOL SRBookChooser::Create(SRWnd *pParentWnd, RECT bounds)
@@ -60,7 +68,7 @@
 {
     RECT clientRect;
     ::GetClientRect(m_hWnd,&clientRect);
-    return ( ((clientRect.right  - BUTTON_PADDING_WIDTH) - clientRect.left)/(BUTTON_PADDING_WIDTH + BUTTON_WIDTH_BOOK) );
+    return ( ((clientRect.right  - BUTTON_PADDING_WIDTH) - clientRect.left)/(BUTTON_PADDING_WIDTH + m_nButtonWidth) );
 }
 
 INT SRBookChooser::MaxRows()
@@ -71,7 +79,7 @@
     ::GetClientRect(m_hWnd,&clientRect);
     
     // 2 less rows due to the Prompt and the More Prev buttons.
-    nMaxRows =  ( ((clientRect.bottom - BUTTON_PADDING_HEIGHT) - clientRect.top)/(BUTTON_PADDING_HEIGHT + BUTTON_HEIGHT) ) - 2;
+    nMaxRows =  ( ((clientRect.bottom - BUTTON_PADDING_HEIGHT) - clientRect.top)/(BUTTON_PADDING_HEIGHT + m_nButtonHeight) ) - 2;
     nMaxBooks =  MaxCols() * nMaxRows;
 
     if(m_nStartAt == 1 && m_nEndBook <= nMaxBooks + MaxCols())
@@ -91,7 +99,7 @@
     RECT clientRect;
     GetClientRect(m_hWnd, &clientRect);
     return ((clientRect.right - clientRect.left)/2) - 
-        ((MaxCols()*BUTTON_WIDTH_BOOK + (MaxCols() - 1)*BUTTON_PADDING_WIDTH)/2 );
+        ((MaxCols()*m_nButtonWidth + (MaxCols() - 1)*BUTTON_PADDING_WIDTH)/2 );
 }
 BOOL SRBookChooser::OnPaint() {
     RECT buttonRect;
@@ -117,14 +125,14 @@
     buttonRect.top = BUTTON_PADDING_HEIGHT;
     buttonRect.left = LeftEdge();
     buttonRect.right = clientRect.right - LeftEdge();
-    buttonRect.bottom = buttonRect.top + BUTTON_HEIGHT;
+    buttonRect.bottom = buttonRect.top + m_nButtonHeight;
     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.top = 2*BUTTON_PADDING_HEIGHT + m_nButtonHeight;
+    buttonRect.bottom = buttonRect.top + m_nButtonHeight;
     buttonRect.left = LeftEdge();
-    buttonRect.right = buttonRect.left + BUTTON_WIDTH_BOOK;
+    buttonRect.right = buttonRect.left + m_nButtonWidth;
     
     for(nRow = 0; nRow < nMaxRows; nRow++){
         for(nCol = 0; nCol < nMaxCols; nCol++){
@@ -146,15 +154,15 @@
                 break;
 
 			// Move the bounds right.
-            buttonRect.left += BUTTON_WIDTH_BOOK + BUTTON_PADDING_WIDTH;
-            buttonRect.right = buttonRect.left + BUTTON_WIDTH_BOOK;
+            buttonRect.left += m_nButtonWidth + BUTTON_PADDING_WIDTH;
+            buttonRect.right = buttonRect.left + m_nButtonWidth;
 
         }
         // Move the bounds down and all the way back to the left.
         buttonRect.left = LeftEdge();
-        buttonRect.right = buttonRect.left + BUTTON_WIDTH_BOOK;
-        buttonRect.top += BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT;
-        buttonRect.bottom = buttonRect.top + BUTTON_HEIGHT;
+        buttonRect.right = buttonRect.left + m_nButtonWidth;
+        buttonRect.top += m_nButtonHeight + BUTTON_PADDING_HEIGHT;
+        buttonRect.bottom = buttonRect.top + m_nButtonHeight;
         if(nCurrent == m_nEndBook)
            break;
     }
@@ -163,7 +171,7 @@
     if(nCurrent < m_nEndBook){
         buttonRect.left = clientRect.right - (BUTTON_WIDTH_MORE + LeftEdge());
         buttonRect.right = buttonRect.left + BUTTON_WIDTH_MORE;
-        buttonRect.top = clientRect.bottom - (BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT);
+        buttonRect.top = clientRect.bottom - (m_nButtonHeight + BUTTON_PADDING_HEIGHT);
         buttonRect.bottom = clientRect.bottom - BUTTON_PADDING_HEIGHT;
         
 		DrawButton(hdc, buttonRect, L"More >>", 0, FALSE);
@@ -173,7 +181,7 @@
     if(m_nStartAt != 1){
         buttonRect.left = LeftEdge();
         buttonRect.right = buttonRect.left + BUTTON_WIDTH_MORE;
-        buttonRect.top = clientRect.bottom - (BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT);
+        buttonRect.top = clientRect.bottom - (m_nButtonHeight + BUTTON_PADDING_HEIGHT);
         buttonRect.bottom = clientRect.bottom - BUTTON_PADDING_HEIGHT;
         
 		DrawButton(hdc, buttonRect, L"<< Prev", 0, FALSE);
@@ -217,21 +225,21 @@
 INT SRBookChooser::BookAt(int x, int y) 
 {
     RECT clientRect;
-    INT nCols = (x - BUTTON_PADDING_WIDTH) / (BUTTON_WIDTH_BOOK + BUTTON_PADDING_WIDTH);
-    INT nRows = (y - BUTTON_PADDING_HEIGHT)/ (BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT) - 1;
+    INT nCols = (x - BUTTON_PADDING_WIDTH) / (m_nButtonWidth + BUTTON_PADDING_WIDTH);
+    INT nRows = (y - BUTTON_PADDING_HEIGHT)/ (m_nButtonHeight + BUTTON_PADDING_HEIGHT) - 1;
     GetClientRect(m_hWnd, &clientRect);
     // I ignore the minimal amount of white space between the buttons.
     INT nBook = m_nStartAt + (nRows * MaxCols()) + nCols; 
     
-    if(y < BUTTON_HEIGHT + 2*BUTTON_PADDING_HEIGHT)
+    if(y < m_nButtonHeight + 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(y > clientRect.bottom - (m_nButtonHeight + BUTTON_PADDING_HEIGHT) ){
         if(x > BUTTON_PADDING_WIDTH && x < BUTTON_PADDING_WIDTH + BUTTON_WIDTH_MORE){
             return -1;
-        }else if( (x > (MaxCols()*(BUTTON_WIDTH_BOOK+BUTTON_PADDING_WIDTH) - BUTTON_WIDTH_MORE)) &&
-                  (x < (MaxCols()*(BUTTON_WIDTH_BOOK+BUTTON_PADDING_WIDTH))) ){
+        }else if( (x > (MaxCols()*(m_nButtonWidth+BUTTON_PADDING_WIDTH) - BUTTON_WIDTH_MORE)) &&
+                  (x < (MaxCols()*(m_nButtonWidth+BUTTON_PADDING_WIDTH))) ){
             return 0;
         }else
             return -2;

Modified: trunk/src/SwordReader_GUI/SRBookChooser.h
===================================================================
--- trunk/src/SwordReader_GUI/SRBookChooser.h	2008-07-20 20:14:56 UTC (rev 151)
+++ trunk/src/SwordReader_GUI/SRBookChooser.h	2008-07-22 02:01:42 UTC (rev 152)
@@ -42,6 +42,8 @@
     static BOOL s_fRegistered;
 	UINT        m_nLastChar;
     BOOL        m_fLButtonDown;
+    INT         m_nButtonWidth;
+    INT         m_nButtonHeight;
 };
 
 #endif

Modified: trunk/src/SwordReader_GUI/SRNumberChooser.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRNumberChooser.cpp	2008-07-20 20:14:56 UTC (rev 151)
+++ trunk/src/SwordReader_GUI/SRNumberChooser.cpp	2008-07-22 02:01:42 UTC (rev 152)
@@ -12,8 +12,16 @@
 ,m_wNextMenuID(wNextMenuID)
 ,m_type(type)
 {   
+    RECT rect = {0,0,0,0};
     m_wcsClassName = "SRNumberChooser";
     m_wcsWindowName = "Number Chooser";
+    // Calculate the button size. the 999 string should be a good representation of the largest string.
+    // Future representations will reflect a preferred font.
+    HDC hdc = ::GetDC(m_hWnd);
+    INT h = ::DrawText(hdc, L"999", -1, &rect, DT_CALCRECT | DT_SINGLELINE | DT_CENTER | DT_VCENTER);
+    m_nButtonHeight = 2*BUTTON_INTERNAL_PADDING + (rect.bottom - rect.top);
+    m_nButtonWidth = 2*BUTTON_INTERNAL_PADDING + (rect.right - rect.left);
+    ::ReleaseDC(m_hWnd, hdc);
 }
 
 BOOL SRNumberChooser::Create(SRWnd *pParentWnd, RECT bounds)
@@ -60,7 +68,7 @@
 {
     RECT clientRect;
     ::GetClientRect(m_hWnd,&clientRect);
-    return ( ((clientRect.right  - BUTTON_PADDING_WIDTH) - clientRect.left)/(BUTTON_PADDING_WIDTH + BUTTON_WIDTH_NUMBER) );
+    return ( ((clientRect.right  - BUTTON_PADDING_WIDTH) - clientRect.left)/(BUTTON_PADDING_WIDTH + m_nButtonWidth) );
 }
 
 INT SRNumberChooser::MaxRows()
@@ -71,7 +79,7 @@
     ::GetClientRect(m_hWnd,&clientRect);
     
     // 2 less rows due to the Prompt and the More Prev buttons.
-    nMaxRows =  ( ((clientRect.bottom - BUTTON_PADDING_HEIGHT) - clientRect.top)/(BUTTON_PADDING_HEIGHT + BUTTON_HEIGHT) ) - 2;
+    nMaxRows =  ( ((clientRect.bottom - BUTTON_PADDING_HEIGHT) - clientRect.top)/(BUTTON_PADDING_HEIGHT + m_nButtonHeight) ) - 2;
     nMaxNumbers =  MaxCols() * nMaxRows;
 
     if(m_nStartAt == 1 && m_nEndNumber <= nMaxNumbers + MaxCols())
@@ -91,7 +99,7 @@
     RECT clientRect;
     GetClientRect(m_hWnd, &clientRect);
     return ((clientRect.right - clientRect.left)/2) - 
-        ((MaxCols()*BUTTON_WIDTH_NUMBER + (MaxCols() - 1)*BUTTON_PADDING_WIDTH)/2 );
+        ((MaxCols()*m_nButtonWidth + (MaxCols() - 1)*BUTTON_PADDING_WIDTH)/2 );
 }
 BOOL SRNumberChooser::OnPaint() {
 	TCHAR buttonText[4];
@@ -118,14 +126,14 @@
     buttonRect.top = BUTTON_PADDING_HEIGHT;
     buttonRect.left = LeftEdge();
     buttonRect.right = clientRect.right - LeftEdge();
-    buttonRect.bottom = buttonRect.top + BUTTON_HEIGHT;
+    buttonRect.bottom = buttonRect.top + m_nButtonHeight;
     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.top = 2*BUTTON_PADDING_HEIGHT + m_nButtonHeight;
+    buttonRect.bottom = buttonRect.top + m_nButtonHeight;
     buttonRect.left = LeftEdge();
-    buttonRect.right = buttonRect.left + BUTTON_WIDTH_NUMBER;
+    buttonRect.right = buttonRect.left + m_nButtonWidth;
     
     SetBkColor(hdc, BUTTON_BACKGROUND);
 
@@ -147,15 +155,15 @@
             if(nCurrent == m_nEndNumber)
                 break;
             // Move the bounds right.
-            buttonRect.left += BUTTON_WIDTH_NUMBER + BUTTON_PADDING_WIDTH;
-            buttonRect.right = buttonRect.left + BUTTON_WIDTH_NUMBER;
+            buttonRect.left += m_nButtonWidth + BUTTON_PADDING_WIDTH;
+            buttonRect.right = buttonRect.left + m_nButtonWidth;
 
         }
         // Move the bounds down and all the way back to the left.
         buttonRect.left = LeftEdge();
-        buttonRect.right = buttonRect.left + BUTTON_WIDTH_NUMBER;
-        buttonRect.top += BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT;
-        buttonRect.bottom = buttonRect.top + BUTTON_HEIGHT;
+        buttonRect.right = buttonRect.left + m_nButtonWidth;
+        buttonRect.top += m_nButtonHeight + BUTTON_PADDING_HEIGHT;
+        buttonRect.bottom = buttonRect.top + m_nButtonHeight;
         if(nCurrent == m_nEndNumber)
            break;
     }
@@ -164,7 +172,7 @@
     if(nCurrent < m_nEndNumber){
         buttonRect.left = clientRect.right - (BUTTON_WIDTH_MORE + LeftEdge());
         buttonRect.right = buttonRect.left + BUTTON_WIDTH_MORE;
-        buttonRect.top = clientRect.bottom - (BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT);
+        buttonRect.top = clientRect.bottom - (m_nButtonHeight + BUTTON_PADDING_HEIGHT);
         buttonRect.bottom = clientRect.bottom - BUTTON_PADDING_HEIGHT;
         
         FillRect(hdc, &buttonRect, brushBG); 
@@ -174,7 +182,7 @@
     if(m_nStartAt != 1){
         buttonRect.left = LeftEdge();
         buttonRect.right = buttonRect.left + BUTTON_WIDTH_MORE;
-        buttonRect.top = clientRect.bottom - (BUTTON_HEIGHT + BUTTON_PADDING_HEIGHT);
+        buttonRect.top = clientRect.bottom - (m_nButtonHeight + BUTTON_PADDING_HEIGHT);
         buttonRect.bottom = clientRect.bottom - BUTTON_PADDING_HEIGHT;
         
         FillRect(hdc, &buttonRect, brushBG); 
@@ -195,21 +203,21 @@
 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) - 1;
+    INT nCols = (x - BUTTON_PADDING_WIDTH) / (m_nButtonWidth + BUTTON_PADDING_WIDTH);
+    INT nRows = (y - BUTTON_PADDING_HEIGHT)/ (m_nButtonHeight + BUTTON_PADDING_HEIGHT) - 1;
     GetClientRect(m_hWnd, &clientRect);
     // I ignore the minimal amount of white space between the buttons.
     INT nNumber = m_nStartAt + (nRows * MaxCols()) + nCols; 
     
-    if(y < BUTTON_HEIGHT + 2*BUTTON_PADDING_HEIGHT)
+    if(y < m_nButtonHeight + 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(y > clientRect.bottom - (m_nButtonHeight + BUTTON_PADDING_HEIGHT) ){
         if(x > BUTTON_PADDING_WIDTH && x < BUTTON_PADDING_WIDTH + BUTTON_WIDTH_MORE){
             return -1;
-        }else if( (x > (MaxCols()*(BUTTON_WIDTH_NUMBER+BUTTON_PADDING_WIDTH) - BUTTON_WIDTH_MORE)) &&
-                  (x < (MaxCols()*(BUTTON_WIDTH_NUMBER+BUTTON_PADDING_WIDTH))) ){
+        }else if( (x > (MaxCols()*(m_nButtonWidth+BUTTON_PADDING_WIDTH) - BUTTON_WIDTH_MORE)) &&
+                  (x < (MaxCols()*(m_nButtonWidth+BUTTON_PADDING_WIDTH))) ){
             return 0;
         }else
             return -2;

Modified: trunk/src/SwordReader_GUI/SRNumberChooser.h
===================================================================
--- trunk/src/SwordReader_GUI/SRNumberChooser.h	2008-07-20 20:14:56 UTC (rev 151)
+++ trunk/src/SwordReader_GUI/SRNumberChooser.h	2008-07-22 02:01:42 UTC (rev 152)
@@ -42,6 +42,8 @@
     static BOOL s_fRegistered;
 	UINT        m_nLastChar;
     BOOL        m_fLButtonDown;
+    INT         m_nButtonWidth;
+    INT         m_nButtonHeight;
 };
 
 #endif

Modified: trunk/src/SwordReader_GUI/SwordReaderResource.h
===================================================================
--- trunk/src/SwordReader_GUI/SwordReaderResource.h	2008-07-20 20:14:56 UTC (rev 151)
+++ trunk/src/SwordReader_GUI/SwordReaderResource.h	2008-07-22 02:01:42 UTC (rev 152)
@@ -56,10 +56,8 @@
 
 #define BUTTON_BACKGROUND       0x00b9ccd5
 #define BUTTON_SEL_BACKGROUND   0x00ffffff
-#define BUTTON_WIDTH_BOOK       36
-#define BUTTON_WIDTH_NUMBER     28
 #define BUTTON_WIDTH_MORE       65
-#define BUTTON_HEIGHT           24
+#define BUTTON_INTERNAL_PADDING 3
 #define BUTTON_PADDING_WIDTH    1
 #define BUTTON_PADDING_HEIGHT   1
 #define BUTTON_FOREGROUND       0x00000000




More information about the sword-cvs mailing list