Graphics refactor finished
This commit is contained in:
parent
37b4993b70
commit
476da8bb92
12 changed files with 114 additions and 110 deletions
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#include "GUI.hpp"
|
||||
#include "Player.hpp"
|
||||
#include "GraphicApplication.hpp"
|
||||
|
||||
// 1) artworks
|
||||
// 2) how to easily add more songs?
|
||||
|
|
@ -13,36 +14,38 @@
|
|||
// 4) queue & repeat & shuffle...
|
||||
// 5) new database with history
|
||||
|
||||
void runApp() {
|
||||
using namespace tp;
|
||||
|
||||
class LibraryViewer : public Application {
|
||||
public:
|
||||
LibraryViewer() : gui(&library, &player) {
|
||||
library.loadJson(getHome() + "Library.json");
|
||||
library.checkExisting();
|
||||
|
||||
gui.updateTracks();
|
||||
}
|
||||
|
||||
void processFrame(EventHandler* eventHandler) override {
|
||||
auto rec = RectF{ { 0, 0 }, mWindow->getSize() };
|
||||
gui.proc(*eventHandler, rec, rec);
|
||||
}
|
||||
|
||||
void drawFrame(Canvas* canvas) override {
|
||||
gui.draw(*canvas);
|
||||
}
|
||||
|
||||
private:
|
||||
Player player;
|
||||
Library library;
|
||||
library.loadJson(getHome() + "Library.json");
|
||||
library.checkExisting();
|
||||
LibraryWidget<EventHandler, Canvas> gui;
|
||||
};
|
||||
|
||||
void runApp() {
|
||||
tp::GlobalGUIConfig config;
|
||||
tp::gGlobalGUIConfig = &config;
|
||||
|
||||
tp::LibraryWidget<tp::Window::Events, tp::Graphics::Canvas> gui(&library, &player);
|
||||
|
||||
auto window = tp::Window::createWindow(800, 600, "Window 1");
|
||||
|
||||
if (window) {
|
||||
while (!window->shouldClose()) {
|
||||
window->processEvents();
|
||||
|
||||
auto area = window->getCanvas().getAvaliableArea();
|
||||
|
||||
gui.proc(window->getEvents(), { area.x, area.y, area.z, area.w }, { area.x, area.y, area.z, area.w });
|
||||
gui.draw(window->getCanvas());
|
||||
|
||||
// tp::sleep(100);
|
||||
|
||||
window->draw();
|
||||
}
|
||||
}
|
||||
|
||||
tp::Window::destroyWindow(window);
|
||||
LibraryViewer lib;
|
||||
lib.run();
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
|
@ -54,8 +57,6 @@ int main() {
|
|||
return 1;
|
||||
}
|
||||
|
||||
tp::HeapAllocGlobal::disableCallstack();
|
||||
|
||||
runApp();
|
||||
|
||||
binModule.deinitialize();
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ namespace tp {
|
|||
|
||||
if (!mTrack) return;
|
||||
if (!areaParent.isOverlap(area)) return;
|
||||
if (area.isInside(events.getPos())) {
|
||||
if (area.isInside(events.getPointer())) {
|
||||
col.set({ 0.15f, 0.15f, 0.15f, 1.f });
|
||||
mSelected = events.isReleased();
|
||||
mSelected = events.isReleased(InputID::MOUSE1);
|
||||
} else {
|
||||
col.set({ 0.15f, 0.15f, 0.15f, 0.f });
|
||||
}
|
||||
|
|
@ -94,6 +94,7 @@ namespace tp {
|
|||
if (!this->mVisible) return;
|
||||
if (!mTrack) return;
|
||||
// canvas.rect(this->mArea, { 0.13f, 0.13f, 0.13f, 1.f }, 4.f);
|
||||
renderUI();
|
||||
}
|
||||
|
||||
void renderUI() {
|
||||
|
|
@ -207,11 +208,16 @@ namespace tp {
|
|||
mLibrary = (lib);
|
||||
mPlayer = (player);
|
||||
|
||||
updateTracks();
|
||||
|
||||
mCurrentTrackInfo.mPlayer = mPlayer;
|
||||
}
|
||||
|
||||
void updateTracks() {
|
||||
mTracks.clear();
|
||||
for (auto track : mLibrary->mTraks) {
|
||||
mTracks.append(TrackWidget<Events, Canvas>(&track.data()));
|
||||
}
|
||||
|
||||
mCurrentTrackInfo.mPlayer = mPlayer;
|
||||
}
|
||||
|
||||
void proc(const Events& events, const RectF& areaParent, const RectF& aArea) override {
|
||||
|
|
@ -219,11 +225,6 @@ namespace tp {
|
|||
this->mVisible = this->mArea.isOverlap(areaParent);
|
||||
if (!this->mVisible) return;
|
||||
|
||||
mCurrentTrackInfo.renderUI();
|
||||
mNeedRedraw = events.isEvent() || mCurrentTrackInfo.songFilter.IsActive();
|
||||
|
||||
if (!mNeedRedraw) return;
|
||||
|
||||
filter();
|
||||
|
||||
mSplitView.proc(events, this->mArea, this->mArea);
|
||||
|
|
@ -249,7 +250,6 @@ namespace tp {
|
|||
mSplitView.draw(canvas);
|
||||
mSongList.draw(canvas);
|
||||
mCurrentTrackInfo.draw(canvas);
|
||||
// mCurrentTrack.proc(canvas);
|
||||
}
|
||||
|
||||
void filter() {
|
||||
|
|
@ -292,7 +292,5 @@ namespace tp {
|
|||
ScrollableWindow<Events, Canvas> mSongList;
|
||||
TrackInfoWidget<Events, Canvas> mCurrentTrackInfo;
|
||||
TrackWidget<Events, Canvas> mCurrentTrack;
|
||||
|
||||
bool mNeedRedraw = false;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue