void KFinderWin::setOffsets( int _xpos, int _ypos ) { if ( _ypos > maxYOffset() ) setYOffset( maxYOffset() ); else setYOffset( _ypos ); if ( _xpos > maxXOffset() ) setXOffset( maxXOffset() ); else setXOffset( _xpos ); }
/* ** decrementYOffset ** Decreases the yOffset on an eponential scale */ float ofxOscilloscope::decrementYOffset() { float inc = 2.71828/2; if (getYOffset() == 0) { setYOffset(-1); } else if (getYOffset() == 1) { setYOffset(0); } else if (getYOffset() > 0) { setYOffset(pow(inc, round(log(getYOffset())/log(inc)) - 1)); } else if (getYOffset() < 0) { setYOffset(-pow(inc, round(log(-getYOffset())/log(inc)) + 1)); } return getYOffset(); }
void ROIPass::setParameters(int xOffset, int yOffset, int width, int height) { setXOffset(xOffset); setYOffset(yOffset); setWidth(width); setHeight(height); }
Image::Image(std::shared_ptr<libfalltergeist::FrmFileType> frm, unsigned int direction) { setTexture(new Texture(frm->width(), frm->height())); _texture->loadFromRGBA(frm->rgba(ResourceManager::palFileType("color.pal"))); setXOffset(frm->offsetX(direction) + frm->shiftX(direction) - width()/2); setYOffset(frm->offsetY(direction) + frm->shiftY(direction) - height()); }
bool RGBImage::loadXML(const QDomElement& root) { if (root.tagName() != KXMLQLCRGBAlgorithm) { qWarning() << Q_FUNC_INFO << "RGB Algorithm node not found"; return false; } if (root.attribute(KXMLQLCRGBAlgorithmType) != KXMLQLCRGBImage) { qWarning() << Q_FUNC_INFO << "RGB Algorithm is not Image"; return false; } QDomNode node = root.firstChild(); while (node.isNull() == false) { QDomElement tag = node.toElement(); if (tag.tagName() == KXMLQLCRGBImageFilename) { setFilename(doc()->denormalizeComponentPath(tag.text())); } else if (tag.tagName() == KXMLQLCRGBImageAnimationStyle) { setAnimationStyle(stringToAnimationStyle(tag.text())); } else if (tag.tagName() == KXMLQLCRGBImageOffset) { QString str; int value; bool ok; str = tag.attribute(KXMLQLCRGBImageOffsetX); ok = false; value = str.toInt(&ok); if (ok == true) setXOffset(value); else qWarning() << Q_FUNC_INFO << "Invalid X offset:" << str; str = tag.attribute(KXMLQLCRGBImageOffsetY); ok = false; value = str.toInt(&ok); if (ok == true) setYOffset(value); else qWarning() << Q_FUNC_INFO << "Invalid Y offset:" << str; } else { qWarning() << Q_FUNC_INFO << "Unknown RGBImage tag:" << tag.tagName(); } node = node.nextSibling(); } return true; }
bool RGBImage::loadXML(QXmlStreamReader &root) { if (root.name() != KXMLQLCRGBAlgorithm) { qWarning() << Q_FUNC_INFO << "RGB Algorithm node not found"; return false; } if (root.attributes().value(KXMLQLCRGBAlgorithmType).toString() != KXMLQLCRGBImage) { qWarning() << Q_FUNC_INFO << "RGB Algorithm is not Image"; return false; } while (root.readNextStartElement()) { if (root.name() == KXMLQLCRGBImageFilename) { setFilename(doc()->denormalizeComponentPath(root.readElementText())); } else if (root.name() == KXMLQLCRGBImageAnimationStyle) { setAnimationStyle(stringToAnimationStyle(root.readElementText())); } else if (root.name() == KXMLQLCRGBImageOffset) { QString str; int value; bool ok; QXmlStreamAttributes attrs = root.attributes(); str = attrs.value(KXMLQLCRGBImageOffsetX).toString(); ok = false; value = str.toInt(&ok); if (ok == true) setXOffset(value); else qWarning() << Q_FUNC_INFO << "Invalid X offset:" << str; str = attrs.value(KXMLQLCRGBImageOffsetY).toString(); ok = false; value = str.toInt(&ok); if (ok == true) setYOffset(value); else qWarning() << Q_FUNC_INFO << "Invalid Y offset:" << str; root.skipCurrentElement(); } else { qWarning() << Q_FUNC_INFO << "Unknown RGBImage tag:" << root.name(); root.skipCurrentElement(); } } return true; }
ClockFace::ClockFace(QGraphicsItem *parent): QGraphicsObject(parent) { scale = 100; foregroundColor = QColor("#dddddd"); shadowColor = QColor("#888888"); auto ef = new QGraphicsDropShadowEffect; ef->setXOffset(.5); ef->setYOffset(.5); ef->setBlurRadius(5); ef->setColor(shadowColor); setGraphicsEffect(ef); startTimer(10000); }
bool EFX::loadXMLAxis(QXmlStreamReader &root) { int frequency = 0; int offset = 0; int phase = 0; QString axis; if (root.name() != KXMLQLCEFXAxis) { qWarning() << "EFX axis node not found!"; return false; } /* Get the axis name */ axis = root.attributes().value(KXMLQLCFunctionName).toString(); /* Load axis contents */ while (root.readNextStartElement()) { if (root.name() == KXMLQLCEFXOffset) offset = root.readElementText().toInt(); else if (root.name() == KXMLQLCEFXFrequency) frequency = root.readElementText().toInt(); else if (root.name() == KXMLQLCEFXPhase) phase = root.readElementText().toInt(); else { qWarning() << "Unknown EFX axis tag:" << root.name(); root.skipCurrentElement(); } } if (axis == KXMLQLCEFXY) { setYOffset(offset); setYFrequency(frequency); setYPhase(phase); return true; } else if (axis == KXMLQLCEFXX) { setXOffset(offset); setXFrequency(frequency); setXPhase(phase); return true; } else { qWarning() << "Unknown EFX axis:" << axis; return false; } }
bool EFX::loadXMLAxis(const QDomElement& root) { int frequency = 0; int offset = 0; int phase = 0; QString axis; if (root.tagName() != KXMLQLCEFXAxis) { qWarning() << "EFX axis node not found!"; return false; } /* Get the axis name */ axis = root.attribute(KXMLQLCFunctionName); /* Load axis contents */ QDomNode node = root.firstChild(); while (node.isNull() == false) { QDomElement tag = node.toElement(); if (tag.tagName() == KXMLQLCEFXOffset) offset = tag.text().toInt(); else if (tag.tagName() == KXMLQLCEFXFrequency) frequency = tag.text().toInt(); else if (tag.tagName() == KXMLQLCEFXPhase) phase = tag.text().toInt(); else qWarning() << "Unknown EFX axis tag:" << tag.tagName(); node = node.nextSibling(); } if (axis == KXMLQLCEFXY) { setYOffset(offset); setYFrequency(frequency); setYPhase(phase); return true; } else if (axis == KXMLQLCEFXX) { setXOffset(offset); setXFrequency(frequency); setXPhase(phase); return true; } else { qWarning() << "Unknown EFX axis:" << axis; return false; } }
/* ** setup ** Initializes the ScopePlot. ** ** INPUT: ** timeWindow Specifies the time in seconds of the oscilloscope window ** sampFreq Specifies the sampling frequency of incoming data ** variableColors Display colors of variables ** yScale Muliplier for Y scaling axis ** yOffset Offset for the Y axis */ void ofxScopePlot::setup(float timeWindow, float sampFreq, std::vector<ofColor> variableColors, float yScale, float yOffset) { _timeWindow = timeWindow; _pointsPerWin = floor(_timeWindow * sampFreq); //(sec) _sampFreq = sampFreq; _nVariables = variableColors.size(); for (int i=0; i<_nVariables; i++) { _buffer.push_back(std::vector<float>(_pointsPerWin, 0.)); } setYScale(yScale); setYOffset(yOffset); setVariableColors(variableColors); }
int QGraphicsDropShadowEffect::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QGraphicsEffect::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 10) qt_static_metacall(this, _c, _id, _a); _id -= 10; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QPointF*>(_v) = offset(); break; case 1: *reinterpret_cast< qreal*>(_v) = xOffset(); break; case 2: *reinterpret_cast< qreal*>(_v) = yOffset(); break; case 3: *reinterpret_cast< qreal*>(_v) = blurRadius(); break; case 4: *reinterpret_cast< QColor*>(_v) = color(); break; } _id -= 5; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setOffset(*reinterpret_cast< QPointF*>(_v)); break; case 1: setXOffset(*reinterpret_cast< qreal*>(_v)); break; case 2: setYOffset(*reinterpret_cast< qreal*>(_v)); break; case 3: setBlurRadius(*reinterpret_cast< qreal*>(_v)); break; case 4: setColor(*reinterpret_cast< QColor*>(_v)); break; } _id -= 5; } else if (_c == QMetaObject::ResetProperty) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 5; } #endif // QT_NO_PROPERTIES return _id; }
void Animation::think() { if (SDL_GetTicks() - _frameTicks >= frames()->at(_currentFrame)->duration()) { _frameTicks = SDL_GetTicks(); if (_currentFrame < frames()->size() - 1) { _currentFrame += 1; } else { _currentFrame = 0; } auto frame = frames()->at(_currentFrame); setXOffset(frame->xOffset() - (int)std::floor(frame->width()*0.5)); setYOffset(frame->yOffset() - frame->height()); } }
bool RGBText::loadXML(const QDomElement& root) { if (root.tagName() != KXMLQLCRGBAlgorithm) { qWarning() << Q_FUNC_INFO << "RGB Algorithm node not found"; return false; } if (root.attribute(KXMLQLCRGBAlgorithmType) != KXMLQLCRGBText) { qWarning() << Q_FUNC_INFO << "RGB Algorithm is not Text"; return false; } QDomNode node = root.firstChild(); while (node.isNull() == false) { QDomElement tag = node.toElement(); if (tag.tagName() == KXMLQLCRGBTextContent) { setText(tag.text()); } else if (tag.tagName() == KXMLQLCRGBTextFont) { QFont font; if (font.fromString(tag.text()) == true) setFont(font); else qWarning() << Q_FUNC_INFO << "Invalid font:" << tag.text(); } else if (tag.tagName() == KXMLQLCRGBTextAnimationStyle) { setAnimationStyle(stringToAnimationStyle(tag.text())); } else if (tag.tagName() == KXMLQLCRGBTextOffset) { QString str; int value; bool ok; str = tag.attribute(KXMLQLCRGBTextOffsetX); ok = false; value = str.toInt(&ok); if (ok == true) setXOffset(value); else qWarning() << Q_FUNC_INFO << "Invalid X offset:" << str; str = tag.attribute(KXMLQLCRGBTextOffsetY); ok = false; value = str.toInt(&ok); if (ok == true) setYOffset(value); else qWarning() << Q_FUNC_INFO << "Invalid Y offset:" << str; } else { qWarning() << Q_FUNC_INFO << "Unknown RGBText tag:" << tag.tagName(); } node = node.nextSibling(); } return true; }
Animation::Animation(std::string frmName, unsigned int direction) : ActiveUI() { auto frm = ResourceManager::frmFileType(frmName); setTexture(ResourceManager::texture(frmName)); int xOffset = frm->shiftX(direction); int yOffset = frm->shiftY(direction); // Смещение кадра в текстуре анимации unsigned int x = 0; unsigned int y = 0; for (unsigned int d = 0; d != direction; ++d) { y += frm->height(d); //? может i - 1 } for (auto f = 0; f != frm->framesPerDirection(); ++f) { xOffset += frm->offsetX(direction, f); yOffset += frm->offsetY(direction, f); auto frame = new AnimationFrame(); frame->setWidth(frm->width(direction, f)); frame->setHeight(frm->height(direction, f)); frame->setXOffset(xOffset); frame->setYOffset(yOffset); frame->setY(y); frame->setX(x); auto fps = frm->framesPerSecond(); if (fps == 0) { frame->setDuration(1000); } else { frame->setDuration(std::round(1000.0/static_cast<double>(frm->framesPerSecond()))); } x += frm->width(direction); frames()->push_back(frame); } if (frm->animatedPalette()) { AnimatedPalette* palette=Game::getInstance()->animatedPalette(); auto masks = frm->animatedMasks(); if ((*masks)[libfalltergeist::FrmFileType::MASK_MONITOR] != NULL) { for (auto i=0; i<5; i++) { unsigned int* mask = new unsigned int[frm->width() * frm->height()](); //modify for (unsigned int j = 0; j< frm->width() * frm->height(); j++) { mask[j] = palette->color((*masks)[libfalltergeist::FrmFileType::MASK_MONITOR][j],i); } //set auto texture = new Texture(frm->width(), frm->height()); texture->loadFromRGBA(mask); _monitorTextures.push_back(texture); } } if ((*masks)[libfalltergeist::FrmFileType::MASK_SLIME] != NULL) { for (auto i=0; i<4; i++) { unsigned int* mask = new unsigned int[frm->width() * frm->height()](); //modify for (unsigned int j = 0; j< frm->width() * frm->height(); j++) { mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_SLIME][j]),i); } //set auto texture = new Texture(frm->width(), frm->height()); texture->loadFromRGBA(mask); _slimeTextures.push_back(texture); } } if ((*masks)[libfalltergeist::FrmFileType::MASK_SHORE] != NULL) { for (auto i=0; i<6; i++) { unsigned int* mask = new unsigned int[frm->width() * frm->height()](); //modify for (unsigned int j = 0; j< frm->width() * frm->height(); j++) { mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_SHORE][j]),i); } //set auto texture = new Texture(frm->width(), frm->height()); texture->loadFromRGBA(mask); _shoreTextures.push_back(texture); } } if ((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_SLOW] != NULL) { for (auto i=0; i<5; i++) { unsigned int* mask = new unsigned int[frm->width() * frm->height()](); //modify for (unsigned int j = 0; j< frm->width() * frm->height(); j++) { mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_SLOW][j]),i); } //set auto texture = new Texture(frm->width(), frm->height()); texture->loadFromRGBA(mask); _fireSlowTextures.push_back(texture); } } if ((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_FAST] != NULL) { for (auto i=0; i<5; i++) { unsigned int* mask = new unsigned int[frm->width() * frm->height()](); //modify for (unsigned int j = 0; j< frm->width() * frm->height(); j++) { mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_FAST][j]),i); } //set auto texture = new Texture(frm->width(), frm->height()); texture->loadFromRGBA(mask); _fireFastTextures.push_back(texture); } } if ((*masks)[libfalltergeist::FrmFileType::MASK_REDDOT] != NULL) { for (auto i=0; i<16; i++) { unsigned int* mask = new unsigned int[frm->width() * frm->height()](); //modify for (unsigned int j = 0; j< frm->width() * frm->height(); j++) { mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_REDDOT][j]),i); } //set auto texture = new Texture(frm->width(), frm->height()); texture->loadFromRGBA(mask); _reddotTextures.push_back(texture); } } } }
AnimatedImage::AnimatedImage(std::shared_ptr<libfalltergeist::FrmFileType> frm, unsigned int direction) { setTexture(new Texture(frm->width(), frm->height())); _texture->loadFromRGBA(frm->rgba(ResourceManager::palFileType("color.pal"))); setXOffset(frm->offsetX(direction) + frm->shiftX(direction)); setYOffset(frm->offsetY(direction) + frm->shiftY(direction)); AnimatedPalette* palette=Game::getInstance()->animatedPalette(); auto masks = frm->animatedMasks(); if ((*masks)[libfalltergeist::FrmFileType::MASK_MONITOR] != NULL) { for (auto i=0; i<5; i++) { unsigned int* mask = new unsigned int[frm->width() * frm->height()](); //modify for (unsigned int j = 0; j< frm->width() * frm->height(); j++) { mask[j] = palette->color((*masks)[libfalltergeist::FrmFileType::MASK_MONITOR][j],i); } //set auto texture = new Texture(frm->width(), frm->height()); texture->loadFromRGBA(mask); _monitorTextures.push_back(texture); } } if ((*masks)[libfalltergeist::FrmFileType::MASK_SLIME] != NULL) { for (auto i=0; i<4; i++) { unsigned int* mask = new unsigned int[frm->width() * frm->height()](); //modify for (unsigned int j = 0; j< frm->width() * frm->height(); j++) { mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_SLIME][j]),i); } //set auto texture = new Texture(frm->width(), frm->height()); texture->loadFromRGBA(mask); _slimeTextures.push_back(texture); } } if ((*masks)[libfalltergeist::FrmFileType::MASK_SHORE] != NULL) { for (auto i=0; i<6; i++) { unsigned int* mask = new unsigned int[frm->width() * frm->height()](); //modify for (unsigned int j = 0; j< frm->width() * frm->height(); j++) { mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_SHORE][j]),i); } //set auto texture = new Texture(frm->width(), frm->height()); texture->loadFromRGBA(mask); _shoreTextures.push_back(texture); } } if ((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_SLOW] != NULL) { for (auto i=0; i<5; i++) { unsigned int* mask = new unsigned int[frm->width() * frm->height()](); //modify for (unsigned int j = 0; j< frm->width() * frm->height(); j++) { mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_SLOW][j]),i); } //set auto texture = new Texture(frm->width(), frm->height()); texture->loadFromRGBA(mask); _fireSlowTextures.push_back(texture); } } if ((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_FAST] != NULL) { for (auto i=0; i<5; i++) { unsigned int* mask = new unsigned int[frm->width() * frm->height()](); //modify for (unsigned int j = 0; j< frm->width() * frm->height(); j++) { mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_FAST][j]),i); } //set auto texture = new Texture(frm->width(), frm->height()); texture->loadFromRGBA(mask); _fireFastTextures.push_back(texture); } } if ((*masks)[libfalltergeist::FrmFileType::MASK_REDDOT] != NULL) { for (auto i=0; i<16; i++) { unsigned int* mask = new unsigned int[frm->width() * frm->height()](); //modify for (unsigned int j = 0; j< frm->width() * frm->height(); j++) { mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_REDDOT][j]),i); } //set auto texture = new Texture(frm->width(), frm->height()); texture->loadFromRGBA(mask); _reddotTextures.push_back(texture); } } }
void Viewport::vScroll(float step) { setYOffset(m_yOffset + step); }
// ---------------------------------------------------------------------------- // Handles the action [id]. // Returns true if the action was handled, false otherwise // ---------------------------------------------------------------------------- bool GfxEntryPanel::handleEntryPanelAction(std::string_view id) { // We're only interested in "pgfx_" actions if (!StrUtil::startsWith(id, "pgfx_")) return false; // For pgfx_brush actions, the string after pgfx is a brush name if (StrUtil::startsWith(id, "pgfx_brush")) { gfx_canvas_->setBrush(SBrush::get(std::string{ id })); button_brush_->setIcon(StrUtil::afterFirst(id, '_')); } // Editing - drag mode else if (id == "pgfx_drag") { editing_ = false; gfx_canvas_->setEditingMode(GfxCanvas::EditMode::None); } // Editing - draw mode else if (id == "pgfx_draw") { editing_ = true; gfx_canvas_->setEditingMode(GfxCanvas::EditMode::Paint); gfx_canvas_->setPaintColour(cb_colour_->colour()); } // Editing - erase mode else if (id == "pgfx_erase") { editing_ = true; gfx_canvas_->setEditingMode(GfxCanvas::EditMode::Erase); } // Editing - translate mode else if (id == "pgfx_magic") { editing_ = true; gfx_canvas_->setEditingMode(GfxCanvas::EditMode::Translate); } // Editing - set translation else if (id == "pgfx_settrans") { // Create translation editor dialog TranslationEditorDialog ted( theMainWindow, *theMainWindow->paletteChooser()->selectedPalette(), " Colour Remap", image()); // Create translation to edit ted.openTranslation(edit_translation_); // Show the dialog if (ted.ShowModal() == wxID_OK) { // Set the translation edit_translation_.copy(ted.getTranslation()); gfx_canvas_->setTranslation(&edit_translation_); } } // Editing - set brush else if (id == "pgfx_setbrush") { auto p = button_brush_->GetScreenPosition() -= GetScreenPosition(); p.y += button_brush_->GetMaxHeight(); PopupMenu(menu_brushes_, p); } // Mirror else if (id == "pgfx_mirror") { // Mirror X image()->mirror(false); // Update UI gfx_canvas_->updateImageTexture(); gfx_canvas_->Refresh(); // Update variables image_data_modified_ = true; setModified(); } // Flip else if (id == "pgfx_flip") { // Mirror Y image()->mirror(true); // Update UI gfx_canvas_->updateImageTexture(); gfx_canvas_->Refresh(); // Update variables image_data_modified_ = true; setModified(); } // Rotate else if (id == "pgfx_rotate") { // Prompt for rotation angle wxString angles[] = { "90", "180", "270" }; int choice = wxGetSingleChoiceIndex("Select rotation angle", "Rotate", 3, angles, 0); // Rotate image switch (choice) { case 0: image()->rotate(90); break; case 1: image()->rotate(180); break; case 2: image()->rotate(270); break; default: break; } // Update UI gfx_canvas_->updateImageTexture(); gfx_canvas_->Refresh(); // Update variables image_data_modified_ = true; setModified(); } // Translate else if (id == "pgfx_remap") { // Create translation editor dialog auto pal = MainEditor::currentPalette(); TranslationEditorDialog ted(theMainWindow, *pal, " Colour Remap", &gfx_canvas_->image()); // Create translation to edit ted.openTranslation(prev_translation_); // Show the dialog if (ted.ShowModal() == wxID_OK) { // Apply translation to image image()->applyTranslation(&ted.getTranslation(), pal); // Update UI gfx_canvas_->updateImageTexture(); gfx_canvas_->Refresh(); // Update variables image_data_modified_ = true; gfx_canvas_->updateImageTexture(); setModified(); prev_translation_.copy(ted.getTranslation()); } } // Colourise else if (id == "pgfx_colourise") { auto pal = MainEditor::currentPalette(); GfxColouriseDialog gcd(theMainWindow, entry_, *pal); gcd.setColour(last_colour); // Show colourise dialog if (gcd.ShowModal() == wxID_OK) { // Colourise image image()->colourise(gcd.colour(), pal); // Update UI gfx_canvas_->updateImageTexture(); gfx_canvas_->Refresh(); // Update variables image_data_modified_ = true; Refresh(); setModified(); } last_colour = gcd.colour().toString(ColRGBA::StringFormat::RGB); } // Tint else if (id == "pgfx_tint") { auto pal = MainEditor::currentPalette(); GfxTintDialog gtd(theMainWindow, entry_, *pal); gtd.setValues(last_tint_colour, last_tint_amount); // Show tint dialog if (gtd.ShowModal() == wxID_OK) { // Tint image image()->tint(gtd.colour(), gtd.amount(), pal); // Update UI gfx_canvas_->updateImageTexture(); gfx_canvas_->Refresh(); // Update variables image_data_modified_ = true; Refresh(); setModified(); } last_tint_colour = gtd.colour().toString(ColRGBA::StringFormat::RGB); last_tint_amount = (int)(gtd.amount() * 100.0); } // Crop else if (id == "pgfx_crop") { auto image = this->image(); auto pal = MainEditor::currentPalette(); GfxCropDialog gcd(theMainWindow, image, pal); // Show crop dialog if (gcd.ShowModal() == wxID_OK) { // Prompt to adjust offsets auto crop = gcd.cropRect(); if (crop.tl.x > 0 || crop.tl.y > 0) { if (wxMessageBox( "Do you want to adjust the offsets? This will keep the graphic in the same relative " "position it was before cropping.", "Adjust Offsets?", wxYES_NO) == wxYES) { image->setXOffset(image->offset().x - crop.tl.x); image->setYOffset(image->offset().y - crop.tl.y); } } // Crop image image->crop(crop.x1(), crop.y1(), crop.x2(), crop.y2()); // Update UI gfx_canvas_->updateImageTexture(); gfx_canvas_->Refresh(); // Update variables image_data_modified_ = true; Refresh(); setModified(); } } // alPh/tRNS else if (id == "pgfx_alph" || id == "pgfx_trns") { setModified(); Refresh(); } // Optimize PNG else if (id == "pgfx_pngopt") { // This is a special case. If we set the entry as modified, SLADE will prompt // to save it, rewriting the entry and cancelling the optimization done... if (EntryOperations::optimizePNG(entry_)) setModified(false); else wxMessageBox( "Warning: Couldn't optimize this image, check console log for info", "Warning", wxOK | wxCENTRE | wxICON_WARNING); Refresh(); } // Extract all else if (id == "pgfx_extract") { extractAll(); } // Convert else if (id == "pgfx_convert") { GfxConvDialog gcd(theMainWindow); gcd.CenterOnParent(); gcd.openEntry(entry_); gcd.ShowModal(); if (gcd.itemModified(0)) { // Get image and conversion info auto image = gcd.itemImage(0); auto format = gcd.itemFormat(0); // Write converted image back to entry format->saveImage(*image, entry_data_, gcd.itemPalette(0)); // This makes the "save" button (and the setModified stuff) redundant and confusing! // The alternative is to save to entry effectively (uncomment the importMemChunk line) // but remove the setModified and image_data_modified lines, and add a call to refresh // to get the PNG tRNS status back in sync. // entry->importMemChunk(entry_data); image_data_modified_ = true; setModified(); // Fix tRNS status if we converted to paletted PNG int MENU_GFXEP_PNGOPT = SAction::fromId("pgfx_pngopt")->wxId(); int MENU_GFXEP_ALPH = SAction::fromId("pgfx_alph")->wxId(); int MENU_GFXEP_TRNS = SAction::fromId("pgfx_trns")->wxId(); int MENU_ARCHGFX_EXPORTPNG = SAction::fromId("arch_gfx_exportpng")->wxId(); if (format->name() == "PNG") { ArchiveEntry temp; temp.importMemChunk(entry_data_); temp.setType(EntryType::fromId("png")); menu_custom_->Enable(MENU_GFXEP_ALPH, true); menu_custom_->Enable(MENU_GFXEP_TRNS, true); menu_custom_->Check(MENU_GFXEP_TRNS, EntryOperations::gettRNSChunk(&temp)); menu_custom_->Enable(MENU_ARCHGFX_EXPORTPNG, false); menu_custom_->Enable(MENU_GFXEP_PNGOPT, true); toolbar_->enableGroup("PNG", true); } else { menu_custom_->Enable(MENU_GFXEP_ALPH, false); menu_custom_->Enable(MENU_GFXEP_TRNS, false); menu_custom_->Enable(MENU_ARCHGFX_EXPORTPNG, true); menu_custom_->Enable(MENU_GFXEP_PNGOPT, false); toolbar_->enableGroup("PNG", false); } // Refresh this->image()->open(entry_data_, 0, format->id()); gfx_canvas_->Refresh(); } } // Unknown action else return false; // Action handled return true; }
// ----------------------------------------------------------------------------- // Saves any changes to the entry // ----------------------------------------------------------------------------- bool GfxEntryPanel::saveEntry() { // Set offsets auto image = this->image(); image->setXOffset(spin_xoffset_->GetValue()); image->setYOffset(spin_yoffset_->GetValue()); // Write new image data if modified bool ok = true; if (image_data_modified_) { auto format = image->format(); wxString error = ""; ok = false; auto writable = format ? format->canWrite(*image) : SIFormat::Writable::No; if (format == SIFormat::unknownFormat()) error = "Image is of unknown format"; else if (writable == SIFormat::Writable::No) error = wxString::Format("Writing unsupported for format \"%s\"", format->name()); else { // Convert image if necessary (using default options) if (writable == SIFormat::Writable::Convert) { format->convertWritable(*image, SIFormat::ConvertOptions()); Log::info("Image converted for writing"); } if (format->saveImage(*image, entry_->data(), &gfx_canvas_->palette())) ok = true; else error = "Error writing image"; } if (ok) { // Set modified entry_->setState(ArchiveEntry::State::Modified); // Re-detect type auto oldtype = entry_->type(); EntryType::detectEntryType(entry_); // Update extension if type changed if (oldtype != entry_->type()) entry_->setExtensionByType(); } else wxMessageBox(wxString("Cannot save changes to image: ") + error, "Error", wxICON_ERROR); } // Otherwise just set offsets else EntryOperations::setGfxOffsets(entry_, spin_xoffset_->GetValue(), spin_yoffset_->GetValue()); // Apply alPh/tRNS options if (entry_->type()->formatId() == "img_png") { bool alph = EntryOperations::getalPhChunk(entry_); bool trns = EntryOperations::gettRNSChunk(entry_); if (alph != menu_custom_->IsChecked(SAction::fromId("pgfx_alph")->wxId())) EntryOperations::modifyalPhChunk(entry_, !alph); if (trns != menu_custom_->IsChecked(SAction::fromId("pgfx_trns")->wxId())) EntryOperations::modifytRNSChunk(entry_, !trns); } if (ok) setModified(false); return ok; }
// DEL, End Key void TableBody::jumpBottom() { setYOffset(maxYOffset()); }
// DEL , Home key void TableBody::jumpTop() { setYOffset(0); }
void GameCritterObject::onMovementAnimationEnded(Event* event) { auto hexagon = movementQueue()->back(); movementQueue()->pop_back(); Game::getInstance()->locationState()->moveObjectToHexagon(this, hexagon); auto animation = dynamic_cast<Animation*>(ui()); if (movementQueue()->size() == 0) { _moving = false; animation->stop(); setActionAnimation("aa"); return; } auto newHexagon = movementQueue()->back(); auto newOrientation = this->hexagon()->orientationTo(newHexagon); if (event->name() == "animationEnded" || (int)newOrientation != orientation()) { _orientation = newOrientation; auto newAnimation = _generateMovementAnimation(); if (event->name() == "actionFrame") { newAnimation->setCurrentFrame(animation->currentFrame()); newAnimation->setActionFrame(animation->actionFrame()); } else { newAnimation->setActionFrame(_running ? 2 : 4); } newAnimation->addEventHandler("actionFrame", std::bind(&GameCritterObject::onMovementAnimationEnded, this, std::placeholders::_1)); newAnimation->addEventHandler("animationEnded", std::bind(&GameCritterObject::onMovementAnimationEnded, this, std::placeholders::_1)); newAnimation->play(); delete _ui; _ui = animation = newAnimation; } if (event->name() == "actionFrame") { // at each action frame critter switches to the next hex and frame positions are offset relative to the action frame offsets auto actionFrame = animation->frames()->at(animation->actionFrame()); for (auto it = animation->frames()->rbegin(); it != animation->frames()->rend(); ++it) { auto frame = (*it); frame->setXOffset(frame->xOffset() - actionFrame->xOffset()); frame->setYOffset(frame->yOffset() - actionFrame->yOffset()); if (frame == actionFrame) break; } if (_running) { switch (animation->actionFrame()) { // those frame numbers were guessed to make seamless running animation case 2: animation->setActionFrame(4); break; case 4: animation->setActionFrame(6); break; case 5: animation->setActionFrame(7); break; } } } }
void Mouse::setType(int type) { delete _animation; _animation = 0; _type = type; switch(_type) { case BIG_ARROW: loadFromSurface(ResourceManager::surface("art/intrface/stdarrow.frm")); setXOffset(0); setYOffset(0); _lastType = _type; break; case SCROLL_W: loadFromSurface(ResourceManager::surface("art/intrface/scrwest.frm")); setYOffset( - ceil(height()/2)); setXOffset(0); break; case SCROLL_W_X: loadFromSurface(ResourceManager::surface("art/intrface/scrwx.frm")); setYOffset( - ceil(height()/2)); setXOffset(0); break; case SCROLL_N: loadFromSurface(ResourceManager::surface("art/intrface/scrnorth.frm")); setXOffset( - ceil(width()/2)); setYOffset(0); break; case SCROLL_N_X: loadFromSurface(ResourceManager::surface("art/intrface/scrnx.frm")); setXOffset( - ceil(width()/2)); setYOffset(0); break; case SCROLL_S: loadFromSurface(ResourceManager::surface("art/intrface/scrsouth.frm")); setXOffset( - ceil(width()/2)); setYOffset( - height()); break; case SCROLL_S_X: loadFromSurface(ResourceManager::surface("art/intrface/scrsx.frm")); setXOffset(- ceil(width()/2)); setYOffset(- height()); break; case SCROLL_E: loadFromSurface(ResourceManager::surface("art/intrface/screast.frm")); setXOffset( - width()); setYOffset( - ceil(height()/2)); break; case SCROLL_E_X: loadFromSurface(ResourceManager::surface("art/intrface/screx.frm")); setXOffset(- width()); setYOffset(- ceil(height()/2)); break; case SCROLL_NW: loadFromSurface(ResourceManager::surface("art/intrface/scrnwest.frm")); setXOffset(0); setYOffset(0); break; case SCROLL_NW_X: loadFromSurface(ResourceManager::surface("art/intrface/scrnwx.frm")); setXOffset(0); setYOffset(0); break; case SCROLL_SW: loadFromSurface(ResourceManager::surface("art/intrface/scrswest.frm")); setXOffset(0); setYOffset(- height()); break; case SCROLL_SW_X: loadFromSurface(ResourceManager::surface("art/intrface/scrswx.frm")); setXOffset(0); setYOffset(- height()); break; case SCROLL_NE: loadFromSurface(ResourceManager::surface("art/intrface/scrneast.frm")); setXOffset(- width()); setYOffset(0); break; case SCROLL_NE_X: loadFromSurface(ResourceManager::surface("art/intrface/scrnex.frm")); setXOffset(- width()); setYOffset(0); break; case SCROLL_SE: loadFromSurface(ResourceManager::surface("art/intrface/scrseast.frm")); setXOffset(- width()); setYOffset(- height()); break; case SCROLL_SE_X: loadFromSurface(ResourceManager::surface("art/intrface/scrsex.frm")); setXOffset(- width()); setYOffset(- height()); break; case HEXAGON_RED: loadFromSurface(ResourceManager::surface("art/intrface/msef000.frm")); setXOffset(- width()/2); setYOffset(- height()/2); _lastType = _type; break; case ACTION: loadFromSurface(ResourceManager::surface("art/intrface/actarrow.frm")); setXOffset(0); setYOffset(0); _lastType = _type; break; case WAIT: _animation = new Animation("art/intrface/wait.frm"); _animation->setEnabled(true); setXOffset(- width()/2); setYOffset(- height()/2); _lastType = _type; break; case NONE: loadFromSurface(new Surface()); break; } }