void TrailCircle::Draw() { static GuiImage* circleImg = 0; static GuiText text; if (!circleImg) { circleImg = new GuiImage; Texture* tex = (Texture*)TheResourceManager::Instance()->GetRes("circ1.png"); tex->SetFilter(AmjuGL::AMJU_TEXTURE_NICE); circleImg->SetTexture(tex); float aspect = (float)Screen::X() / (float)Screen::Y(); circleImg->SetSize(Vec2f(CIRCLE_SIZE, CIRCLE_SIZE * aspect)); text.SetSize(Vec2f(0.1f, 0.1f)); } const Colour BLACK(0, 0, 0, 1); const Colour WHITE(1, 1, 1, 1); const Colour RED(1, 0, 0, 1); circleImg->SetLocalPos(Vec2f(m_pos.x - CIRCLE_SIZE * 0.5f, m_pos.y + CIRCLE_SIZE * 0.5f)); PushColour(); MultColour(m_incorrect ? RED : (m_clicked ? BLACK : WHITE)); circleImg->Draw(); PopColour(); // Draw number/letter text.SetSize(Vec2f(0.2f, 0.1f)); text.SetJust(GuiText::AMJU_JUST_CENTRE); text.SetLocalPos(m_pos + Vec2f(-0.1f, 0.012f)); text.SetText(m_str); text.SetFgCol(m_clicked || m_incorrect ? WHITE : BLACK); text.Draw(); }
void BroadcastConsole::OnMsgRecv(const std::string& str) { // Discard if same as last msg if (!m_texts.empty()) { if (m_texts[0]->GetText() == str) { std::cout << "Discarding duplicate msg\n"; return; } } GuiText* text = new GuiText; text->SetIsMulti(true); text->SetTextSize(1.0f); // TODO CONFIG text->SetSize(Vec2f(2.0f, 0.1f)); // assume single line text->SetText(str); text->SizeToText(); text->SetFgCol(Colour(1, 1, 0, 1)); m_texts.push_front(text); static const unsigned int NUM_LINES = ROConfig()->GetInt("chat-max-lines", 10); if (m_texts.size() > NUM_LINES) { m_texts.pop_back(); } ReposText(); }
void GSMain::Draw2d() { AmjuGL::Viewport(0, 0, Screen::X(), Screen::Y()); TheHud::Instance()->Draw(); // Store scaled modelview matrix float mat[16]; AmjuGL::GetMatrix(AmjuGL::AMJU_MODELVIEW_MATRIX, mat); // Split screen -- draw all screens int numVps = TheViewportManager::Instance()->GetNumViewports(); for (int i = 0; i < numVps; i++) { AmjuGL::SetMatrixMode(AmjuGL::AMJU_MODELVIEW_MATRIX); AmjuGL::SetIdentity(); // Restore scaled mv matrix AmjuGL::MultMatrix(mat); TheViewportManager::Instance()->GetViewport(i)->Draw2d(); } m_gui->Draw(); // split screen line etc TheLurker::Instance()->Draw(); #ifdef GEKKO TheCursorManager::Instance()->Draw(); #endif #ifdef SHOW_INFO // TODO Switch on/off if (true) { static GuiText t; t.SetFgCol(Colour(1, 1, 1, 1)); t.SetBgCol(Colour(0, 0, 0, 1)); t.SetDrawBg(true); t.SetFontSize(0.8f); // TODO CONFIG t.SetIsMulti(true); t.SetLocalPos(Vec2f(-1.0f, -0.8f)); t.SetSize(Vec2f(1.0f, 0.2f)); t.SetJust(GuiText::AMJU_JUST_LEFT); float playerX = Player::GetPlayer(AMJU_P1)->GetPos().x; static std::string old; std::string s = "Depth: " + ToString((int)GetCurrentDepth()) + " X: " + ToString((int)playerX) + "\nNum Game Objects: " + ToString((int)TheGame::Instance()->GetGameObjects()->size()); if (old != s) { t.SetText(s); } old = s; t.Draw(); } #endif // SHOW_INFO }
virtual void Draw() { // Don't draw name of local player ? if (IsVisible() && m_player->GetId() != GetLocalPlayerId()) { //Assert(m_player->GetAABB()); //DrawAABB(*(m_player->GetAABB())); // Print name // TODO Do all these in one go, to minimise state changes AmjuGL::PushAttrib(AmjuGL::AMJU_BLEND | AmjuGL::AMJU_DEPTH_READ); AmjuGL::Enable(AmjuGL::AMJU_BLEND); AmjuGL::Disable(AmjuGL::AMJU_DEPTH_READ); GuiText text; text.SetTextSize(5.0f); // TODO CONFIG text.SetText(m_player->GetName()); static const float MAX_NAME_WIDTH = 4.0f; // minimise this to reduce overdraw - calc from text text.SetSize(Vec2f(MAX_NAME_WIDTH, 1.0f)); text.SetJust(GuiText::AMJU_JUST_CENTRE); //text.SetInverse(true); //text.SetDrawBg(true); text.SetFgCol(Colour(1, 1, 1, 1)); AmjuGL::PushMatrix(); Matrix m; m.SetIdentity(); // Reverse modelview rotation Matrix r; r.ModelView(); m = TransposeRot(r); Vec3f tr(m_combined[12], m_combined[13], m_combined[14]); m.TranslateKeepRotation(tr); AmjuGL::MultMatrix(m); static const float SCALE_FACTOR = 20.0f; float x = MAX_NAME_WIDTH * SCALE_FACTOR * -0.5f; AmjuGL::Translate(x, 60.0f, 0); // TODO CONFIG AmjuGL::Scale(SCALE_FACTOR, SCALE_FACTOR, 10); text.Draw(); AmjuGL::PopMatrix(); AmjuGL::PopAttrib(); } }
void LurkMsg::Set(const std::string& str, const Colour& fgCol, const Colour& bgCol, LurkPos lp, CommandFunc onFinished) { GuiText* text = new GuiText; if (lp == AMJU_CENTRE) { text->SetIsMulti(true); } text->SetTextSize(1.5f); // TODO CONFIG text->SetSize(Vec2f(1.6f, 0.1f)); // assume single line text->SetText(str); text->SizeToText(); text->SetFgCol(fgCol); Set(text, fgCol, bgCol, lp, onFinished); }
void Game::RunOneLoop() { #ifdef SHOW_FRAME_TIME static std::string fps; static int framesThisSec = 0; framesThisSec++; static int elapsed = 0; float e = TheTimer::Instance()->GetElapsedTime(); if ((int)e != elapsed) { elapsed = (int)e; fps = ToString(framesThisSec); framesThisSec = 0; } #ifdef WIN32 unsigned long start = GetTickCount(); #else // Get time taken to update/draw/flip, giving the 'real' FPS, not fixed to screen refresh rate timeval tbefore; gettimeofday(&tbefore, 0); #endif #endif // SHOW_FRAME_TIME Update(); #ifdef SHOW_FRAME_TIME #ifdef WIN32 unsigned long mid = GetTickCount(); #else // Get time taken to update/draw/flip, giving the 'real' FPS, not fixed to screen refresh rate timeval mid; gettimeofday(&mid, 0); #endif #endif // SHOW_FRAME_TIME Draw(); #ifdef SHOW_FRAME_TIME if (m_font) { #ifdef WIN32 unsigned long draw = GetTickCount() - mid; unsigned long update = mid - start; std::string s = "Draw: " + ToString((unsigned int)draw) + " update: " + ToString((unsigned int)update); #else timeval tafter; gettimeofday(&tafter, 0); double draw = tafter.tv_sec - mid.tv_sec + (tafter.tv_usec - mid.tv_usec) * 1e-6; double update = mid.tv_sec - tbefore.tv_sec + (mid.tv_usec - tbefore.tv_usec) * 1e-6; int idraw = (int)(draw * 1000.0f); int iupdate = (int)(update * 1000.0f); std::string s = std::string("Draw: ") + std::string((idraw < 10 ? "0" : "")) + ToString(idraw) + std::string("ms update: ") + std::string((iupdate < 10 ? "0" : "")) + ToString(iupdate) + "ms"; #endif s += " fps: " + fps; // Display time per frame static GuiText t; t.SetFont(m_font); t.SetScaleX(0.7f); t.SetFgCol(Colour(1, 1, 1, 1)); t.SetLocalPos(Vec2f(-1.0f, 1.0f)); t.SetSize(Vec2f(2.0f, 0.1f)); t.SetJust(GuiText::AMJU_JUST_LEFT); t.SetText(s); AmjuGL::PushAttrib(AmjuGL::AMJU_LIGHTING | AmjuGL::AMJU_TEXTURE_2D); AmjuGL::Disable(AmjuGL::AMJU_LIGHTING); AmjuGL::Enable(AmjuGL::AMJU_TEXTURE_2D); t.Draw(); AmjuGL::PopAttrib(); } #endif // SHOW_FRAME_TIME AmjuGL::Flip(); }