AppSetupInfos getInitInfos() { AppSetupInfos initInfos; initInfos.windowTitle = WINDOW_TITLE_DESKTOP_APP; initInfos.windowSize = Int2(AUTOMATIC_FIT_TO_WINDOW_SIZE ? INIT_REAL_WINDOW_WIDTH : WINDOW_WIDTH, AUTOMATIC_FIT_TO_WINDOW_SIZE ? INIT_REAL_WINDOW_HEIGHT : WINDOW_HEIGHT); initInfos.isFullscreen = IS_FULLSCREEN; initInfos.defaultFontImgPath = IMG_FONT_PATH; initInfos.appDataFolderBasename = APP_DATA_FOLDER_BASENAME; initInfos.automaticFitToWindowSize = AUTOMATIC_FIT_TO_WINDOW_SIZE; initInfos.virtualSize = Int2(WINDOW_WIDTH, WINDOW_HEIGHT); initInfos.virtualSizeAllowRatioDeformation = false; return initInfos; }
//================================================================================================= void FlowContainer::UpdateSize(const Int2& _pos, const Int2& _size, bool _visible) { global_pos = pos = _pos; if(size.y != _size.y && _visible) { size = _size; Reposition(); } else size = _size; scroll.global_pos = scroll.pos = global_pos + Int2(size.x - 17, 0); scroll.size = Int2(16, size.y); scroll.part = size.y; }
MapTemplatePixelKernel MapGenerator::getKernel(const Surface& surface, const ::Int2& position) const { const Int2 positionL = position + Int2(-1, 0); const Int2 positionR = position + Int2( 1, 0); const Int2 positionD = position + Int2( 0, -1); const Int2 positionU = position + Int2( 0, 1); return MapTemplatePixelKernel( surface[position], surface.isInside(positionL) ? surface[positionL] : RGBA32(0, 0, 0, 0), surface.isInside(positionR) ? surface[positionR] : RGBA32(0, 0, 0, 0), surface.isInside(positionD) ? surface[positionD] : RGBA32(0, 0, 0, 0), surface.isInside(positionU) ? surface[positionU] : RGBA32(0, 0, 0, 0) ); }
void CullingComponent::onEvent(Event* e) { EventType type = e->getType(); switch (type) { case EVENT_START_DEATHMATCH: nodes_.clear(); yminmax=min_=max_=Int2(0,0); while(itrRender.hasNext()) { AttributePtr<Attribute_Render> ptr_render = itrRender.getNext(); if(ptr_render->meshID == 200 || ptr_render->meshID == 250) { Float3 position = ptr_render->ptr_spatial->ptr_position->position; if(min_.x > ((int)position.x)) min_.x = ((int)position.x); if(min_.y > ((int)position.z)) min_.y = ((int)position.z); if(max_.x < ((int)position.x)) max_.x = ((int)position.x); if(max_.y < ((int)position.z)) max_.y = ((int)position.z); if(yminmax.x > ((int)position.y)); yminmax.x = position.y; if(yminmax.y < ((int)position.y)); yminmax.y = position.y; } } max_.x++; max_.y++; int width = max_.x-min_.x; int height = max_.y-min_.y; nodes_ = std::vector<std::vector<AttributePtr<Attribute_Render>>>((width)*(height)); while(itrRender.hasNext()) { AttributePtr<Attribute_Render> ptr_render = itrRender.getNext(); if(ptr_render->meshID == 200 || ptr_render->meshID == 250) { Int2 pos = Int2((int)ptr_render->ptr_spatial->ptr_position->position.x-min_.x,(int)ptr_render->ptr_spatial->ptr_position->position.z-min_.y); nodes_.at((pos.x) + (pos.y) * width).push_back(ptr_render); } } break; } }
static Int2 LIBCALLBACK WriteAsn(Pointer data, CharPtr buffer, Uint2 size) { if ( !data || !buffer ) return -1; return Int2(static_cast<AsnMemoryWrite*>(data)->Write(buffer, size)); }
LoadGamePanel::LoadGamePanel(GameState *gameState) : Panel(gameState) { this->backButton = [gameState]() { auto function = [gameState]() { // Back button behavior depends on if game data is active. auto backPanel = gameState->gameDataIsActive() ? std::unique_ptr<Panel>(new PauseMenuPanel(gameState)) : std::unique_ptr<Panel>(new MainMenuPanel(gameState)); gameState->setPanel(std::move(backPanel)); }; return std::unique_ptr<Button>(new Button(function)); }(); this->underConstructionTextBox = [gameState]() { auto center = Int2(160, 85); auto color = Color::White; std::string text = "Under construction!"; auto fontName = FontName::A; return std::unique_ptr<TextBox>(new TextBox( center, color, text, fontName, gameState->getTextureManager())); }(); }
InfInt operator/(const InfInt& self, const InfInt& other) { bool sign_result= true; if(self.thesign!= other.thesign){ sign_result= false; } InfInt Int1(self); InfInt Int2(other); Int1.thesign= Int2.thesign= true; InfInt quo; InfInt dummy("1"); InfInt dummy2("-1"); while(Int1.thesign== true){ Int1= Int1- Int2; if(Int1.thesign== true){ quo= quo+ dummy; } } if(sign_result== false){ quo= quo* dummy2; } return quo; }
static Int2 LIBCALLBACK ReadAsn(Pointer data, CharPtr buffer, Uint2 size) { if ( !data || !buffer ) return -1; return Int2(static_cast<AsnMemoryRead*>(data)->Read(buffer, size)); }
void EditText::draw(float fontScale) { Scene2D& scene2D = Engine::instance().getScene2DMgr(); //AssertRelease(font != NULL); if (isCrypted) { Int2 posRes = pos; for (size_t i = 0; i < text.size(); ++i) { //posx = font->drawText(color, Int2(posx,pos.y()),"*",fontScale).x(); posRes = scene2D.drawText(NULL, "*", posRes, fontScale, color); } } else { //font->drawText(color, Int2(pos.x(), pos.y()),text.c_str(),fontScale); scene2D.drawText(NULL, text.c_str(), pos, fontScale, color); } if (isFocused) { int64_t tim = Utils::getMillisecond(); if (tim > timeCount + 500) { timeCount = tim; timeIsDisplayed = !timeIsDisplayed; } if (timeIsDisplayed) { if (isCrypted) { //font->drawText(color, Int2(pos.x()+font->getWidth("*",-1,fontScale)*keypos-3,pos.y()),"|",fontScale); Int2 size = scene2D.getSizeText(NULL, "*", fontScale); scene2D.drawText(NULL, "|", Int2(pos.x()+size.width()*keypos-3,pos.y()), fontScale, color); } else { Int2 size = scene2D.getSizeText(NULL, text.c_str(), fontScale, keypos); //font->drawText(color, Int2(pos.x()+font->getWidth(text.c_str(),keypos,fontScale)-3,pos.y()),"|",fontScale); scene2D.drawText(NULL, "|", Int2(pos.x()+size.width()-3,pos.y()), fontScale, color); } } } }
/** * Constructeur */ Config::Config() { musicsVolume = 50; soundEffectsVolume = 50; fullscreen = true; resolution = Int2(800,600); vsync = true; }
//================================================================================================= void FlowContainer::Draw(ControlDrawData*) { GUI.DrawItem(GUI.tBox, global_pos, size - Int2(16, 0), WHITE, 8, 32); scroll.Draw(); int sizex = size.x - 16; Rect rect; Rect clip = Rect::Create(global_pos + Int2(2, 2), Int2(sizex - 2, size.y - 2)); int offset = (int)scroll.offset; DWORD flags = (word_warp ? 0 : DT_SINGLELINE) | DT_PARSE_SPECIAL; for(FlowItem* fi : items) { if(fi->type != FlowItem::Button) { rect = Rect::Create(global_pos + fi->pos - Int2(0, offset), fi->size); // text above box if(rect.Bottom() < global_pos.y) continue; if(fi->state == Button::DOWN) { Rect rs = { global_pos.x + 2, rect.Top(), global_pos.x + sizex, rect.Bottom() }; Rect out; if(Rect::Intersect(rs, clip, out)) GUI.DrawSpriteRect(GUI.tPix, out, COLOR_RGBA(0, 255, 0, 128)); } if(!GUI.DrawText(fi->type == FlowItem::Section ? GUI.fBig : GUI.default_font, fi->text, flags, (fi->state != Button::DISABLED ? BLACK : COLOR_RGB(64, 64, 64)), rect, &clip)) break; } else { // button above or below box if(global_pos.y + fi->pos.y - offset + fi->size.y < global_pos.y || global_pos.y + fi->pos.y - offset > global_pos.y + size.y) continue; GUI.DrawSprite(button_tex[fi->tex_id].tex[fi->state], global_pos + fi->pos - Int2(0, offset), WHITE, &clip); } } }
//================================================================================================= MpBox::MpBox() : have_focus(false) { itb.parent = this; itb.max_cache = 10; itb.max_lines = 100; itb.esc_clear = true; itb.lose_focus = true; itb.pos = Int2(0, 0); itb.global_pos = Int2(100, 50); itb.size = Int2(320, 182); itb.event = InputEvent(this, &MpBox::OnInput); itb.background = &GUI.tPix; itb.background_color = Color(0, 142, 254, 43); itb.Init(); visible = false; }
World::World() : cellArray(unique_ptr< CellArray >(new CellArray)), cellArraySize(Int2(0, 0)) { cellArray->loopElements([](Cell& cell, const Int2& position) { cell.setGridPosition(position); }); biome = unique_ptr< Biome >(new DefaultBiome()); physics = MapPhysics(1.0f, 0.0f); }
TileKernel World::getTileKernel(const Int2 position) const { const Int2 positionL = position + Int2(-1, 0); const Int2 positionR = position + Int2( 1, 0); const Int2 positionD = position + Int2( 0, -1); const Int2 positionU = position + Int2( 0, 1); Tile center = isTilePositionOK(position) ? tileAt(position) : Tile(); return TileKernel( center, isTilePositionOK(positionL) ? tileAt(positionL) : center, isTilePositionOK(positionR) ? tileAt(positionR) : center, isTilePositionOK(positionD) ? tileAt(positionD) : center, isTilePositionOK(positionU) ? tileAt(positionU) : center, position ); }
void AppSetup::onResizeWindow(const Int2& newSize) { m_inf.windowSize = newSize; Float2 newSizeF = Float2((float)newSize.width(), (float)newSize.height()); Float2 virtualSizeF = Float2((float)m_inf.virtualSize.width(), (float)m_inf.virtualSize.height()); if (m_inf.automaticFitToWindowSize && (newSize.width() != m_inf.virtualSize.width() || newSize.height() != m_inf.virtualSize.height())) { Float2 ppp(-1.f,-1.f); Int2 virtualPos(-1,-1); float ratioW = (float)newSize.width() / (float)m_inf.virtualSize.width(); float ratioH = (float)newSize.height() / (float)m_inf.virtualSize.height(); if (m_inf.virtualSizeAllowRatioDeformation) { ppp = Float2(ratioW,ratioH); virtualPos = Int2(0,0); } else if (newSizeF.width()/newSizeF.height() > virtualSizeF.width() / virtualSizeF.height()) { ppp = Float2(ratioH,ratioH); virtualPos = Int2((int)((newSizeF.width()-virtualSizeF.width()*ratioH)/2.f), 0); } else { ppp = Float2(ratioW,ratioW); virtualPos = Int2(0, (int)((newSizeF.height()-virtualSizeF.height()*ratioW)/2.f)); } this->setPixelPerPointLowLevel(ppp, virtualPos); } else { this->setPixelPerPointLowLevel(Float2(1.f,1.f), Int2(0,0)); #if defined(USES_WINDOWS_OPENGL) || defined(USES_LINUX) m_openGL->setRealWindowSize(newSize); m_openGL->set2DMode(); #else // do nothing here #endif } m_isUsingVirtualSize = (this->getPixelPerPoint() != Float2(1.f, 1.f) || this->getVirtualTopLeftCornerInWindow() != Int2(0, 0)); }
CannonBullet::CannonBullet(const Double2& pos, float angleRadians, bool isMini) : m_cannonBulletPos(pos), m_speed(SPEED_BULLET*cos(angleRadians), SPEED_BULLET*sin(angleRadians)) { m_cannonBullet = new Sprite(isMini ? "data/cannon_mini_bullet.png" : "data/cannon_bullet.png"); m_cannonBullet->setHotSpotPointCenter(); m_cannonBullet->setPosition(Int2(-100,-100)); }
Fire::Fire(const Int2& pos, const Int2& posReference):m_animFrame(0), m_pos(pos), m_posReference(posReference) { m_anim.push_back(new Sprite("data/fire1.png")); m_anim.push_back(new Sprite("data/fire2.png")); m_anim.push_back(new Sprite("data/fire3.png")); m_anim.push_back(new Sprite("data/fire4.png")); iterateVector(m_anim, Sprite*) { (*it)->setHotSpotPoint(Int2((int)((*it)->getScaledSize().width()*0.5f), (*it)->getScaledSize().height())); }
//================================================================================================= void GameMenu::Draw(ControlDrawData*) { GUI.DrawSpriteFull(tBackground, Color::Alpha(128)); GUI.DrawItem(tDialog, global_pos, size, Color::Alpha(222), 16); GUI.DrawSprite(tLogo, global_pos + Int2(8, 8)); for(int i = 0; i < 6; ++i) bt[i].Draw(); }
//================================================================================================= PickItemDialog::PickItemDialog(const DialogInfo& info) : DialogBox(info) { flow.allow_select = true; flow.on_select = VoidF(this, &PickItemDialog::OnSelect); btClose.custom = &custom_x; btClose.id = Cancel; btClose.size = Int2(32, 32); btClose.parent = this; }
TFunctor for_each_implementation(region<2> aRegion, TFunctor aOperator) { for (int j = aRegion.corner[1]; j < aRegion.size[1]; ++j) { for (int i = aRegion.corner[0]; i < aRegion.size[0]; ++i) { aOperator(Int2(i, j)); } } return aOperator; }
//================================================================================================= void SingleInsideLocation::ApplyContext(LevelContext& ctx) { ctx.units = &units; ctx.objects = &objects; ctx.chests = &chests; ctx.traps = &traps; ctx.doors = &doors; ctx.items = &items; ctx.usables = &usables; ctx.bloods = &bloods; ctx.lights = &lights; ctx.have_terrain = false; ctx.require_tmp_ctx = true; ctx.type = LevelContext::Inside; ctx.building_id = -1; ctx.mine = Int2(0, 0); ctx.maxe = Int2(w, h); ctx.tmp_ctx = nullptr; ctx.masks = nullptr; }
//================================================================================================= void FlowContainer::Reposition() { int sizex = (word_warp ? size.x - 20 : 10000); int y = 2; bool have_button = false; for(FlowItem* fi : items) { if(fi->type != FlowItem::Button) { if(fi->type != FlowItem::Section) { if(have_button) { fi->size = GUI.default_font->CalculateSize(fi->text, sizex - 2 - button_size.x); fi->pos = Int2(4 + button_size.x, y); } else { fi->size = GUI.default_font->CalculateSize(fi->text, sizex); fi->pos = Int2(2, y); } } else { fi->size = GUI.fBig->CalculateSize(fi->text, sizex); fi->pos = Int2(2, y); } have_button = false; y += fi->size.y; } else { fi->size = button_size; fi->pos = Int2(2, y); have_button = true; } } UpdateScrollbar(y); }
//================================================================================================= MultiplayerPanel::MultiplayerPanel(const DialogInfo& info) : GameDialogBox(info) { size = Int2(344, 380); bts.resize(5); txMultiplayerGame = Str("multiplayerGame"); txNick = Str("nick"); txNeedEnterNick = Str("needEnterNick"); txEnterValidNick = Str("enterValidNick"); const Int2 bt_size(180, 44); const int x = (size.x - bt_size.x) / 2; bts[0].text = Str("joinLAN"); bts[0].parent = this; bts[0].id = IdJoinLan; bts[0].size = bt_size; bts[0].pos = Int2(x, 100); bts[1].text = Str("joinIP"); bts[1].parent = this; bts[1].id = IdJoinIp; bts[1].size = bt_size; bts[1].pos = Int2(x, 150); bts[2].text = Str("host"); bts[2].parent = this; bts[2].id = IdCreate; bts[2].size = bt_size; bts[2].pos = Int2(x, 200); bts[3].text = Str("load"); bts[3].parent = this; bts[3].id = IdLoad; bts[3].size = bt_size; bts[3].pos = Int2(x, 250); bts[4].text = GUI.txCancel; bts[4].parent = this; bts[4].id = IdCancel; bts[4].size = bt_size; bts[4].pos = Int2(x, 300); textbox.limit = 16; textbox.parent = this; textbox.pos = Int2((size.x - 200) / 2, 57); textbox.size = Int2(200, 32); visible = false; }
//================================================================================================= void GameMenu::LoadLanguage() { txSave = Str("saveGame"); txSaveAndExit = Str("saveAndExit"); txExitToMenuDialog = Str("exitToMenuDialog"); cstring names[] = { "returnToGame", "saveGame", "loadGame", "options", "exitToMenu", "quit" }; Int2 maxsize(0, 0); for(int i = 0; i < 6; ++i) { bt[i].id = IdReturnToGame + i; bt[i].parent = this; bt[i].text = Str(names[i]); bt[i].size = GUI.default_font->CalculateSize(bt[i].text) + Int2(24, 24); maxsize = Int2::Max(maxsize, bt[i].size); } size = Int2(256 + 16, 128 + 16 + (maxsize.y + 8) * 6); Int2 offset((size.x - maxsize.x) / 2, 128 + 8); // ustaw przyciski for(int i = 0; i < 6; ++i) { bt[i].pos = offset; bt[i].size = maxsize; offset.y += maxsize.y + 8; } }
AmmoView::AmmoView() :Ammo(),MyDrawable() { Int2 tmp_siz; if(type==BULLET || type==HEAVY_BULLET || type==LIGHT_BULLET) tmp_siz = Int2(50,12); if(type==FLAME) tmp_siz = Int2(300,150); if(type==GRENADE) tmp_siz = Int2(25,45); body.setOrigin(size.x/2,size.y/2); body.setSize(Vector2f(tmp_siz.x,tmp_siz.y)); initRotation(); loadRessources(); initRessources(); updateIntRect(); }
void AppSetup::manageRender() { if (m_isUsingVirtualSize) { Int2 virtualPos = this->getVirtualTopLeftCornerInWindow(); Float2 ppp = this->getPixelPerPoint(); Int2 sizeOrtho2DWindow = this->getSizeOrtho2DWindow(); this->setPixelPerPointLowLevel(Float2(1.f,1.f), Int2(0,0)); if (m_inf.virtualSizeBorderColor.a() != 0) { if (m_inf.virtualSize.width() < sizeOrtho2DWindow.width()) { Engine::instance().getScene2DMgr().drawRectangle( Int2(0,0), Int2(virtualPos.width(), m_inf.windowSize.height()), m_inf.virtualSizeBorderColor, true); Engine::instance().getScene2DMgr().drawRectangle( Int2(m_inf.windowSize.width()-virtualPos.width(), 0), m_inf.windowSize, m_inf.virtualSizeBorderColor, true); } else if (m_inf.virtualSize.height() < sizeOrtho2DWindow.height()) { Engine::instance().getScene2DMgr().drawRectangle( Int2(0, 0), Int2(m_inf.windowSize.width(), virtualPos.height()), m_inf.virtualSizeBorderColor, true); Engine::instance().getScene2DMgr().drawRectangle( Int2(0, m_inf.windowSize.height()-virtualPos.height()), m_inf.windowSize, m_inf.virtualSizeBorderColor, true); } } this->setPixelPerPointLowLevel(ppp, virtualPos); } #if defined(USES_WINDOWS_OPENGL) || defined(USES_LINUX) m_openGL->manageOpenGL(m_inf.windowSize); #else #endif }
static Int2 getRotatedPoint(int posX, int posY, float angleRadians, int posRotationCenterX, int posRotationCenterY, int xDeformation) { //definition de la position du point dans le nouveau repere dont le centre est le point de rotation float newPosX = (float)(posX - posRotationCenterX); float newPosY = (float)(posY - posRotationCenterY); //calcul de la position du point apres rotation (toujours dans ce nouveau repere) float angleNewPos = atan2f(newPosY, newPosX); #ifdef WIN32 float moduleNewPos = 1.f / MathUtils::fastInverseSqrt(newPosX*newPosX + newPosY*newPosY); #else float moduleNewPos = sqrt(newPosX*newPosX+newPosY*newPosY); #endif float finalAngle = angleNewPos + angleRadians; float rotatedNewPosX = cos(finalAngle) * moduleNewPos; float rotatedNewPosY = sin(finalAngle) * moduleNewPos; //retour des valeurs en remettant les coordonnees dans le repere normal return Int2(roundNumber(rotatedNewPosX) + posRotationCenterX + xDeformation, roundNumber(rotatedNewPosY) + posRotationCenterY); }
void OpenGLApp_onPointerPressedOrReleased(int button, int state,int x, int y) { Int2 pos = AppSetup::instance().convertRealPositionToVirtualPosition(Int2(x,y)); if (button==GLUT_WHEEL_UP) { s_mainClass->onPointerWheelChanged(120, pos.x(), pos.y()); } else if (button==GLUT_WHEEL_DOWN) { s_mainClass->onPointerWheelChanged(-120, pos.x(), pos.y()); } else if (state==GLUT_DOWN) { Engine::instance().onPointerPressedInternals(button, x, y); s_mainClass->onPointerPressed(button, pos.x(), pos.y()); } else if (state==GLUT_UP) { Engine::instance().onPointerReleasedInternals(button, x, y); s_mainClass->onPointerReleased(button, pos.x(), pos.y()); } s_eventHappened = true; }
CValueConvert<SSafeSqlCP, CDB_Object>::operator Int2(void) const { if (m_Value.IsNULL()) { return Int2(); } const EDB_Type cur_type = m_Value.GetType(); switch (cur_type) { case eDB_SmallInt: return ConvertSafe(static_cast<const CDB_SmallInt&>(m_Value).Value()); case eDB_TinyInt: return ConvertSafe(static_cast<const CDB_TinyInt&>(m_Value).Value()); case eDB_Bit: // CDB_Bit is for some reason "Int4" ... // return Convert(static_cast<const CDB_Bit&>(m_Value).Value()); return (static_cast<const CDB_Bit&>(m_Value).Value() == 0 ? 0 : 1); default: ReportTypeConvError(cur_type, "Int2"); } return 0; }
//================================================================================================= void TeamPanel::UpdateButtons() { if(Net::IsOnline()) { int s = (size.x - 16 - 12) / 4; bt[0].size.x = s; bt[0].size.y = 48; bt[0].pos = Int2(8, size.y - 58); bt[0].global_pos = bt[0].pos + global_pos; bt[1].size.x = s; bt[1].size.y = 48; bt[1].pos = Int2(8 + s + 4, size.y - 58); bt[1].global_pos = bt[1].pos + global_pos; bt[2].size.x = s; bt[2].size.y = 48; bt[2].pos = Int2(8 + s * 2 + 8, size.y - 58); bt[2].global_pos = bt[2].pos + global_pos; bt[3].size.x = s; bt[3].size.y = 48; bt[3].pos = Int2(8 + s * 3 + 12, size.y - 58); bt[3].global_pos = bt[3].pos + global_pos; } else { int s = (size.x - 16 - 6) / 2; bt[0].size.x = s; bt[0].size.y = 48; bt[0].pos = Int2(8, size.y - 58); bt[0].global_pos = bt[0].pos + global_pos; bt[1].size.x = s; bt[1].size.y = 48; bt[1].pos = Int2(8 + s + 4, size.y - 58); bt[1].global_pos = bt[1].pos + global_pos; } }