Texture::Texture(SDL_Surface* surface): _size(surface->w, surface->h) { _width = surface->w; _height = surface->h; glGenTextures(1, &_textureID); loadFromSurface(surface); }
void Texture::loadFromRGBA(unsigned int* data) { Uint32 rmask, gmask, bmask, amask; rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; SDL_Surface* tempSurf = SDL_CreateRGBSurfaceFrom(data, _width, _height, 32, _width*4, rmask, gmask, bmask, amask); loadFromSurface(tempSurf); SDL_FreeSurface(tempSurf); }
void TextArea::draw() { if (!needRedraw()) return; InteractiveSurface::draw(); if (!_font) throw Exception("TextArea::draw() - font is not setted"); // if text is empty if (_text.length() == 0) { loadFromSurface(new Surface(0, 0, this->x(), this->y())); return; } unsigned int line = 0; for (std::vector<std::string>::iterator it = textLines()->begin(); it != textLines()->end(); ++it) { //draw characters on string surface unsigned int x = 0; for(unsigned int i = 0; i != (*it).size(); ++i) { unsigned char chr = (*it).at(i); if (chr == ' ') { x += _font->spaceWidth(); } else { Surface * glyph = _font->glyph(chr); glyph->setX(x); glyph->setY(0); glyph->copyTo(textSurfaces()->at(line)); x += glyph->width() + _font->horizontalGap(); if (i == (*it).size() - 1) x -= _font->horizontalGap(); } } line++; } // Creating resulting surface Surface * surface = new Surface(this->width(), this->height()); surface->setBackgroundColor(backgroundColor()); surface->clear(); // foreach lines surfaces unsigned int x = 0; unsigned int y = 0; for (std::vector<Surface *>::iterator it = textSurfaces()->begin(); it != textSurfaces()->end(); ++it) { switch(_horizontalAlign) { case HORIZONTAL_ALIGN_LEFT: break; case HORIZONTAL_ALIGN_CENTER: x = (this->width() -(*it)->width())/2; break; case HORIZONTAL_ALIGN_RIGHT: x = this->width() - (*it)->width(); break; case HORIZONTAL_ALIGN_JUSTIFY: //@todo justify break; } (*it)->setX(x); (*it)->setY(y); (*it)->copyTo(surface); y += _font->height() + _font->verticalGap(); } surface->setX(this->x()); surface->setY(this->y()); loadFromSurface(surface); // clear used memory while(!_textSurfaces->empty()) { delete _textSurfaces->back(); _textSurfaces->pop_back(); } delete _textSurfaces; _textSurfaces = 0; delete surface; }
void LocationObject::setOrientation(unsigned int value) { _orientation = value; libfalltergeist::FrmFileType * frm = 0; unsigned int id = PID() & 0x00000FFF; unsigned int frmId = FID() & 0x00000FFF; unsigned int typeId = PID() >> 24; unsigned int ID1 = (FID() & 0x0000F000) >> 12; unsigned int ID2 = (FID() & 0x00FF0000) >> 16; unsigned int ID3 = (FID() & 0xF0000000) >> 28; if (typeId == 1) { std::cout << " >>> " << std::hex << FID() << std::endl; auto lst = ResourceManager::lstFileType("art/critters/critters.lst"); std::string frmName = lst->strings()->at(frmId); std::string frmBase = frmName.substr(0, 6); if (ID2 >= 0x26 && ID2 <= 0x2F) { if (ID1 >= 0x0B || ID1 == 0) { throw Exception("Critter ID1 unsupported value"); } else { frmBase += ID1 + 0x63; frmBase += ID2 + 0x3D; } } else if (ID2 == 0x24) { frmBase += "ch"; } else if (ID2 == 0x25) { frmBase += "cj"; } else if (ID2 == 0x40) { frmBase += "na"; } else if (ID2 >= 0x30) { frmBase += "r"; frmBase += ID2 + 0x31; } else if (ID2 >= 0x14) { frmBase += "b"; frmBase += ID2 + 0x4d; } else if (ID2 == 0x12) { if (ID1 == 0x01) { frmBase += "dm"; } else if (ID1 == 0x04) { frmBase += "gm"; } else { frmBase += "as"; } } else if (ID2 == 0x0D) { if (ID1 > 0) { frmBase += ID1 + 0x63; frmBase += "e"; } else { frmBase += "an"; } } else if (ID2 <= 0x01 && ID1 > 0) { frmBase += ID1 + 0x63; frmBase += ID2 + 0x61; } else { frmBase += "a"; frmBase += ID2 + 0x61; } std::string extensions[] = {"frm", "frm0", "frm1", "frm2", "fr3", "frm4", "frm5", "frm6"}; frmBase += "." + extensions[ID3]; //std::cout << frmBase << std::endl; frm = ResourceManager::frmFileType("art/critters/" + frmBase); //std::cout << "Frm: " << frm << std::endl; } else if(typeId == 5) { if (id == 12) // какая то хрень выстроенная форму прямоугольника { //frm = ResourceManager::frmFileType("art/intrface/msef000.frm"); } else if (id >= 16 && id <= 23) // exit { frm = ResourceManager::frmFileType("art/intrface/msef001.frm"); } else { //std::cout << std::dec << object->objectTypeId() << " - " << object->objectId() << " - " << object->descriptionId() << " : "; //std::cout << object->name() << " | " << object->description() << std::endl; //continue; // SKIP MISC for now } } else { frm = ResourceManager::frmFileType(FID()); } if (!frm) { loadFromSurface(new Surface()); } else if (frm->framesPerDirection() > 1) { delete _animation; setAnimation(new Animation(frm)); if (typeId == 1) // critters { if (ID3 == 0) { animation()->setCurrentSurfaceSet(orientation()); } } } else { loadFromSurface(new Surface(frm)); } }
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; } }