From 6872e29fe6d628acd95a5f5eded6f372102fea31 Mon Sep 17 00:00:00 2001 From: louis Date: Sat, 11 Apr 2015 16:21:33 +0200 Subject: added possibility to draw a debug grid in views --- views/displaymenurootview.c | 1 + views/view.c | 56 ++++++++++++++++++++++++++++++++++++++++++++- views/view.h | 2 ++ 3 files changed, 58 insertions(+), 1 deletion(-) (limited to 'views') diff --git a/views/displaymenurootview.c b/views/displaymenurootview.c index 7b514d7..a29f56d 100644 --- a/views/displaymenurootview.c +++ b/views/displaymenurootview.c @@ -422,6 +422,7 @@ cFont *cDisplayMenuRootView::GetTextAreaFont(void) { void cDisplayMenuRootView::Render(void) { if (!view) return; + view->DrawDebugGrid(); if (!view->DrawBackground()) { defaultBackgroundDrawn = true; DrawBackground(); diff --git a/views/view.c b/views/view.c index 09bae74..1680379 100644 --- a/views/view.c +++ b/views/view.c @@ -5,7 +5,7 @@ using namespace std; -cView::cView(cTemplateView *tmplView) : cPixmapContainer(tmplView->GetNumPixmaps()) { +cView::cView(cTemplateView *tmplView) : cPixmapContainer(tmplView->DrawGebugGrid() ? tmplView->GetNumPixmaps() + 1 : tmplView->GetNumPixmaps()) { this->tmplView = tmplView; tvScaled = tmplView->GetScalingWindow(scalingWindow); if (tvScaled) { @@ -42,6 +42,12 @@ cView::~cView() { } } +void cView::DrawDebugGrid(void) { + if (tmplView && tmplView->DrawGebugGrid()) { + DoDrawDebugGrid(); + } +} + void cView::Init(void) { viewInit = true; scrolling = false; @@ -483,6 +489,54 @@ void cView::DebugTokens(string viewElement, map *stringTokens, ma * Private Functions *****************************************************************/ +void cView::DoDrawDebugGrid(void) { + int stepsX = tmplView->DebugGridX(); + int stepsY = tmplView->DebugGridY(); + cRect osdSize = tmplView->GetOsdSize(); + tColor col = tmplView->DebugGridColor(); + tColor colFont = tmplView->DebugGridFontColor(); + + cRect size(0, 0, osdSize.Width(), osdSize.Height()); + //use last pixmap as grid pixmap + int numGridPixmap = NumPixmaps() - 1; + CreatePixmap(numGridPixmap, 7, size); + + int width = size.Width(); + int height = size.Height(); + float stepWidthX = (double)width / (double)stepsX; + float stepWidthY = (double)height / (double)stepsY; + int fontSize = height / stepsY / 5; + + for (int i = 0; i <= stepsX; i++) { + int x = (float)i * stepWidthX; + if (i==stepsX) + x = x-1; + cRect line(x, 0, 1, height); + DrawRectangle(numGridPixmap, line, col); + if (i==stepsX) + continue; + float percent = (float)i / (float)stepsX * 100.0; + cPoint textPosPerc(x+2, 2); + cPoint textPosAbs(x+2, fontSize + 4); + DrawText(numGridPixmap, textPosPerc, *cString::sprintf("%.1f%%", percent), colFont, 0x00000000, "vdrOsd", fontSize); + DrawText(numGridPixmap, textPosAbs, *cString::sprintf("%dpx", x), colFont, 0x00000000, "vdrOsd", fontSize); + } + for (int i = 0; i <= stepsY; i++) { + int y = (float)i * stepWidthY; + if (i==stepsY) + y = y-1; + cRect line(0, y, width, 1); + DrawRectangle(numGridPixmap, line, col); + if (i==0 || i==stepsY) + continue; + float percent = (float)i / (float)stepsY * 100.0; + cPoint textPosPerc(2, y + 2); + cPoint textPosAbs(2, y + fontSize + 4); + DrawText(numGridPixmap, textPosPerc, *cString::sprintf("%.1f%%", percent), colFont, 0x00000000, "vdrOsd", fontSize); + DrawText(numGridPixmap, textPosAbs, *cString::sprintf("%dpx", y), colFont, 0x00000000, "vdrOsd", fontSize); + } +} + void cView::DoFill(int num, cTemplateFunction *func) { tColor col = func->GetColorParameter(ptColor); Fill(num, col); diff --git a/views/view.h b/views/view.h index f81885f..e6ee909 100644 --- a/views/view.h +++ b/views/view.h @@ -13,6 +13,7 @@ class cViewElement; class cView : public cPixmapContainer { private: void Init(void); + void DoDrawDebugGrid(void); void DoFill(int num, cTemplateFunction *func); void DoDrawText(int num, cTemplateFunction *func, int x0 = 0, int y0 = 0); void DoDrawTextVertical(int num, cTemplateFunction *func, int x0 = 0, int y0 = 0); @@ -61,6 +62,7 @@ public: cView(cTemplateView *tmplView); cView(cTemplateViewElement *tmplViewElement); cView(cTemplateViewTab *tmplTab); + void DrawDebugGrid(void); virtual ~cView(); virtual void Stop(void); }; -- cgit v1.2.3