void MessageOut::writeCoordinates(const uint16_t x, const uint16_t y, unsigned char direction, const char *const str) { DEBUGLOG2(strprintf("writeCoordinates: %u,%u %u", CAST_U32(x), static_cast<unsigned>(y), CAST_U32(direction)), mPos, str); unsigned char *const data = reinterpret_cast<unsigned char*>(mData) + CAST_SIZE(mPos); mNetwork->mOutSize += 3; mPos += 3; uint16_t temp = x; temp <<= 6; data[0] = 0; data[1] = 1; data[2] = 2; data[0] = HIBYTE(temp); data[1] = CAST_U8(temp); temp = y; temp <<= 4; data[1] |= HIBYTE(temp); data[2] = LOBYTE(temp); direction = toServerDirection(direction); data[2] |= direction; PacketCounters::incOutBytes(3); }
void extractAssets() { if (!getenv("APPDIR")) { logger->log("error: APPDIR is not set!"); return; } const std::string fileName = std::string(getenv( "APPDIR")).append("/data.zip"); logger->log("Extracting asset into: " + fileName); uint8_t *buf = new uint8_t[1000000]; FILE *const file = fopen(fileName.c_str(), "w"); for (int f = 0; f < 100; f ++) { std::string part = strprintf("manaplus-data.zip%u%u", CAST_U32(f / 10), CAST_U32(f % 10)); logger->log("testing asset: " + part); SDL_RWops *const rw = SDL_RWFromFile(part.c_str(), "r"); if (rw) { const int size = SDL_RWsize(rw); int size2 = SDL_RWread(rw, buf, 1, size); logger->log("asset size: %d", size2); fwrite(buf, 1, size2, file); SDL_RWclose(rw); Dirs::setProgress(); } else { break; } } fclose(file); const std::string fileName2 = std::string(getenv( "APPDIR")).append("/locale.zip"); FILE *const file2 = fopen(fileName2.c_str(), "w"); SDL_RWops *const rw = SDL_RWFromFile("manaplus-locale.zip", "r"); if (rw) { const int size = SDL_RWsize(rw); int size2 = SDL_RWread(rw, buf, 1, size); fwrite(buf, 1, size2, file2); SDL_RWclose(rw); Dirs::setProgress(); } fclose(file2); delete [] buf; }
Inventory::Inventory(const InventoryTypeT type, const int size1) : mInventoryListeners(), mVirtualRemove(), mType(type), mSize(size1 == -1 ? CAST_U32( inventoryHandler->getSize(type)) : CAST_U32(size1)), mItems(new Item*[mSize]), mUsed(0) { std::fill_n(mItems, mSize, static_cast<Item*>(nullptr)); }
void FocusHandler::requestFocus(const Widget *const widget) { if (!widget || widget == mFocusedWidget) return; int toBeFocusedIndex = -1; for (unsigned int i = 0, fsz = CAST_U32( mWidgets.size()); i < fsz; ++i) { if (mWidgets[i] == widget) { toBeFocusedIndex = i; break; } } if (toBeFocusedIndex < 0) return; Widget *const oldFocused = mFocusedWidget; if (oldFocused != widget) { mFocusedWidget = mWidgets.at(toBeFocusedIndex); if (oldFocused) { Event focusEvent(oldFocused); distributeFocusLostEvent(focusEvent); } Event focusEvent(mWidgets.at(toBeFocusedIndex)); distributeFocusGainedEvent(focusEvent); } }
void EmoteShortcut::save() const { for (int i = 0; i < SHORTCUT_EMOTES; i++) { const unsigned char emoteId = mEmotes[i] != 0U ? mEmotes[i] : CAST_U8(0); serverConfig.setValue("emoteshortcut" + toString(i), CAST_U32(emoteId)); } }
void RegisterDialog::postInit() { Window::postInit(); setVisible(Visible_true); mUserField->requestFocus(); mUserField->setCaretPosition(CAST_U32( mUserField->getText().length())); mRegisterButton->setEnabled(canSubmit()); }
void ItemShortcut::save() const { std::string name; std::string color; std::string data; if (mNumber == SHORTCUT_AUTO_TAB) return; if (mNumber != 0) { name = std::string("shortcut").append( toString(CAST_S32(mNumber))).append("_"); color = std::string("shortcutColor").append( toString(CAST_U32(mNumber))).append("_"); data = std::string("shortcutData").append( toString(CAST_U32(mNumber))).append("_"); } else { name = "shortcut"; color = "shortcutColor"; data = "shortcutData"; } for (unsigned int i = 0; i < SHORTCUT_ITEMS; i++) { const int itemId = mItems[i] != 0 ? mItems[i] : -1; const int itemColor = toInt(mItemColors[i], int); if (itemId != -1) { const std::string itemData = mItemData[i]; serverConfig.setValue(name + toString(i), itemId); serverConfig.setValue(color + toString(i), itemColor); serverConfig.setValue(data + toString(i), itemData); } else { serverConfig.deleteKey(name + toString(i)); serverConfig.deleteKey(color + toString(i)); serverConfig.deleteKey(data + toString(i)); } } }
void Logger::unimplemented(const int id) { if (!mReportUnimplemented) return; const std::string str = strprintf("Unimplimented packet: %d (0x%x)", id, CAST_U32(id)); DebugMessageListener::distributeEvent(str); log(str); }
void Logger::log_r(const char *const log_text, ...) { if (settings.disableLoggingInGame) return; SDL_mutexP(mMutex); unsigned size = 1024; if (strlen(log_text) * 3 > size) size = CAST_U32(strlen(log_text) * 3); char* buf = new char[CAST_SIZE(size + 1)]; va_list ap; // Use a temporary buffer to fill in the variables va_start(ap, log_text); vsnprintf(buf, size, log_text, ap); buf[size] = 0; va_end(ap); // Get the current system time timeval tv; gettimeofday(&tv, nullptr); // Print the log entry DATESTREAM SPECIALLOG(buf) if (mLogFile != nullptr) { std::string tmpStr = strprintf( "%s %s\n", timeStr.c_str(), buf); mThreadLocked = true; mDelayedLog.push_back(tmpStr); mThreadLocked = false; } if (mLogToStandardOut) { fprintf(stdout, "%s %s\n", timeStr.c_str(), buf); } // Delete temporary buffer delete [] buf; SDL_mutexV(mMutex); }
void IntTextField::setValue(const int i) { if (i < mMin) mValue = mMin; else if (i > mMax) mValue = mMax; else mValue = i; const std::string valStr = toString(mValue); setText(valStr); setCaretPosition(CAST_U32(valStr.length()) + 1); }
signed char MessageIn::readInt8(const char *const str) { signed char value = CAST_S8(-1); if (mPos < mLength) value = CAST_S8(mData[mPos]); DEBUGLOG2("readInt8: " + toStringPrint(CAST_U32( CAST_U8(value))), mPos, str); mPos += 1; PacketCounters::incInBytes(1); return value; }
void MessageOut::writeInt32(const int32_t value, const char *const str) { DEBUGLOG2("writeInt32: " + toStringPrint(CAST_U32(value)), mPos, str); expand(4); #if SDL_BYTEORDER == SDL_BIG_ENDIAN int32_t swap = SDL_Swap32(value); memcpy(mData + CAST_SIZE(mPos), &swap, sizeof(int32_t)); #else memcpy(mData + CAST_SIZE(mPos), &value, sizeof(int32_t)); #endif mPos += 4; PacketCounters::incOutBytes(4); }
ListBox::ListBox(const Widget2 *const widget, ListModel *const listModel, const std::string &skin) : Widget(widget), MouseListener(), KeyListener(), mSelected(-1), mListModel(listModel), mWrappingEnabled(false), mSelectionListeners(), mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT, 255U)), mForegroundSelectedColor(getThemeColor(ThemeColorId::LISTBOX_SELECTED, 255U)), mForegroundSelectedColor2(getThemeColor( ThemeColorId::LISTBOX_SELECTED_OUTLINE, 255U)), mOldSelected(-1), mPadding(0), mPressedIndex(-2), mRowHeight(0), mItemPadding(1), mSkin(nullptr), mDistributeMousePressed(true), mCenterText(false) { setWidth(100); setFocusable(true); addMouseListener(this); addKeyListener(this); mForegroundColor = getThemeColor(ThemeColorId::LISTBOX, 255U); mForegroundColor2 = getThemeColor(ThemeColorId::LISTBOX_OUTLINE, 255U); if (theme != nullptr) { mSkin = theme->load(skin, "listbox.xml", true, Theme::getThemePath()); } if (mSkin != nullptr) { mPadding = mSkin->getPadding(); mItemPadding = mSkin->getOption("itemPadding"); } const Font *const font = getFont(); mRowHeight = CAST_U32( font->getHeight() + 2 * mItemPadding); }
void ItemShortcut::load() { std::string name; std::string color; std::string data; if (mNumber == SHORTCUT_AUTO_TAB) return; const Configuration *cfg = &serverConfig; if (mNumber != 0) { name = std::string("shortcut").append( toString(CAST_S32(mNumber))).append("_"); color = std::string("shortcutColor").append( toString(CAST_U32(mNumber))).append("_"); data = std::string("shortcutData").append( toString(CAST_U32(mNumber))).append("_"); } else { name = "shortcut"; color = "shortcutColor"; data = "shortcutData"; } for (unsigned int i = 0; i < SHORTCUT_ITEMS; i++) { const int itemId = cfg->getValue(name + toString(i), -1); const ItemColor itemColor = fromInt( cfg->getValue(color + toString(i), 1), ItemColor); mItems[i] = itemId; mItemColors[i] = itemColor; mItemData[i] = cfg->getValue(data + toString(i), std::string()); } }
void Logger::assertLog(const char *const log_text, ...) { if (settings.disableLoggingInGame) return; unsigned size = 1024; if (strlen(log_text) * 3 > size) size = CAST_U32(strlen(log_text) * 3); char* buf = new char[CAST_SIZE(size + 1)]; va_list ap; // Use a temporary buffer to fill in the variables va_start(ap, log_text); vsnprintf(buf, size, log_text, ap); buf[size] = 0; va_end(ap); // Get the current system time timeval tv; gettimeofday(&tv, nullptr); // Print the log entry DATESTREAM SPECIALLOG(buf) if (mLogFile != nullptr) { fprintf(mLogFile, "%s %s\n", timeStr.c_str(), buf); fflush(mLogFile); } if (mLogToStandardOut) { fprintf(stdout, "%s %s\n", timeStr.c_str(), buf); } DebugMessageListener::distributeEvent(buf); // Delete temporary buffer delete [] buf; }
ColorPage::ColorPage(const Widget2 *const widget, ListModel *const listModel, const std::string &skin) : ListBox(widget, listModel, skin) { mItemPadding = mSkin != nullptr ? mSkin->getOption("itemPadding") : 1; const Font *const font = getFont(); mRowHeight = CAST_U32(font->getHeight() + 2 * mItemPadding); if (mListModel != nullptr) { setHeight(CAST_S32(getRowHeight()) * mListModel->getNumberOfElements() + 2 * mPadding + 20); } }
void MumbleManager::setServer(const std::string &serverName) { if (!mLinkedMem) return; unsigned size = CAST_U32(serverName.size()); if (size > sizeof(mLinkedMemCache.context) - 1) size = sizeof(mLinkedMemCache.context) - 1; memset(mLinkedMemCache.context, 0, sizeof(mLinkedMemCache.context)); memcpy(mLinkedMemCache.context, serverName.c_str(), size); mLinkedMemCache.context[size] = '\0'; mLinkedMemCache.context_len = size; mLinkedMemCache.uiTick ++; memcpy(mLinkedMem, &mLinkedMemCache, sizeof(mLinkedMemCache)); }
int64_t MessageIn::readInt64(const char *const str) { int64_t value = -1; if (mPos + 8 <= mLength) { #if SDL_BYTEORDER == SDL_BIG_ENDIAN int64_t swap; memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int64_t)); value = SDL_Swap64(swap); #else // SDL_BYTEORDER == SDL_BIG_ENDIAN memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int64_t)); #endif // SDL_BYTEORDER == SDL_BIG_ENDIAN } DEBUGLOG2("readInt64: " + toStringPrint(CAST_U32(value)), mPos, str); mPos += 8; PacketCounters::incInBytes(8); return value; }
uint16_t MessageIn::readUInt16(const char *const str) { uint16_t value = 0xffU; if (mPos + 2 <= mLength) { #if SDL_BYTEORDER == SDL_BIG_ENDIAN uint16_t swap; memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(uint16_t)); value = SDL_Swap16(swap); #else // SDL_BYTEORDER == SDL_BIG_ENDIAN memcpy(&value, mData + CAST_SIZE(mPos), sizeof(uint16_t)); #endif // SDL_BYTEORDER == SDL_BIG_ENDIAN } DEBUGLOG2("readUInt16: " + toStringPrint(CAST_U32( CAST_U16(value))), mPos, str); mPos += 2; PacketCounters::incInBytes(2); return value; }
void Logger::log(const char *const log_text, ...) { if (settings.disableLoggingInGame) return; unsigned size = 1024; if (strlen(log_text) * 3 > size) size = CAST_U32(strlen(log_text) * 3); char* buf = new char[CAST_SIZE(size + 1)]; va_list ap; // Use a temporary buffer to fill in the variables va_start(ap, log_text); vsnprintf(buf, size, log_text, ap); buf[size] = 0; va_end(ap); // Get the current system time timeval tv; gettimeofday(&tv, nullptr); // Print the log entry std::stringstream timeStr; DATESTREAM SPECIALLOG(buf) if (mLogFile.is_open()) mLogFile << timeStr.str() << buf << std::endl; if (mLogToStandardOut) std::cout << timeStr.str() << buf << std::endl; // Delete temporary buffer delete [] buf; }
Setup_Joystick::Setup_Joystick(const Widget2 *const widget) : SetupTab(widget), mCalibrateLabel(new Label(this, // TRANSLATORS: joystick settings tab label _("Press the button to start calibration"))), // TRANSLATORS: joystick settings tab button mCalibrateButton(new Button(this, _("Calibrate"), "calibrate", BUTTON_SKIN, this)), // TRANSLATORS: joystick settings tab button mDetectButton(new Button(this, _("Detect joysticks"), "detect", BUTTON_SKIN, this)), // TRANSLATORS: joystick settings tab checkbox mJoystickEnabled(new CheckBox(this, _("Enable joystick"), false, nullptr, std::string())), mNamesModel(new NamesModel), mNamesDropDown(new DropDown(this, mNamesModel, false, Modal_false, nullptr, std::string())), mUseInactiveCheckBox(new CheckBox(this, // TRANSLATORS: joystick settings tab checkbox _("Use joystick if client window inactive"), config.getBoolValue("useInactiveJoystick"), nullptr, std::string())), mOriginalJoystickEnabled(config.getBoolValue("joystickEnabled")) { // TRANSLATORS: joystick settings tab name setName(_("Joystick")); Joystick::getNames(mNamesModel->getNames()); mJoystickEnabled->setSelected(mOriginalJoystickEnabled); mJoystickEnabled->setActionEventId("joystick"); mJoystickEnabled->addActionListener(this); mCalibrateButton->setEnabled(mOriginalJoystickEnabled); mNamesDropDown->setActionEventId("name"); mNamesDropDown->addActionListener(this); if (joystick != nullptr) { mNamesDropDown->setSelected(joystick->getNumber()); } else { unsigned int sel = config.getIntValue("selectedJoystick"); if (sel >= CAST_U32(mNamesModel->size())) sel = 0; mNamesDropDown->setSelected(sel); } // Do the layout LayoutHelper h(this); ContainerPlacer place = h.getPlacer(0, 0); place(0, 0, mJoystickEnabled, 1, 1); place(0, 1, mNamesDropDown, 1, 1); place(0, 2, mUseInactiveCheckBox, 1, 1); place(0, 3, mDetectButton, 1, 1); place(0, 4, mCalibrateLabel, 1, 1); place(0, 5, mCalibrateButton, 1, 1); setDimension(Rect(0, 0, 365, 75)); }
+ 2 * mPadding + 20); } } ColorPage::~ColorPage() { } void ColorPage::draw(Graphics *const graphics) { BLOCK_START("ColorPage::draw") const ColorModel *const model = static_cast<const ColorModel*>( mListModel); mHighlightColor.a = CAST_U32(mAlpha * 255.0F); updateAlpha(); Font *const font = getFont(); const int rowHeight = CAST_S32(getRowHeight()); const int width = mDimension.width; if (mSelected >= 0) { graphics->setColor(mHighlightColor); graphics->fillRectangle(Rect(mPadding, rowHeight * mSelected + mPadding, mDimension.width - 2 * mPadding, rowHeight)); const ColorPair *const colors = model->getColorAt(mSelected); const std::string str = mListModel->getElementAt(mSelected);
void MessageOut::expand(const size_t bytes) const { mNetwork->mOutSize += CAST_U32(bytes); PacketCounters::incOutBytes(CAST_S32(bytes)); }
void ListBox::draw(Graphics *const graphics) { if (!mListModel) return; BLOCK_START("ListBox::draw") updateAlpha(); mHighlightColor.a = CAST_U32(mAlpha * 255.0F); graphics->setColor(mHighlightColor); Font *const font = getFont(); const int rowHeight = CAST_S32(getRowHeight()); const int width = mDimension.width; if (mCenterText) { // Draw filled rectangle around the selected list element if (mSelected >= 0) { graphics->fillRectangle(Rect(mPadding, rowHeight * mSelected + mPadding, mDimension.width - 2 * mPadding, rowHeight)); const std::string str = mListModel->getElementAt(mSelected); font->drawString(graphics, mForegroundSelectedColor, mForegroundSelectedColor2, str, (width - font->getWidth(str)) / 2, mSelected * rowHeight + mPadding + mItemPadding); } // Draw the list elements const int sz = mListModel->getNumberOfElements(); for (int i = 0, y = mPadding + mItemPadding; i < sz; ++i, y += rowHeight) { if (i != mSelected) { const std::string str = mListModel->getElementAt(i); font->drawString(graphics, mForegroundColor, mForegroundColor2, str, (width - font->getWidth(str)) / 2, y); } } } else { // Draw filled rectangle around the selected list element if (mSelected >= 0) { graphics->fillRectangle(Rect(mPadding, rowHeight * mSelected + mPadding, mDimension.width - 2 * mPadding, rowHeight)); const std::string str = mListModel->getElementAt(mSelected); font->drawString(graphics, mForegroundSelectedColor, mForegroundSelectedColor2, str, mPadding, mSelected * rowHeight + mPadding + mItemPadding); } // Draw the list elements const int sz = mListModel->getNumberOfElements(); for (int i = 0, y = mPadding + mItemPadding; i < sz; ++i, y += rowHeight) { if (i != mSelected) { const std::string str = mListModel->getElementAt(i); font->drawString(graphics, mForegroundColor, mForegroundColor2, str, mPadding, y); } } } BLOCK_END("ListBox::draw") }
void Setup_Video::action(const ActionEvent &event) { const std::string &id = event.getId(); if (id == "videomode") { std::string mode = mModeListModel->getElementAt( mModeList->getSelected()); if (mode == "custom") { if (mDialog) { mode = mDialog->getText(); mDialog = nullptr; } else { CREATEWIDGETV(mDialog, TextDialog, // TRANSLATORS: resolution question dialog _("Custom resolution (example: 1024x768)"), // TRANSLATORS: resolution question dialog _("Enter new resolution: ")); mDialog->setActionEventId("videomode"); mDialog->addActionListener(this); return; } } const int width = atoi(mode.substr(0, mode.find("x")).c_str()); const int height = atoi(mode.substr(mode.find("x") + 1).c_str()); if (!width || !height) return; if (width != mainGraphics->mActualWidth || height != mainGraphics->mActualHeight) { #if defined(WIN32) || defined(__APPLE__) || defined(ANDROID) if (intToRenderType(config.getIntValue("opengl")) == RENDER_SOFTWARE) { WindowManager::doResizeVideo(width, height, false); } else { if (width < mainGraphics->mActualWidth || height < mainGraphics->mActualHeight) { CREATEWIDGET(OkDialog, // TRANSLATORS: video settings warning _("Screen Resolution Changed"), // TRANSLATORS: video settings warning _("Restart your client for the change to take effect.") // TRANSLATORS: video settings warning + std::string("\n") + _("Some windows may be moved to " "fit the lowered resolution."), // TRANSLATORS: ok dialog button _("OK"), DialogType::OK, Modal_true, ShowCenter_true, nullptr, 260); } else { CREATEWIDGET(OkDialog, // TRANSLATORS: video settings warning _("Screen Resolution Changed"), // TRANSLATORS: video settings warning _("Restart your client for the change" " to take effect."), // TRANSLATORS: ok dialog button _("OK"), DialogType::OK, Modal_true, ShowCenter_true, nullptr, 260); } } #else // defined(WIN32) || defined(__APPLE__) || defined(ANDROID) mainGraphics->setWindowSize(width, height); WindowManager::doResizeVideo(width, height, false); #endif // defined(WIN32) || defined(__APPLE__) || defined(ANDROID) } config.setValue("oldscreen", config.getBoolValue("screen")); config.setValue("oldscreenwidth", mainGraphics->mActualWidth); config.setValue("oldscreenheight", mainGraphics->mActualHeight); config.setValue("screenwidth", width); config.setValue("screenheight", height); } if (id == "~videomode") { mDialog = nullptr; } else if (id == "customcursor") { config.setValue("customcursor", mCustomCursorCheckBox->isSelected()); } else if (id == "fpslimitcheckbox" || id == "fpslimitslider") { int tempFps = CAST_S32(mFpsSlider->getValue()); if (id == "fpslimitcheckbox" && !mFpsSlider->isEnabled()) tempFps = 60; else tempFps = tempFps > 0 ? tempFps : 60; mFps = mFpsCheckBox->isSelected() ? tempFps : 0; // TRANSLATORS: video settings label const std::string text = mFps > 0 ? toString(mFps) : _("None"); mFpsLabel->setCaption(text); mFpsSlider->setEnabled(mFps > 0); mFpsSlider->setValue(mFps); } else if (id == "altfpslimitslider") { int tempFps = CAST_S32(mAltFpsSlider->getValue()); tempFps = tempFps > 0 ? tempFps : CAST_S32( mAltFpsSlider->getScaleStart()); mAltFps = tempFps; // TRANSLATORS: video settings label const std::string text = mAltFps > 0 ? toString(mAltFps) : _("None"); // TRANSLATORS: video settings label mAltFpsLabel->setCaption(_("Alt FPS limit: ") + text); mAltFpsSlider->setEnabled(mAltFps > 0); mAltFpsSlider->setValue(mAltFps); } else if (id == "enableresize") { config.setValue("enableresize", mEnableResizeCheckBox->isSelected()); } else if (id == "noframe") { config.setValue("noframe", mNoFrameCheckBox->isSelected()); } #if defined(USE_OPENGL) && !defined(ANDROID) && !defined(__APPLE__) else if (id == "detect") { TestMain *test = graphicsManager.startDetection(); if (test) { Configuration &conf = test->getConfig(); const int val = conf.getValueInt("opengl", -1); if (val >= 0 && CAST_U32(val) < sizeof(renderToIndex) / sizeof(int)) { mOpenGLDropDown->setSelected(renderToIndex[val]); } config.setValue("textureSize", conf.getValue("textureSize", "1024,1024,1024,1024,1024,1024")); config.setValue("testInfo", conf.getValue("testInfo", "")); delete test; } } #endif // defined(USE_OPENGL) && !defined(ANDROID) && !defined(__APPLE__) }
void Setup_Video::apply() { // Full screen changes bool fullscreen = mFsCheckBox->isSelected(); if (fullscreen != config.getBoolValue("screen")) { /* The OpenGL test is only necessary on Windows, since switching * to/from full screen works fine on Linux. On Windows we'd have to * reinitialize the OpenGL state and reload all textures. * * See http://libsdl.org/cgi/docwiki.cgi/SDL_SetVideoMode */ #if defined(WIN32) || defined(__APPLE__) || defined(ANDROID) // checks for opengl usage if (intToRenderType(config.getIntValue("opengl")) == RENDER_SOFTWARE) { #endif // defined(WIN32) || defined(__APPLE__) || defined(ANDROID) if (!WindowManager::setFullScreen(fullscreen)) { fullscreen = !fullscreen; if (!WindowManager::setFullScreen(fullscreen)) { std::stringstream errorMsg; if (fullscreen) { // TRANSLATORS: video error message errorMsg << _("Failed to switch to windowed mode " "and restoration of old mode also " "failed!") << std::endl; } else { // TRANSLATORS: video error message errorMsg << _("Failed to switch to fullscreen mode" " and restoration of old mode also " "failed!") << std::endl; } logger->safeError(errorMsg.str()); } } #if defined(WIN32) || defined(__APPLE__) || defined(ANDROID) } else { CREATEWIDGET(OkDialog, // TRANSLATORS: video settings warning _("Switching to Full Screen"), // TRANSLATORS: video settings warning _("Restart needed for changes to take effect."), // TRANSLATORS: ok dialog button _("OK"), DialogType::OK, Modal_true, ShowCenter_true, nullptr, 260); } #endif // defined(WIN32) || defined(__APPLE__) || defined(ANDROID) config.setValue("screen", fullscreen); } const int sel = mOpenGLDropDown->getSelected(); RenderType mode = RENDER_SOFTWARE; if (sel >= 0 && CAST_U32(sel) < sizeof(indexToRender)) mode = indexToRender[mOpenGLDropDown->getSelected()]; // OpenGL change if (mode != mOpenGLEnabled) { config.setValue("opengl", CAST_S32(mode)); // OpenGL can currently only be changed by restarting, notify user. CREATEWIDGET(OkDialog, // TRANSLATORS: video settings warning _("Changing to OpenGL"), // TRANSLATORS: video settings warning _("Applying change to OpenGL requires restart."), // TRANSLATORS: ok dialog button _("OK"), DialogType::OK, Modal_true, ShowCenter_true, nullptr, 260); } mFps = mFpsCheckBox->isSelected() ? CAST_S32(mFpsSlider->getValue()) : 0; mAltFps = CAST_S32(mAltFpsSlider->getValue()); mFpsSlider->setEnabled(mFps > 0); mAltFpsSlider->setEnabled(mAltFps > 0); // FPS change config.setValue("fpslimit", mFps); config.setValue("altfpslimit", mAltFps); // We sync old and new values at apply time mFullScreenEnabled = config.getBoolValue("screen"); mCustomCursorEnabled = config.getBoolValue("customcursor"); mOpenGLEnabled = intToRenderType(config.getIntValue("opengl")); mEnableResize = config.getBoolValue("enableresize"); mNoFrame = config.getBoolValue("noframe"); }
DropDown::DropDown(const Widget2 *const widget, ListModel *const listModel, const bool extended, const Modal modal, ActionListener *const listener, const std::string &eventId) : ActionListener(), BasicContainer(widget), KeyListener(), MouseListener(), FocusListener(), SelectionListener(), mPopup(CREATEWIDGETR(PopupList, this, listModel, extended, modal)), mShadowColor(getThemeColor(ThemeColorId::DROPDOWN_SHADOW)), mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT)), mPadding(1), mImagePadding(2), mSpacing(0), mFoldedUpHeight(0), mSelectionListeners(), mExtended(extended), mDroppedDown(false), mPushed(false), mIsDragged(false) { mAllowLogic = false; mFrameSize = 2; mForegroundColor2 = getThemeColor(ThemeColorId::DROPDOWN_OUTLINE); mPopup->setHeight(100); // Initialize graphics if (instances == 0 && theme) { // Load the background skin for (int i = 0; i < 2; i ++) { Skin *const skin = theme->load(dropdownFiles[i], "dropdown.xml"); if (skin) { if (!i) mSkin = skin; const ImageRect &rect = skin->getBorder(); for (int f = 0; f < 2; f ++) { if (rect.grid[f]) { rect.grid[f]->incRef(); buttons[f][i] = rect.grid[f]; buttons[f][i]->setAlpha(mAlpha); } else { buttons[f][i] = nullptr; } } if (i) theme->unload(skin); } else { for (int f = 0; f < 2; f ++) buttons[f][i] = nullptr; } } // get the border skin theme->loadRect(skinRect, "dropdown_background.xml", ""); } instances++; setWidth(100); setFocusable(true); setListModel(listModel); if (mPopup->getSelected() < 0) mPopup->setSelected(0); addMouseListener(this); addKeyListener(this); addFocusListener(this); adjustHeight(); // mPopup->setForegroundColorAll(getThemeColor(ThemeColorId::DROPDOWN), // getThemeColor(ThemeColorId::DROPDOWN_OUTLINE)); mForegroundColor = getThemeColor(ThemeColorId::DROPDOWN); mForegroundColor2 = getThemeColor(ThemeColorId::DROPDOWN_OUTLINE); if (!eventId.empty()) setActionEventId(eventId); if (listener) addActionListener(listener); mPopup->adjustSize(); if (mSkin) { mSpacing = mSkin->getOption("spacing"); mFrameSize = CAST_U32(mSkin->getOption("frameSize")); mPadding = mSkin->getPadding(); mImagePadding = mSkin->getOption("imagePadding"); } adjustHeight(); }
InputActionT operator+(InputActionT action, const unsigned int& i) { action = static_cast<InputActionT>(CAST_U32(action) + i); return action; }
void GuiTable::safeDraw(Graphics *const graphics) { if (!getRowHeight()) return; BLOCK_START("GuiTable::draw") if (settings.guiAlpha != mAlpha) mAlpha = settings.guiAlpha; const Rect &rect = mDimension; const int width = rect.width; const int height = rect.height; const int y = rect.y; if (mOpaque) { mBackgroundColor.a = CAST_U32(mAlpha * 255.0F); graphics->setColor(mBackgroundColor); graphics->fillRectangle(Rect(0, 0, width, height)); } // First, determine how many rows we need to draw, // and where we should start. int rHeight = getRowHeight(); if (!rHeight) rHeight = 1; int first_row = -(y / rHeight); if (first_row < 0) first_row = 0; unsigned int rows_nr = CAST_U32( 1 + height / rHeight); // May overestimate by one. unsigned int max_rows_nr; if (mModel->getRows() < first_row) { max_rows_nr = 0; } else { max_rows_nr = CAST_U32( mModel->getRows() - first_row); // clip if neccessary: } if (max_rows_nr < rows_nr) rows_nr = max_rows_nr; // Now determine the first and last column // Take the easy way out; these are usually bounded and all visible. const unsigned int first_column = 0; const unsigned int last_column1 = CAST_U32( mModel->getColumns()); int y_offset = first_row * rHeight; for (unsigned int r = CAST_U32(first_row); r < CAST_U32(first_row + CAST_S32(rows_nr)); ++r) { int x_offset = 0; for (unsigned c = first_column; c + 1 <= last_column1; ++c) { Widget *const widget = mModel->getElementAt(CAST_S32(r), CAST_S32(c)); const int cWidth = CAST_S32(getColumnWidth( CAST_S32(c))); if (widget) { Rect bounds(x_offset, y_offset, cWidth, rHeight); if (widget == mTopWidget) { bounds.height = widget->getHeight(); bounds.width = widget->getWidth(); } widget->setDimension(bounds); if (mSelectedRow > -1) { mHighlightColor.a = CAST_U32( mAlpha * 255.0F); graphics->setColor(mHighlightColor); if (mLinewiseMode && r == CAST_U32( mSelectedRow) && c == 0) { graphics->fillRectangle(Rect(0, y_offset, width, rHeight)); } else if (!mLinewiseMode && mSelectedColumn > 0 && c == CAST_U32(mSelectedColumn) && r == CAST_U32(mSelectedRow)) { graphics->fillRectangle(Rect( x_offset, y_offset, cWidth, rHeight)); } } graphics->pushClipArea(bounds); widget->safeDraw(graphics); graphics->popClipArea(); } x_offset += cWidth; } y_offset += rHeight; } if (mTopWidget) { const Rect &bounds = mTopWidget->getDimension(); graphics->pushClipArea(bounds); mTopWidget->safeDraw(graphics); graphics->popClipArea(); } BLOCK_END("GuiTable::draw") }