[sword-svn] r148 - trunk/src/SwordReader_GUI
alsites at www.crosswire.org
alsites at www.crosswire.org
Sat Jul 12 08:19:33 MST 2008
Author: alsites
Date: 2008-07-12 08:19:33 -0700 (Sat, 12 Jul 2008)
New Revision: 148
Modified:
trunk/src/SwordReader_GUI/SRBookChooser.cpp
trunk/src/SwordReader_GUI/SRBookChooser.h
trunk/src/SwordReader_GUI/SwordReaderResource.h
Log:
This change adds the paging ability when using the navigation buttons.
Modified: trunk/src/SwordReader_GUI/SRBookChooser.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRBookChooser.cpp 2008-07-11 05:08:23 UTC (rev 147)
+++ trunk/src/SwordReader_GUI/SRBookChooser.cpp 2008-07-12 15:19:33 UTC (rev 148)
@@ -1,5 +1,6 @@
#include "SRBookChooser.h"
#include "SwordReaderResource.h"
+#include <winuserm.h>
BOOL SRBookChooser::s_fRegistered = false;
@@ -105,13 +106,9 @@
HDC hdc = BeginPaint(m_hWnd, &ps);
- if (selCol < 0 || selCol >= MaxCols())
- selCol = 0;
+ if (m_nSelectedBook < 1 || m_nSelectedBook > 66)
+ m_nSelectedBook = 1;
- if (selRow < 0 || selRow >= MaxRows())
- selRow = 0;
-
- HBRUSH brushBG = CreateSolidBrush((COLORREF)BUTTON_BACKGROUND);
GetClientRect(m_hWnd, &clientRect);
FillRect(hdc, &clientRect, (HBRUSH)GetStockObject(WHITE_BRUSH));
@@ -132,22 +129,17 @@
for(nCol = 0; nCol < nMaxCols; nCol++){
nCurrent = m_nStartAt + (nRow * nMaxCols) + nCol;
- SetTextColor(hdc, BUTTON_FOREGROUND);
- if(nCol == selCol && nRow == selRow) {
- //if(nCurrent == nSelectedBook) {
- SetBkColor(hdc, BUTTON_SEL_BACKGROUND);
- FillRect(hdc, &buttonRect, brushBG);
- Rectangle(hdc, buttonRect.left, buttonRect.top, buttonRect.right, buttonRect.bottom);
+ if(m_nSelectedBook == nCurrent) {
+ DrawButton(hdc, buttonRect, m_wcsBookNames[nCurrent - 1].w_str(), TRUE);
} else {
- SetBkColor(hdc, BUTTON_BACKGROUND);
- FillRect(hdc, &buttonRect, brushBG);
+ DrawButton(hdc, buttonRect, m_wcsBookNames[nCurrent - 1].w_str(), FALSE);
}
- DrawText(hdc, m_wcsBookNames[nCurrent - 1].w_str(), -1, &buttonRect, DT_CENTER | DT_VCENTER);
if(nCurrent == m_nEndBook)
break;
- // Move the bounds right.
+
+ // Move the bounds right.
buttonRect.left += BUTTON_WIDTH_BOOK + BUTTON_PADDING_WIDTH;
buttonRect.right = buttonRect.left + BUTTON_WIDTH_BOOK;
@@ -168,25 +160,42 @@
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);
+ DrawButton(hdc, buttonRect, L"More >>", FALSE);
}
- // We are not on the first page of Books we need to draw a Prev button...
+
+ // We are not on the first page of Books we need to draw a Prev button...
if(m_nStartAt != 1){
buttonRect.left = LeftEdge();
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);
+ DrawButton(hdc, buttonRect, L"<< Prev", FALSE);
}
- //Clean up.
- DeleteObject(brushBG);
+
+ //Clean up.
EndPaint(m_hWnd,&ps);
return TRUE;
}
+void SRBookChooser::DrawButton(HDC hdc, RECT buttonRect, LPCWSTR caption, bool selected)
+{
+ HBRUSH brushBG = CreateSolidBrush((COLORREF)BUTTON_BACKGROUND);
+ SetTextColor(hdc, BUTTON_FOREGROUND);
+
+ if (selected) {
+ SetBkColor(hdc, BUTTON_SEL_BACKGROUND);
+ FillRect(hdc, &buttonRect, brushBG);
+ Rectangle(hdc, buttonRect.left, buttonRect.top, buttonRect.right, buttonRect.bottom);
+ } else {
+ SetBkColor(hdc, BUTTON_BACKGROUND);
+ FillRect(hdc, &buttonRect, brushBG);
+ }
+
+ DrawText(hdc, caption, -1, &buttonRect, DT_CENTER | DT_VCENTER);
+ DeleteObject(brushBG);
+}
+
/* Return:
* > 0 - the Book found.
* 0 - More button pressed.
@@ -223,42 +232,102 @@
BOOL SRBookChooser::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags){
if(nChar == VK_RIGHT){
- INT tempBook = (MaxCols() * selRow) + selCol + 1;
- if (tempBook == m_nEndBook) {
- selCol = 0;
- selRow = 0;
- } else if (selCol == (MaxCols() - 1)) {
- selCol = 0;
- selRow++;
- } else {
- selCol++;
- }
+ lastChar = VK_RIGHT;
+ MoveRight();
RefreshWindow();
} else if(nChar == VK_DOWN){
- selRow++;
- if(selRow >= MaxRows())
- selRow = 0;
+ lastChar = VK_DOWN;
+ MoveDown();
RefreshWindow();
} else if(nChar == VK_LEFT){
- if(selCol <= 0)
- selCol = MaxCols() - 1;
- else
- selCol--;
+ lastChar = VK_LEFT;
+ MoveLeft();
RefreshWindow();
} else if(nChar == VK_UP){
- if(selRow <= 0)
- selRow = MaxRows() - 1;
- else
- selRow--;
+ lastChar = VK_UP;
+ MoveUp();
RefreshWindow();
+ } else if (nChar == VK_ROCKER) {
+ if (lastChar == VK_UP) {
+ MoveDown();
+ MoveLeft();
+ RefreshWindow();
+ } else if (lastChar == VK_DOWN) {
+ MoveUp();
+ MoveRight();
+ RefreshWindow();
+ }
} else if(nChar == VK_RETURN){
- INT book = (selRow * MaxCols()) + selCol + 1;
- ::SendMessage(m_pParentWnd->GetWindowHandle(),WM_COMMAND,SR_SETBOOK, book);
- ::SendMessage(m_pParentWnd->GetWindowHandle(),WM_COMMAND,m_wNextMenuID, book);
+ ::SendMessage(m_pParentWnd->GetWindowHandle(),WM_COMMAND,SR_SETBOOK, m_nSelectedBook);
+ ::SendMessage(m_pParentWnd->GetWindowHandle(),WM_COMMAND,m_wNextMenuID, m_nSelectedBook);
}
return true;
}
+void SRBookChooser::MoveDown()
+{
+ INT nMaxCols = MaxCols();
+ INT nMaxRows = MaxRows();
+ INT curRow = (m_nSelectedBook - m_nStartAt + 1) / nMaxCols;
+ INT curTrueRow = m_nSelectedBook / nMaxCols;
+ INT curCol = m_nSelectedBook - (nMaxCols * curTrueRow);
+
+ if (curCol != nMaxCols)
+ curRow++;
+
+ if ((m_nSelectedBook + nMaxCols) > m_nEndBook) {
+ if ((curRow == nMaxRows) && (((nMaxCols - curCol) + m_nSelectedBook) < m_nEndBook))
+ m_nStartAt += nMaxCols;
+ m_nSelectedBook = m_nEndBook;
+ } else {
+ if (curRow == nMaxRows)
+ m_nStartAt += nMaxCols;
+ m_nSelectedBook += nMaxCols;
+ }
+}
+
+void SRBookChooser::MoveLeft()
+{
+ if (m_nSelectedBook == m_nStartAt) {
+ if (m_nStartAt != 1) {
+ m_nSelectedBook--;
+ m_nStartAt -= MaxCols();
+ }
+ } else {
+ m_nSelectedBook--;
+ }
+}
+
+void SRBookChooser::MoveRight()
+{
+ INT nMaxCols = MaxCols();
+ INT nMaxRows = MaxRows();
+ INT curRow = (m_nSelectedBook - m_nStartAt + 1) / nMaxCols;
+ INT curTrueRow = m_nSelectedBook / nMaxCols;
+ INT curCol = m_nSelectedBook - (nMaxCols * (curTrueRow - 1));
+
+ if (m_nSelectedBook != m_nEndBook) { //sizeof(m_wcsBookNames)/sizeof(m_wcsBookNames[0])) {
+ if ((curRow == nMaxRows) && (curCol == nMaxCols)) {
+ m_nStartAt += nMaxCols;
+ }
+ m_nSelectedBook++;
+ }
+}
+
+void SRBookChooser::MoveUp()
+{
+ INT nMaxCols = MaxCols();
+
+ if ((m_nSelectedBook - nMaxCols) < m_nStartAt) {
+ if (!((m_nSelectedBook - nMaxCols) < 1)) {
+ m_nSelectedBook -= nMaxCols;
+ m_nStartAt -= nMaxCols;
+ }
+ } else {
+ m_nSelectedBook -= nMaxCols;
+ }
+}
+
BOOL SRBookChooser::OnLButtonUp(WORD fwKeys, INT xPos, INT yPos)
{
TCHAR buf[16] = {0};
Modified: trunk/src/SwordReader_GUI/SRBookChooser.h
===================================================================
--- trunk/src/SwordReader_GUI/SRBookChooser.h 2008-07-11 05:08:23 UTC (rev 147)
+++ trunk/src/SwordReader_GUI/SRBookChooser.h 2008-07-12 15:19:33 UTC (rev 148)
@@ -19,21 +19,28 @@
BOOL OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
BOOL OnLButtonUp(WORD fwKeys, INT xPos, INT yPos);
protected:
- INT BookAt(int x, int y);
- INT LeftEdge();
- INT MaxRows();
- INT MaxCols();
- INT MaxBooksPerScreen();
+ INT BookAt(int x, int y);
+ void DrawButtons();
+ void DrawButton(HDC hdc, RECT buttonRect, LPCWSTR caption, bool selected);
+ INT LeftEdge();
+ INT MaxRows();
+ INT MaxCols();
+ INT MaxBooksPerScreen();
+ void MoveDown();
+ void MoveLeft();
+ void MoveRight();
+ void MoveUp();
INT m_nEndBook;
INT m_nStartAt;
INT m_nSelectedBook;
- INT selCol;
- INT selRow;
+// INT selCol;
+// INT selRow;
WORD m_wNextMenuID;
WCString m_wcsPrompt;
WCString *m_wcsBookNames;
static BOOL s_fRegistered;
+ UINT lastChar;
};
#endif
Modified: trunk/src/SwordReader_GUI/SwordReaderResource.h
===================================================================
--- trunk/src/SwordReader_GUI/SwordReaderResource.h 2008-07-11 05:08:23 UTC (rev 147)
+++ trunk/src/SwordReader_GUI/SwordReaderResource.h 2008-07-12 15:19:33 UTC (rev 148)
@@ -56,12 +56,12 @@
#define BUTTON_BACKGROUND 0x00b9ccd5
#define BUTTON_SEL_BACKGROUND 0x00ffffff
-#define BUTTON_WIDTH_BOOK 28
+#define BUTTON_WIDTH_BOOK 30
#define BUTTON_WIDTH_NUMBER 20
#define BUTTON_WIDTH_MORE 60
-#define BUTTON_HEIGHT 19
-#define BUTTON_PADDING_WIDTH 2
-#define BUTTON_PADDING_HEIGHT 2
+#define BUTTON_HEIGHT 21
+#define BUTTON_PADDING_WIDTH 1
+#define BUTTON_PADDING_HEIGHT 1
#define BUTTON_FOREGROUND 0x00000000
More information about the sword-cvs
mailing list