Revision 31e4e8ba chunker_player/player_gui.c

View differences:

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

  
4
#define OVERLAY_H_OFFSET (BUTTONS_LAYER_OFFSET + BUTTONS_CONTAINER_HEIGHT + STATS_BOX_HEIGHT)
4
#define SCREEN_BOTTOM_PADDING (BUTTONS_LAYER_OFFSET + BUTTONS_CONTAINER_HEIGHT + STATS_BOX_HEIGHT)
5

  
6
SDL_Cursor *InitSystemCursor(const char *image[]);
7
void AspectRatioResize(float aspect_ratio, int width, int height, int* out_width, int* out_height);
8
void UpdateOverlaySize(float aspect_ratio, int width, int height);
9
void RedrawButtons();
10
void RedrawChannelName();
11
void RedrawStats();
12
void SetupGUI();
13

  
14
static char AudioStatsText[255];
15
static char VideoStatsText[255];
5 16

  
6 17
SDL_Surface *ChannelTitleSurface = NULL;
7
SDL_Surface *StatisticsSurface = NULL;
8
SDL_Rect ChannelTitleRect, StatisticsRect;
18
SDL_Surface *AudioStatisticsSurface = NULL, *VideoStatisticsSurface = NULL;
19
SDL_Rect ChannelTitleRect, StatisticsRect, StatisticsRect;
9 20
SDL_Color ChannelTitleColor = { 255, 0, 0 }, StatisticsColor = { 255, 255, 255 }; ;
10 21
SDL_Color ChannelTitleBgColor = { 0, 0, 0 }, StatisticsBgColor = { 0, 0, 0 };
11 22
TTF_Font *MainFont = NULL;
12 23
TTF_Font *StatisticsFont = NULL;
13 24

  
25
/* XPM */
26
static const char *handXPM[] = {
27
/* columns rows colors chars-per-pixel */
28
"32 32 3 1",
29
"  c black",
30
". c gray100",
31
"X c None",
32
/* pixels */
33
"XXXXX  XXXXXXXXXXXXXXXXXXXXXXXXX",
34
"XXXX .. XXXXXXXXXXXXXXXXXXXXXXXX",
35
"XXXX .. XXXXXXXXXXXXXXXXXXXXXXXX",
36
"XXXX .. XXXXXXXXXXXXXXXXXXXXXXXX",
37
"XXXX .. XXXXXXXXXXXXXXXXXXXXXXXX",
38
"XXXX ..   XXXXXXXXXXXXXXXXXXXXXX",
39
"XXXX .. ..   XXXXXXXXXXXXXXXXXXX",
40
"XXXX .. .. ..  XXXXXXXXXXXXXXXXX",
41
"XXXX .. .. .. . XXXXXXXXXXXXXXXX",
42
"   X .. .. .. .. XXXXXXXXXXXXXXX",
43
" ..  ........ .. XXXXXXXXXXXXXXX",
44
" ... ........... XXXXXXXXXXXXXXX",
45
"X .. ........... XXXXXXXXXXXXXXX",
46
"XX . ........... XXXXXXXXXXXXXXX",
47
"XX ............. XXXXXXXXXXXXXXX",
48
"XXX ............ XXXXXXXXXXXXXXX",
49
"XXX ........... XXXXXXXXXXXXXXXX",
50
"XXXX .......... XXXXXXXXXXXXXXXX",
51
"XXXX .......... XXXXXXXXXXXXXXXX",
52
"XXXXX ........ XXXXXXXXXXXXXXXXX",
53
"XXXXX ........ XXXXXXXXXXXXXXXXX",
54
"XXXXX          XXXXXXXXXXXXXXXXX",
55
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
56
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
57
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
58
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
59
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
60
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
61
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
62
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
63
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
64
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
65
"0,0"
66
};
67

  
14 68
int ChunkerPlayerGUI_Init()
15 69
{
16 70
	// some initializations
......
28 82

  
29 83
void SetVideoMode(int width, int height, int fullscreen)
30 84
{
85
	if(SilentMode)
86
		return;
87
		
31 88
	// printf("SetVideoMode(%d, %d, %d)\n", width, height, fullscreen);
32 89
	SDL_LockMutex(OverlayMutex);
33 90

  
......
75 132
		else
76 133
			Buttons[i].ButtonIconBox.x = (resize_w + Buttons[i].XOffset);
77 134
			
78
		Buttons[i].ButtonIconBox.y = resize_h - Buttons[i].ButtonIconBox.h - (OVERLAY_H_OFFSET/2);
135
		Buttons[i].ButtonIconBox.y = resize_h - Buttons[i].ButtonIconBox.h - (SCREEN_BOTTOM_PADDING/2);
79 136
	}
80 137
	
81 138
	RedrawButtons();
82 139
	RedrawChannelName();
140
	RedrawStats();
83 141
}
84 142

  
85 143
void ChunkerPlayerGUI_HandleGetFocus()
86 144
{
87 145
	RedrawButtons();
88 146
	RedrawChannelName();
147
	RedrawStats();
89 148
}
90 149

  
91 150
void ChunkerPlayerGUI_HandleMouseMotion(int x, int y)
......
150 209
	if(ChannelTitleSurface != NULL)
151 210
		SDL_FreeSurface( ChannelTitleSurface );
152 211
	
153
	if(StatisticsSurface != NULL)
154
		SDL_FreeSurface( StatisticsSurface );
212
	if(AudioStatisticsSurface != NULL)
213
		SDL_FreeSurface( AudioStatisticsSurface );
214
	if(VideoStatisticsSurface != NULL)
215
		SDL_FreeSurface( VideoStatisticsSurface );
155 216
	
156 217
	TTF_CloseFont( MainFont );
157 218
	TTF_CloseFont( StatisticsFont );
......
219 280
			else
220 281
				Buttons[i].ButtonIconBox.x = (FullscreenWidth + Buttons[i].XOffset);
221 282
				
222
			Buttons[i].ButtonIconBox.y = FullscreenHeight - Buttons[i].ButtonIconBox.h - (OVERLAY_H_OFFSET/2);
283
			Buttons[i].ButtonIconBox.y = FullscreenHeight - Buttons[i].ButtonIconBox.h - (SCREEN_BOTTOM_PADDING/2);
223 284
		}
224 285

  
225 286
		//Set the window state flag
......
246 307
			else
247 308
				Buttons[i].ButtonIconBox.x = (window_width + Buttons[i].XOffset);
248 309
				
249
			Buttons[i].ButtonIconBox.y = window_height - Buttons[i].ButtonIconBox.h - (OVERLAY_H_OFFSET/2);
310
			Buttons[i].ButtonIconBox.y = window_height - Buttons[i].ButtonIconBox.h - (SCREEN_BOTTOM_PADDING/2);
250 311
		}
251 312
		
252 313
		//Set the window state flag
......
258 319

  
259 320
	RedrawButtons();
260 321
	RedrawChannelName();
322
	RedrawStats();
261 323
}
262 324

  
263 325
void AspectRatioResize(float aspect_ratio, int width, int height, int* out_width, int* out_height)
264 326
{
265
	int h,w,x,y;
327
	int h,w;
266 328
	h = (int)((float)width/aspect_ratio);
267 329
	if(h<=height)
268 330
	{
......
284 346
{
285 347
	// printf("UpdateOverlaySize(%f, %d, %d)\n", aspect_ratio, width, height);
286 348
	// height -= (BUTTONS_LAYER_OFFSET + BUTTONS_CONTAINER_HEIGHT);
287
	height -= OVERLAY_H_OFFSET;
349
	height -= SCREEN_BOTTOM_PADDING;
288 350
	int h = 0, w = 0, x, y;
289 351
	AspectRatioResize(aspect_ratio, width, height, &w, &h);
290 352
	x = (width - w) / 2;
......
299 361

  
300 362
void GetScreenSizeFromOverlay(int overlayWidth, int overlayHeight, int* screenWidth, int* screenHeight)
301 363
{
302
	*screenHeight = overlayHeight + OVERLAY_H_OFFSET;
364
	*screenHeight = overlayHeight + SCREEN_BOTTOM_PADDING;
303 365
	*screenWidth = overlayWidth;
304 366
}
305 367

  
......
355 417
	StatisticsFont = TTF_OpenFont(STATS_FONT_FILE, STATS_FONT_SIZE );
356 418
	
357 419
	//If there was an error in loading the font
358
	if( MainFont == NULL || StatisticsFont == NULL)
420
	if( MainFont == NULL)
359 421
	{
360 422
		printf("Cannot initialize GUI, %s file not found\n", MAIN_FONT_FILE);
361 423
		exit(1);
362 424
	}
425
	if( StatisticsFont == NULL )
426
	{
427
		printf("Cannot initialize GUI, %s file not found\n", STATS_FONT_FILE);
428
		exit(1);
429
	}
363 430
	
364 431
	// init SDL_image
365 432
	int flags=IMG_INIT_JPG|IMG_INIT_PNG;
......
382 449
		screen_w = OverlayRect.w;
383 450
	else
384 451
		screen_w = BUTTONS_CONTAINER_WIDTH;
385
	screen_h = OverlayRect.h + OVERLAY_H_OFFSET;
452
	screen_h = OverlayRect.h + SCREEN_BOTTOM_PADDING;
386 453

  
387 454
	SDL_WM_SetCaption("Filling buffer...", NULL);
388 455
	// Make a screen to put our video
......
478 545
	Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIconBox.x = 20;
479 546
	Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIconBox.w = Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIcon->w;
480 547
	Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIconBox.h = Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIcon->h;
481
	Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIconBox.y = screen_h - Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIconBox.h - (OVERLAY_H_OFFSET/2);
548
	Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIconBox.y = screen_h - Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIconBox.h - (SCREEN_BOTTOM_PADDING/2);
482 549
	
483 550
	Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonIconBox.x = 20;
484 551
	Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonIconBox.w = Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonIcon->w;
485 552
	Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonIconBox.h = Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonIcon->h;
486
	Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonIconBox.y = screen_h - Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonIconBox.h - (OVERLAY_H_OFFSET/2);
553
	Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonIconBox.y = screen_h - Buttons[NO_FULLSCREEN_BUTTON_INDEX].ButtonIconBox.h - (SCREEN_BOTTOM_PADDING/2);
487 554
	
488 555
	Buttons[CHANNEL_UP_BUTTON_INDEX].XOffset = -61;
489 556
	Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonIconBox.w = Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonIcon->w;
490 557
	Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonIconBox.h = Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonIcon->h;
491 558
	Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonIconBox.x = (screen_w + Buttons[CHANNEL_UP_BUTTON_INDEX].XOffset);
492
	Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonIconBox.y = screen_h - Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonIconBox.h - (OVERLAY_H_OFFSET/2);
559
	Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonIconBox.y = screen_h - Buttons[CHANNEL_UP_BUTTON_INDEX].ButtonIconBox.h - (SCREEN_BOTTOM_PADDING/2);
493 560
	
494 561
	Buttons[CHANNEL_DOWN_BUTTON_INDEX].XOffset = -36;
495 562
	Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIconBox.w = Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIcon->w;
496 563
	Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIconBox.h = Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIcon->h;
497 564
	Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIconBox.x = (screen_w + Buttons[CHANNEL_DOWN_BUTTON_INDEX].XOffset);
498
	Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIconBox.y = screen_h - Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIconBox.h - (OVERLAY_H_OFFSET/2);
565
	Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIconBox.y = screen_h - Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIconBox.h - (SCREEN_BOTTOM_PADDING/2);
499 566
	
500 567
	// Setting up buttons events
501 568
	Buttons[FULLSCREEN_BUTTON_INDEX].ToggledButton = &(Buttons[NO_FULLSCREEN_BUTTON_INDEX]);
......
522 589
	RedrawChannelName();
523 590
}
524 591

  
525
void ChunkerPlayerGUI_SetStatsText(char* text)
592
void ChunkerPlayerGUI_SetStatsText(char* audio_text, char* video_text)
593
{
594
	if(audio_text == NULL)
595
		audio_text = AudioStatsText;
596
	
597
	if(video_text == NULL)
598
		video_text = VideoStatsText;
599

  
600
	if((strlen(audio_text) > 255) || (strlen(video_text) > 255))
601
	{
602
		printf("WARNING IN player_gui.c: stats text too long, could not refresh text\n");
603
		return;
604
	}
605
	
606
	strcpy(AudioStatsText, audio_text);
607
	strcpy(VideoStatsText, video_text);
608
	
609
	RedrawStats();
610
}
611

  
612
void RedrawStats()
526 613
{
527 614
	SDL_LockMutex(OverlayMutex);
528 615
	
529
	SDL_FreeSurface( StatisticsSurface );
616
	SDL_FreeSurface( AudioStatisticsSurface );
530 617
	// ChannelTitleSurface = TTF_RenderText_Solid( MainFont, channel->Title, ChannelTitleColor );
531
	StatisticsSurface = TTF_RenderText_Shaded( StatisticsFont, text, StatisticsColor, StatisticsBgColor );
532
	if(StatisticsSurface == NULL)
533
		printf("WARNING: CANNOT RENDER CHANNEL TITLE\n");
534
		
618
	AudioStatisticsSurface = TTF_RenderText_Shaded( StatisticsFont, AudioStatsText, StatisticsColor, StatisticsBgColor );
619
	if(AudioStatisticsSurface == NULL)
620
	{
621
		printf("WARNING: CANNOT PRINT STATS\n");
622
		return;
623
	}
535 624
	SDL_UnlockMutex(OverlayMutex);
536 625
	
537
	StatisticsRect.w = StatisticsSurface->w;
538
	StatisticsRect.h = StatisticsSurface->h;
626
	StatisticsRect.w = AudioStatisticsSurface->w;
627
	StatisticsRect.h = AudioStatisticsSurface->h;
539 628
	StatisticsRect.x = ((FullscreenMode?FullscreenWidth:window_width) - StatisticsRect.w)/2;
540 629
	StatisticsRect.y = Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIconBox.y+40;
541 630
	
542 631
	SDL_LockMutex(OverlayMutex);
543
	SDL_BlitSurface(StatisticsSurface, NULL, MainScreen, &StatisticsRect);
632
	SDL_BlitSurface(AudioStatisticsSurface, NULL, MainScreen, &StatisticsRect);
633
	SDL_UpdateRects(MainScreen, 1, &StatisticsRect);
634
	SDL_UnlockMutex(OverlayMutex);
635
	
636
	
637
	
638
	SDL_FreeSurface( VideoStatisticsSurface );
639
	// ChannelTitleSurface = TTF_RenderText_Solid( MainFont, channel->Title, ChannelTitleColor );
640
	VideoStatisticsSurface = TTF_RenderText_Shaded( StatisticsFont, VideoStatsText, StatisticsColor, StatisticsBgColor );
641
	if( VideoStatisticsSurface == NULL )
642
	{
643
		printf("WARNING: CANNOT PRINT STATS\n");
644
		return;
645
	}
646
	SDL_UnlockMutex(OverlayMutex);
647
	
648
	StatisticsRect.w = VideoStatisticsSurface->w;
649
	StatisticsRect.h = VideoStatisticsSurface->h;
650
	StatisticsRect.x = ((FullscreenMode?FullscreenWidth:window_width) - StatisticsRect.w)/2;
651
	StatisticsRect.y = Buttons[FULLSCREEN_BUTTON_INDEX].ButtonIconBox.y+25;
652
	
653
	SDL_LockMutex(OverlayMutex);
654
	SDL_BlitSurface(VideoStatisticsSurface, NULL, MainScreen, &StatisticsRect);
544 655
	SDL_UpdateRects(MainScreen, 1, &StatisticsRect);
545 656
	SDL_UnlockMutex(OverlayMutex);
546 657
}

Also available in: Unified diff