SaveIdea::SaveIdea(const BMessage &msg, const BMessenger &msgr, float mainX, float mainY, int currentID) : BWindow(BRect(0, 0, 358, 60), "Save As", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS, B_CURRENT_WORKSPACE), updatetitleMessage(msg), updatetitleMessenger(msgr) { // initialize controls AddShortcut(B_TAB, B_COMMAND_KEY, new BMessage(END_SAVE_IDEA)); AddShortcut(B_ENTER, B_COMMAND_KEY, new BMessage(SAVE_IDEA)); AddShortcut(B_ESCAPE, B_COMMAND_KEY, new BMessage(CANCEL_SAVE)); SetDefaultButton(saveButton); BRect textFrame(0, 0, 300, 10); titleText = new BTextView(textFrame, NULL, textFrame, B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW); titleText->MakeResizable(false); titleText->SetWordWrap(false); titleText->DisallowChar(B_ENTER); titleString = new BStringView(BRect(10, 10, 200, 30), NULL, "Enter Thought Title:"); saveButton = new BButton(BRect(190, 50, 270, 75), NULL, "Save", new BMessage(SAVE_IDEA)); cancelButton = new BButton(BRect(190, 50, 270, 75), NULL, "Cancel", new BMessage(CANCEL_SAVE)); backView = new BView(Bounds(), "backview", B_FOLLOW_ALL, B_WILL_DRAW); backView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(backView); // gui layout builder backView->SetLayout(new BGroupLayout(B_HORIZONTAL, 0.0)); backView->AddChild(BGridLayoutBuilder() .Add(titleString, 0, 0, 2, 1) .Add(titleText, 2, 0, 3, 1) .Add(cancelButton, 3, 1) .Add(saveButton, 4, 1) .Add(BSpaceLayoutItem::CreateGlue(), 0, 2, 2, 1) .SetInsets(2, 5, 2, 2) ); MoveTo(mainX, mainY); // move to window position currentideaID = currentID; // make current idea id available to }
void BTextControl::DoLayout() { // Bail out, if we shan't do layout. if (!(Flags() & B_SUPPORTS_LAYOUT)) return; CALLED(); // If the user set a layout, we let the base class version call its // hook. if (GetLayout()) { BView::DoLayout(); return; } _ValidateLayoutData(); // validate current size BSize size(Bounds().Size()); if (size.width < fLayoutData->min.width) size.width = fLayoutData->min.width; if (size.height < fLayoutData->min.height) size.height = fLayoutData->min.height; // divider float divider = 0; if (fLayoutData->label_layout_item && fLayoutData->text_view_layout_item) { // We have layout items. They define the divider location. divider = fLayoutData->text_view_layout_item->Frame().left - fLayoutData->label_layout_item->Frame().left; } else { if (fLayoutData->label_width > 0) divider = fLayoutData->label_width + 5; } // text view BRect dirty(fText->Frame()); BRect textFrame(divider + kFrameMargin, kFrameMargin, size.width - kFrameMargin, size.height - kFrameMargin); // place the text view and set the divider BLayoutUtils::AlignInFrame(fText, textFrame); fDivider = divider; // invalidate dirty region dirty = dirty | fText->Frame(); dirty.InsetBy(-kFrameMargin, -kFrameMargin); Invalidate(dirty); }
void RETextField::render() { if (_cursorView) { _cursorView->setVisible(_isActualShowCursor); if (_cursorView->isVisible()) { RERect textFrame(this->getTextFrame()); RERect frame(_cursorView->frame()); frame.x = textFrame.x + textFrame.width; _cursorView->setFrame(frame); } } RELabel::render(); }
void RETextField::renderWithOffset(const REFloat32 offsetX, const REFloat32 offsetY) { if (_cursorView) { _cursorView->setVisible(_isActualShowCursor); if (_cursorView->isVisible()) { RERect textFrame(this->getTextFrame()); RERect frame(_cursorView->frame()); frame.x = textFrame.x + textFrame.width; _cursorView->setFrame(frame); } } RELabel::renderWithOffset(offsetX, offsetY); }
// Game loop void gameLoop() { int c; // char // Init frames Frame viewFrame(COLS-2, LINES-2, RFOrientation::TOP_LEFT); Frame textFrame(COLS-2, 4, RFOrientation::BOTTOM_LEFT); Frame inventoryFrame(18, 4, RFOrientation::BOTTOM_RIGHT); Frame statusFrame(15, 4, RFOrientation::TOP_RIGHT); int hasText = 0; int showedHint = 0; int showedNothingMessage = 0; plA = player.c_area; plX = player.x; plY = player.y; renderMap(viewFrame, area, &player); viewFrame.update(); renderInventory(&inventoryFrame, &player); renderStatus(&statusFrame, &player); while(1) { c = getch(); if (c == KEY_UP){ if (isValid(area, player.c_area, player.x, player.y - 1) && area[player.c_area][player.x][player.y].doorInfo[D_UP] == DC_OPEN && player.direction == D_UP) { player.y = player.y - 1; } player.direction = D_UP; } else if (c == KEY_RIGHT){ if (isValid(area, player.c_area, player.x + 1, player.y) && area[player.c_area][player.x][player.y].doorInfo[D_RIGHT] == DC_OPEN && player.direction == D_RIGHT) { player.x = player.x + 1; } else if (isValid(area, player.c_area, player.x + 1, player.y) && area[player.c_area][player.x][player.y].doorInfo[D_RIGHT] == DC_LOCKED && player.hasKey) { area[player.c_area][player.x][player.y].doorInfo[D_RIGHT] = DC_OPEN; player.hasKey = 0; } player.direction = D_RIGHT; }else if (c == KEY_DOWN){ if ( isValid(area, player.c_area, player.x, player.y + 1) && area[player.c_area][player.x][player.y].doorInfo[D_DOWN] == DC_OPEN ) { if (player.direction == D_DOWN) { player.y = player.y + 1; } } else if (isValid(area, player.c_area, player.y + 1, player.y) && area[player.c_area][player.x][player.y].doorInfo[D_DOWN] == DC_LOCKED && player.hasKey) { area[player.c_area][player.x][player.y].doorInfo[D_DOWN] = DC_OPEN; player.hasKey = 0; } player.direction = D_DOWN; } else if (c == KEY_LEFT){ if ( isValid(area, player.c_area, player.x - 1, player.y) && area[player.c_area][player.x][player.y].doorInfo[D_LEFT] == DC_OPEN ) { if (player.direction == D_LEFT) { player.x = player.x - 1; } } player.direction = D_LEFT; } hasText = 0; // Render view if (c == 'z') { textFrame.clear(); if (area[player.c_area][player.x][player.y].hasKey) { textFrame.println("キーを見つけた...!"); hasText = 1; player.hasKey = 1; area[player.c_area][player.x][player.y].hasKey = 0; } else if (area[player.c_area][player.x][player.y].hint != "" && !showedHint) { textFrame.println("ヒントを見つけた...\n"); textFrame.println(area[player.c_area][player.x][player.y].hint.c_str()); showedHint = 1; showedNothingMessage = 1; hasText = 1; } else if (area[player.c_area][player.x][player.y].hasPotion && player.hasPotion) { textFrame.println("ポーション見つけたが、持てない..."); hasText = 1; } else if (area[player.c_area][player.x][player.y].hasPotion) { textFrame.println("ポーション見つけた...!"); hasText = 1; player.hasPotion = 1; area[player.c_area][player.x][player.y].hasPotion = 0; } else if (area[player.c_area][player.x][player.y].canJump) { viewFrame.move(0, 0); viewFrame.print(filledWith(viewFrame, "□"), 10); player.c_area = 1; player.x = 7; player.y = 2; } else if (!showedNothingMessage) { textFrame.println("何も無いようだ..."); showedNothingMessage = 1; hasText = 1; } else { showedNothingMessage = 0; hasText = 0; showedHint = 0; } } else if (c == 's') { textFrame.clear(); if (player.hasPotion) { textFrame.println("ポーション使う...?"); textFrame.println("z = はい"); textFrame.println("x = いいえ"); while(1) { c = getch(); if (c == 'z') { textFrame.clear(); textFrame.println("ポーション使いました..."); textFrame.println("HP全回しました"); player.hp = 15; hasText = 1; player.hasPotion = 0; break; } else if (c == 'x'){ textFrame.clear(); textFrame.println("ポーション使うのをやめた..."); textFrame.println("HP全回しました、なんてウソです"); hasText = 1; break; } } } else if (!player.hasPotion) { textFrame.println("ポーションない..."); hasText = 1; } } area[player.c_area][player.x][player.y].playerVisited = 1; renderMap(viewFrame, area, &player); viewFrame.update(); if (hasText) textFrame.update(); renderInventory(&inventoryFrame, &player); renderStatus(&statusFrame, &player); // 前回描画した時からプレイヤーは移動したか? if (isPlayerMoved(plA, plX, plY, player.c_area, player.x, player.y)) { // Zakoがいるなら戦闘 int eob = checkEncountGauge(&viewFrame, &inventoryFrame, &statusFrame); if (eob == EOB_PLAYER_LOST) { gameOver(&viewFrame); return; } } // 特殊ボス会敵 if (area[player.c_area][player.x][player.y].uniqueBossId == 1 && !player.beatenHBoss) { int eob = battleSequence(&viewFrame); if (eob == EOB_PLAYER_LOST) { gameOver(&viewFrame); return; } else if (eob == EOB_PLAYER_BEATEN_BOSS) { gameWon(&viewFrame); return; } } else if (area[player.c_area][player.x][player.y].uniqueBossId == 0) { int eob = battleSequence(&viewFrame); if (eob == EOB_PLAYER_LOST) { gameOver(&viewFrame); return; } else if (eob == EOB_PLAYER_BEATEN_BOSS) { gameWon(&viewFrame); return; } } plA = player.c_area; plX = player.x; plY = player.y; } }