]> git.vomp.tv Git - vompclient.git/blob - wpictureview.cc
Bitmap and VPictureBanner CWFs
[vompclient.git] / wpictureview.cc
1 /*
2     Copyright 2005 Brian Walton (WTextBox)
3     Copyright 2014 Marten Richter (WPictureView)
4
5     This file is part of VOMP.
6
7     VOMP is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     VOMP is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
19 */
20
21 #include <math.h>
22 #include <algorithm>
23
24 #include "colour.h"
25 #include "input.h"
26 #include "osd.h"
27 #include "movieinfo.h"
28 #include "seriesinfo.h"
29
30 #include "wpictureview.h"
31
32 WPictureView::WPictureView():
33 foreColour(DrawStyle::LIGHTTEXT)
34 {
35   cur_scroll_line=0;
36   rem_scroll_line=0;
37   const_height=0;
38 }
39
40 WPictureView::~WPictureView()
41 {
42 }
43
44 void WPictureView::setForegroundColour(const DrawStyle& fcolour)
45 {
46   foreColour = fcolour;
47 }
48
49 void WPictureView::draw()
50 {
51   Boxx::draw();
52   int fontHeight = getFontHeight();
53   float ypos = cur_scroll_line * (fontHeight*8.f);
54   ypos = -ypos;
55   float height = 0;
56
57   drawClippingRectangle(1,1,area.w-1,area.h-1);
58
59   std::list<Picture>::iterator itty=pictures.begin();
60   while (itty!=pictures.end())
61   {
62           // We now calculate the pictures in one row
63           std::list<Picture*> cur_pict;
64           float cur_width=0;
65           float max_height=const_height;
66
67
68           while (itty != pictures.end())
69           {
70                   if ((((*itty).w + cur_width+ 10.f) > area.w || const_height) && cur_pict.size() > 0) break;
71                   cur_width += 10 + (*itty).w;
72                   if (!const_height) max_height = std::max(max_height,(*itty).h);
73                   cur_pict.push_back(&(*itty));
74                   itty++;
75           }
76           // ok now we have a list of pictures, let's draw them
77           std::list<Picture*>::iterator citty=cur_pict.begin();
78           float xpos= (area.w - cur_width)*0.5f;
79           if (xpos < 0) xpos=0;
80           while (citty!=cur_pict.end())
81           {
82                   if (!const_height) {
83                           drawTVMedia((*citty)->media,
84                                           xpos, ypos + max_height /*- (*citty)->h*/,
85                                           (*citty)->w,
86                                           /*(*citty)->h*/0.f,BottomLeft);
87                   } else {
88                           if (!(*citty)->banner) {
89                                   drawTVMedia((*citty)->media,
90                                                   xpos+area.w*0.5f, ypos,
91                                                   0.f,
92                                                   const_height,TopMiddle);
93                           } else {
94                                   drawTVMedia((*citty)->media,
95                                                 xpos+area.w*0.5f, ypos,
96                                                 area.w-2.f,
97                                                 0.f,TopMiddle);
98                           }
99                   }
100                   xpos += (*citty)->w + 10.f;
101                   citty++;
102           }
103           ypos += max_height;
104           height += max_height;
105           bool caption1=false;
106           bool caption2=false;
107
108           citty=cur_pict.begin();
109           xpos= (area.w - cur_width)*0.5f;
110            if (xpos < 0) xpos=0;
111           while (citty!=cur_pict.end())
112           {
113                   if (!(*citty)->caption.empty())
114                   {
115                           drawTextCentre((*citty)->caption.c_str(), (int)(xpos + (*citty)->w*0.5f), (int)ypos, foreColour);
116                           caption1 = true;
117                   }
118                   if (!(*citty)->caption2.empty())
119                   {
120                           drawTextCentre((*citty)->caption2.c_str(), (int)(xpos + (*citty)->w*0.5f), (int)(ypos + fontHeight*1.f), foreColour);
121                           caption2 = true;
122                   }
123                   xpos += (*citty)->w + 10.f;
124                   citty++;
125           }
126           if (caption1) {
127                   ypos +=fontHeight*1.f;
128                   height += fontHeight*1.f;
129           }
130           if (caption2) {
131                   ypos +=fontHeight*1.f;
132                   height += fontHeight*1.f;
133           }
134           ypos +=fontHeight*1.f;
135           height += fontHeight*1.f;
136
137   }
138   rem_scroll_line = (UINT)ceil((height - area.h  -cur_scroll_line * fontHeight*8.f)/fontHeight/8.f);
139  // Log::getInstance()->log("WActorGallery", Log::DEBUG, "TVMedia rml %d",rem_scroll_line);
140   drawClippingRectangle(0,0,0,0);
141
142 }
143
144 void WPictureView::addPicture(TVMediaInfo& pict,  float pwidth, float pheight , bool banner, std::string caption, std::string caption2)
145 {
146         pictures.push_back(Picture(pict,pwidth,pheight, banner, caption,caption2));
147 }
148
149 int WPictureView::handleCommand(int command)
150 {
151   switch(command)
152   {
153     case Input::UP:
154     {
155       if (cur_scroll_line > 0)
156       {
157           cur_scroll_line--;
158           rem_scroll_line++;
159           return 1;
160       }
161       else
162       {
163           return 4; // Signal return control to parent
164       }
165     }
166     case Input::DOWN:
167     {
168         if (rem_scroll_line > 0)
169         {
170                 cur_scroll_line++;
171                 rem_scroll_line--;
172                 return 1;
173         } else {
174                 return 4;
175         }
176     }
177     case Input::LEFT:
178     case Input::RIGHT:
179     {
180         return 5;
181     }
182
183   }
184
185   return 0;
186 }
187
188
189 bool WPictureView::mouseAndroidScroll(int x, int y, int sx, int sy)
190 {
191         if ((x - getRootBoxOffsetX()) >= 0 && (y - getRootBoxOffsetY()) >= 0
192                 && (x - getRootBoxOffsetX()) <= (int)area.w && (y - getRootBoxOffsetY()) <= (int)area.h)
193         {
194                 int change = -sy / 120;
195                 if (change < 0) {
196                         int rel_change = min(cur_scroll_line, -change);
197                         cur_scroll_line -= rel_change;
198                         rem_scroll_line += rel_change;
199                 }
200                 else if (change > 0) {
201                         int rel_change = min(rem_scroll_line, change);
202                         cur_scroll_line += rel_change;
203                         rem_scroll_line -= rel_change;
204                 }
205                 return true;
206         }
207         return false;
208
209 }
210
211 WActorGallery::WActorGallery(Actors& actors)
212 {
213         Actors::iterator itty=actors.begin();
214         float pixelaspect=Osd::getInstance()->getPixelAspect();
215         while (itty!= actors.end())
216         {
217                 float aspect=((float)(*itty).thumb.height)/((float)(*itty).thumb.width)/pixelaspect;
218                 float width= 100;
219                 float height= aspect*width;
220
221                 //Log::getInstance()->log("WActorGallery", Log::DEBUG, "TVMedia %d %d %g", (*itty).thumb.width,(*itty).thumb.height,aspect);
222                 addPicture((*itty).thumb.info, width, height, false,(*itty).name,"\""+(*itty).role+"\"");
223                 itty++;
224         }
225 }
226
227 WArtworkGallery::WArtworkGallery(MovieInfo& movie)
228 {
229 //      float pixelaspect=Osd::getInstance()->getPixelAspect();
230         addTVMedia(movie.fanart);
231         addTVMedia(movie.collectionFanart);
232         addTVMedia(movie.collectionPoster);
233         addTVMedia(movie.poster);
234         const_height=400;
235 }
236
237 WArtworkGallery::WArtworkGallery(SeriesInfo& series)
238 {
239         addTVMedia(series.seasonposter);
240         addTVMedia(series.episode.image);
241
242         addTVMedias(series.banners, true);
243         addTVMedias(series.fanart);
244         addTVMedias(series.posters);
245         const_height=400;
246 }
247
248 void WArtworkGallery::addTVMedias(TVMedias& medias, bool banner)
249 {
250         if (medias.size()) {
251                 TVMedias::iterator titty=medias.begin();
252                 while (titty!=medias.end())
253                 {
254                         addTVMedia(*titty, banner);
255                         titty++;
256                 }
257
258         }
259 }
260
261 void WArtworkGallery::addTVMedia(TVMedia& media, bool banner)
262 {
263         if (media.width)
264                 addPicture(media.info, media.width, media.height, banner);
265 }