LLPanel::LLPanel(const LLPanel::Params& p) : LLUICtrl(p), mBgVisible(p.background_visible), mBgOpaque(p.background_opaque), mBgOpaqueColor(p.bg_opaque_color()), mBgAlphaColor(p.bg_alpha_color()), mBgOpaqueImageOverlay(p.bg_opaque_image_overlay), mBgAlphaImageOverlay(p.bg_alpha_image_overlay), mBgOpaqueImage(p.bg_opaque_image()), mBgAlphaImage(p.bg_alpha_image()), mDefaultBtn(NULL), mBorder(NULL), mLabel(p.label), mHelpTopic(p.help_topic), mCommitCallbackRegistrar(false), mEnableCallbackRegistrar(false), mXMLFilename(p.filename), mVisibleSignal(NULL) // *NOTE: Be sure to also change LLPanel::initFromParams(). We have too // many classes derived from LLPanel to retrofit them all to pass in params. { if (p.has_border) { addBorder(p.border); } mPanelHandle.bind(this); }
void LLPanel::initFromParams(const LLPanel::Params& p) { //setting these here since panel constructor not called with params //and LLView::initFromParams will use them to set visible and enabled setVisible(p.visible); setEnabled(p.enabled); setFocusRoot(p.focus_root); setSoundFlags(p.sound_flags); // control_name, tab_stop, focus_lost_callback, initial_value, rect, enabled, visible LLUICtrl::initFromParams(p); // visible callback if (p.visible_callback.isProvided()) { setVisibleCallback(initCommitCallback(p.visible_callback)); } for (LLInitParam::ParamIterator<LocalizedString>::const_iterator it = p.strings.begin(); it != p.strings.end(); ++it) { mUIStrings[it->name] = it->value; } setLabel(p.label()); setHelpTopic(p.help_topic); setShape(p.rect); parseFollowsFlags(p); setToolTip(p.tool_tip()); setFromXUI(p.from_xui); mHoverCursor = getCursorFromString(p.hover_cursor); if (p.has_border) { addBorder(p.border); } // let constructors set this value if not provided if (p.use_bounding_rect.isProvided()) { setUseBoundingRect(p.use_bounding_rect); } setDefaultTabGroup(p.default_tab_group); setMouseOpaque(p.mouse_opaque); setBackgroundVisible(p.background_visible); setBackgroundOpaque(p.background_opaque); setBackgroundColor(p.bg_opaque_color().get()); setTransparentColor(p.bg_alpha_color().get()); mBgOpaqueImage = p.bg_opaque_image(); mBgAlphaImage = p.bg_alpha_image(); mBgOpaqueImageOverlay = p.bg_opaque_image_overlay; mBgAlphaImageOverlay = p.bg_alpha_image_overlay; mAcceptsBadge = p.accepts_badge; }
void QQuickTextNodeEngine::addFrameDecorations(QTextDocument *document, QTextFrame *frame) { QTextDocumentLayout *documentLayout = qobject_cast<QTextDocumentLayout *>(document->documentLayout()); QTextFrameFormat frameFormat = frame->format().toFrameFormat(); QTextTable *table = qobject_cast<QTextTable *>(frame); QRectF boundingRect = table == 0 ? documentLayout->frameBoundingRect(frame) : documentLayout->tableBoundingRect(table); QBrush bg = frame->frameFormat().background(); if (bg.style() != Qt::NoBrush) m_backgrounds.append(qMakePair(boundingRect, bg.color())); if (!frameFormat.hasProperty(QTextFormat::FrameBorder)) return; qreal borderWidth = frameFormat.border(); if (qFuzzyIsNull(borderWidth)) return; QBrush borderBrush = frameFormat.borderBrush(); QTextFrameFormat::BorderStyle borderStyle = frameFormat.borderStyle(); if (borderStyle == QTextFrameFormat::BorderStyle_None) return; addBorder(boundingRect.adjusted(frameFormat.leftMargin(), frameFormat.topMargin(), -frameFormat.rightMargin(), -frameFormat.bottomMargin()), borderWidth, borderStyle, borderBrush); if (table != 0) { int rows = table->rows(); int columns = table->columns(); for (int row=0; row<rows; ++row) { for (int column=0; column<columns; ++column) { QTextTableCell cell = table->cellAt(row, column); QRectF cellRect = documentLayout->tableCellBoundingRect(table, cell); addBorder(cellRect.adjusted(-borderWidth, -borderWidth, 0, 0), borderWidth, borderStyle, borderBrush); } } } }
LLPanel::LLPanel(const std::string& name, const LLRect& rect, BOOL bordered) : LLUICtrl(name, rect, TRUE, NULL, NULL), mRectControl() { init(); if (bordered) { addBorder(); } }
LLPanel::LLPanel(const std::string& name, const std::string& rect_control, BOOL bordered) : LLUICtrl(name, LLUI::sConfigGroup->getRect(rect_control), TRUE, NULL, NULL), mRectControl( rect_control ) { init(); if (bordered) { addBorder(); } }
void LLPanel::setPanelParameters(LLXMLNodePtr node, LLView* parent) { /////// Rect, follows, tool_tip, enabled, visible attributes /////// initFromXML(node, parent); /////// Border attributes /////// BOOL border = mBorder != NULL; node->getAttributeBOOL("border", border); if (border) { LLViewBorder::EBevel bevel_style = LLViewBorder::BEVEL_OUT; LLViewBorder::getBevelFromAttribute(node, bevel_style); LLViewBorder::EStyle border_style = LLViewBorder::STYLE_LINE; std::string border_string; node->getAttributeString("border_style", border_string); LLStringUtil::toLower(border_string); if (border_string == "texture") { border_style = LLViewBorder::STYLE_TEXTURE; } S32 border_thickness = LLPANEL_BORDER_WIDTH; node->getAttributeS32("border_thickness", border_thickness); addBorder(bevel_style, border_style, border_thickness); } else { removeBorder(); } /////// Background attributes /////// BOOL background_visible = mBgVisible; node->getAttributeBOOL("background_visible", background_visible); setBackgroundVisible(background_visible); BOOL background_opaque = mBgOpaque; node->getAttributeBOOL("background_opaque", background_opaque); setBackgroundOpaque(background_opaque); LLColor4 color; color = mBgColorOpaque; LLUICtrlFactory::getAttributeColor(node,"bg_opaque_color", color); setBackgroundColor(color); color = mBgColorAlpha; LLUICtrlFactory::getAttributeColor(node,"bg_alpha_color", color); setTransparentColor(color); std::string label = getLabel(); node->getAttributeString("label", label); setLabel(label); }
void updateLabelText(Label *l, char *text) { if (l->text != NULL) { SDL_FreeSurface(l->text); l->text = NULL; } l->text = addBorder(generateTextSurface(text, game.font, 255, 255, 255, 0, 0, 0), 255, 255, 255, 0, 0, 0); }
LLPanel::LLPanel(const std::string& name, const std::string& rect_control, BOOL bordered) : LLUICtrl(name, LLUI::sConfigGroup->getRect(rect_control)), mRectControl( rect_control ), mCommitCallbackRegistrar(false), mEnableCallbackRegistrar(false) { init(); if (bordered) { addBorder(); } }
LLPanel::LLPanel(const std::string& name, const LLRect& rect, BOOL bordered) : LLUICtrl(name,rect), mRectControl(), mCommitCallbackRegistrar(false), mEnableCallbackRegistrar(false) { init(); if (bordered) { addBorder(); } }
static void loadMenuLayout() { int y; char versionText[MAX_VALUE_LENGTH], copyright[MAX_VALUE_LENGTH]; menu.widgetCount = 3; menu.widgets = malloc(sizeof(Widget *) * menu.widgetCount); snprintf(versionText, MAX_VALUE_LENGTH, _("The Legend of Edgar v%0.2f"), VERSION); if (menu.widgets == NULL) { showErrorAndExit("Ran out of memory when creating About Menu"); } y = BUTTON_PADDING + BORDER_PADDING; menu.widgets[0] = createWidget(versionText, NULL, NULL, NULL, NULL, -1, y, FALSE, 255, 255, 255); y += menu.widgets[0]->selectedState->h + BUTTON_PADDING; snprintf(copyright, MAX_VALUE_LENGTH, _("Copyright Parallel Realities 2009 - %d"), YEAR); menu.widgets[1] = createWidget(copyright, NULL, NULL, NULL, NULL, -1, y, FALSE, 255, 255, 255); y += menu.widgets[1]->selectedState->h + BUTTON_PADDING; menu.widgets[2] = createWidget(_("OK"), NULL, NULL, NULL, NULL, -1, y, TRUE, 255, 255, 255); y += menu.widgets[2]->selectedState->h + BUTTON_PADDING; /* Resize */ if (menu.widgets[0]->selectedState->w > menu.widgets[1]->selectedState->w) { menu.w = menu.widgets[0]->selectedState->w; } else { menu.w = menu.widgets[1]->selectedState->w; } menu.h = y - BORDER_PADDING; menu.background = addBorder(createSurface(menu.w, menu.h), 255, 255, 255, 0, 0, 0); menu.x = (SCREEN_WIDTH - menu.background->w) / 2; menu.y = (SCREEN_HEIGHT - menu.background->h) / 2; }
static void loadMenuLayout(char *text) { int x, y; x = 20; y = 0; menu.widgetCount = 3; menu.widgets = malloc(sizeof(Widget *) * menu.widgetCount); if (menu.widgets == NULL) { showErrorAndExit("Ran out of memory when creating Script Menu"); } menu.widgets[0] = createWidget(_(text), NULL, NULL, NULL, NULL, -1, 20, FALSE, 255, 255, 255); menu.widgets[1] = createWidget(_("Yes"), NULL, NULL, NULL, doYes, x, y, TRUE, 255, 255, 255); menu.widgets[2] = createWidget(_("No"), NULL, NULL, NULL, doNo, x, y, TRUE, 255, 255, 255); /* Resize */ menu.widgets[0]->y = BORDER_PADDING + BUTTON_PADDING; menu.widgets[1]->y = menu.widgets[0]->y + menu.widgets[0]->selectedState->h + BUTTON_PADDING; menu.widgets[2]->y = menu.widgets[1]->y; menu.w = menu.widgets[0]->selectedState->w; if (menu.w < 150) { menu.w = 150; } menu.h = menu.widgets[2]->y + menu.widgets[2]->selectedState->h + BUTTON_PADDING - BORDER_PADDING; x = menu.widgets[1]->normalState->w + BUTTON_PADDING + menu.widgets[2]->normalState->w; menu.widgets[1]->x = (menu.w - x) / 2; menu.widgets[2]->x = menu.widgets[1]->x + menu.widgets[1]->selectedState->w + BUTTON_PADDING; menu.background = addBorder(createSurface(menu.w, menu.h), 255, 255, 255, 0, 0, 0); menu.x = (SCREEN_WIDTH - menu.background->w) / 2; menu.y = (SCREEN_HEIGHT - menu.background->h) / 2; }
Label *createLabel(char *text, int x, int y) { Label *l; l = malloc(sizeof(Label)); if (l == NULL) { showErrorAndExit("Failed to allocate %d bytes to create Label %s", (int)sizeof(Label), text); } l->text = addBorder(generateTextSurface(text, game.font, 255, 255, 255, 0, 0, 0), 255, 255, 255, 0, 0, 0); l->x = x; l->y = y; return l; }
Widget *createWidget(char *text, int *controlValue, void (*leftAction)(void), void (*rightAction)(void), void (*clickAction)(void), int x, int y, int border, int r, int g, int b) { Widget *w; w = malloc(sizeof(Widget)); if (w == NULL) { showErrorAndExit("Failed to allocate %d bytes to create Widget %s", (int)sizeof(Widget), text); } if (border == TRUE) { w->normalState = addBorder(createWidgetText(text, game.font, r, g, b, 0, 0, 0), 255, 255, 255, 0, 0, 0); w->selectedState = addBorder(createWidgetText(text, game.font, r, g, b, 0, 200, 0), 255, 255, 255, 0, 200, 0); w->disabledState = addBorder(createWidgetText(text, game.font, r, g, b, 100, 100, 100), 255, 255, 255, 100, 100, 100); } else { w->normalState = addBorder(createWidgetText(text, game.font, r, g, b, 0, 0, 0), 0, 0, 0, 0, 0, 0); w->selectedState = addBorder(createWidgetText(text, game.font, r, g, b, 0, 200, 0), 0, 200, 0, 0, 200, 0); w->disabledState = addBorder(createWidgetText(text, game.font, r, g, b, 100, 100, 100), 0, 0, 0, 0, 0, 0); } w->value = controlValue; w->leftAction = leftAction; w->rightAction = rightAction; w->clickAction = clickAction; w->x = x; w->y = y; w->label = NULL; w->disabled = FALSE; w->hidden = FALSE; return w; }
static void loadMenuLayout(int saving) { char **saveFile; int y, i, j, width , maxWidth, w; w = i = 0; y = BUTTON_PADDING / 2 + BORDER_PADDING; menu.widgetCount = MAX_SAVE_SLOTS + 2; menu.widgets = malloc(sizeof(Widget *) * menu.widgetCount); if (menu.widgets == NULL) { showErrorAndExit("Ran out of memory when creating IO Menu"); } saveFile = getSaveFileIndex(); if (saving == TRUE) { menu.widgets[0] = createWidget(_("Choose slot to save to"), NULL, NULL, NULL, NULL, -1, y, FALSE, 255, 255, 255); } else { menu.widgets[0] = createWidget(_("Choose slot to load from"), NULL, NULL, NULL, NULL, -1, y, FALSE, 255, 255, 255); } maxWidth = 0; i = 1; for (j=0;j<MAX_SAVE_SLOTS;j++) { if (saveFile == NULL || strlen(saveFile[j]) == 0) { menu.widgets[i] = createWidget(_("<Empty>"), NULL, NULL, NULL, saving == TRUE ? &saveGameInSlot : NULL, -1, y, FALSE, 255, 255, 255); } else { menu.widgets[i] = createWidget(saveFile[j], NULL, NULL, NULL, saving == TRUE ? &saveGameInSlot : &loadGameInSlot, -1, y, FALSE, 255, 255, 255); } if (saveFile[j] != NULL) { free(saveFile[j]); } if (menu.widgets[i]->selectedState->w > width) { width = menu.widgets[i]->selectedState->w; } i++; } menu.widgets[i] = createWidget(_("Back"), NULL, 0, 0, &showMainMenu, -1, y, TRUE, 255, 255, 255); for (i=0;i<menu.widgetCount;i++) { menu.widgets[i]->y = y; if (menu.widgets[i]->x != -1) { menu.widgets[i]->x = BUTTON_PADDING + BORDER_PADDING; } if (menu.widgets[i]->label != NULL) { menu.widgets[i]->label->y = y; menu.widgets[i]->label->x = menu.widgets[i]->x + maxWidth + 10; if (menu.widgets[i]->label->x + menu.widgets[i]->label->text->w > w) { w = menu.widgets[i]->label->x + menu.widgets[i]->label->text->w; } } else { if (menu.widgets[i]->x + menu.widgets[i]->selectedState->w > w) { w = menu.widgets[i]->x + menu.widgets[i]->selectedState->w; } } y += menu.widgets[i]->selectedState->h + BUTTON_PADDING / 2; } menu.w = w + BUTTON_PADDING; menu.h = y - BORDER_PADDING; menu.background = addBorder(createSurface(menu.w, menu.h), 255, 255, 255, 0, 0, 0); menu.x = (SCREEN_WIDTH - menu.background->w) / 2; menu.y = (SCREEN_HEIGHT - menu.background->h) / 2; }
static void loadMenuLayout() { int i, x, y, w, maxWidth; menu.widgetCount = 4; menu.widgets = malloc(sizeof(Widget *) * menu.widgetCount); if (menu.widgets == NULL) { showErrorAndExit("Ran out of memory when creating Cheat Menu"); } x = 20; y = 0; menu.widgets[0] = createWidget(_("Infinite Health"), NULL, &toggleInfiniteHealth, &toggleInfiniteHealth, &toggleInfiniteHealth, x, y, TRUE, 255, 255, 255); menu.widgets[0]->label = createLabel(game.infiniteEnergy == TRUE ? _("Yes") : _("No"), menu.widgets[0]->x + menu.widgets[0]->normalState->w + 10, y); healthCheat = game.infiniteEnergy; menu.widgets[1] = createWidget(_("Infinite Arrows"), NULL, &toggleInfiniteArrows, &toggleInfiniteArrows, &toggleInfiniteArrows, x, y, TRUE, 255, 255, 255); menu.widgets[1]->label = createLabel(game.infiniteArrows == TRUE ? _("Yes") : _("No"), menu.widgets[1]->x + menu.widgets[1]->normalState->w + 10, y); arrowCheat = game.infiniteArrows; menu.widgets[2] = createWidget(_("Lava is fatal"), NULL, &toggleLavaIsFatal, &toggleLavaIsFatal, &toggleLavaIsFatal, x, y, TRUE, 255, 255, 255); menu.widgets[2]->label = createLabel(game.lavaIsFatal == TRUE ? _("Yes") : _("No"), menu.widgets[2]->x + menu.widgets[2]->normalState->w + 10, y); lavaCheat = game.lavaIsFatal == TRUE ? FALSE : TRUE; menu.widgets[3] = createWidget(_("Back"), NULL, NULL, NULL, &showOptionsMenu, -1, y, TRUE, 255, 255, 255); y = BUTTON_PADDING + BORDER_PADDING; maxWidth = w = 0; for (i=0;i<menu.widgetCount;i++) { if (menu.widgets[i]->label != NULL && menu.widgets[i]->normalState->w > maxWidth) { maxWidth = menu.widgets[i]->normalState->w; } } for (i=0;i<menu.widgetCount;i++) { menu.widgets[i]->y = y; if (menu.widgets[i]->x != -1) { menu.widgets[i]->x = BUTTON_PADDING + BORDER_PADDING; } if (menu.widgets[i]->label != NULL) { menu.widgets[i]->label->y = y; menu.widgets[i]->label->x = menu.widgets[i]->x + maxWidth + 10; if (menu.widgets[i]->label->x + menu.widgets[i]->label->text->w > w) { w = menu.widgets[i]->label->x + menu.widgets[i]->label->text->w; } } else { if (menu.widgets[i]->x + menu.widgets[i]->selectedState->w > w) { w = menu.widgets[i]->x + menu.widgets[i]->selectedState->w; } } y += menu.widgets[i]->selectedState->h + BUTTON_PADDING; } menu.w = w + BUTTON_PADDING; menu.h = y - BORDER_PADDING; menu.background = addBorder(createSurface(menu.w, menu.h), 255, 255, 255, 0, 0, 0); menu.x = (SCREEN_WIDTH - menu.background->w) / 2; menu.y = (SCREEN_HEIGHT - menu.background->h) / 2; }
void LLPanel::addBorder() { LLViewBorder::Params p; p.border_thickness(LLPANEL_BORDER_WIDTH); addBorder(p); }
GameView::GameView(QWidget *parent){ // Сглаживание this -> setRenderHint(QPainter::Antialiasing); // Количество игроков count_players = 2; // Количество действий // X A W S D Tab Q E Space count_actions = 9; // Забиваем вектор из действий if ( count_players > 0 ){ QVector<int> temp = { Qt::Key_X, Qt::Key_A, Qt::Key_W, Qt::Key_S, Qt::Key_D, Qt::Key_Tab, Qt::Key_Q, Qt::Key_E, Qt::Key_Space }; controls.push_back(temp); } if ( count_players > 1 ){ QVector<int> temp = { Qt::Key_2, Qt::Key_4, Qt::Key_8, Qt::Key_5, Qt::Key_6, Qt::Key_Plus, Qt::Key_7, Qt::Key_9, Qt::Key_0 }; controls.push_back(temp); } // Инициализируем переменную fps fps = 120; // Создаем графическую сцену scene = new QGraphicsScene(this); scene -> setSceneRect(-1, -1, screen_size.x()+1, screen_size.y()+1); // Ставим фон сцены QImage * img = new QImage(":/images/bg_1_1.png"); resizeImage(img, QSize(1920.0*resize_factor, 1080.0*resize_factor)); QBrush bg_brush(*img); scene -> setBackgroundBrush(bg_brush); // Добавляем границы сцены addBorder(); // Ставим нашу сцену setScene(scene); // Отключение полос прокрутки setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // Ставим заголовок окна setWindowTitle("Space Wars"); // Добавление игрока 1 player1 = new Ship(1, 1, 3, 1); placeShip(player1, scene -> width() / 2.0 - player1 -> boundingRect().width(), scene -> height() / 2.0 - player1 -> boundingRect().height() / 2.0 ); // Добавление игрока 2 player2 = new Ship(1, 2, 4, 1); placeShip(player2, scene -> width() / 2.0, scene -> height() / 2.0 - player1 -> boundingRect().height() / 2.0 ); // Добавление мобов /* for (int j = 2; j <= 2; ++j) for (int i = 1; i <= 4; ++i){ Ship * ship = new Ship(1, j, i, qrand()%4+1); npcs.insert(ship); placeShip(ship, qrand()%qRound(scene -> width()- ship -> boundingRect().width() ), qrand()%qRound(scene -> height()- ship -> boundingRect().height() ) ); } */ // Главный таймер QTimer * timer = new QTimer(); connect(timer, SIGNAL(timeout()), this, SLOT(mainTimer())); timer -> start(1000.0 / fps); }
static void loadMenuLayout(char *text) { int y, i, w, maxWidth; i = 0; menu.widgetCount = 2; menu.widgets = malloc(sizeof(Widget *) * menu.widgetCount); if (menu.widgets == NULL) { showErrorAndExit("Ran out of memory when creating OK Menu"); } menu.widgets[0] = createWidget(text, NULL, NULL, NULL, NULL, -1, 10, FALSE, 255, 255, 255); menu.widgets[1] = createWidget(_("OK"), NULL, NULL, NULL, &doOK, -1, 10, TRUE, 255, 255, 255); y = BUTTON_PADDING + BORDER_PADDING; maxWidth = w = 0; for (i=0;i<menu.widgetCount;i++) { if (menu.widgets[i]->label != NULL && menu.widgets[i]->normalState->w > maxWidth) { maxWidth = menu.widgets[i]->normalState->w; } } for (i=0;i<menu.widgetCount;i++) { menu.widgets[i]->y = y; if (menu.widgets[i]->x != -1) { menu.widgets[i]->x = BUTTON_PADDING + BORDER_PADDING; } if (menu.widgets[i]->label != NULL) { menu.widgets[i]->label->y = y; menu.widgets[i]->label->x = menu.widgets[i]->x + maxWidth + 10; if (menu.widgets[i]->label->x + menu.widgets[i]->label->text->w > w) { w = menu.widgets[i]->label->x + menu.widgets[i]->label->text->w; } } else { if (menu.widgets[i]->x + menu.widgets[i]->selectedState->w > w) { w = menu.widgets[i]->x + menu.widgets[i]->selectedState->w; } } y += menu.widgets[i]->selectedState->h + BUTTON_PADDING; } menu.w = w + BUTTON_PADDING; menu.h = y - BORDER_PADDING; menu.background = addBorder(createSurface(menu.w, menu.h), 255, 255, 255, 0, 0, 0); menu.x = (SCREEN_WIDTH - menu.background->w) / 2; menu.y = (SCREEN_HEIGHT - menu.background->h) / 2; }
static void loadMenuLayout() { char *text; int x, y, w, maxWidth, i; menu.widgetCount = 5; menu.widgets = malloc(sizeof(Widget *) * menu.widgetCount); if (menu.widgets == NULL) { showErrorAndExit("Ran out of memory when creating Control Menu"); } x = y = 0; menu.widgets[0] = createWidget(_("Sound"), &control.button[CONTROL_UP], &toggleSound, &toggleSound, &toggleSound, x, y, TRUE, 255, 255, 255); menu.widgets[0]->label = createLabel(game.audio == TRUE || game.audioDisabled == TRUE ? _("Yes") : _("No"), menu.widgets[0]->x + menu.widgets[0]->normalState->w + 10, y); menu.widgets[1] = createWidget(_("SFX Volume"), &game.sfxDefaultVolume, &lowerSFXVolume, &raiseSFXVolume, NULL, x, y, TRUE, 255, 255, 255); text = getVolumePercent(game.sfxDefaultVolume); menu.widgets[1]->label = createLabel(_(text), menu.widgets[1]->x + menu.widgets[1]->normalState->w + 10, y); free(text); menu.widgets[2] = createWidget(_("Music Volume"), &game.musicDefaultVolume, &lowerMusicVolume, &raiseMusicVolume, NULL, x, y, TRUE, 255, 255, 255); text = getVolumePercent(game.musicDefaultVolume); menu.widgets[2]->label = createLabel(_(text), menu.widgets[2]->x + menu.widgets[2]->normalState->w + 10, y); free(text); menu.widgets[3] = createWidget(_("Audio Quality"), &game.audioQuality, &toggleQuality, &toggleQuality, &toggleQuality, x, y, TRUE, 255, 255, 255); text = getQuality(); menu.widgets[3]->label = createLabel(text, menu.widgets[3]->x + menu.widgets[3]->normalState->w + 10, y); free(text); menu.widgets[4] = createWidget(_("Back"), NULL, NULL, NULL, &showOptionsMenu, -1, y, TRUE, 255, 255, 255); y = BUTTON_PADDING + BORDER_PADDING; maxWidth = w = 0; for (i=0;i<menu.widgetCount;i++) { if (menu.widgets[i]->label != NULL && menu.widgets[i]->normalState->w > maxWidth) { maxWidth = menu.widgets[i]->normalState->w; } } for (i=0;i<menu.widgetCount;i++) { menu.widgets[i]->y = y; if (menu.widgets[i]->x != -1) { menu.widgets[i]->x = BUTTON_PADDING + BORDER_PADDING; } if (menu.widgets[i]->label != NULL) { menu.widgets[i]->label->y = y; menu.widgets[i]->label->x = menu.widgets[i]->x + maxWidth + 10; if (menu.widgets[i]->label->x + menu.widgets[i]->label->text->w > w) { w = menu.widgets[i]->label->x + menu.widgets[i]->label->text->w; } } else { if (menu.widgets[i]->x + menu.widgets[i]->selectedState->w > w) { w = menu.widgets[i]->x + menu.widgets[i]->selectedState->w; } } y += menu.widgets[i]->selectedState->h + BUTTON_PADDING; } menu.w = w + BUTTON_PADDING; menu.h = y - BORDER_PADDING; menu.background = addBorder(createSurface(menu.w, menu.h, FALSE), 255, 255, 255, 0, 0, 0); menu.x = (SCREEN_WIDTH - menu.background->w) / 2; menu.y = (SCREEN_HEIGHT - menu.background->h) / 2; }
static void loadMenuLayout() { Medal *medal; int i, width, medalCount; Texture *texture; medal = getMedals(); medalCount = getMedalCount(); i = 0; width = 0; menu.w = 0; menu.h = 0; menu.startY = 0; menu.endY = 0; menu.widgetCount = medalCount; menu.widgets = malloc(sizeof(Widget *) * menu.widgetCount); if (menu.widgets == NULL) { showErrorAndExit("Ran out of memory when creating Medals Menu"); } for (i=0;i<menu.widgetCount;i++) { if (medal[i].hidden == TRUE && medal[i].obtained == FALSE) { menu.widgets[i] = createWidget(_("Hidden Medal"), NULL, NULL, NULL, NULL, 10, 20 + i * 40, FALSE, 255, 255, 255); } else { if (medal[i].obtained == TRUE) { menu.widgets[i] = createWidget(_(medal[i].description), NULL, NULL, NULL, NULL, 10, 20 + i * 40, FALSE, 0, 200, 0); } else { menu.widgets[i] = createWidget(_(medal[i].description), NULL, NULL, NULL, NULL, 10, 20 + i * 40, FALSE, 255, 255, 255); } } if (width < menu.widgets[i]->x + menu.widgets[i]->normalState->w) { width = menu.widgets[i]->x + menu.widgets[i]->normalState->w; } texture = getMedalImage(medal[i].medalType, medal[i].obtained); menu.widgets[i]->label = createImageLabel(texture, menu.widgets[i]->x, menu.widgets[i]->y); menu.widgets[i]->label->y = menu.widgets[i]->y + menu.widgets[i]->normalState->h / 2 - menu.widgets[i]->label->text->h / 2; menu.endY = menu.widgets[i]->y + menu.widgets[i]->normalState->h - menu.h; } width += 15; menu.h = SCREEN_HEIGHT - BUTTON_PADDING; for (i=0;i<menu.widgetCount;i++) { if (menu.widgets[i]->label != NULL) { menu.widgets[i]->label->x = width; if (menu.w < menu.widgets[i]->label->x + menu.widgets[i]->label->text->w) { menu.w = menu.widgets[i]->label->x + menu.widgets[i]->label->text->w; } } } menu.background = addBorder(createSurface(menu.w, menu.h, FALSE), 255, 255, 255, 0, 0, 0); menu.x = (SCREEN_WIDTH - menu.background->w) / 2; menu.y = (SCREEN_HEIGHT - menu.background->h) / 2; }
//static void GradientsMergeMosaic::mergeMosaicProcessImage(imageType_t const & rImage_p, realType_t dBlackPoint_p, pcl_enum eType_p, int32 shrinkCount_p, int32 featherRadius_p, imageType_t &rSumImageDx_p, imageType_t &rSumImageDy_p, sumMaskImageType_t &rSumMaskImage_p, weightImageType_t &rCountImageDx_p, weightImageType_t &rCountImageDy_p) { #ifdef DEBUG int const nCols=rImage_p.Width(); int const nRows=rImage_p.Height(); int const nChannels=rImage_p.NumberOfChannels(); #endif Assert(nCols==rSumImageDx_p.Width()+1); Assert(nRows==rSumImageDx_p.Height()); Assert(nChannels==rSumImageDx_p.NumberOfChannels()); Assert(nCols==rSumImageDy_p.Width()); Assert(nRows==rSumImageDy_p.Height()+1); Assert(nChannels==rSumImageDy_p.NumberOfChannels()); Assert(nCols==rSumMaskImage_p.Width()); Assert(nRows==rSumMaskImage_p.Height()); Assert(1==rSumMaskImage_p.NumberOfChannels()); Assert(eType_p!=GradientsMergeMosaicType::Average || nCols==rCountImageDx_p.Width()+1); Assert(eType_p!=GradientsMergeMosaicType::Average || nRows==rCountImageDx_p.Height()); Assert(eType_p!=GradientsMergeMosaicType::Average || 1==rCountImageDx_p.NumberOfChannels()); Assert(eType_p!=GradientsMergeMosaicType::Average || nCols==rCountImageDy_p.Width()); Assert(eType_p!=GradientsMergeMosaicType::Average || nRows==rCountImageDy_p.Height()+1); Assert(eType_p!=GradientsMergeMosaicType::Average || 1==rCountImageDy_p.NumberOfChannels()); Assert(shrinkCount_p>=0); Assert(featherRadius_p>=0); Assert(dBlackPoint_p>=0.0); weightImageType_t maskImage; TimeMessage startAddImage("Adding image to data"); TimeMessage startBinarize("Binarize Image"); binarizeImage(rImage_p,dBlackPoint_p,maskImage); // save this for border computation later weightImageType_t fullMask(maskImage); startBinarize.Stop(); // we are doing this because image after StarAlign usually contain aliased pixels. // These must not to be used during merge. TimeMessage startShrink("Shrinking mask"); erodeMask(maskImage,shrinkCount_p); startShrink.Stop(); TimeMessage startFeather("Feathering mask"); featherMask(maskImage,featherRadius_p); startFeather.Stop(); TimeMessage startBorder("Computing border"); addBorder(fullMask,maskImage); fullMask.AllocateData(0,0); // save memory startBorder.Stop(); TimeMessage startSumMask("Creating combined mask"); addToMask(maskImage,eType_p,rSumMaskImage_p); startSumMask.Stop(); TimeMessage startAddGradients("Adding gradients data"); addToImage(rImage_p,eType_p,maskImage,rSumImageDx_p,rSumImageDy_p,rCountImageDx_p, rCountImageDy_p); startAddGradients.Stop(); }
SDL_Surface *createDialogBox(char *title, char *msg) { char *text, *token, word[MAX_VALUE_LENGTH], *savePtr, *titleText; int i, lines, w, h, maxWidth, lineBreak, *lineBreaks; SDL_Surface **surface, *tempSurface; SDL_Rect dest; savePtr = NULL; freeDialogBox(); text = malloc(strlen(msg) + 1); if (text == NULL) { showErrorAndExit("Failed to allocate a whole %d bytes for the Dialog Text", (int)strlen(msg) + 1); } STRNCPY(text, msg, strlen(msg) + 1); titleText = NULL; if (title != NULL) { titleText = malloc(strlen(title) + 1); if (titleText == NULL) { showErrorAndExit("Failed to allocate a whole %d bytes for the Dialog Text", (int)strlen(title) + 1); } STRNCPY(titleText, title, strlen(title) + 1); } token = strtok_r(text, " ", &savePtr); i = 0; while (token != NULL) { i++; token = strtok_r(NULL, " ", &savePtr); } lines = i; if (titleText != NULL) { token = titleText; while (*token != '\0') { if (*token == '_') { *token = ' '; } token++; } lines++; } surface = malloc(sizeof(SDL_Surface *) * lines); if (surface == NULL) { showErrorAndExit("Failed to allocate a whole %d bytes for the Dialog Surfaces", (int)sizeof(SDL_Surface *) * lines); } lineBreaks = malloc(sizeof(int) * lines); if (lineBreaks == NULL) { showErrorAndExit("Failed to allocate a whole %d bytes for the line breaks", (int)sizeof(int) * lines); } STRNCPY(text, msg, strlen(msg) + 1); token = strtok_r(text, " ", &savePtr); i = 0; maxWidth = w = h = 0; if (titleText != NULL) { surface[i] = generateTextSurface(titleText, game.font, 255, 255, 0, 0, 0, 0); h = surface[i]->h + 5; maxWidth = surface[i]->w; i++; } while (token != NULL) { lineBreak = FALSE; snprintf(word, sizeof(word), "%d", game.kills); token = replaceString(token, "[GAME_KILLS]", word); token = replaceString(token, "[HOURS]", getPlayTimeHours()); snprintf(word, sizeof(word), "%d", game.continues); token = replaceString(token, "[CONTINUE_COUNT]", word); token = replaceString(token, "[INPUT_LEFT]", getKeyValue(control.button[CONTROL_LEFT])); token = replaceString(token, "[INPUT_RIGHT]", getKeyValue(control.button[CONTROL_RIGHT])); token = replaceString(token, "[INPUT_JUMP]", getKeyValue(control.button[CONTROL_JUMP])); token = replaceString(token, "[INPUT_BLOCK]", getKeyValue(control.button[CONTROL_BLOCK])); token = replaceString(token, "[INPUT_ATTACK]", getKeyValue(control.button[CONTROL_ATTACK])); token = replaceString(token, "[INPUT_INTERACT]", getKeyValue(control.button[CONTROL_INTERACT])); token = replaceString(token, "[INPUT_ACTIVATE]", getKeyValue(control.button[CONTROL_ACTIVATE])); token = replaceString(token, "[INPUT_INVENTORY]", getKeyValue(control.button[CONTROL_INVENTORY])); token = replaceString(token, "[INPUT_PREVIOUS]", getKeyValue(control.button[CONTROL_PREVIOUS])); token = replaceString(token, "[INPUT_NEXT]", getKeyValue(control.button[CONTROL_NEXT])); snprintf(word, sizeof(word), "%s ", token); if (word[strlen(word) - 2] == '\n') { lineBreak = TRUE; word[strlen(word) - 2] = '\0'; } token = strtok_r(NULL, " ", &savePtr); if (token == NULL) { word[strlen(word) - 1] = '\0'; } surface[i] = generateTextSurface(word, game.font, 255, 255, 255, 0, 0, 0); lineBreaks[i] = lineBreak; if (h == 0 || (i == 1 && titleText != NULL)) { h += surface[i]->h + 5; } if (w + surface[i]->w > MAX_DIALOG_WIDTH) { w = 0; h += surface[i]->h + 5; } w += surface[i]->w; if (w > maxWidth) { maxWidth = w; } if (lineBreak == TRUE) { w = 0; h += surface[i]->h + 5; } i++; } h -= 5; tempSurface = createSurface(maxWidth, h); w = h = 0; for (i=0; i<lines; i++) { if (w + surface[i]->w > MAX_DIALOG_WIDTH || (titleText != NULL && i == 1)) { w = 0; h += surface[i]->h + 5; } dest.x = w; dest.y = h; dest.w = surface[i]->w; dest.h = surface[i]->h; SDL_BlitSurface(surface[i], NULL, tempSurface, &dest); w += surface[i]->w; SDL_FreeSurface(surface[i]); if (lineBreaks[i] == TRUE) { w = 0; h += surface[i]->h + 5; } } tempSurface = addBorder(tempSurface, 255, 255, 255, 0, 0, 0); free(surface); free(text); if (titleText != NULL) { free(titleText); } free(lineBreaks); return tempSurface; }
static void loadMenuLayout() { char menuName[MAX_VALUE_LENGTH], *token; int w, y, i, maxWidth; float distance; w = 0; i = 0; maxWidth = 0; menu.widgetCount = 11; menu.widgets = malloc(sizeof(Widget *) * menu.widgetCount); if (menu.widgets == NULL) { showErrorAndExit("Ran out of memory when creating Stats Menu"); } menu.widgets[0] = createWidget(_("Statistics"), NULL, NULL, NULL, NULL, -1, 0, TRUE, 255, 255, 255); token = getPlayTimeAsString(); snprintf(menuName, MAX_VALUE_LENGTH, _("Play Time: %s"), token); free(token); menu.widgets[1] = createWidget(menuName, NULL, NULL, NULL, NULL, 10, 0, FALSE, 255, 255, 255); snprintf(menuName, MAX_VALUE_LENGTH, _("Kills: %d"), game.kills); menu.widgets[2] = createWidget(menuName, NULL, NULL, NULL, NULL, 10, 0, FALSE, 255, 255, 255); snprintf(menuName, MAX_VALUE_LENGTH, _("Arrows Fired: %d"), game.arrowsFired); menu.widgets[3] = createWidget(menuName, NULL, NULL, NULL, NULL, 10, 0, FALSE, 255, 255, 255); snprintf(menuName, MAX_VALUE_LENGTH, _("Bats Drowned: %d"), game.batsDrowned); menu.widgets[4] = createWidget(menuName, NULL, NULL, NULL, NULL, 10, 0, FALSE, 255, 255, 255); snprintf(menuName, MAX_VALUE_LENGTH, _("Times Eaten: %d"), game.timesEaten); menu.widgets[5] = createWidget(menuName, NULL, NULL, NULL, NULL, 10, 0, FALSE, 255, 255, 255); distance = game.distanceTravelled; distance /= 45000; /* 45 pixels is 1 metre */ snprintf(menuName, MAX_VALUE_LENGTH, _("Distanced Travelled: %0.1fKM"), distance); menu.widgets[6] = createWidget(menuName, NULL, NULL, NULL, NULL, 10, 0, FALSE, 255, 255, 255); snprintf(menuName, MAX_VALUE_LENGTH, _("Attacks Blocked: %d"), game.attacksBlocked); menu.widgets[7] = createWidget(menuName, NULL, NULL, NULL, NULL, 10, 0, FALSE, 255, 255, 255); token = getSlimeTimeAsString(); snprintf(menuName, MAX_VALUE_LENGTH, _("Time Spent As A Slime: %s"), token); free(token); menu.widgets[8] = createWidget(menuName, NULL, NULL, NULL, NULL, 10, 0, FALSE, 255, 255, 255); snprintf(menuName, MAX_VALUE_LENGTH, _("Secrets Found: %d / %d"), game.secretsFound, TOTAL_SECRETS); menu.widgets[9] = createWidget(menuName, NULL, NULL, NULL, NULL, 10, 0, FALSE, 255, 255, 255); menu.widgets[10] = createWidget(_("OK"), NULL, NULL, NULL, NULL, -1, 0, TRUE, 255, 255, 255); y = BUTTON_PADDING / 2 + BORDER_PADDING; for (i=0;i<menu.widgetCount;i++) { menu.widgets[i]->y = y; if (menu.widgets[i]->x != -1) { menu.widgets[i]->x = BUTTON_PADDING / 2 + BORDER_PADDING; } if (menu.widgets[i]->label != NULL) { menu.widgets[i]->label->y = y; menu.widgets[i]->label->x = menu.widgets[i]->x + maxWidth + 10; if (menu.widgets[i]->label->x + menu.widgets[i]->label->text->w > w) { w = menu.widgets[i]->label->x + menu.widgets[i]->label->text->w; } } else { if (menu.widgets[i]->x + menu.widgets[i]->selectedState->w > w) { w = menu.widgets[i]->x + menu.widgets[i]->selectedState->w; } } y += menu.widgets[i]->selectedState->h + BUTTON_PADDING / 2; } menu.w = w + BUTTON_PADDING; menu.h = y - BORDER_PADDING; menu.background = addBorder(createSurface(menu.w, menu.h), 255, 255, 255, 0, 0, 0); menu.x = (SCREEN_WIDTH - menu.background->w) / 2; menu.y = (SCREEN_HEIGHT - menu.background->h) / 2; }
static void loadMenuLayout() { int i, x, y, w, maxWidth; y = x = -1; menu.widgetCount = 10; menu.widgets = malloc(sizeof(Widget *) * menu.widgetCount); if (menu.widgets == NULL) { showErrorAndExit("Ran out of memory when creating Main Menu"); } menu.widgets[0] = createWidget(_("New Game"), NULL, NULL, NULL, &doNewGame, x, y, TRUE, 255, 255, 255); menu.widgets[1] = createWidget(_("Continue"), NULL, NULL, NULL, &continueGame, x, y, TRUE, 255, 255, 255); menu.widgets[1]->disabled = game.canContinue == TRUE ? FALSE : TRUE; menu.widgets[2] = createWidget(_("Restart Checkpoint"), NULL, NULL, NULL, &restartCheckpoint, x, y, TRUE, 255, 255, 255); menu.widgets[2]->disabled = game.canContinue == TRUE ? FALSE : TRUE; menu.widgets[3] = createWidget(_("Tutorial"), NULL, NULL, NULL, &doTutorial, x, y, TRUE, 255, 255, 255); menu.widgets[4] = createWidget(_("Load Game"), NULL, NULL, NULL, &showIOMenu, x, y, TRUE, 255, 255, 255); menu.widgets[5] = createWidget(_("Options"), NULL, NULL, NULL, &showOptionsMenu, x, y, TRUE, 255, 255, 255); menu.widgets[6] = createWidget(_("Statistics"), NULL, NULL, NULL, &showStatsMenu, x, y, TRUE, 255, 255, 255); menu.widgets[7] = createWidget(_("Medals"), NULL, NULL, NULL, &showMedalsMenu, x, y, TRUE, 255, 255, 255); menu.widgets[8] = createWidget(_("About"), NULL, NULL, NULL, &showAboutMenu, x, y, TRUE, 255, 255, 255); menu.widgets[9] = createWidget(_("Quit"), NULL, NULL, NULL, &doQuit, x, y, TRUE, 255, 255, 255); y = BUTTON_PADDING + BORDER_PADDING; w = 0; maxWidth = 0; for (i=0;i<menu.widgetCount;i++) { if (menu.widgets[i]->label != NULL && menu.widgets[i]->normalState->w > maxWidth) { maxWidth = menu.widgets[i]->normalState->w; } } for (i=0;i<menu.widgetCount;i++) { menu.widgets[i]->y = y; if (menu.widgets[i]->x != -1) { menu.widgets[i]->x = BUTTON_PADDING + BORDER_PADDING; } if (menu.widgets[i]->label != NULL) { menu.widgets[i]->label->y = y; menu.widgets[i]->label->x = menu.widgets[i]->x + maxWidth + 10; if (menu.widgets[i]->label->x + menu.widgets[i]->label->text->w > w) { w = menu.widgets[i]->label->x + menu.widgets[i]->label->text->w; } } else { if (menu.widgets[i]->x + menu.widgets[i]->selectedState->w > w) { w = menu.widgets[i]->x + menu.widgets[i]->selectedState->w; } } if (i != 1) { y += menu.widgets[i]->selectedState->h + BUTTON_PADDING; } } menu.w = w + BUTTON_PADDING; menu.h = y - BORDER_PADDING; menu.background = addBorder(createSurface(menu.w, menu.h), 255, 255, 255, 0, 0, 0); menu.x = (SCREEN_WIDTH - menu.background->w) / 2; menu.y = (SCREEN_HEIGHT - menu.background->h) / 2; }
//MAIN RENDER CODE ================================================ void DataGrid::render() { //vector<T> xData(_xData); //Assign xData to non-const so we can pass by const reference. // Add the border if flagged if (flags & (int)o_t::BORDER) { addBorder(); const int shrink = 4; plotArea.setSize(plotArea.getWidth()-shrink, plotArea.getHeight()-shrink); plotArea.translate(shrink/2, shrink/2); } // Add the title if flagged if (flags & (int)o_t::TITLE) { addTitle(); } // Abort if series vec is empty if (series.getNumSeries()==0){ cout << "No data series available, aborting. \n"; return; } // get ranges const float xMin = series.getXmin(); const float xMax = series.getXmax(); const float yMin = series.getYmin(); const float yMax = series.getYmax(); // Another way of aliasing - pointless here bu I <3 lambdas // To use this alternative, replace xMin with xMin() below // auto xMin = [&](){return series.getXmin();}; // Add the y-axis if flagged if (flags & (int)o_t::YAXIS) { const int yaxWidth = 10; Rectangle rAx = Rectangle(plotArea.getTL(), yaxWidth, plotArea.getHeight()); addYAxis(yMin, yMax, rAx); // Shift the plot area plotArea.setWidth(plotArea.getWidth()-yaxWidth); plotArea.translate(yaxWidth, 0); } // Add simple x-axis indicators if requested if (flags & (int)o_t::XAXIS) { addXAxis(xMin, xMax, plotArea); } for (size_t ii=0; ii<series.getNumSeries(); ++ii){ // Warn if input is messed up vector<float> xData(series.getXdata(ii)); vector<float> yData(series.getYdata(ii)); if (xData.size()!=yData.size()) { cout << "WARNING: x and y data size mismatch, not plotting.\n"; return; } for(size_t nn=0; nn<xData.size(); ++nn){ int intX = mapVal( xData[nn], xMin, xMax, plotArea.getLeft(), plotArea.getRight() ); // Notice the subtle reversal of yMax and yMin here so data flipped the correct way int intY = mapVal( yData[nn], yMax, yMin, plotArea.getTop(), plotArea.getBtm() ); addPoint(Point(intX, intY), series.getMarker(ii) ); } } // Add the legend if flagged if (flags & (int)o_t::LEGEND) { addLegend(); } } // End of rendering function
void Window::addStructuralElements() { addBackground(); addHeading(); addBorder(); addContent(); }