summaryrefslogtreecommitdiff
path: root/displaytracks.c
diff options
context:
space:
mode:
authorroot <root@maschine.(none)>2012-11-27 02:11:15 +0100
committerroot <root@maschine.(none)>2012-11-27 02:11:15 +0100
commit4b51af06327270caa4f38c31f28cdfbc1baabc4e (patch)
tree2556e7eb912d5f1352866924cfe3e6f3d2dc13bb /displaytracks.c
downloadskin-nopacity-4b51af06327270caa4f38c31f28cdfbc1baabc4e.tar.gz
skin-nopacity-4b51af06327270caa4f38c31f28cdfbc1baabc4e.tar.bz2
Initial push nOpacity 0.0.3
Diffstat (limited to 'displaytracks.c')
-rw-r--r--displaytracks.c184
1 files changed, 184 insertions, 0 deletions
diff --git a/displaytracks.c b/displaytracks.c
new file mode 100644
index 0000000..ab1add7
--- /dev/null
+++ b/displaytracks.c
@@ -0,0 +1,184 @@
+
+#include "displaytracks.h"
+
+cNopacityDisplayTracks::cNopacityDisplayTracks(const char *Title, int NumTracks, const char * const *Tracks) {
+ config.setDynamicValues();
+ initial = true;
+ currentIndex = -1;
+ numTracks = NumTracks;
+ FrameTime = config.tracksFrameTime;
+ FadeTime = config.tracksFadeTime;
+ SetGeometry();
+ CreatePixmaps();
+ CreateFonts();
+ CreateBackgroundImages();
+ DrawHeader(Title);
+ for (int i = 0; i < NumTracks; i++)
+ SetItem(Tracks[i], i, false);
+}
+
+cNopacityDisplayTracks::~cNopacityDisplayTracks() {
+ osd->DestroyPixmap(pixmapContainer);
+ osd->DestroyPixmap(pixmapHeader);
+ menuItems.Clear();
+ for (int i=0; i<2; i++)
+ cOsdProvider::DropImage(handleBackgrounds[i]);
+ delete font;
+ delete fontHeader;
+ delete osd;
+}
+
+cBitmap cNopacityDisplayTracks::bmStereo(audio_xpm);
+cBitmap cNopacityDisplayTracks::bmDolbyDigital(dolbydigital_xpm);
+
+void cNopacityDisplayTracks::SetGeometry(void) {
+ width = cOsd::OsdWidth() * config.tracksWidth / 100;
+ height = cOsd::OsdHeight() * config.tracksHeight / 100;
+ if (!height%(numTracks + 1)) {
+ height += numTracks + 1 - height%(numTracks + 1);
+ }
+ menuItemWidth = width - 4;
+ menuItemHeight = (height - 2*(numTracks + 1)) / (numTracks + 1) - 1;
+
+ int top, left;
+ switch(config.tracksPosition) {
+ case 0: //middle bottom
+ top = cOsd::OsdHeight() - cOsd::OsdTop() - height - config.tracksBorderHorizontal;
+ left = (cOsd::OsdWidth() - width) / 2;
+ break;
+ case 1: //left bottom
+ top = cOsd::OsdHeight() - cOsd::OsdTop() - height - config.tracksBorderHorizontal;
+ left = cOsd::OsdLeft();
+ break;
+ case 2: //left middle
+ top = (cOsd::OsdHeight() - height) / 2;
+ left = cOsd::OsdLeft() + config.tracksBorderVertical;
+ break;
+ case 3: //left top
+ top = cOsd::OsdTop() + config.tracksBorderHorizontal;
+ left = cOsd::OsdLeft() + config.tracksBorderVertical;
+ break;
+ case 4: //top middle
+ top = cOsd::OsdTop() + config.tracksBorderHorizontal;
+ left = (cOsd::OsdWidth() - width) / 2;
+ break;
+ case 5: //top right
+ top = cOsd::OsdTop() + config.tracksBorderHorizontal;
+ left = cOsd::OsdWidth() - cOsd::OsdLeft() - width - config.tracksBorderVertical;
+ break;
+ case 6: //right middle
+ top = (cOsd::OsdHeight() - height) / 2;
+ left = cOsd::OsdWidth() - cOsd::OsdLeft() - width - config.tracksBorderVertical;
+ break;
+ case 7: //right bottom
+ top = cOsd::OsdHeight() - cOsd::OsdTop() - height - config.tracksBorderHorizontal;
+ left = cOsd::OsdWidth() - cOsd::OsdLeft() - width - config.tracksBorderVertical;
+ break;
+ default: //middle bottom
+ top = cOsd::OsdHeight() - cOsd::OsdTop() - height - config.tracksBorderHorizontal;
+ left = (cOsd::OsdWidth() - width) / 2;
+ break;
+ }
+ osd = CreateOsd(left, top, width, height);
+}
+
+void cNopacityDisplayTracks::CreatePixmaps(void) {
+ pixmapContainer = osd->CreatePixmap(1, cRect(0, 0, width, height));
+ pixmapHeader = osd->CreatePixmap(2, cRect(2, 2, menuItemWidth, menuItemHeight));
+ if (config.tracksFadeTime) {
+ pixmapContainer->SetAlpha(0);
+ pixmapHeader->SetAlpha(0);
+ }
+}
+
+void cNopacityDisplayTracks::CreateFonts(void) {
+ font = cFont::CreateFont(config.fontName, menuItemHeight/3 + config.fontTracks);
+ fontHeader = cFont::CreateFont(config.fontName, menuItemHeight/2 + config.fontTracksHeader);
+}
+
+void cNopacityDisplayTracks::CreateBackgroundImages(void) {
+ cImageLoader imgLoader;
+ imgLoader.DrawBackground(Theme.Color(clrMenuItem), Theme.Color(clrMenuItemBlend), menuItemWidth-2, menuItemHeight-2);
+ handleBackgrounds[0] = cOsdProvider::StoreImage(imgLoader.GetImage());
+ imgLoader.DrawBackground(Theme.Color(clrMenuItemHigh), Theme.Color(clrMenuItemHighBlend), menuItemWidth-2, menuItemHeight-2);
+ handleBackgrounds[1] = cOsdProvider::StoreImage(imgLoader.GetImage());
+}
+
+void cNopacityDisplayTracks::DrawHeader(const char *Title) {
+ pixmapContainer->Fill(Theme.Color(clrMenuBorder));
+ pixmapContainer->DrawRectangle(cRect(1, 1, width-2, height-2), Theme.Color(clrMenuBack));
+
+ pixmapHeader->Fill(Theme.Color(clrMenuItem));
+ pixmapHeader->DrawImage(cPoint(1, 1), handleBackgrounds[0]);
+ pixmapIcon = osd->CreatePixmap(3, cRect(2, 2, menuItemHeight-2, menuItemHeight-2));
+ pixmapIcon->Fill(clrTransparent);
+ cImageLoader imgLoader;
+ if (imgLoader.LoadIcon("tracks", menuItemHeight-6)) {
+ pixmapIcon->DrawImage(cPoint(3, 3), imgLoader.GetImage());
+ }
+ pixmapHeader->DrawText(cPoint((width - fontHeader->Width(Title)) / 2, (menuItemHeight - fontHeader->Height()) / 2), Title, Theme.Color(clrTracksFontHead), clrTransparent, fontHeader);
+}
+
+void cNopacityDisplayTracks::SetItem(const char *Text, int Index, bool Current) {
+ cNopacityMenuItem *item;
+ item = new cNopacityTrackMenuItem(osd, Text, Current);
+ item->SetFont(font);
+ item->CreatePixmap(menuItemHeight+5, 2, Index, menuItemWidth, menuItemHeight);
+ item->SetBackgrounds(handleBackgrounds);
+ menuItems.Add(item);
+ item->Render();
+}
+
+void cNopacityDisplayTracks::SetTrack(int Index, const char * const *Tracks) {
+ cNopacityMenuItem *item;
+ if (currentIndex >= 0) {
+ item = menuItems.Get(currentIndex);
+ item->SetCurrent(false);
+ item->Render();
+ }
+ item = menuItems.Get(Index);
+ item->SetCurrent(true);
+ item->Render();
+ currentIndex = Index;
+}
+
+void cNopacityDisplayTracks::SetAudioChannel(int AudioChannel) {
+ cBitmap *bm = NULL;
+ switch (AudioChannel) {
+ case -1: bm = &bmDolbyDigital; break;
+ case 0: bm = &bmStereo; break;
+ default: ;
+ }
+ if (bm)
+ pixmapHeader->DrawBitmap(cPoint(width - bm->Width() - 10, (menuItemHeight - bm->Width()) / 2), *bm, Theme.Color(clrChannelSymbolOn), Theme.Color(clrMenuBack));
+}
+
+void cNopacityDisplayTracks::Flush(void) {
+ if (initial)
+ if (config.tracksFadeTime)
+ Start();
+ initial = false;
+ osd->Flush();
+}
+
+void cNopacityDisplayTracks::Action(void) {
+ uint64_t Start = cTimeMs::Now();
+ while (true) {
+ uint64_t Now = cTimeMs::Now();
+ cPixmap::Lock();
+ double t = min(double(Now - Start) / FadeTime, 1.0);
+ int Alpha = t * ALPHA_OPAQUE;
+ pixmapContainer->SetAlpha(Alpha);
+ pixmapHeader->SetAlpha(Alpha);
+ for (cNopacityMenuItem *item = menuItems.First(); item; item = menuItems.Next(item)) {
+ item->SetAlpha(Alpha);
+ }
+ osd->Flush();
+ cPixmap::Unlock();
+ int Delta = cTimeMs::Now() - Now;
+ if (Delta < FrameTime)
+ cCondWait::SleepMs(FrameTime - Delta);
+ if ((int)(Now - Start) > FadeTime)
+ break;
+ }
+} \ No newline at end of file