Revision e11386c0 chunker_player/player_gui.c

View differences:

chunker_player/player_gui.c
10 10
void RedrawChannelName();
11 11
void RedrawStats();
12 12
void SetupGUI();
13
void ToggleAudio();
13 14

  
14 15
static char AudioStatsText[255];
15 16
static char VideoStatsText[255];
......
71 72
	ratio = DEFAULT_RATIO;
72 73
	FullscreenWidth = 0;
73 74
	FullscreenHeight = 0;
75
	Audio_ON = 1;
74 76
	
75 77
	UpdateOverlaySize(ratio, DEFAULT_WIDTH, DEFAULT_HEIGHT);
76 78
	
......
80 82
	return 0;
81 83
}
82 84

  
83
void SetVideoMode(int width, int height, int fullscreen)
85
int SetVideoMode(int width, int height, int fullscreen)
84 86
{
85 87
	if(SilentMode)
86
		return;
88
		return 1;
87 89
		
88 90
	// printf("SetVideoMode(%d, %d, %d)\n", width, height, fullscreen);
89 91
	SDL_LockMutex(OverlayMutex);
......
106 108
	}
107 109

  
108 110
	if(!MainScreen) {
109
		fprintf(stderr, "SDL_SetVideoMode returned null: could not set video mode - exiting\n");
110
		exit(1);
111
		fprintf(stderr, "ERROR: could not change video mode\n");
112
		return 1;
111 113
	}
112 114
	SDL_UnlockMutex(OverlayMutex);
115
	
116
	return 0;
113 117
}
114 118

  
115 119
void ChunkerPlayerGUI_HandleResize(int resize_w, int resize_h)
......
117 121
	if(SilentMode)
118 122
		return;
119 123
		
120
	// printf("ChunkerPlayerGUI_HandleResize(%d, %d)\n", resize_w, resize_h);
121
	SetVideoMode(resize_w, resize_h, FullscreenMode?1:0);
124
	SDL_LockMutex(OverlayMutex);
125
	
126
	int res = SetVideoMode(resize_w, resize_h, FullscreenMode?1:0);
127

  
128
	if(res && FullscreenMode)
129
	{
130
		// an error has occurred while switching to fullscreen mode
131
		
132
		// trying resize without fullscreen mode
133
		FullscreenMode = 0;
134
		res = SetVideoMode(resize_w, resize_h, 0);
135
	}
136
	if(res)
137
	{
138
		// nothing to do
139
		fprintf(stderr, "CRITICAL ERROR: could not change video mode\n");
140
		exit(1);
141
	}
122 142
	
123 143
	window_width = resize_w;
124 144
	window_height = resize_h;
......
141 161
	RedrawButtons();
142 162
	RedrawChannelName();
143 163
	RedrawStats();
164
	
165
	SDL_UnlockMutex(OverlayMutex);
144 166
}
145 167

  
146 168
void ChunkerPlayerGUI_HandleGetFocus()
......
235 257
	int i;
236 258
	for(i=0; i<NBUTTONS; i++)
237 259
	{
260
		if(!Buttons[i].Visible)
261
		{
262
			SDL_LockMutex(OverlayMutex);
263
			SDL_FillRect( MainScreen, &Buttons[i].ButtonIconBox, SDL_MapRGB(MainScreen->format, 0, 0, 0) );
264
			SDL_UpdateRects(MainScreen, 1, &Buttons[i].ButtonIconBox);
265
			SDL_UnlockMutex(OverlayMutex);
266
		}
267
	}
268
	for(i=0; i<NBUTTONS; i++)
269
	{
238 270
		if(Buttons[i].Visible)
239 271
		{
240 272
			if(!Buttons[i].Hover)
......
280 312
{
281 313
	if(SilentMode)
282 314
		return;
315

  
316
	SDL_LockMutex(OverlayMutex);
283 317
		
284
	int i;
318
	int i, done = 0;
285 319
	//If the screen is windowed
286 320
	if( !FullscreenMode )
287 321
	{
288
		// printf("SETTING FULLSCREEN ON\n");
289
		SetVideoMode(FullscreenWidth, FullscreenHeight, 1);
290
		
291
		// update the overlay surface size, mantaining the aspect ratio
292
		UpdateOverlaySize(ratio, FullscreenWidth, FullscreenHeight);
293
		
294
		// update each button coordinates
295
		for(i=0; i<NBUTTONS; i++)
296
		{
297
			if(Buttons[i].XOffset > 0)
298
				Buttons[i].ButtonIconBox.x = Buttons[i].XOffset;
299
			else
300
				Buttons[i].ButtonIconBox.x = (FullscreenWidth + Buttons[i].XOffset);
301
				
302
			Buttons[i].ButtonIconBox.y = FullscreenHeight - Buttons[i].ButtonIconBox.h - (SCREEN_BOTTOM_PADDING/2);
303
		}
304

  
322
		int res = SetVideoMode(FullscreenWidth, FullscreenHeight, 1);
305 323
		//Set the window state flag
306 324
		FullscreenMode = 1;
307
		
308
		Buttons[FULLSCREEN_BUTTON_INDEX].Visible = 0;
309
		Buttons[NO_FULLSCREEN_BUTTON_INDEX].Visible = 1;
325

  
326
		if(res)
327
		{
328
			fprintf(stderr, "ERROR: an error has occurred while switching to fullscreen mode\n");
329
		}
330
		else
331
		{
332
			// update the overlay surface size, mantaining the aspect ratio
333
			UpdateOverlaySize(ratio, FullscreenWidth, FullscreenHeight);
334
			
335
			// update each button coordinates
336
			for(i=0; i<NBUTTONS; i++)
337
			{
338
				if(Buttons[i].XOffset > 0)
339
					Buttons[i].ButtonIconBox.x = Buttons[i].XOffset;
340
				else
341
					Buttons[i].ButtonIconBox.x = (FullscreenWidth + Buttons[i].XOffset);
342
					
343
				Buttons[i].ButtonIconBox.y = FullscreenHeight - Buttons[i].ButtonIconBox.h - (SCREEN_BOTTOM_PADDING/2);
344
			}
345
			
346
			Buttons[FULLSCREEN_BUTTON_INDEX].Visible = 0;
347
			Buttons[NO_FULLSCREEN_BUTTON_INDEX].Visible = 1;
348
			
349
			done = 1;
350
		}
310 351
	}
311 352
	
312 353
	//If the screen is fullscreen
313
	else
354
	if(FullscreenMode && !done)
314 355
	{
315
		// printf("ToggleFullscreen callback, setting WINDOWED\n");
316
		SetVideoMode(window_width, window_height, 0);
356
		int res = SetVideoMode(window_width, window_height, 0);
357
		if(res)
358
		{
359
			// nothing to do
360
			fprintf(stderr, "CRITICAL ERROR: could not change video mode\n");
361
			exit(1);
362
		}
317 363
		
318 364
		// update the overlay surface size, mantaining the aspect ratio
319 365
		UpdateOverlaySize(ratio, window_width, window_height);
......
339 385
	RedrawButtons();
340 386
	RedrawChannelName();
341 387
	RedrawStats();
388
	
389
	SDL_UnlockMutex(OverlayMutex);
390
}
391

  
392
void ChunkerPlayerGUI_AspectRatioResize(float aspect_ratio, int width, int height, int* out_width, int* out_height)
393
{
394
	AspectRatioResize(aspect_ratio, width, height, out_width, out_height);
342 395
}
343 396

  
344 397
void AspectRatioResize(float aspect_ratio, int width, int height, int* out_width, int* out_height)
......
363 416
 */
364 417
void UpdateOverlaySize(float aspect_ratio, int width, int height)
365 418
{
366
	// printf("UpdateOverlaySize(%f, %d, %d)\n", aspect_ratio, width, height);
367 419
	// height -= (BUTTONS_LAYER_OFFSET + BUTTONS_CONTAINER_HEIGHT);
368 420
	height -= SCREEN_BOTTOM_PADDING;
369 421
	int h = 0, w = 0, x, y;
......
386 438
	*screenWidth = overlayWidth;
387 439
}
388 440

  
389
/* From SDL documentation. */
441
/* From the SDL documentation. */
390 442
SDL_Cursor *InitSystemCursor(const char *image[])
391 443
{
392 444
	int i, row, col;
......
473 525
	screen_h = OverlayRect.h + SCREEN_BOTTOM_PADDING;
474 526

  
475 527
	SDL_WM_SetCaption("Filling buffer...", NULL);
476
	// Make a screen to put our video
477
	
478
	// printf("screen_w = %d, screen_h = %d\n", screen_w, screen_h);
479 528
	
529
	// Make a screen to put our video
480 530
	SetVideoMode(screen_w, screen_h, 0);
481 531
	
482 532
	window_width = screen_w;
......
560 610
	Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIcon = SDL_DisplayFormatAlpha(temp);
561 611
	Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonHoverIcon = SDL_DisplayFormatAlpha(temp);
562 612
	SDL_FreeSurface(temp);
613
	
614
	// audio OFF
615
	temp = IMG_Load(AUDIO_OFF_ICON_FILE);
616
	if (temp == NULL) {
617
		fprintf(stderr, "Error loading %s: %s\n", AUDIO_OFF_ICON_FILE, SDL_GetError());
618
		exit(1);
619
	}
620
	Buttons[AUDIO_OFF_BUTTON_INDEX].ButtonIcon = SDL_DisplayFormatAlpha(temp);
621
	Buttons[AUDIO_OFF_BUTTON_INDEX].ButtonHoverIcon = SDL_DisplayFormatAlpha(temp);
622
	SDL_FreeSurface(temp);
623
	
624
	// audio ON
625
	temp = IMG_Load(AUDIO_ON_ICON_FILE);
626
	if (temp == NULL) {
627
		fprintf(stderr, "Error loading %s: %s\n", AUDIO_ON_ICON_FILE, SDL_GetError());
628
		exit(1);
629
	}
630
	Buttons[AUDIO_ON_BUTTON_INDEX].ButtonIcon = SDL_DisplayFormatAlpha(temp);
631
	Buttons[AUDIO_ON_BUTTON_INDEX].ButtonHoverIcon = SDL_DisplayFormatAlpha(temp);
632
	SDL_FreeSurface(temp);
563 633

  
564 634
	/** Setting up icon boxes */
565 635
	Buttons[FULLSCREEN_BUTTON_INDEX].XOffset = Buttons[NO_FULLSCREEN_BUTTON_INDEX].XOffset = 20;
......
585 655
	Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIconBox.x = (screen_w + Buttons[CHANNEL_DOWN_BUTTON_INDEX].XOffset);
586 656
	Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIconBox.y = screen_h - Buttons[CHANNEL_DOWN_BUTTON_INDEX].ButtonIconBox.h - (SCREEN_BOTTOM_PADDING/2);
587 657
	
658
	Buttons[AUDIO_OFF_BUTTON_INDEX].XOffset = Buttons[AUDIO_ON_BUTTON_INDEX].XOffset = 70;
659
	Buttons[AUDIO_OFF_BUTTON_INDEX].ButtonIconBox.x = 20;
660
	Buttons[AUDIO_OFF_BUTTON_INDEX].ButtonIconBox.w = Buttons[AUDIO_OFF_BUTTON_INDEX].ButtonIcon->w;
661
	Buttons[AUDIO_OFF_BUTTON_INDEX].ButtonIconBox.h = Buttons[AUDIO_OFF_BUTTON_INDEX].ButtonIcon->h;
662
	Buttons[AUDIO_OFF_BUTTON_INDEX].ButtonIconBox.y = screen_h - Buttons[AUDIO_OFF_BUTTON_INDEX].ButtonIconBox.h - (SCREEN_BOTTOM_PADDING/2);
663
	Buttons[AUDIO_OFF_BUTTON_INDEX].Visible = 1;
664

  
665
	Buttons[AUDIO_ON_BUTTON_INDEX].ButtonIconBox.x = 20;
666
	Buttons[AUDIO_ON_BUTTON_INDEX].ButtonIconBox.w = Buttons[AUDIO_ON_BUTTON_INDEX].ButtonIcon->w;
667
	Buttons[AUDIO_ON_BUTTON_INDEX].ButtonIconBox.h = Buttons[AUDIO_ON_BUTTON_INDEX].ButtonIcon->h;
668
	Buttons[AUDIO_ON_BUTTON_INDEX].ButtonIconBox.y = screen_h - Buttons[AUDIO_ON_BUTTON_INDEX].ButtonIconBox.h - (SCREEN_BOTTOM_PADDING/2);
669
	Buttons[AUDIO_ON_BUTTON_INDEX].Visible = 0;
670
	
588 671
	// Setting up buttons events
589 672
	Buttons[FULLSCREEN_BUTTON_INDEX].ToggledButton = &(Buttons[NO_FULLSCREEN_BUTTON_INDEX]);
590 673
	Buttons[FULLSCREEN_BUTTON_INDEX].LButtonUpCallback = &ChunkerPlayerGUI_ToggleFullscreen;
591 674
	Buttons[NO_FULLSCREEN_BUTTON_INDEX].LButtonUpCallback = &ChunkerPlayerGUI_ToggleFullscreen;
592 675
	Buttons[CHANNEL_UP_BUTTON_INDEX].LButtonUpCallback = &ZapUp;
593 676
	Buttons[CHANNEL_DOWN_BUTTON_INDEX].LButtonUpCallback = &ZapDown;
677
	Buttons[AUDIO_OFF_BUTTON_INDEX].LButtonUpCallback = &ToggleAudio;
678
	Buttons[AUDIO_ON_BUTTON_INDEX].LButtonUpCallback = &ToggleAudio;
594 679
}
595 680

  
596 681
void ChunkerPlayerGUI_SetChannelTitle(char* title)
......
695 780
	ratio = channel->Ratio;
696 781
	int w, h;
697 782
	GetScreenSizeFromOverlay(channel->Width, channel->Height, &w, &h);
698
	// printf("CALLING UpdateOverlaySize(%f, %d, %d)\n", ratio, w, h);
699 783
	UpdateOverlaySize(ratio, w, h);
700 784
	// UpdateOverlaySize(ratio, channel->Width, channel->Height);
701 785
}
......
707 791
	GetScreenSizeFromOverlay(width, height, &w, &h);
708 792
	ChunkerPlayerGUI_HandleResize(w, h);
709 793
}
794

  
795
void ToggleAudio()
796
{
797
	if(Audio_ON)
798
	{
799
		SDL_PauseAudio(1);
800
		Buttons[AUDIO_OFF_BUTTON_INDEX].Visible = 0;
801
		Buttons[AUDIO_ON_BUTTON_INDEX].Visible = 1;
802
		Audio_ON = 0;
803
	}
804
	else
805
	{
806
		SDL_PauseAudio(0);
807
		Buttons[AUDIO_OFF_BUTTON_INDEX].Visible = 1;
808
		Buttons[AUDIO_ON_BUTTON_INDEX].Visible = 0;
809
		Audio_ON = 1;
810
	}
811
	
812
	RedrawButtons();
813
}
814

  
815
void ChunkerPlayerGUI_ChannelSwitched()
816
{
817
	if(!Audio_ON)
818
	{
819
		SDL_PauseAudio(1);
820
		Buttons[AUDIO_OFF_BUTTON_INDEX].Visible = 0;
821
		Buttons[AUDIO_ON_BUTTON_INDEX].Visible = 1;
822
	}
823
	
824
	RedrawButtons();
825
}

Also available in: Unified diff