Statistics
| Branch: | Revision:

chunker-player / chunker_player / player_gui.c @ 10c75ef7

History | View | Annotate | Download (16.1 KB)

1
#include "player_gui.h"
2
// #include "player_commons.h"
3

    
4
SDL_Surface *ChannelTitleSurface = NULL;
5
SDL_Surface *StatisticsSurface = NULL;
6
SDL_Rect ChannelTitleRect, StatisticsRect;
7
SDL_Color ChannelTitleColor = { 255, 255, 255 }, StatisticsColor = { 255, 255, 255 }; ;
8
SDL_Color ChannelTitleBgColor = { 0, 0, 0 }, StatisticsBgColor = { 0, 0, 0 };
9
TTF_Font *MainFont = NULL;
10
TTF_Font *StatisticsFont = NULL;
11

    
12
int ChunkerPlayerGUI_Init()
13
{
14
        // some initializations
15
        ratio = DEFAULT_RATIO;
16
        FullscreenWidth = 0;
17
        FullscreenHeight = 0;
18
        
19
        UpdateOverlaySize(ratio, DEFAULT_WIDTH, DEFAULT_HEIGHT);
20
        
21
        if(!SilentMode)
22
                SetupGUI();
23
        
24
        return 0;
25
}
26

    
27
void SetVideoMode(int width, int height, int fullscreen)
28
{
29
        // printf("SetVideoMode(%d, %d, %d)\n", width, height, fullscreen);
30
        SDL_LockMutex(OverlayMutex);
31

    
32
        if(fullscreen)
33
        {
34
#ifndef __DARWIN__
35
                MainScreen = SDL_SetVideoMode(width, height, 0, SDL_SWSURFACE | SDL_NOFRAME | SDL_FULLSCREEN);
36
#else
37
                MainScreen = SDL_SetVideoMode(width, height, 24, SDL_SWSURFACE | SDL_NOFRAME | SDL_FULLSCREEN);
38
#endif
39
        }
40
        else
41
        {
42
#ifndef __DARWIN__
43
                MainScreen = SDL_SetVideoMode(width, height, 0, SDL_SWSURFACE | SDL_RESIZABLE);
44
#else
45
                MainScreen = SDL_SetVideoMode(width, height, 24, SDL_SWSURFACE | SDL_RESIZABLE);
46
#endif
47
        }
48

    
49
        if(!MainScreen) {
50
                fprintf(stderr, "SDL_SetVideoMode returned null: could not set video mode - exiting\n");
51
                exit(1);
52
        }
53
        SDL_UnlockMutex(OverlayMutex);
54
}
55

    
56
void ChunkerPlayerGUI_HandleResize(int resize_w, int resize_h)
57
{
58
        // printf("ChunkerPlayerGUI_HandleResize(%d, %d)\n", resize_w, resize_h);
59
        SetVideoMode(resize_w, resize_h, FullscreenMode?1:0);
60
        
61
        window_width = resize_w;
62
        window_height = resize_h;
63
        
64
        // update the overlay surface size, mantaining the aspect ratio
65
        UpdateOverlaySize(ratio, resize_w, resize_h);
66
        
67
        // update each button coordinates
68
        int i;
69
        for(i=0; i<NBUTTONS; i++)
70
        {
71
                if(Buttons[i].XOffset > 0)
72
                        Buttons[i].ButtonIconBox.x = Buttons[i].XOffset;
73
                else
74
                        Buttons[i].ButtonIconBox.x = (resize_w + Buttons[i].XOffset);
75
                        
76
                Buttons[i].ButtonIconBox.y = resize_h - Buttons[i].ButtonIconBox.h - (BUTTONS_LAYER_OFFSET/2);
77
        }
78
        
79
        RedrawButtons();
80
        RedrawChannelName();
81
}
82

    
83
void ChunkerPlayerGUI_HandleGetFocus()
84
{
85
        RedrawButtons();
86
        RedrawChannelName();
87
}
88

    
89
void ChunkerPlayerGUI_HandleMouseMotion(int x, int y)
90
{
91
        int i;
92
        for(i=0; i<NBUTTONS; i++)
93
        {
94
                //If the mouse is over the button
95
                if(
96
                        ( x > Buttons[i].ButtonIconBox.x ) && ( x < Buttons[i].ButtonIconBox.x + Buttons[i].ButtonIcon->w )
97
                        && ( y > Buttons[i].ButtonIconBox.y ) && ( y < Buttons[i].ButtonIconBox.y + Buttons[i].ButtonIcon->h )
98
                )
99
                {
100
                        Buttons[i].Hover = 1;
101
                        SDL_SetCursor(handCursor);
102
                        break;
103
                }
104
                
105
                else
106
                {
107
                        Buttons[i].Hover = 0;
108
                        SDL_SetCursor(defaultCursor);
109
                }
110
        }
111
}
112

    
113
void ChunkerPlayerGUI_HandleLButton(int x, int y)
114
{
115
        int i;
116
        for(i=0; i<NBUTTONS; i++)
117
        {
118
                //If the mouse is over the button
119
                if(
120
                        ( x > Buttons[i].ButtonIconBox.x ) && ( x < Buttons[i].ButtonIconBox.x + Buttons[i].ButtonIcon->w )
121
                        && ( y > Buttons[i].ButtonIconBox.y ) && ( y < Buttons[i].ButtonIconBox.y + Buttons[i].ButtonIcon->h )
122
                )
123
                {
124
                        Buttons[i].LButtonUpCallback();
125
                        break;
126
                }
127
        }
128
}
129

    
130
void ChunkerPlayerGUI_HandleKey()
131
{
132
        static Uint32 LastTime=0;
133
        static int LastKey=-1;
134

    
135
        Uint32 Now=SDL_GetTicks();
136
        Uint8* keystate=SDL_GetKeyState(NULL);
137
        if(keystate[SDLK_ESCAPE] &&
138
          (LastKey!=SDLK_ESCAPE || (LastKey==SDLK_ESCAPE && (Now-LastTime>1000))))
139
        {
140
                LastKey=SDLK_ESCAPE;
141
                LastTime=Now;
142
                quit=1;
143
        }
144
}
145

    
146
void ChunkerPlayerGUI_Close()
147
{
148
        if(ChannelTitleSurface != NULL)
149
                SDL_FreeSurface( ChannelTitleSurface );
150
        
151
        if(StatisticsSurface != NULL)
152
                SDL_FreeSurface( StatisticsSurface );
153
        
154
        TTF_CloseFont( MainFont );
155
        TTF_CloseFont( StatisticsFont );
156
        TTF_Quit();
157
        IMG_Quit();
158
}
159

    
160
void RedrawButtons()
161
{
162
        int i;
163
        for(i=0; i<NBUTTONS; i++)
164
        {
165
                if(Buttons[i].Visible)
166
                {
167
                        if(!Buttons[i].Hover)
168
                        {
169
                                SDL_LockMutex(OverlayMutex);
170
                                SDL_BlitSurface(Buttons[i].ButtonIcon, NULL, MainScreen, &Buttons[i].ButtonIconBox);
171
                                SDL_UpdateRects(MainScreen, 1, &Buttons[i].ButtonIconBox);
172
                                SDL_UnlockMutex(OverlayMutex);
173
                        }
174
                        else
175
                        {
176
                                SDL_LockMutex(OverlayMutex);
177
                                SDL_BlitSurface(Buttons[i].ButtonHoverIcon, NULL, MainScreen, &(Buttons[i].ButtonIconBox));
178
                                SDL_UpdateRects(MainScreen, 1, &(Buttons[i].ButtonIconBox));
179
                                SDL_UnlockMutex(OverlayMutex);
180
                        }
181
                }
182
        }
183
}
184

    
185
void RedrawChannelName()
186
{
187
        if(ChannelTitleSurface != NULL)
188
        {
189
                ChannelTitleRect.w = ChannelTitleSurface->w;
190
                ChannelTitleRect.h = ChannelTitleSurface->h;
191
                ChannelTitleRect.x = ((FullscreenMode?FullscreenWidth:window_width) - ChannelTitleRect.w)/2;
192
                ChannelTitleRect.y = Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIconBox.y+5;
193
                SDL_LockMutex(OverlayMutex);
194
                SDL_BlitSurface(ChannelTitleSurface, NULL, MainScreen, &ChannelTitleRect);
195
                SDL_UpdateRects(MainScreen, 1, &ChannelTitleRect);
196
                SDL_UnlockMutex(OverlayMutex);
197
        }
198
}
199

    
200
void ChunkerPlayerGUI_ToggleFullscreen()
201
{
202
        int i;
203
        //If the screen is windowed
204
        if( !FullscreenMode )
205
        {
206
                // printf("SETTING FULLSCREEN ON\n");
207
                SetVideoMode(FullscreenWidth, FullscreenHeight, 1);
208
                
209
                // update the overlay surface size, mantaining the aspect ratio
210
                UpdateOverlaySize(ratio, FullscreenWidth, FullscreenHeight);
211
                
212
                // update each button coordinates
213
                for(i=0; i<NBUTTONS; i++)
214
                {
215
                        if(Buttons[i].XOffset > 0)
216
                                Buttons[i].ButtonIconBox.x = Buttons[i].XOffset;
217
                        else
218
                                Buttons[i].ButtonIconBox.x = (FullscreenWidth + Buttons[i].XOffset);
219
                                
220
                        Buttons[i].ButtonIconBox.y = FullscreenHeight - Buttons[i].ButtonIconBox.h - (BUTTONS_LAYER_OFFSET/2);
221
                }
222

    
223
                //Set the window state flag
224
                FullscreenMode = 1;
225
                
226
                Buttons[FULLSCREEN_BUTTON_INDEX].Visible = 0;
227
                Buttons[NO_FULLSCREEN_BUTTON_INDEX].Visible = 1;
228
        }
229
        
230
        //If the screen is fullscreen
231
        else
232
        {
233
                // printf("ToggleFullscreen callback, setting WINDOWED\n");
234
                SetVideoMode(window_width, window_height, 0);
235
                
236
                // update the overlay surface size, mantaining the aspect ratio
237
                UpdateOverlaySize(ratio, window_width, window_height);
238
                
239
                // update each button coordinates
240
                for(i=0; i<NBUTTONS; i++)
241
                {
242
                        if(Buttons[i].XOffset > 0)
243
                                Buttons[i].ButtonIconBox.x = Buttons[i].XOffset;
244
                        else
245
                                Buttons[i].ButtonIconBox.x = (window_width + Buttons[i].XOffset);
246
                                
247
                        Buttons[i].ButtonIconBox.y = window_height - Buttons[i].ButtonIconBox.h - (BUTTONS_LAYER_OFFSET/2);
248
                }
249
                
250
                //Set the window state flag
251
                FullscreenMode = 0;
252
                
253
                Buttons[FULLSCREEN_BUTTON_INDEX].Visible = 1;
254
                Buttons[NO_FULLSCREEN_BUTTON_INDEX].Visible = 0;
255
        }
256

    
257
        RedrawButtons();
258
        RedrawChannelName();
259
}
260

    
261
void AspectRatioResize(float aspect_ratio, int width, int height, int* out_width, int* out_height)
262
{
263
        int h,w,x,y;
264
        h = (int)((float)width/aspect_ratio);
265
        if(h<=height)
266
        {
267
                w = width;
268
        }
269
        else
270
        {
271
                w = (int)((float)height*aspect_ratio);
272
                h = height;
273
        }
274
        *out_width = w;
275
        *out_height = h;
276
}
277

    
278
/**
279
 * Updates the overlay surface size, mantaining the aspect ratio
280
 */
281
void UpdateOverlaySize(float aspect_ratio, int width, int height)
282
{
283
        // printf("UpdateOverlaySize(%f, %d, %d)\n", aspect_ratio, width, height);
284
        height -= (BUTTONS_LAYER_OFFSET + BUTTONS_CONTAINER_HEIGHT);
285
        // height -= (BUTTONS_LAYER_OFFSET + BUTTONS_CONTAINER_HEIGHT + STATS_BOX_HEIGHT);
286
        int h = 0, w = 0, x, y;
287
        AspectRatioResize(aspect_ratio, width, height, &w, &h);
288
        x = (width - w) / 2;
289
        y = (height - h) / 2;
290
        SDL_LockMutex(OverlayMutex);
291
        OverlayRect.x = x;
292
        OverlayRect.y = y;
293
        OverlayRect.w = w;
294
        OverlayRect.h = h;
295
        SDL_UnlockMutex(OverlayMutex);
296
}
297

    
298
void GetScreenSizeFromOverlay(int overlayWidth, int overlayHeight, int* screenWidth, int* screenHeight)
299
{
300
        *screenHeight = overlayHeight + (BUTTONS_LAYER_OFFSET + BUTTONS_CONTAINER_HEIGHT);
301
        *screenWidth = overlayWidth;
302
}
303

    
304
/* From SDL documentation. */
305
SDL_Cursor *InitSystemCursor(const char *image[])
306
{
307
        int i, row, col;
308
        Uint8 data[4*32];
309
        Uint8 mask[4*32];
310
        int hot_x, hot_y;
311

    
312
        i = -1;
313
        for ( row=0; row<32; ++row ) {
314
                for ( col=0; col<32; ++col ) {
315
                        if ( col % 8 ) {
316
                                data[i] <<= 1;
317
                                mask[i] <<= 1;
318
                        } else {
319
                                ++i;
320
                                data[i] = mask[i] = 0;
321
                        }
322
                        
323
                        switch (image[4+row][col]) {
324
                                case ' ':
325
                                        data[i] |= 0x01;
326
                                        mask[i] |= 0x01;
327
                                        break;
328
                                case '.':
329
                                        mask[i] |= 0x01;
330
                                        break;
331
                                case 'X':
332
                                        break;
333
                        }
334
                }
335
        }
336
        
337
        sscanf(image[4+row], "%d,%d", &hot_x, &hot_y);
338
        return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
339
}
340

    
341
void SetupGUI()
342
{
343
        //Initialize SDL_ttf 
344
        if( TTF_Init() == -1 )
345
        {
346
                printf("TTF_Init: Failed to init SDL_ttf library!\n");
347
                printf("TTF_Init: %s\n", TTF_GetError());
348
                exit(1);
349
        }
350
        
351
        //Open the font
352
        MainFont = TTF_OpenFont(MAIN_FONT_FILE , MAIN_FONT_SIZE );
353
        StatisticsFont = TTF_OpenFont(STATS_FONT_FILE, STATS_FONT_SIZE );
354
        
355
        //If there was an error in loading the font
356
        if( MainFont == NULL || StatisticsFont == NULL)
357
        {
358
                printf("Cannot initialize GUI, %s file not found\n", MAIN_FONT_FILE);
359
                exit(1);
360
        }
361
        
362
        // init SDL_image
363
        int flags=IMG_INIT_JPG|IMG_INIT_PNG;
364
        int initted=IMG_Init(flags);
365
        if(initted&flags != flags)
366
        {
367
                printf("IMG_Init: Failed to init required jpg and png support!\n");
368
                printf("IMG_Init: %s\n", IMG_GetError());
369
                exit(1);
370
        }
371
        
372
        SDL_VideoInfo* InitialVideoInfo = SDL_GetVideoInfo();
373
        FullscreenWidth = InitialVideoInfo->current_w;
374
        FullscreenHeight = InitialVideoInfo->current_h;
375

    
376
        SDL_Surface *temp;
377
        int screen_w = 0, screen_h = 0;
378

    
379
        if(OverlayRect.w > BUTTONS_CONTAINER_WIDTH)
380
                screen_w = OverlayRect.w;
381
        else
382
                screen_w = BUTTONS_CONTAINER_WIDTH;
383
        screen_h = OverlayRect.h + BUTTONS_CONTAINER_HEIGHT + BUTTONS_LAYER_OFFSET;
384

    
385
        SDL_WM_SetCaption("Filling buffer...", NULL);
386
        // Make a screen to put our video
387
        
388
        // printf("screen_w = %d, screen_h = %d\n", screen_w, screen_h);
389
        
390
        SetVideoMode(screen_w, screen_h, 0);
391
        
392
        window_width = screen_w;
393
        window_height = screen_h;
394
        
395
        /** Setting up cursors */
396
        defaultCursor = SDL_GetCursor();
397
        handCursor = InitSystemCursor(handXPM);
398
        
399
        /** Init Buttons */
400
        int i;
401
        for(i=0; i<NBUTTONS; i++)
402
        {
403
                SButton* tmp = &(Buttons[i]);
404
                tmp->Hover = 0;
405
                tmp->ToggledButton = NULL;
406
                tmp->Visible = 1;
407
                tmp->HoverCallback = NULL;
408
                tmp->LButtonUpCallback = NULL;
409
        }
410
        
411
        /** Loading icons */
412
        
413
        // fullscreen
414
        temp = IMG_Load(FULLSCREEN_ICON_FILE);
415
        if (temp == NULL) {
416
                fprintf(stderr, "Error loading %s: %s\n", FULLSCREEN_ICON_FILE, SDL_GetError());
417
                exit(1);
418
        }
419
        Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIcon = SDL_DisplayFormatAlpha(temp);
420
        if(Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIcon == NULL)
421
        {
422
                printf("ERROR in SDL_DisplayFormatAlpha, cannot load fullscreen button, error message: '%s'\n", SDL_GetError());
423
                exit(1);
424
        }
425
        SDL_FreeSurface(temp);
426
        
427
        // fullscreen hover
428
        temp = IMG_Load(FULLSCREEN_HOVER_ICON_FILE);
429
        if (temp == NULL) {
430
                fprintf(stderr, "Error loading %s: %s\n", FULLSCREEN_HOVER_ICON_FILE, SDL_GetError());
431
                exit(1);
432
        }
433
        Buttons[FULLSCREEN_BUTTON_INDEX].ButtonHoverIcon = SDL_DisplayFormatAlpha(temp);
434
        SDL_FreeSurface(temp);
435

    
436
        // no fullscreen
437
        temp = IMG_Load(NOFULLSCREEN_ICON_FILE);
438
        if (temp == NULL) {
439
                fprintf(stderr, "Error loading %s: %s\n", NOFULLSCREEN_ICON_FILE, SDL_GetError());
440
                exit(1);
441
        }
442
        Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonIcon = SDL_DisplayFormatAlpha(temp);
443
        SDL_FreeSurface(temp);
444

    
445
        // no fullscreen hover
446
        temp = IMG_Load(NOFULLSCREEN_HOVER_ICON_FILE);
447
        if (temp == NULL) {
448
                fprintf(stderr, "Error loading %s: %s\n", NOFULLSCREEN_HOVER_ICON_FILE, SDL_GetError());
449
                exit(1);
450
        }
451
        Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonHoverIcon = SDL_DisplayFormatAlpha(temp);
452
        SDL_FreeSurface(temp);
453
        
454
        // channel up
455
        temp = IMG_Load(CHANNEL_UP_ICON_FILE);
456
        if (temp == NULL) {
457
                fprintf(stderr, "Error loading %s: %s\n", CHANNEL_UP_ICON_FILE, SDL_GetError());
458
                exit(1);
459
        }
460
        Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonIcon = SDL_DisplayFormatAlpha(temp);
461
        Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonHoverIcon = SDL_DisplayFormatAlpha(temp);
462
        SDL_FreeSurface(temp);
463
        
464
        // channel down
465
        temp = IMG_Load(CHANNEL_DOWN_ICON_FILE);
466
        if (temp == NULL) {
467
                fprintf(stderr, "Error loading %s: %s\n", CHANNEL_DOWN_ICON_FILE, SDL_GetError());
468
                exit(1);
469
        }
470
        Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIcon = SDL_DisplayFormatAlpha(temp);
471
        Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonHoverIcon = SDL_DisplayFormatAlpha(temp);
472
        SDL_FreeSurface(temp);
473

    
474
        /** Setting up icon boxes */
475
        Buttons[FULLSCREEN_BUTTON_INDEX].XOffset = Buttons[NO_FULLSCREEN_BUTTON_INDEX].XOffset = 20;
476
        Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIconBox.x = 20;
477
        Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIconBox.w = Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIcon->w;
478
        Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIconBox.h = Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIcon->h;
479
        Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIconBox.y = screen_h - Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIconBox.h - (BUTTONS_LAYER_OFFSET/2);
480
        
481
        Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonIconBox.x = 20;
482
        Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonIconBox.w = Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonIcon->w;
483
        Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonIconBox.h = Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonIcon->h;
484
        Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonIconBox.y = screen_h - Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonIconBox.h - (BUTTONS_LAYER_OFFSET/2);
485
        
486
        Buttons[CHANNEL_UP_BUTTON_INDEX].XOffset = -61;
487
        Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonIconBox.w = Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonIcon->w;
488
        Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonIconBox.h = Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonIcon->h;
489
        Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonIconBox.x = (screen_w + Buttons[CHANNEL_UP_BUTTON_INDEX].XOffset);
490
        Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonIconBox.y = screen_h - Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonIconBox.h - (BUTTONS_LAYER_OFFSET/2);
491
        
492
        Buttons[CHANNEL_DOWN_BUTTON_INDEX].XOffset = -36;
493
        Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIconBox.w = Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIcon->w;
494
        Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIconBox.h = Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIcon->h;
495
        Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIconBox.x = (screen_w + Buttons[CHANNEL_DOWN_BUTTON_INDEX].XOffset);
496
        Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIconBox.y = screen_h - Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIconBox.h - (BUTTONS_LAYER_OFFSET/2);
497
        
498
        // Setting up buttons events
499
        Buttons[FULLSCREEN_BUTTON_INDEX].ToggledButton = &(Buttons[NO_FULLSCREEN_BUTTON_INDEX]);
500
        Buttons[FULLSCREEN_BUTTON_INDEX].LButtonUpCallback = &ChunkerPlayerGUI_ToggleFullscreen;
501
        Buttons[NO_FULLSCREEN_BUTTON_INDEX].LButtonUpCallback = &ChunkerPlayerGUI_ToggleFullscreen;
502
        Buttons[CHANNEL_UP_BUTTON_INDEX].LButtonUpCallback = &ZapUp;
503
        Buttons[CHANNEL_DOWN_BUTTON_INDEX].LButtonUpCallback = &ZapDown;
504
}
505

    
506
void ChunkerPlayerGUI_SetChannelTitle(char* title)
507
{
508
        SDL_LockMutex(OverlayMutex);
509
        
510
        SDL_FreeSurface( ChannelTitleSurface );
511
        // ChannelTitleSurface = TTF_RenderText_Solid( MainFont, channel->Title, ChannelTitleColor );
512
        ChannelTitleSurface = TTF_RenderText_Shaded( MainFont, title, ChannelTitleColor, ChannelTitleBgColor );
513
        if(ChannelTitleSurface == NULL)
514
        {
515
                printf("WARNING: CANNOT RENDER CHANNEL TITLE\n");
516
        }
517
        
518
        SDL_UnlockMutex(OverlayMutex);
519
        
520
        RedrawChannelName();
521
}
522

    
523
void ChunkerPlayerGUI_SetStatsText(char* text)
524
{
525
        SDL_LockMutex(OverlayMutex);
526
        
527
        SDL_FreeSurface( StatisticsSurface );
528
        // ChannelTitleSurface = TTF_RenderText_Solid( MainFont, channel->Title, ChannelTitleColor );
529
        StatisticsSurface = TTF_RenderText_Shaded( StatisticsFont, text, StatisticsColor, StatisticsBgColor );
530
        if(StatisticsSurface == NULL)
531
                printf("WARNING: CANNOT RENDER CHANNEL TITLE\n");
532
                
533
        SDL_UnlockMutex(OverlayMutex);
534
        
535
        StatisticsRect.w = StatisticsSurface->w;
536
        StatisticsRect.h = StatisticsSurface->h;
537
        StatisticsRect.x = ((FullscreenMode?FullscreenWidth:window_width) - StatisticsRect.w)/2;
538
        StatisticsRect.y = Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIconBox.y+5;
539
        
540
        SDL_LockMutex(OverlayMutex);
541
        SDL_BlitSurface(StatisticsSurface, NULL, MainScreen, &StatisticsRect);
542
        SDL_UpdateRects(MainScreen, 1, &StatisticsRect);
543
        SDL_UnlockMutex(OverlayMutex);
544
}
545

    
546
void ChunkerPlayerGUI_SetupOverlayRect(SChannel* channel)
547
{
548
        ratio = channel->Ratio;
549
        int w, h;
550
        GetScreenSizeFromOverlay(channel->Width, channel->Height, &w, &h);
551
        // printf("CALLING UpdateOverlaySize(%f, %d, %d)\n", ratio, w, h);
552
        UpdateOverlaySize(ratio, w, h);
553
        // UpdateOverlaySize(ratio, channel->Width, channel->Height);
554
}
555

    
556
void ChunkerPlayerGUI_ForceResize(int width, int height)
557
{
558
        FullscreenMode = 0;
559
        int w, h;
560
        GetScreenSizeFromOverlay(width, height, &w, &h);
561
        ChunkerPlayerGUI_HandleResize(w, h);
562
}