StartingMenuScreen::StartingMenuScreen(MenuHandler& menu) : Parent(menu) { auto renderer = FARender::Renderer::get(); mFocus42.reset(new FARender::AnimationPlayer()); mFocus42->playAnimation(renderer->loadImage("ui_art/focus42.pcx&trans=0,255,0&vanim=42"), FAWorld::World::getTicksInPeriod("0.06"), FARender::AnimationPlayer::AnimationType::Looped); mSmLogo = menu.createSmLogo(); auto drawItem = [&](const char* text, const struct nk_rect& rect) { return [=](nk_context* ctx, bool isActive) { nk_layout_space_push(ctx, rect); menuText(ctx, text, MenuFontColor::gold, 42, NK_TEXT_ALIGN_CENTERED); auto ret = DrawFunctionResult::noAction; if (nk_widget_is_mouse_click_down_inactive(ctx, NK_BUTTON_LEFT)) { ret = DrawFunctionResult::executeAction; } if (isActive) { auto frame = mFocus42->getCurrentFrame(); auto frameRect = nk_rect(0, 0, frame.first->getWidth(), frame.first->getHeight()); nk_layout_space_push(ctx, alignRect(frameRect, rect, halign_t::left, valign_t::center)); nk_image(ctx, frame.first->getNkImage(frame.second)); nk_layout_space_push(ctx, alignRect(frameRect, rect, halign_t::right, valign_t::center)); nk_image(ctx, frame.first->getNkImage(frame.second)); } return ret; }; }; mMenuItems.push_back({drawItem("Single Player", {65, 192, 510, 42}), [this]() { mMenuHandler.setActiveScreen<SelectHeroMenuScreen>(); return ActionResult::stopDrawing; }}); mMenuItems.push_back({drawItem("Multi Player", {65, 235, 510, 42}), []() { return ActionResult::continueDrawing; }}); mMenuItems.push_back({drawItem("Replay Intro", {65, 277, 510, 42}), []() { return ActionResult::continueDrawing; }}); mMenuItems.push_back({drawItem("Show Credits", {65, 320, 510, 42}), []() { return ActionResult::continueDrawing; }}); mRejectAction = [this]() { mMenuHandler.engine().stop(); return ActionResult::stopDrawing; }; mMenuItems.push_back({drawItem("Exit Diablo", {65, 363, 510, 42}), mRejectAction}); }
bool WidgetManager::alignWindow(QWidget *AWindow, Qt::Alignment AAlign) { if (AAlign > 0) { QRect frameRect = AWindow->frameGeometry(); QRect windowRect = AWindow->geometry(); if (!frameRect.isEmpty() && !windowRect.isEmpty() && frameRect.contains(windowRect)) { QRect availRect = AWindow!=NULL ? QApplication::desktop()->availableGeometry(AWindow) : QApplication::desktop()->availableGeometry(); QRect rect = alignRect(frameRect,availRect,AAlign); rect.adjust(windowRect.left()-frameRect.left(),windowRect.top()-frameRect.top(),windowRect.right()-frameRect.right(),windowRect.bottom()-frameRect.bottom()); AWindow->setGeometry(rect); return true; } } return false; }