Ejemplo n.º 1
0
BOOL CCandidateWindow::_Create(ATOM atom, _In_ UINT wndWidth, _In_opt_ HWND parentWndHandle)
{
    BOOL ret = FALSE;
    _wndWidth = wndWidth;

    ret = _CreateMainWindow(atom, parentWndHandle);
    if (FALSE == ret)
    {
        goto Exit;
    }

    ret = _CreateBackGroundShadowWindow();
    if (FALSE == ret)
    {
        goto Exit;
    }

    ret = _CreateVScrollWindow();
    if (FALSE == ret)
    {
        goto Exit;
    }

    _ResizeWindow();

Exit:
    return TRUE;
}
Ejemplo n.º 2
0
void
PairsWindow::_MakeGameView(uint8 rows, uint8 cols)
{
	BRect viewBounds = Bounds();
	viewBounds.top = fMenuBar->Bounds().Height() + 1;

	uint8 iconSize;
	BMenuItem* marked = fIconSizeMenu->FindMarked();
	if (marked != NULL) {
		switch (fIconSizeMenu->IndexOf(marked)) {
			case 0:
				iconSize = kSmallIconSize;
				break;

			case 2:
				iconSize = kLargeIconSize;
				break;

			case 1:
			default:
				iconSize = kMediumIconSize;
		}
	} else {
		iconSize = kMediumIconSize;
		fIconSizeMenu->ItemAt(1)->SetMarked(true);
	}

	fPairsView = new PairsView(viewBounds, "PairsView", rows, cols, iconSize);
	AddChild(fPairsView);
	_ResizeWindow(rows, cols);
}
Ejemplo n.º 3
0
void
PairsWindow::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case MENU_NEW:
			NewGame();
			break;

		case MENU_DIFFICULTY:
		{
			int32 rows;
			int32 cols;
			if (message->FindInt32("rows", &rows) == B_OK
				&& message->FindInt32("cols", &cols) == B_OK) {
				SetGameSize(rows, cols);
			}
			break;
		}

		case MENU_ICON_SIZE:
		{
			int32 size;
			if (message->FindInt32("size", &size) == B_OK) {
				fPairsView->SetIconSize(size);
				_ResizeWindow(fPairsView->Rows(), fPairsView->Cols());
			}

			break;
		}

		case MENU_QUIT:
			be_app->PostMessage(B_QUIT_REQUESTED);
			break;

		case kMsgCardButton:
		{
			if (!fIsPairsActive)
				break;

			int32 buttonNumber;
			if (message->FindInt32("button number", &buttonNumber) != B_OK)
				break;

			BObjectList<PairsButton>* pairsButtonList
				= fPairsView->PairsButtonList();
			if (pairsButtonList == NULL)
				break;

			// look at what icon is behind a button
			int32 buttonCount = pairsButtonList->CountItems();
			for (int32 i = 0; i < buttonCount; i++) {
				int32 iconPosition = fPairsView->GetIconPosition(i);
				if (iconPosition == buttonNumber) {
					fPairCardPosition = i % (buttonCount / 2);
					fButtonPosition = iconPosition;
					break;
				}
			}

			// gameplay
			fButtonClicks++;
			pairsButtonList->ItemAt(fButtonPosition)->Hide();

			if (fIsFirstClick) {
				fPairCardTmpPosition = fPairCardPosition;
				fButtonTmpPosition = fButtonPosition;
			} else {
				delete fPairComparing;
					// message of message runner might not have arrived
					// yet, so it is deleted here to prevent any leaking
					// just in case
				BMessage message(kMsgPairComparing);
				fPairComparing = new BMessageRunner(BMessenger(this),
					&message,  5 * 100000L, 1);
				fIsPairsActive = false;
			}

			fIsFirstClick = !fIsFirstClick;
			break;
		}

		case kMsgPairComparing:
		{
			BObjectList<PairsButton>* pairsButtonList
				= fPairsView->PairsButtonList();
			if (pairsButtonList == NULL)
				break;

			delete fPairComparing;
			fPairComparing = NULL;

			fIsPairsActive = true;

			if (fPairCardPosition == fPairCardTmpPosition)
				fFinishPairs++;
			else {
				pairsButtonList->ItemAt(fButtonPosition)->Show();
				pairsButtonList->ItemAt(fButtonTmpPosition)->Show();
			}

			// game end and results
			if (fFinishPairs == pairsButtonList->CountItems() / 2) {
				BString score;
				score << fButtonClicks;
				BString strAbout = B_TRANSLATE("%app%\n"
					"\twritten by Ralf Schülke\n"
					"\tCopyright 2008-2010, Haiku Inc.\n"
					"\n"
					"You completed the game in %num% clicks.\n");

				strAbout.ReplaceFirst("%app%",
					B_TRANSLATE_SYSTEM_NAME("Pairs"));
				strAbout.ReplaceFirst("%num%", score);

				BAlert* alert = new BAlert("about",
					strAbout.String(),
					B_TRANSLATE("New game"),
					B_TRANSLATE("Quit game"));

				BTextView* view = alert->TextView();
				BFont font;

				view->SetStylable(true);

				view->GetFont(&font);
				font.SetSize(18);
				font.SetFace(B_BOLD_FACE);
				view->SetFontAndColor(0,
					strlen(B_TRANSLATE_SYSTEM_NAME("Pairs")), &font);
				view->ResizeToPreferred();
				alert->SetShortcut(0, B_ESCAPE);

				if (alert->Go() == 0)
					NewGame();
				else
					be_app->PostMessage(B_QUIT_REQUESTED);
			}
			break;
		}

		default:
			BWindow::MessageReceived(message);
	}
}