]> git.vomp.tv Git - vompclient.git/blob - wpictureview.cc
Add tvscraper support and other image handling stuff to vomp
[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, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 */
21
22 #include "wpictureview.h"
23
24 #include "colour.h"
25 #include "remote.h"
26 #include "osd.h"
27 #include "movieinfo.h"
28 #include "seriesinfo.h"
29 #include <math.h>
30
31 WPictureView::WPictureView():
32 foreColour(DrawStyle::LIGHTTEXT)
33 {
34   cur_scroll_line=0;
35   rem_scroll_line=0;
36   const_height=0;
37 }
38
39 WPictureView::~WPictureView()
40 {
41 }
42
43
44
45 void WPictureView::setForegroundColour(const DrawStyle& fcolour)
46 {
47   foreColour = fcolour;
48 }
49
50 void WPictureView::draw()
51 {
52   Boxx::draw();
53   int fontHeight = getFontHeight();
54   float ypos = cur_scroll_line * (fontHeight*8.f);
55   ypos = -ypos;
56   float height = 0;
57
58   drawClippingRectangle(1,1,area.w-1,area.h-1);
59
60   list<Picture>::iterator itty=pictures.begin();
61   while (itty!=pictures.end())
62   {
63           // We now calculate the pictures in one row
64           list<Picture*> cur_pict;
65           float cur_width=0;
66           float max_height=const_height;
67
68
69           while (itty != pictures.end())
70           {
71                   if ((((*itty).w + cur_width+ 10.f) > area.w || const_height) && cur_pict.size() > 0) break;
72                   cur_width += 10 + (*itty).w;
73                   if (!const_height) max_height = max(max_height,(*itty).h);
74                   cur_pict.push_back(&(*itty));
75                   itty++;
76           }
77           // ok now we have a list of pictures, let's draw them
78           list<Picture*>::iterator citty=cur_pict.begin();
79           float xpos= (area.w - cur_width)*0.5f;
80           if (xpos < 0) xpos=0;
81           while (citty!=cur_pict.end())
82           {
83                   if (!const_height) {
84                           drawTVMedia((*citty)->media,
85                                           xpos, ypos + max_height /*- (*citty)->h*/,
86                                           (*citty)->w,
87                                           /*(*citty)->h*/0.f,BottomLeft);
88                   } else {
89                           if (!(*citty)->banner) {
90                                   drawTVMedia((*citty)->media,
91                                                   xpos+area.w*0.5f, ypos,
92                                                   0.f,
93                                                   const_height,TopMiddle);
94                           } else {
95                                   drawTVMedia((*citty)->media,
96                                                 xpos+area.w*0.5f, ypos,
97                                                 area.w-2.f,
98                                                 0.f,TopMiddle);
99                           }
100                   }
101                   xpos += (*citty)->w + 10.f;
102                   citty++;
103           }
104           ypos += max_height;
105           height += max_height;
106           bool caption1=false;
107           bool caption2=false;
108
109           citty=cur_pict.begin();
110           xpos= (area.w - cur_width)*0.5f;
111            if (xpos < 0) xpos=0;
112           while (citty!=cur_pict.end())
113           {
114                   if (!(*citty)->caption.empty())
115                   {
116                           drawTextCentre((*citty)->caption.c_str(), xpos + (*citty)->w*0.5f, ypos, foreColour);
117                           caption1 = true;
118                   }
119                   if (!(*citty)->caption2.empty())
120                   {
121                           drawTextCentre((*citty)->caption2.c_str(), xpos + (*citty)->w*0.5f, ypos + fontHeight*1.f, foreColour);
122                           caption2 = true;
123                   }
124                   xpos += (*citty)->w + 10.f;
125                   citty++;
126           }
127           if (caption1) {
128                   ypos +=fontHeight*1.f;
129                   height += fontHeight*1.f;
130           }
131           if (caption2) {
132                   ypos +=fontHeight*1.f;
133                   height += fontHeight*1.f;
134           }
135           ypos +=fontHeight*1.f;
136           height += fontHeight*1.f;
137
138   }
139   rem_scroll_line = ceil((height - area.h  -cur_scroll_line * fontHeight*8.f)/fontHeight/8.f);
140  // Log::getInstance()->log("WActorGallery", Log::DEBUG, "TVMedia rml %d",rem_scroll_line);
141   drawClippingRectangle(0,0,0,0);
142
143 }
144
145 void WPictureView::addPicture(TVMediaInfo& pict,  float pwidth, float pheight , bool banner, std::string caption, std::string caption2)
146 {
147         pictures.push_back(Picture(pict,pwidth,pheight, banner, caption,caption2));
148 }
149
150 int WPictureView::handleCommand(int command)
151 {
152   switch(command)
153   {
154     case Remote::DF_UP:
155     case Remote::UP:
156     {
157       if (cur_scroll_line > 0)
158       {
159           cur_scroll_line--;
160           rem_scroll_line++;
161           return 1;
162       }
163       else
164       {
165           return 4; // Signal return control to parent
166       }
167     }
168     case Remote::DF_DOWN:
169     case Remote::DOWN:
170     {
171         if (rem_scroll_line > 0)
172         {
173                 cur_scroll_line++;
174                 rem_scroll_line--;
175                 return 1;
176         } else {
177                 return 4;
178         }
179     }
180     case Remote::LEFT:
181     case Remote::RIGHT:
182     case Remote::DF_LEFT:
183     case Remote::DF_RIGHT:
184     {
185         return 5;
186     }
187
188   }
189
190   return 0;
191 }
192
193 WActorGallery::WActorGallery(Actors& actors)
194 {
195         Actors::iterator itty=actors.begin();
196         float pixelaspect=Osd::getInstance()->getPixelAspect();
197         while (itty!= actors.end())
198         {
199                 float aspect=((float)(*itty).thumb.height)/((float)(*itty).thumb.width)/pixelaspect;
200                 float width= 100;
201                 float height= aspect*width;
202
203                 //Log::getInstance()->log("WActorGallery", Log::DEBUG, "TVMedia %d %d %g", (*itty).thumb.width,(*itty).thumb.height,aspect);
204                 addPicture((*itty).thumb.info, width, height, false,(*itty).name,"\""+(*itty).role+"\"");
205                 itty++;
206         }
207 }
208
209 WArtworkGallery::WArtworkGallery(MovieInfo& movie)
210 {
211         float pixelaspect=Osd::getInstance()->getPixelAspect();
212         addTVMedia(movie.fanart);
213         addTVMedia(movie.collectionFanart);
214         addTVMedia(movie.collectionPoster);
215         addTVMedia(movie.poster);
216         const_height=400;
217 }
218
219 WArtworkGallery::WArtworkGallery(SeriesInfo& series)
220 {
221         addTVMedia(series.seasonposter);
222         addTVMedia(series.episode.image);
223
224         addTVMedias(series.banners, true);
225         addTVMedias(series.fanart);
226         addTVMedias(series.posters);
227         const_height=400;
228 }
229
230 void WArtworkGallery::addTVMedias(TVMedias& medias, bool banner)
231 {
232         if (medias.size()) {
233                 TVMedias::iterator titty=medias.begin();
234                 while (titty!=medias.end())
235                 {
236                         addTVMedia(*titty, banner);
237                         titty++;
238                 }
239
240         }
241 }
242
243 void WArtworkGallery::addTVMedia(TVMedia& media, bool banner)
244 {
245         if (media.width)
246                 addPicture(media.info, media.width, media.height, banner);
247 }