void draw_circle(sf::RenderWindow& app, Point pos, const sf::Color& col) { sf::Shape h; h.AddPoint(pos.x/10*app.GetWidth()-4, pos.y/10*app.GetHeight(), col); h.AddPoint(pos.x/10*app.GetWidth(), pos.y/10*app.GetHeight()-4, col); h.AddPoint(pos.x/10*app.GetWidth()+4, pos.y/10*app.GetHeight(), col); h.AddPoint(pos.x/10*app.GetWidth(), pos.y/10*app.GetHeight()+4, col); app.Draw(h); }
void df::Context::ExtractRenderWindowStatus(sf::RenderWindow const &renderWindow) { _ellapsedTime = renderWindow.GetFrameTime(); _frameRate = 1.f/_ellapsedTime; _windowSize.Width = renderWindow.GetWidth(); _windowSize.Height = renderWindow.GetHeight(); }
void DrawQuad(GLuint programID) { GL_CHECK(glMatrixMode(GL_PROJECTION)); GL_CHECK(glLoadIdentity()); GL_CHECK(gluOrtho2D(-1, 1, -1, 1)); glViewport(0, 0, window.GetWidth(), window.GetHeight()); GL_CHECK(glMatrixMode(GL_MODELVIEW)); GL_CHECK(glLoadIdentity()); GL_CHECK(glEnable(GL_TEXTURE_2D)); loadShaderVariables(programID); frame->Bind(); glBegin(GL_QUADS); glTexCoord2f(0, 1); glVertex2f(-1, -1); glTexCoord2f(1, 1); glVertex2f(1, -1); glTexCoord2f(1, 0); glVertex2f(1, 1); glTexCoord2f(0, 0); glVertex2f(-1, 1); glEnd(); }
FreeFlyCamera::FreeFlyCamera(const sf::Vector3f & position, const sf::Vector3f & target, sf::RenderWindow & win) { lastPosition = position; up = _UP_; fov = 80; _near = 0.1; _far = 10000; ratio = ((float)win.GetWidth() / (float)win.GetHeight()); speed = 100.f; this->position = position; this->target = target; sensivity = 0.5f; theta = 45;//utils::VectorsAngle(sf::Vector2f(target.x, target.z), sf::Vector2f(position.x, position.z)); phi = -45;//utils::VectorsAngle(sf::Vector2f(target.z, target.y), sf::Vector2f(up.x, up.y)); psi = 0; CompileVectors(); float tang = (float) tan(fov * 0.5f * M_PI / 180.f); Hnear = tang * _near; Wnear = Hnear * ratio; Hfar = tang * _far; Wfar = Hfar * ratio; }
void KeyboardMenu::Display(sf::RenderWindow& Window, VerticalPositions VPos, HorizontalPositions HPos) { Window.SetActive(true); sf::String DisplayString; DisplayString.SetFont(font); DisplayString.SetSize(default_size); DisplayString.SetColor(sf::Color::Red); int startHeight; int Height; if(menu_options.size() > 10) { throw std::runtime_error("Not Implemented: Option List Larger than 10"); } else { if(VPos == VerticalPositions::TOP) { startHeight = Height = 10; for(int i = 0; i < menu_options.size(); i++) { DisplayString.SetText(key_list[i].OutputString + " : " + menu_options[i]); set_string_position(DisplayString, Height, Window.GetWidth()); Window.Draw(DisplayString); Height += default_size + 10; } } else { startHeight = Height = Window.GetHeight() - 10; for(int i = menu_options.size() - 1; i >= 0; i--) { DisplayString.SetText(key_list[i].OutputString + " : " + menu_options[i]); Height -= DisplayString.GetRect().GetHeight(); set_string_position(DisplayString, Height, Window.GetWidth()); Window.Draw(DisplayString); Height -= 10; } } } }
void SplashScreen::Show(sf::RenderWindow& renderWindow) { sf::Image image; sf::Color bgColor = sf::Color(40,40,40); //Replace this? if (image.LoadFromFile("test.png") != true) return; sf::Sprite sprite(image); cerr<<renderWindow.GetWidth()/2<<" "<< renderWindow.GetHeight()/2<<endl; sprite.SetCenter(184/2,184/2); sprite.SetPosition(renderWindow.GetWidth()/2 , renderWindow.GetHeight()/2); renderWindow.Clear(bgColor); renderWindow.Draw(sprite); renderWindow.Display(); sf::Event event; sf::Clock clock; while(clock.GetElapsedTime()<3) { while(renderWindow.GetEvent(event)) { if ( event.Type == sf::Event::KeyPressed || event.Type == sf::Event::MouseButtonPressed || event.Type == sf::Event::Closed) { renderWindow.Clear(bgColor); return; } } } renderWindow.Clear(bgColor); return; }
void DisplayManager::display(AnimatedManager &AM, sf::RenderWindow &App){ if(sprites.isEmpty()) return; for(int j = 0 ;j < App.GetHeight()/TAILLE ; j++ ){ spriteMap::iterator it = sprites.find(j); if(it == sprites.end()) continue; QVector<sprite> tmp = it.value(); for(int i = 0; i < tmp.size();i++){ QPoint coord = tmp[i].first; //if(tmp[i].second!=1) //EM.value(tmp[i].second)->get_trigger().draw(App); //AM.get(EM.value(tmp[i].second)->get_nom()).setFrame(EM.value(tmp[i].second)->getFrame()); //affichage de la trainee derriere la mouche if(tmp[i].second == 1){//!(((Fly*) EM.value(tmp[i].second))->getPos().isEmpty()) ){ QPoint tmpPoint; // AM.get(EM.value(tmp[i].second)->get_nom()).setAngle(-EM.value(tmp[i].second)->getAngle()); for(int k = 0; k < ((Fly*) EM.value(tmp[i].second))->getPos().size()-5; k++){ tmpPoint = ((Fly*) EM.value(tmp[i].second))->getPos()[k]; AM.get("Circle").getImage().Resize(k/2+TAILLE,k/2+TAILLE); AM.get("Circle").setPosition(tmpPoint.x(),tmpPoint.y()); AM.get("Circle").affichage(App); } } //Displays of all entity if(EM.contains(tmp[i].second)){ AM.get(EM.value(tmp[i].second)->get_nom()).setFrame(EM.value(tmp[i].second)->getFrame()); AM.get(EM.value(tmp[i].second)->get_nom()).setPosition(coord.x(),coord.y()); AM.get(EM.value(tmp[i].second)->get_nom()).affichage(App); } } } }
void WorldCamera2D::Reset (sf::RenderWindow& win) { sfView.SetFromRect(sf::FloatRect(0, 0, win.GetWidth(), win.GetHeight())); sfView.SetCenter(camCenterPos * fakeScale); sfView.Zoom(zoom); }
gra_screen::gra_screen(sf::RenderWindow &App,sf::Font & font) { osttime=0; korektatime=0; zam=false; WspolTarciaGracz=0; WspolTarciaPilka=0; dan=0; pozres=false; lingran=0; pilka=0; slupek=0; gracz1_im=0; gracz2_im=0; gracz=0; boisko_im=0; wynl=0; wynp=0; bg=100; bd=500; bl=100; bp=700; bramka=100; gracze_ob=0; gracze_ev=0; obiekty=0; loaded=false; view=App.GetDefaultView(); events=new EventComp; (*events).Set(sf::Event::KeyPressed,sf::Key::Escape); wynik_obl.SetFont(font); //wynik_obs.SetFont(font); wynik_obp.SetFont(font); Timer_ob1.SetFont(font); //Timer_ob2.SetFont(font); wynik_obl.SetSize(80); //wynik_obs.SetSize(80); wynik_obp.SetSize(80); wynik_obl.SetStyle(sf::String::Bold); //wynik_obs.SetStyle(sf::String::Bold); wynik_obp.SetStyle(sf::String::Bold); wynik_obl.SetText("0"); //wynik_obs.SetText(":"); wynik_obp.SetText("0"); wynik_obl.SetPosition(App.GetWidth()/4,wynik_obl.GetRect().GetHeight()/2); //wynik_obs.SetPosition(App.GetWidth()/2-wynik_obs.GetRect().GetWidth()/2,0); wynik_obp.SetPosition(App.GetWidth()*3/4,wynik_obp.GetRect().GetHeight()/2); wynik_obl.SetColor(sf::Color(30,30,250)); //wynik_obs.SetColor(sf::Color(250,30,30)); wynik_obp.SetColor(sf::Color(30,250,30)); wynik_obl.SetCenter(wynik_obl.GetRect().GetWidth()/2,wynik_obl.GetRect().GetHeight()/2); wynik_obp.SetCenter(wynik_obp.GetRect().GetWidth()/2,wynik_obp.GetRect().GetHeight()/2); Timer_ob1.SetSize(60); //Timer_ob2.SetSize(60); Timer_ob1.SetStyle(sf::String::Bold); //Timer_ob2.SetStyle(sf::String::Bold); Timer_ob1.SetText("00:00"); //Timer_ob2.SetText("00:00"); Timer_ob1.SetPosition(App.GetWidth()/2,wynik_obl.GetRect().GetHeight()/2); // wynik_obl zastosowany umyslnie. aby byly wzglednie wysrodkowane. Timer_ob1.SetCenter(Timer_ob1.GetRect().GetWidth()/2,Timer_ob1.GetRect().GetHeight()/2); //Timer_ob2.SetPosition(App.GetWidth()-Timer_ob2.GetRect().GetWidth(),0); Techdata.SetPosition(10,App.GetHeight()-40); }
void ScreenManager::init(sf::RenderWindow& app) { ScreenManager::_app = &app; ScreenManager::_screenLayout = Layout(sf::FloatRect(0,0,(float)app.GetWidth(),(float)app.GetHeight())); }
static void DrawLevel(const WadLevel_c &level, sf::RenderWindow& screen, uint32_t flags) { float scaleX, scaleY; float offsetX, offsetY; const Vertex_s &mapMin = level.GetMin(); const Vertex_s &mapMax = level.GetMax(); scaleX = (float)screen.GetWidth() / ((float)(mapMax.iX - mapMin.iX) * 1.05f); scaleY = (float)screen.GetHeight() / ((float)(mapMax.iY - mapMin.iY) * -1.05f); offsetX = -mapMin.iX * scaleX; offsetY = (-mapMin.iY * scaleY) + screen.GetHeight(); const uint32_t red = 0xFF0000FF; const uint32_t white = 0xFFFFFFFF; const uint32_t yellow = 0xFFFF00FF; const LineDef_s *lineDefs = level.GetLineDefs(); const size_t numLineDefs = level.GetNumLineDefs(); const Vertex_s *vertices = level.GetVertices(); for(size_t i = 0; i < numLineDefs; ++i) { const Vertex_s &a = vertices[lineDefs[i].iStartVertex]; const Vertex_s &b = vertices[lineDefs[i].iEndVertex]; float x1 = (a.iX * scaleX) + offsetX; float y1 = (a.iY * scaleY) + offsetY; float x2 = (b.iX * scaleX) + offsetX; float y2 = (b.iY * scaleY) + offsetY; sf::Color color = (lineDefs[i].iLeftSideDef < 0) ? sf::Color::White : sf::Color::Red; if (lineDefs[i].iSpecialType > 0) color = sf::Color::Yellow; //uint32_t color = (lineDefs[i].iLeftSideDef < 0) ? white : red; //color = lineDefs[i].iSpecialType > 0 ? yellow : color; //lineColor(screen, (int16_t)x1, (int16_t)y1, (int16_t)x2, (int16_t)y2, color); DrawLine(screen, x1, y1, x2, y2, 1.f, color); float midX = (a.iX + b.iX) / 2.0f; float midY = (a.iY + b.iY) / 2.0f; if(flags & DF_SHOW_LINE_SIDES) { Vector2d_s v(Vector2d_s(b.iX, b.iY), Vector2d_s(a.iX, a.iY)); v.Normalize(); v.Rotate90(); v.Scale(20.0f); v.Add(Vector2d_s(midX, midY)); x1 = (midX * scaleX) + offsetX; y1 = (midY * scaleY) + offsetY; x2 = (v.fX * scaleX) + offsetX; y2 = (v.fY * scaleY) + offsetY; DrawLine(screen, x1, y1, x2, y2, 1.f, color); } if(flags & DF_SHOW_VERTICES) { //filledCircleColor(screen, (int16_t)x1, (int16_t)y1, 1, 0x0000FFFF); //filledCircleColor(screen, (int16_t)x2, (int16_t)y2, 1, 0x0000FFFF); DrawCircle(screen, x1, y1,1.f, sf::Color(0,0,255)); DrawCircle(screen, x2, y2,1.f, sf::Color(0,0,255)); } } if(flags & DF_SHOW_SEGMENTS) { const Segment_s *segments = level.GetSegments(); const size_t numSegments = level.GetNumSegments(); for(size_t i = 0; i < numSegments; ++i) { const Vertex_s &a = vertices[segments[i].iStartVertex]; const Vertex_s &b = vertices[segments[i].iEndVertex]; float x1 = (a.iX * scaleX) + offsetX; float y1 = (a.iY * scaleY) + offsetY; float x2 = (b.iX * scaleX) + offsetX; float y2 = (b.iY * scaleY) + offsetY; DrawCircle(screen, x1, y1, 1.f, sf::Color(255,0,255)); DrawCircle(screen, x2, y2, 1.f, sf::Color(255,0,255)); //filledCircleColor(screen, (int16_t)x1, (int16_t)y1, 1, 0x00FF00FF); //filledCircleColor(screen, (int16_t)x2, (int16_t)y2, 1, 0x00FF00FF); } } if(flags & DF_SHOW_PARTITION_LINES) { const Node_s *nodes = level.GetNodes(); const size_t numNodes = level.GetNumNodes(); for(size_t i = 0; i < numNodes; ++i) { Vector2d_s a(nodes[i].iX, nodes[i].iY); Vector2d_s b(nodes[i].iCX, nodes[i].iCY); b.Add(a); float x1 = (a.fX * scaleX) + offsetX; float y1 = (a.fY * scaleY) + offsetY; float x2 = (b.fX * scaleX) + offsetX; float y2 = (b.fY * scaleY) + offsetY; DrawLine(screen, x1,y1,x2,y2,1.f, sf::Color(0,0,255)); //lineColor(screen, (int16_t)x1, (int16_t)y1, (int16_t)x2, (int16_t)y2, 0x0000FFFF); } } if(flags & DF_SHOW_SUBSECTORS) { const GLSegment5_s *segments = level.GetGLSegments(); const GLSubSector3_s *subSectors = level.GetGLSubSectors(); const size_t numSubSectors = level.GetNumGLSubSectors(); for(size_t i = 0; i < numSubSectors; ++i) { const GLSubSector3_s &sub = subSectors[i]; for(uint32_t j = 0; j < sub.iCount; ++j) { const GLSegment5_s ¤t = segments[sub.iFirstSeg+j]; Vector2d_s a = level.GetGLVertex(current.iStartVertex); Vector2d_s b = level.GetGLVertex(current.iEndVertex); float x1 = (a.fX * scaleX) + offsetX; float y1 = (a.fY * scaleY) + offsetY; float x2 = (b.fX * scaleX) + offsetX; float y2 = (b.fY * scaleY) + offsetY; DrawLine(screen, x1,y1,x2,y2,1.f,sf::Color(255,0,255)); //lineColor(screen, (int16_t)x1, (int16_t)y1, (int16_t)x2, (int16_t)y2, 0xFF00FFFF); } } } if(flags & DF_SHOW_THINGS) { const Thing_s *things = level.GetThings(); for(size_t i = 0, len = level.GetNumThings(); i < len; ++i) { float x1 = (things[i].iX * scaleX) + offsetX; float y1 = (things[i].iY * scaleY) + offsetY; //circleColor(screen, (int16_t)x1, (int16_t)y1, 2, yellow); DrawCircle(screen, x1, y1, 2.0, sf::Color::Yellow); } } }