[Gcblue-commits] gcb_wx/src/common tcOptionsView.cpp,1.6,1.7
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-06-14 22:37:23
|
Update of /cvsroot/gcblue/gcb_wx/src/common In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3774/src/common Modified Files: tcOptionsView.cpp Log Message: Index: tcOptionsView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/common/tcOptionsView.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** tcOptionsView.cpp 9 Apr 2004 14:09:15 -0000 1.6 --- tcOptionsView.cpp 14 Jun 2004 22:37:11 -0000 1.7 *************** *** 32,240 **** bool tcOptionsView::Init() { ! char zBuff[96]; ! strcpy(zBuff,IMAGE_PATH); ! strcat(zBuff,"options_bk.jpg"); ! MultiByteToWideChar(CP_ACP, 0, zBuff, -1, mzwchar, 255); ! mpiBackground = new Image(mzwchar,false); ! strcpy(zBuff,IMAGE_PATH); ! strcat(zBuff,"options_bon.bmp"); ! MultiByteToWideChar(CP_ACP, 0, zBuff, -1, mzwchar, 255); ! mpiButtonOn = new Image(mzwchar,false); ! strcpy(zBuff,IMAGE_PATH); ! strcat(zBuff,"options_boff.bmp"); ! MultiByteToWideChar(CP_ACP, 0, zBuff, -1, mzwchar, 255); ! mpiButtonOff = new Image(mzwchar,false); ! if (mpiBackground == NULL) { ! WTL("tcOptions - background bitmap (options_bk.jpg) load error"); ! return false; ! } ! if (mpiButtonOn == NULL) { ! WTL("tcOptions - background bitmap (options_bon.bmp) load error"); ! return false; ! } ! if (mpiButtonOff == NULL) { ! WTL("tcOptions - background bitmap (options_boff.bmp) load error"); ! return false; ! } ! FontFamily ff(L"Arial"); ! mpFont = new Font(&ff,12,FontStyleBold,UnitPixel); ! if (mpFont == NULL) { ! WTL("tcOptionsView - mpFont creation failed\n"); ! return false; ! } ! mpBrush = new SolidBrush(Color(0xFEFFFFFF)); // color is ARGB ! if (mpBrush == NULL) { ! WTL("tcOptionsView - mpBrush creation failed\n"); ! return false; ! } ! mpPen = new Pen(Color(255,200,200,200),2); ! if (mpPen == NULL) { ! WTL("tcTOptionsView - mpPen creation failed\n"); ! return false; ! } ! // Get dimensions and limit to window dimensions ! // mpiButtonOn dimensions are used for all buttons ! mnBackgroundWidth = mpiBackground->GetWidth(); ! if (mnBackgroundWidth > mnWidth) {mnBackgroundWidth = mnWidth;} ! mnBackgroundHeight = mpiBackground->GetHeight(); ! if (mnBackgroundHeight > mnHeight) {mnBackgroundHeight = mnHeight;} ! mnButtonWidth = mpiButtonOn->GetWidth(); ! if (mnButtonWidth > mnWidth) {mnButtonWidth = mnWidth;} //limit dimensions to window ! mnButtonHeight = mpiButtonOn->GetHeight(); ! if (mnButtonHeight > mnHeight) {mnButtonHeight = mnHeight;} ! return true; } /*******************************************************************************/ ! int tcOptionsView::Draw() { ! static nTestCount = 0; ! static WCHAR szwchar[256]; // wide char array buffer for string conversion ! Graphics *pGraphics; ! Erase(); ! if (!GetGraphics(pGraphics)) { ! return false; ! } ! if (mpiBackground == NULL) {return false;} ! if (mpOptions == NULL) {return false;} ! pGraphics->DrawImage(mpiBackground,0,0,mnWidth,mnHeight); ! ! mpBrush->SetColor(Color(0xFEFFFFFF)); ! ! /*** Draw test text **/ ! ! tcString sText; ! int xpos,ypos; ! ypos = mnYStart; ! RectF rstring; ! for(int i=0;i<mpOptions->mnNumOptions;i++) { ! xpos = mnXStart; ! int nBoxWidth = maButtonPosition[i][mpOptions->maOptionInfo[i].mnStateCount-1].mnButtonX - ! maButtonPosition[i][0].mnTextX + 2*mnButtonWidth; ! mpBrush->SetColor(Color(0x60FFFFFF)); ! pGraphics->FillRectangle(mpBrush, ! maButtonPosition[i][0].mnTextX - mnButtonHeight/2, ypos - 3*mnButtonHeight/2, ! nBoxWidth, 2*mnButtonHeight); ! mpBrush->SetColor(Color(255,255,220,220)); - for(int j=0;j<mpOptions->maOptionInfo[i].mnStateCount;j++) { - sText = mpOptions->maOptionInfo[i].mzCaption[j]; - MultiByteToWideChar(CP_ACP, 0, sText.GetBuffer(), -1, szwchar, 255); - pGraphics->MeasureString(szwchar,-1,mpFont,PointF(0,0),&rstring); - maButtonPosition[i][j].mnTextX = xpos; - maButtonPosition[i][j].mnTextY = ypos-mnButtonHeight+2; - xpos += (int)(rstring.Width) + 1; - maButtonPosition[i][j].mnButtonX = xpos; - maButtonPosition[i][j].mnButtonY = ypos-mnButtonHeight-mnButtonHeight/6; - xpos += 3*mnButtonWidth; ! } ! pGraphics->DrawRectangle(mpPen, ! maButtonPosition[i][0].mnTextX - mnButtonHeight/2, ypos - 3*mnButtonHeight/2, ! nBoxWidth, 2*mnButtonHeight); ! ypos += 3*mnButtonHeight; ! } ! ! for(i=0;i<mpOptions->mnNumOptions;i++) { ! for(int j=0;j<mpOptions->maOptionInfo[i].mnStateCount;j++) { ! sText = mpOptions->maOptionInfo[i].mzCaption[j]; ! MultiByteToWideChar(CP_ACP, 0, sText.GetBuffer(), -1, szwchar, 255); ! pGraphics->DrawString(szwchar, -1, mpFont, ! PointF((float)maButtonPosition[i][j].mnTextX, (float)maButtonPosition[i][j].mnTextY), ! mpBrush); ! ! ! if (mpOptions->maOptionInfo[i].mnValue == j) { ! DrawButton(pGraphics,maButtonPosition[i][j].mnButtonX, ! maButtonPosition[i][j].mnButtonY,1); ! } ! else { ! DrawButton(pGraphics,maButtonPosition[i][j].mnButtonX, ! maButtonPosition[i][j].mnButtonY,0); ! } ! } ! } ! ! ReleaseGraphics(pGraphics); ! DrawBorder(); ! return true; } /*******************************************************************************/ void tcOptionsView::DrawButton(Graphics *apGraphics, int x, int y, int abOn) { ! Image *pButton; ! if (apGraphics == NULL) {return;} ! pButton = (abOn == 1) ? mpiButtonOn : mpiButtonOff; ! if (pButton == NULL) {return;} ! apGraphics->DrawImage(pButton,x,y); } /******************************************************************************/ void tcOptionsView::OnLButtonDown(wxMouseEvent& event) { ! bool bButtonClicked; ! int nOption, nValue; ! if (!mbActive) ! { ! event.Skip(); ! return; ! } ! // TranslatePoint(point); // adjust for flipped up/down ! bButtonClicked = ButtonContainingPoint(event.GetPosition(), nOption, nValue); ! if (bButtonClicked) { ! if ((nOption >= mpOptions->mnNumOptions)|| ! (nValue >= mpOptions->maOptionInfo[nOption].mnStateCount)) { ! WTL("tcOptionsView::OnLButtonDown error"); ! return; ! } ! mpOptions->maOptionInfo[nOption].mnValue = nValue; ! if (mpOptions->maOptionInfo[nOption].mpAssociated != NULL) { ! *mpOptions->maOptionInfo[nOption].mpAssociated = nValue; ! } ! mpOptions->Serialize(false); // create new options file - tcSound::Get()->PlayEffect(SEFFECT_BEEP2); - } - else - { - // switch back to start view if no buttons clicked (for now) - wxCommandEvent command(wxEVT_COMMAND_BUTTON_CLICKED, ID_STARTVIEW) ; - command.SetEventObject(this); - AddPendingEvent(command); - } - } /******************************************************************************/ bool tcOptionsView::ButtonContainingPoint(wxPoint point, int& rnOption, int& rnValue) { ! int i,j; ! int nx, ny; ! for(i=0;i<mpOptions->mnNumOptions;i++) { ! for(j=0;j<mpOptions->maOptionInfo[i].mnStateCount;j++) { ! nx = maButtonPosition[i][j].mnButtonX; ! ny = maButtonPosition[i][j].mnButtonY; ! wxRect cr(nx,ny,mnButtonWidth,mnButtonHeight); ! if (cr.Inside(point)) { ! rnOption = i; ! rnValue = j; ! return true; ! } ! } ! } ! return false; } --- 32,245 ---- bool tcOptionsView::Init() { ! char zBuff[96]; ! strcpy(zBuff,IMAGE_PATH); ! strcat(zBuff,"options_bk.jpg"); ! MultiByteToWideChar(CP_ACP, 0, zBuff, -1, mzwchar, 255); ! mpiBackground = new Image(mzwchar,false); ! strcpy(zBuff,IMAGE_PATH); ! strcat(zBuff,"options_bon.bmp"); ! MultiByteToWideChar(CP_ACP, 0, zBuff, -1, mzwchar, 255); ! mpiButtonOn = new Image(mzwchar,false); ! strcpy(zBuff,IMAGE_PATH); ! strcat(zBuff,"options_boff.bmp"); ! MultiByteToWideChar(CP_ACP, 0, zBuff, -1, mzwchar, 255); ! mpiButtonOff = new Image(mzwchar,false); ! if (mpiBackground == NULL) { ! WTL("tcOptions - background bitmap (options_bk.jpg) load error"); ! return false; ! } ! if (mpiButtonOn == NULL) { ! WTL("tcOptions - background bitmap (options_bon.bmp) load error"); ! return false; ! } ! if (mpiButtonOff == NULL) { ! WTL("tcOptions - background bitmap (options_boff.bmp) load error"); ! return false; ! } ! FontFamily ff(L"Arial"); ! mpFont = new Font(&ff,12,FontStyleBold,UnitPixel); ! if (mpFont == NULL) { ! WTL("tcOptionsView - mpFont creation failed\n"); ! return false; ! } ! mpBrush = new SolidBrush(Color(0xFEFFFFFF)); // color is ARGB ! if (mpBrush == NULL) { ! WTL("tcOptionsView - mpBrush creation failed\n"); ! return false; ! } ! mpPen = new Pen(Color(255,200,200,200),2); ! if (mpPen == NULL) { ! WTL("tcTOptionsView - mpPen creation failed\n"); ! return false; ! } ! // Get dimensions and limit to window dimensions ! // mpiButtonOn dimensions are used for all buttons ! mnBackgroundWidth = mpiBackground->GetWidth(); ! if (mnBackgroundWidth > mnWidth) {mnBackgroundWidth = mnWidth;} ! mnBackgroundHeight = mpiBackground->GetHeight(); ! if (mnBackgroundHeight > mnHeight) {mnBackgroundHeight = mnHeight;} ! mnButtonWidth = mpiButtonOn->GetWidth(); ! if (mnButtonWidth > mnWidth) {mnButtonWidth = mnWidth;} //limit dimensions to window ! mnButtonHeight = mpiButtonOn->GetHeight(); ! if (mnButtonHeight > mnHeight) {mnButtonHeight = mnHeight;} ! return true; } /*******************************************************************************/ ! int tcOptionsView::Draw() ! { ! static nTestCount = 0; ! static WCHAR szwchar[256]; // wide char array buffer for string conversion ! Graphics *pGraphics; ! Erase(); ! if (!GetGraphics(pGraphics)) { ! return false; ! } ! if (mpiBackground == NULL) {return false;} ! if (mpOptions == NULL) {return false;} ! pGraphics->DrawImage(mpiBackground,0,0,mnWidth,mnHeight); ! mpBrush->SetColor(Color(0xFEFFFFFF)); ! /*** Draw test text **/ ! tcString sText; ! int xpos,ypos; ! ypos = mnYStart; ! RectF rstring; ! for(int i=0;i<mpOptions->mnNumOptions;i++) { ! xpos = mnXStart; ! int nBoxWidth = maButtonPosition[i][mpOptions->maOptionInfo[i].mnStateCount-1].mnButtonX - ! maButtonPosition[i][0].mnTextX + 2*mnButtonWidth; ! mpBrush->SetColor(Color(0x60FFFFFF)); ! pGraphics->FillRectangle(mpBrush, ! maButtonPosition[i][0].mnTextX - mnButtonHeight/2, ypos - 3*mnButtonHeight/2, ! nBoxWidth, 2*mnButtonHeight); ! mpBrush->SetColor(Color(255,255,220,220)); ! for(int j=0;j<mpOptions->maOptionInfo[i].mnStateCount;j++) { ! sText = mpOptions->maOptionInfo[i].mzCaption[j]; ! MultiByteToWideChar(CP_ACP, 0, sText.GetBuffer(), -1, szwchar, 255); ! pGraphics->MeasureString(szwchar,-1,mpFont,PointF(0,0),&rstring); ! maButtonPosition[i][j].mnTextX = xpos; ! maButtonPosition[i][j].mnTextY = ypos-mnButtonHeight+2; ! xpos += (int)(rstring.Width) + 1; ! maButtonPosition[i][j].mnButtonX = xpos; ! maButtonPosition[i][j].mnButtonY = ypos-mnButtonHeight-mnButtonHeight/6; ! xpos += 3*mnButtonWidth; ! ! } ! ! pGraphics->DrawRectangle(mpPen, ! maButtonPosition[i][0].mnTextX - mnButtonHeight/2, ypos - 3*mnButtonHeight/2, ! nBoxWidth, 2*mnButtonHeight); ! ! ypos += 3*mnButtonHeight; ! } ! ! for(i=0;i<mpOptions->mnNumOptions;i++) { ! for(int j=0;j<mpOptions->maOptionInfo[i].mnStateCount;j++) { ! sText = mpOptions->maOptionInfo[i].mzCaption[j]; ! MultiByteToWideChar(CP_ACP, 0, sText.GetBuffer(), -1, szwchar, 255); ! pGraphics->DrawString(szwchar, -1, mpFont, ! PointF((float)maButtonPosition[i][j].mnTextX, (float)maButtonPosition[i][j].mnTextY), ! mpBrush); ! ! ! if (mpOptions->maOptionInfo[i].mnValue == j) { ! DrawButton(pGraphics,maButtonPosition[i][j].mnButtonX, ! maButtonPosition[i][j].mnButtonY,1); ! } ! else { ! DrawButton(pGraphics,maButtonPosition[i][j].mnButtonX, ! maButtonPosition[i][j].mnButtonY,0); ! } ! } ! } ! ! DrawChildren(pGraphics); ! ! ReleaseGraphics(pGraphics); ! DrawBorder(); ! return true; } /*******************************************************************************/ void tcOptionsView::DrawButton(Graphics *apGraphics, int x, int y, int abOn) { ! Image *pButton; ! if (apGraphics == NULL) {return;} ! pButton = (abOn == 1) ? mpiButtonOn : mpiButtonOff; ! if (pButton == NULL) {return;} ! apGraphics->DrawImage(pButton,x,y); } /******************************************************************************/ void tcOptionsView::OnLButtonDown(wxMouseEvent& event) { ! bool bButtonClicked; ! int nOption, nValue; ! if (!mbActive) ! { ! event.Skip(); ! return; ! } ! // TranslatePoint(point); // adjust for flipped up/down ! bButtonClicked = ButtonContainingPoint(event.GetPosition(), nOption, nValue); ! if (bButtonClicked) { ! if ((nOption >= mpOptions->mnNumOptions)|| ! (nValue >= mpOptions->maOptionInfo[nOption].mnStateCount)) { ! WTL("tcOptionsView::OnLButtonDown error"); ! return; ! } ! mpOptions->maOptionInfo[nOption].mnValue = nValue; ! if (mpOptions->maOptionInfo[nOption].mpAssociated != NULL) { ! *mpOptions->maOptionInfo[nOption].mpAssociated = nValue; ! } ! mpOptions->Serialize(false); // create new options file ! ! tcSound::Get()->PlayEffect(SEFFECT_BEEP2); ! } ! else ! { ! /* Now this uses tcStandardWindow button bar to switch back to start ! // switch back to start view if no buttons clicked (for now) ! wxCommandEvent command(wxEVT_COMMAND_BUTTON_CLICKED, ID_STARTVIEW) ; ! command.SetEventObject(this); ! AddPendingEvent(command); ! */ ! } } /******************************************************************************/ bool tcOptionsView::ButtonContainingPoint(wxPoint point, int& rnOption, int& rnValue) { ! int i,j; ! int nx, ny; ! for(i=0;i<mpOptions->mnNumOptions;i++) { ! for(j=0;j<mpOptions->maOptionInfo[i].mnStateCount;j++) { ! nx = maButtonPosition[i][j].mnButtonX; ! ny = maButtonPosition[i][j].mnButtonY; ! wxRect cr(nx,ny,mnButtonWidth,mnButtonHeight); ! if (cr.Inside(point)) { ! rnOption = i; ! rnValue = j; ! return true; ! } ! } ! } ! return false; } *************** *** 243,278 **** ////////////////////////////////////////////////////////////////////// ! tcOptionsView::tcOptionsView(wxWindow *parent, ! const wxPoint& pos, const wxSize& size, ! const wxString& name, tcWindow *sharedSurface) : ! tcWindow(parent, pos, size, name, sharedSurface) { ! mpiBackground = NULL; ! mpiButtonOn = NULL; ! mpiButtonOff = NULL; ! mpOptions = NULL; ! mpFont = NULL; ! mpBrush = NULL; ! mnXStart = 100; ! mnYStart = 100; ! for(int i=0;i<N_OPTIONS;i++) ! { ! for(int k=0;k<N_OPTION_VALUES;k++) ! { ! maButtonPosition[i][k].mnButtonX = -100; ! maButtonPosition[i][k].mnButtonY = -100; ! maButtonPosition[i][k].mnTextX = -100; ! maButtonPosition[i][k].mnTextY = -100; ! } ! } } tcOptionsView::~tcOptionsView() { ! if (mpiBackground != NULL) {delete mpiBackground;} ! if (mpiButtonOn != NULL) {delete mpiButtonOn;} ! if (mpiButtonOff != NULL) {delete mpiButtonOff;} ! if (mpFont != NULL) {delete mpFont;} ! if (mpBrush != NULL) {delete mpBrush;} ! if (mpPen != NULL) {delete mpPen;} } --- 248,295 ---- ////////////////////////////////////////////////////////////////////// ! tcOptionsView::tcOptionsView(wxWindow *parent, tcWindow *surfaceHost, ! const wxPoint& pos, const wxSize& size, const wxString& name) ! : ! tcStandardWindow(parent, pos, size, "xml/options_view.xml", name, surfaceHost) { ! wxASSERT(surfaceHost); ! ! if (config) ! { ! AddXMLControls(); ! } ! else ! { ! fprintf(stderr, "tcOptionsView::tcOptionsView - NULL xml config node\n"); ! return; ! } ! ! mpiBackground = NULL; ! mpiButtonOn = NULL; ! mpiButtonOff = NULL; ! mpOptions = NULL; ! mpFont = NULL; ! mpBrush = NULL; ! mnXStart = 100; ! mnYStart = 150; ! for(int i=0;i<N_OPTIONS;i++) ! { ! for(int k=0;k<N_OPTION_VALUES;k++) ! { ! maButtonPosition[i][k].mnButtonX = -100; ! maButtonPosition[i][k].mnButtonY = -100; ! maButtonPosition[i][k].mnTextX = -100; ! maButtonPosition[i][k].mnTextY = -100; ! } ! } } tcOptionsView::~tcOptionsView() { ! if (mpiBackground != NULL) {delete mpiBackground;} ! if (mpiButtonOn != NULL) {delete mpiButtonOn;} ! if (mpiButtonOff != NULL) {delete mpiButtonOff;} ! if (mpFont != NULL) {delete mpFont;} ! if (mpBrush != NULL) {delete mpBrush;} ! if (mpPen != NULL) {delete mpPen;} } |