Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 |
void SongObject::refresh_time_lable() { std::chrono::milliseconds current = this->song.get_time_position(); this->time_lable->SetText(time_to_string(current, true)/*"00:00:00"*/); float fractrion = static_cast<float>(current.count()) / static_cast<float>(this->endtime.count()); this->time_prgressbar->SetFraction(fractrion/*1.0f*/); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
void MainClass::draw() { try { this->desktop.Update(1.0f); // Time 1 second this->render_window.clear(sf::Color{ 50, 50, 50 }); this->sfgui.Display(this->render_window); this->render_window.display(); } catch (std::exception &e) { std::cout << e.what() << std::endl; } } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
std::string SongObject::time_to_string(std::chrono::milliseconds time, bool mili) { std::stringstream out; std::chrono::milliseconds t = time; std::chrono::hours hour = std::chrono::duration_cast<std::chrono::hours>(t); t -= hour; std::chrono::minutes min = std::chrono::duration_cast<std::chrono::minutes>(t); t -= min; std::chrono::seconds sec = std::chrono::duration_cast<std::chrono::seconds>(t); t -= sec; if (hour > std::chrono::hours{ 0 }) out << hour.count() << ":"; if (min.count() < 10 && hour > std::chrono::hours{ 0 }) out << "0" << min.count() << ":"; else out << min.count() << ":"; if (sec.count() < 10) out << "0" << sec.count(); else out << sec.count(); if (hour <= std::chrono::hours{ 0 } && mili) out << ":" << static_cast<unsigned int>(t.count() / 100); return out.str(); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
#include <SFML\Graphics.hpp> #include <SFGUI\SFGUI.hpp> #include <SFGUI\Desktop.hpp> #include <SFGUI\Window.hpp> #include <SFGUI\Table.hpp> #include <SFGUI\Button.hpp> #include <SFGUI\Notebook.hpp> #include <SFGUI\Box.hpp> #include <SFGUI\Label.hpp> #include <SFGUI\Frame.hpp> #include <SFGUI\ScrolledWindow.hpp> #include <SFGUI\Renderer.hpp> #include <SFGUI\ProgressBar.hpp> int main() { sf::VideoMode video_mode{ 200, 200 }; sf::RenderWindow window{ video_mode, "Test" }; window.resetGLStates(); sfg::SFGUI sfgui; sfg::Desktop desktop; sf::Event event; sfg::Notebook::Ptr notebook = sfg::Notebook::Create(); sfg::ScrolledWindow::Ptr scroled_window = sfg::ScrolledWindow::Create(); sfg::Box::Ptr scenebox = sfg::Box::Create(sfg::Box::Orientation::HORIZONTAL); sfg::Box::Ptr box = sfg::Box::Create(sfg::Box::Orientation::VERTICAL); sfg::Frame::Ptr frame = sfg::Frame::Create(L"Test"); sfg::Table::Ptr table = sfg::Table::Create(); sfg::Button::Ptr button = sfg::Button::Create("Test"); sfg::ProgressBar::Ptr bar = sfg::ProgressBar::Create(); table->Attach(button, sf::Rect < sf::Uint32 > {0, 0, 2, 1}); table->Attach(bar, sf::Rect < sf::Uint32 > {1, 1, 1, 1}); frame->Add(table); frame->SetRequisition(sf::Vector2f{ 50.0f, 500.0f }); box->Pack(frame); scenebox->Pack(box); scroled_window->SetScrollbarPolicy(sfg::ScrolledWindow::HORIZONTAL_NEVER | sfg::ScrolledWindow::VERTICAL_ALWAYS); scroled_window->AddWithViewport(scenebox); scroled_window->SetRequisition(sf::Vector2f{ 50.0f, 500.0f }); notebook->AppendPage(scroled_window, sfg::Label::Create(L"Page 1")); notebook->SetRequisition(sf::Vector2f{ 50.0f, 500.0f }); desktop.Add(notebook); size_t frameCount = 0; while (window.isOpen()) { while (window.pollEvent(event)) { desktop.HandleEvent(event); if (event.type == sf::Event::Closed) { window.close(); } if (event.type == sf::Event::Resized) { } } button->SetLabel("Test"); bar->SetFraction(1.0f); desktop.Update(1.0f); // Time 1 second window.clear(sf::Color{ 50, 50, 50 }); sfgui.Display(window); window.display(); frameCount++; std::cout << frameCount << std::endl; } } |
Werbeanzeige