void SplashScreen::initialize() { Engine& engine = Engine::instance(); _d->textPic = Picture( Size( 800, 30 ), 0, true ); _d->fadetx = Picture( engine.screenSize(), 0, true ); _d->fadetx.fill( NColor(0xff, 0, 0, 0), Rect() ); }
// /// IsValidInput overrides TValidator's virtual function and checks the string /// passed in str against the format picture specified in Pic. IsValid returns true /// if Pic is NULL or Picture does not return Error for str; otherwise, it returns /// false. The suppressFill parameter overrides the value in voFill for the duration /// of the call to IsValidInput. /// If suppressFill is false and voFill is set, the call to Picture returns a filled /// string based on str, so the image in the edit control automatically reflects the /// format specified in Pic. // bool TPXPictureValidator::IsValidInput(LPTSTR input, bool suppressFill) { bool autoFill = (Options&voFill) && !suppressFill; return Pic.empty() || Picture(input, autoFill) != prError; }
void Pictures::load(const std::string& rc, int startIndex, int number, int multiplier) { for( int i = 0; i < number; ++i) { this->push_back( Picture(rc, startIndex + i*multiplier) ); } }
//! constructor Console::Console( Widget* parent, int id, const Rect& rectangle ) : Widget( parent, id, rectangle ), consoleHistoryIndex_(0), toggle_visible_(NONE), _d(new Impl) { calculateConsoleRect(ui()->rootWidget()->size()); //calculate the console rectangle hide(); cursorPos_ = 1; setFont( Font::create("default",12).withColor(ColorList::yellow) ); _opacity = 0; _logger = SmartPtr<ConsoleLogger>(new ConsoleLogger()); _logger->drop(); _logger->console = this; _d->bg = Picture(size(),0,true); Logger::registerWriter(TEXT(ConsoleLogger), _logger.object() ); Widget::setVisible(false); resizeMessages(); registerDefaultCommands_(); appendMessage( "Console initialized" ); //append a message _updateCommandRect(); }
void SdlBatcher::reset() { _d->onwork->texture = Picture(); _d->onwork->clip = Rect(); _d->onwork->dstrects.clear(); _d->onwork->srcrects.clear(); }
void GfxGlEngine::unloadPicture(Picture &ioPicture) { const GLuint& texture = (GLuint)ioPicture.getGlTextureID(); glDeleteTextures(1, &texture ); SDL_FreeSurface(ioPicture.getSurface()); ioPicture = Picture(); }
Picture Picture::clone() const { unsigned char* data = new unsigned char[width * height * colors]; for (int i = 0; i < width * height * colors; ++i) { data[i] = pic.get()[i]; } return Picture(data, width, height, colors); }
// /// IsValid overrides TValidator's virtual function and compares the string passed /// in str with the format picture specified in Pic. IsValid returns true if Pic is /// NULL or if Picture returns Complete for str, indicating that str needs no /// further input to meet the specified format; otherwise, it returns false. // bool TPXPictureValidator::IsValid(LPCTSTR input) { if (Pic.empty()) return true; TPicResult rslt = Picture(CONST_CAST(LPTSTR,input), false); return rslt == prComplete || rslt == prEmpty; }
Water::Water( Camera& camera, PlayerCityPtr city) : Layer( &camera, city ), _d( new Impl ) { _d->showWaterValue = false; _initialize(); for( int i=1; i < 32; i++ ) _d->pics[ i ] = Picture( config::layer.water, i ); }
Picture FramesGetter::readPic() { if (frameGetters[usedDataType]) { Picture res = frameGetters[usedDataType]->nextPic(); videoSaver.saveNextPicture(res); return res; } return Picture(); }
void Decorator::drawFrame(Pictures& stack, const Rect& rectangle, const int picId ) { // pics are: 0TopLeft, 1Top, 2TopRight, 3Left, 4Center, 5Right, 6BottomLeft, 7Bottom, 8BottomRight // draws the inside of the box Picture bg( gui::rc.panel, picId+4); const int sw = bg.width(); const int sh = bg.height(); for (int j = 0; j<(rectangle.height()/sh-1); ++j) { for (int i = 0; i<(rectangle.width()/sw-1); ++i) { stack.append( bg, rectangle.lefttop() + Point( sw+sw*i, sh+sh*j ) ); } } // draws horizontal borders Picture topBorder( gui::rc.panel, picId+1); Picture bottomBorder( gui::rc.panel, picId+7); for (int i = 0; i<(rectangle.width()/sw-1); ++i) { stack.append( topBorder, rectangle.lefttop() + Point( sw+sw*i, 0 )); stack.append( bottomBorder, rectangle.lefttop() + Point( sw+sw*i, rectangle.height()-sh ) ); } // draws vertical borders Picture leftBorder( gui::rc.panel, picId+3); Picture rightBorder( gui::rc.panel, picId+5); for (int i = 0; i<(rectangle.height()/sh-1); ++i) { stack.append( leftBorder, rectangle.lefttop() + Point( 0, sh+sh*i ) ); stack.append( rightBorder, rectangle.lefttop() + Point( rectangle.width()-sw, sh+sh*i ) ); } // topLeft corner stack.append( Picture( gui::rc.panel, picId+0), rectangle.lefttop() ); // topRight corner stack.append( Picture( gui::rc.panel, picId+2), Point( rectangle.right()-sh, rectangle.top() ) ); // bottomLeft corner stack.append( Picture( gui::rc.panel, picId+6), Point( rectangle.left(), rectangle.bottom() - sh ) ); // bottomRight corner stack.append( Picture( gui::rc.panel, picId+8), rectangle.rightbottom() - Point( 16, 16 ) ); }
void PictureBank::Impl::setPicture( const std::string &name, const Picture& pic ) { int dot_pos = name.find_last_of('.'); std::string rcname = name.substr(0, dot_pos); // first: we deallocate the current picture, if any unsigned int picId = Hash( rcname ); Picture* ptrPic = 0; Impl::ItPicture it = resources.find( picId ); if( it != resources.end() ) { //SDL_DestroyTexture( it->second.texture() ); if( it->second.texture() > 0 ) txCounters[ it->second.texture() ]--; ptrPic = &it->second; } else { resources[ picId ] = Picture(); ptrPic = &resources[ picId ]; } *ptrPic = pic; if( pic.texture() > 0 ) txCounters[ pic.texture() ]++; Point offset( 0, 0 ); // decode the picture name => to set the offset manually Point pic_info = PictureInfoBank::instance().getOffset( rcname ); if( pic_info == PictureInfoBank::instance().getDefaultOffset( PictureInfoBank::tileOffset ) ) { // this is a tiled picture=> automatic offset correction int cw = gfx::tilemap::cellSize().width() * 2; int ch = gfx::tilemap::cellSize().width() / 2; offset.setY( pic.height()-ch*( (pic.width()+2)/cw ) ); // (w+2)/60 is the size of the tile: (1x1, 2x2, 3x3, ...) } else if( pic_info == PictureInfoBank::instance().getDefaultOffset( PictureInfoBank::walkerOffset ) ) { // this is a walker picture=> automatic offset correction offset = Point( -pic.width()/2, int(pic.height()*3./4.) ); } else { offset = pic_info; } ptrPic->setOffset( offset ); ptrPic->setName( rcname ); }
void Decorator::drawBorder(Pictures& stack, const Rect& rectangle, const int offset) { // pics are: 0TopLeft, 1Top, 2TopRight, 3Right, 4BottomRight, 5Bottom, 6BottomLeft, 7Left Picture topborder( gui::rc.panel, offset+1); const int sw = topborder.width(); const int sh = topborder.height(); Picture bottomBorder( gui::rc.panel, offset+5); if( !sw || !sh ) { Logger::warning( "!!! Cant draw border for sw={0}, sh={1}", sw, sh ); return; } // draws horizontal borders for (int i = 0; i<(rectangle.width()/sw-1); ++i) { stack.append( topborder, rectangle.lefttop() + Point( sw+sw*i, 0 ) ); stack.append( bottomBorder, rectangle.lefttop() + Point( sw+sw*i, -rectangle.height()+sh ) ); } // draws vertical borders Picture leftborder( gui::rc.panel, offset+7); Picture rightborder( gui::rc.panel, offset+3); for (int i = 0; i<(rectangle.height()/sh+1); ++i) { stack.append( leftborder, rectangle.lefttop() + Point( 0, -rectangle.height()+sh*i ) ); stack.append( rightborder, rectangle.lefttop() + Point( rectangle.width()-sw, -rectangle.height()+sh*i ) ); } // topLeft corner stack.append( Picture( gui::rc.panel, offset+0), rectangle.lefttop()); // topRight corner stack.append( Picture( gui::rc.panel, offset+2), Point( rectangle.right()-sw, rectangle.top() ) ); // bottomLeft corner stack.append( Picture( gui::rc.panel, offset+6), Point( rectangle.left(), -rectangle.bottom()+sh ) ); // bottomRight corner stack.append( Picture( gui::rc.panel, offset+4), Point( rectangle.right()-16, -rectangle.bottom()+sh ) ); }
void SdlEngine::unloadPicture( Picture& ioPicture ) { try { if( ioPicture.surface() ) SDL_FreeSurface( ioPicture.surface() ); if( ioPicture.texture() ) SDL_DestroyTexture( ioPicture.texture() ); } catch(...) { } ioPicture = Picture(); }
Picture UnStabilizator::nextStep(Picture basePic) { if (basePic.getWidth() == 0) return Picture(); double angle = dif_lib::randomDoubleSigned(shiftAngle * M_PI / 180.0); double* homoData = new double[6]; homoData[2] = dif_lib::randomDoubleSigned(shiftX); homoData[5] = dif_lib::randomDoubleSigned(shiftY); homoData[0] = cos(angle); homoData[4] = cos(angle); homoData[1] = sin(angle); homoData[3] = -sin(angle); Homography h**o = Homography(Matrix(2,3,sh_ptr_db(homoData))); basePic = picConverter.applyHomo(basePic, h**o); return basePic; }
Picture PictureDao::read (QString path) { Picture result; m_database->open(); QString query (QString("SELECT id,name,path,brightness,contrast,gamma,wb_red,wb_green,wb_blue FROM pictures WHERE path=") + m_database->formatString( path ) + ";"); qDebug () << query; QSqlQuery qsql_query = m_database->exec( query ); if (qsql_query.isActive()) { QSqlRecord record = qsql_query.record(); int id_index = record.indexOf ("id"); int name_index = record.indexOf ("name"); int path_index = record.indexOf ("path"); int brightness_index = record.indexOf ("brightness"); int constrast_index = record.indexOf ("contrast"); int gamma_index = record.indexOf ("gamma"); int wb_red_index = record.indexOf ("wb_red"); int wb_green_index = record.indexOf ("wb_green"); int wb_blue_index = record.indexOf ("wb_blue"); while (qsql_query.next()) { result = Picture( qsql_query.value(id_index).toInt(), qsql_query.value(name_index).toString(), qsql_query.value(path_index).toString(), qsql_query.value(brightness_index).toFloat(), qsql_query.value(constrast_index).toFloat(), qsql_query.value(gamma_index).toFloat(), qsql_query.value(wb_red_index).toFloat(), qsql_query.value(wb_green_index).toFloat(), qsql_query.value(wb_blue_index).toFloat()); } } m_database->close(); return result; }
void Decorator::drawBorder( Pictures& stack, const Rect& rectangle, int tp, int bp, int lp, int rp, int pCount, int hCount, int ltc, int lbc, int rtc, int rbc ) { // draws horizontal borders Size size = Picture( gui::rc.panel, tp ).size(); const int sw = size.width(); const int sh = size.height(); if( !sw || !sh ) { Logger::debug( "Decorator::drawBorder() can't finf texture {} {}", gui::rc.panel, tp ); return; } int xOff=sw, yOff=sh, i=0; for( ; xOff < rectangle.width()-sw; xOff += sw) { Point offset = Point( xOff, 0 ); stack.append( Picture( gui::rc.panel, tp+i%pCount), offset ); // top border stack.append( Picture( gui::rc.panel, bp+i%pCount), offset - Point( 0, rectangle.height()-sh ) ); // bottom border i++; } // draws vertical borders i = 0; for( ; yOff < rectangle.height()-sh; yOff += sh) { Point offset = rectangle.lefttop() + Point( 0, -yOff ); stack.append( Picture( gui::rc.panel, lp+hCount*(i%pCount)), offset ); // left border stack.append( Picture( gui::rc.panel, rp+hCount*(i%pCount)), offset + Point( rectangle.width()-sw, 0 ) ); // right border i++; } stack.append( Picture( gui::rc.panel, ltc), rectangle.lefttop() ); // left-top corner stack.append( Picture( gui::rc.panel, lbc), Point( rectangle.left(), -rectangle.bottom()+sh ) ); // left-bottom corner stack.append( Picture( gui::rc.panel, rtc), Point( rectangle.right() - sw, rectangle.top() ) ); // right-top corner stack.append( Picture( gui::rc.panel, rbc), Point( rectangle.right() - sw, -rectangle.bottom()+sh ) ); // right-bottom corner }
QList <Picture> PictureDao::pictures () { m_database->open(); QList <Picture> result; QString query ("SELECT id,name,path,brightness,contrast,gamma,wb_red,wb_green,wb_blue FROM pictures;"); QSqlQuery qsql_query = m_database->exec( query ); if (qsql_query.isActive()) { QSqlRecord record = qsql_query.record(); int id_index = record.indexOf ("id"); int name_index = record.indexOf ("name"); int path_index = record.indexOf ("path"); int brightness_index = record.indexOf ("brightness"); int constrast_index = record.indexOf ("contrast"); int gamma_index = record.indexOf ("gamma"); int wb_red_index = record.indexOf ("wb_red"); int wb_green_index = record.indexOf ("wb_green"); int wb_blue_index = record.indexOf ("wb_blue"); while (qsql_query.next()) { result.push_back( Picture ( qsql_query.value(id_index).toInt(), qsql_query.value(name_index).toString(), qsql_query.value(path_index).toString(), qsql_query.value(brightness_index).toFloat(), qsql_query.value(constrast_index).toFloat(), qsql_query.value(gamma_index).toFloat(), qsql_query.value(wb_red_index).toFloat(), qsql_query.value(wb_green_index).toFloat(), qsql_query.value(wb_blue_index).toFloat())); } } m_database->close(); return result; }
void SplashScreen::exitScene(bool devText) { #ifdef DEBUG devText = false; #endif script::Core::execFunction("OnExitSplashScreen"); Engine& engine = Engine::instance(); int offset = 3; Font textFont = Font::create("FONT_3") ; if( OSystem::isAndroid() ) { offset = 12; textFont = Font::create("FONT_4"); } _d->fade( engine, _d->background, true, offset ); _d->textPic = Picture( engine.screenSize(), 0, true ); _d->textPic.fill( ColorList::black, Rect( Point( 0, 0 ), _d->textPic.size() ) ); if (devText) { script::Core::execFunction("OnDevtextSplashScreen"); int offset = 0; for( const auto& line : _d->devText ) { Rect textRect = textFont.getTextRect( line, Rect( Point(), _d->textPic.size() ), align::center, align::center ); bool defaultColor = ( (line)[0] != ' '); textFont.setColor( defaultColor ? ColorList::dodgerBlue : ColorList::indianRed ); textFont.draw( _d->textPic, line, textRect.left(), textRect.top() + offset, false, true ); offset += 20; } _d->fade( engine, _d->textPic, false, offset ); engine.delay( 3000 ); } _d->fade( engine, _d->textPic, true, offset ); }
void CartPusher::onDestination() { Walker::onDestination(); _d->cartPicture = Picture(); if( _d->consumerBuilding != NULL ) { GranaryPtr granary = _d->consumerBuilding.as<Granary>(); WarehousePtr warehouse = _d->consumerBuilding.as<Warehouse>(); FactoryPtr factory = _d->consumerBuilding.as<Factory>(); if( granary != NULL ) { granary->getGoodStore().applyStorageReservation(_d->stock, _d->reservationID); _d->reservationID = 0; } else if ( warehouse != NULL ) { warehouse->getGoodStore().applyStorageReservation(_d->stock, _d->reservationID); _d->reservationID = 0; } else if( factory != NULL ) { factory->getGoodStore().applyStorageReservation(_d->stock, _d->reservationID); // factory->computePictures(); _d->reservationID = 0; } } // if( !_getPathway().isReverse() ) { _getPathway().toggleDirection(); computeDirection(); go(); _d->consumerBuilding = 0; } else { deleteLater(); } }
Picture Picture::mk_composed( const std::vector<Picture> & v ) { return Picture( COMPOSED, new std::vector<Picture> (v) ); }
// Copyright 2012-2013 Gregoire Athanase, [email protected] #include "oc3_picture.hpp" #include <SDL_image.h> #include "oc3_exception.hpp" #include "oc3_positioni.hpp" #include "oc3_rectangle.hpp" #include "oc3_picture_bank.hpp" #include "oc3_gfx_engine.hpp" #include "oc3_requirements.hpp" #include "oc3_color.hpp" // Picture class functions static const Picture _invalidPicture = Picture(); class Picture::Impl { public: // the image is shifted when displayed Point offset; Size size; // for game save std::string name; // for SDL surface SDL_Surface* surface;
void CartSupplier::onNewDirection() { Walker::onNewDirection(); _d->cartPicture = Picture(); // need to get the new graphic }
Sample::Sample() { picture = Picture(); }
namespace gfx { static const Picture _invalidPicture = Picture(); Picture::Picture() : _d( new PictureImpl ) { _d->drop(); _d->texture = NULL; _d->surface = 0; _d->opengltx = 0; _name = ""; _offset = Point( 0, 0 ); } Picture::Picture( const Picture& other ) : _d( new PictureImpl ) { _d->drop(); *this = other; } void Picture::init(SDL_Texture *texture, SDL_Surface* srf, unsigned int ogltx) { _d->texture = texture; _d->surface = srf; _d->opengltx = ogltx; } void Picture::setOffset(const Point &offset ) { _offset = offset; } void Picture::setOffset(int x, int y) { _offset = Point( x, y ); } void Picture::setOriginRect(const Rect& rect) { _orect = rect; } void Picture::addOffset( const Point& offset ){ _offset += offset; } void Picture::addOffset( int x, int y ) { _offset += Point( x, y ); } const Rect& Picture::originRect() const { return _orect; } SDL_Texture* Picture::texture() const { return _d->texture;} SDL_Surface* Picture::surface() const { return _d->surface; } unsigned int Picture::textureID() const { return _d->opengltx; } unsigned int& Picture::textureID() { return _d->opengltx; } const Point& Picture::offset() const { return _offset;} int Picture::width() const { return _orect.width();} int Picture::height() const { return _orect.height();} int Picture::pitch() const { return width() * 4; } void Picture::setName(const std::string &name){ _name = name;} const std::string& Picture::name() const { return _name;} Size Picture::size() const { return _orect.size(); } unsigned int Picture::sizeInBytes() const { return size().area() * 4; } bool Picture::isValid() const { return (_d->texture || _d->opengltx); } void Picture::load( const std::string& group, const int id ) { *this = PictureBank::instance().getPicture( group, id ); } void Picture::load(const std::string& filename ) { *this = PictureBank::instance().getPicture( filename ); } void Picture::setAlpha(unsigned char value) { if( _d->texture ) { SDL_SetTextureAlphaMod( _d->texture, value ); } if( _d->surface ) { SDL_SetSurfaceAlphaMod( _d->surface, value ); } } unsigned int* Picture::lock() { /*if( _d->texture ) { int a; SDL_QueryTexture( _d->texture, 0, &a, 0, 0 ); if( a == SDL_TEXTUREACCESS_STREAMING ) { unsigned int* pixels; int pitch; int rc = SDL_LockTexture(_d->texture, 0, (void**)&pixels, &pitch ); if (rc < 0) { Logger::warning( "Picture: cannot lock texture: %s", SDL_GetError() ); return 0; } return pixels; } }*/ if( _d->surface ) { if( SDL_MUSTLOCK(_d->surface) ) { SDL_LockSurface(_d->surface); } return (unsigned int*)_d->surface->pixels; } return 0; } void Picture::unlock() { /*if( _d->texture ) { int a; SDL_QueryTexture( _d->texture, 0, &a, 0, 0 ); if( a == SDL_TEXTUREACCESS_STREAMING ) { SDL_UnlockTexture(_d->texture); } } else if( _d->surface )*/ { if( SDL_MUSTLOCK(_d->surface) ) { SDL_UnlockSurface(_d->surface); } } } Picture& Picture::operator=( const Picture& other ) { _d = other._d; _name = other._name; _orect = other._orect; _offset = other._offset; return *this; } Picture::~Picture(){} void Picture::update() { if( _d->texture && _d->surface ) { SDL_UpdateTexture(_d->texture, 0, _d->surface->pixels, _d->surface->pitch ); return; } if( _d->surface && _d->opengltx > 0 ) { Engine::instance().loadPicture( *this, false ); } } void Picture::fill( const NColor& color, Rect rect ) { if( _d->surface ) { SDL_Rect r = { rect.left(), rect.top(), rect.width(), rect.height() }; SDL_FillRect( _d->surface, rect.width() == 0 ? 0 : &r, color.color ); } else { Logger::warning( "Picture: surface not loading " + _name ); } } Picture::Picture(const Size& size, unsigned char* data, bool mayChange) : _d( new PictureImpl ) { _d->drop(); _orect = Rect( 0, 0, size.width(), size.height() ); if( data ) { _d->surface = SDL_CreateRGBSurfaceFrom( data, size.width(), size.height(), 32, size.width() * 4, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 ); } else { _d->surface = SDL_CreateRGBSurface( 0, size.width(), size.height(), 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 ); SDL_FillRect( _d->surface, 0, 0 ); } Engine::instance().loadPicture( *this, mayChange ); if( !mayChange ) { SDL_FreeSurface( _d->surface ); _d->surface = 0; } } Picture::Picture(const std::string& group, const int id) : _d( new PictureImpl ) { _d->drop(); load( group, id ); } Picture::Picture(const std::string& filename ) : _d( new PictureImpl ) { _d->drop(); load( filename ); } const Picture& Picture::getInvalid() { return _invalidPicture; } }//end namespace gfx
Picture MotionDetectorAction::nextStep(Picture pic) { if (pic.getWidth() == 0) return Picture(); motionDetector->nextStep(pic); return motionDetector->getPicByMode(); }
void Pictures::load(const StringArray& names) { foreach( it, names ) this->push_back( Picture( *it ) ); }
Picture Picture::mk_rectangle( const Rectangle & v ) { return Picture( RECTANGLE, new Rectangle(v) ); }
Picture Picture::mk_circle( const Circle & v ) { return Picture( CIRCLE, new Circle(v) ); }
Picture Picture::mk_translated( const Translated<Picture> & v ) { return Picture( TRANSLATED, new Translated<Picture> (v) ); }