Changeset - r12831:ca6be2d6185b
[Not reviewed]
master
0 1 0
yexo - 15 years ago 2009-08-30 21:31:54
yexo@openttd.org
(svn r17331) -Codechange: don't depend on static widget position/size for drawing of volumer sliders in music window
1 file changed with 22 insertions and 28 deletions:
0 comments (0 inline, 0 general)
src/music_gui.cpp
Show inline comments
 
@@ -398,148 +398,142 @@ static void ShowMusicTrackSelection()
 
enum MusicWidgets {
 
	MW_CLOSE,
 
	MW_CAPTION,
 
	MW_PREV,
 
	MW_NEXT,
 
	MW_STOP,
 
	MW_PLAY,
 
	MW_SLIDERS,
 
	MW_MUSIC_VOL,
 
	MW_GAUGE,
 
	MW_EFFECT_VOL,
 
	MW_BACKGROUND,
 
	MW_INFO,
 
	MW_SHUFFLE,
 
	MW_PROGRAMME,
 
	MW_ALL,
 
	MW_OLD,
 
	MW_NEW,
 
	MW_EZY,
 
	MW_CUSTOM1,
 
	MW_CUSTOM2,
 
};
 

	
 
struct MusicWindow : public Window {
 
	static const int slider_bar_height = 4;
 
	static const int slider_height = 7;
 
	static const int slider_width = 3;
 

	
 
	MusicWindow(const WindowDesc *desc, WindowNumber number) : Window()
 
	{
 
		this->InitNested(desc, number);
 
		this->LowerWidget(msf.playlist + MW_ALL);
 
		this->SetWidgetLoweredState(MW_SHUFFLE, msf.shuffle);
 
	}
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		switch (widget) {
 
			case MW_GAUGE:
 
				GfxFillRect(r.left, r.top, r.right, r.bottom, 0);
 

	
 
				for (uint i = 0; i != 8; i++) {
 
					int colour = 0xD0;
 
					if (i > 4) {
 
						colour = 0xBF;
 
						if (i > 6) {
 
							colour = 0xB8;
 
						}
 
					}
 
					GfxFillRect(r.left, r.bottom - i * 2, r.right, r.bottom - i * 2, colour);
 
				}
 
				break;
 

	
 
			case MW_INFO: {
 
				GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, 0);
 
				StringID str = STR_MUSIC_TRACK_NONE;
 
				if (_song_is_active != 0 && _music_wnd_cursong != 0) {
 
					SetDParam(0, _music_wnd_cursong);
 
					str = (_music_wnd_cursong < 10) ? STR_MUSIC_TRACK_SINGLE_DIGIT : STR_MUSIC_TRACK_DOUBLE_DIGIT;
 
				}
 
				DrawString(r.left + 3, r.right - 3, r.top + 1, str);
 
				str = STR_MUSIC_TITLE_NONE;
 
				if (_song_is_active != 0 && _music_wnd_cursong != 0) {
 
					str = STR_MUSIC_TITLE_NAME;
 
					SetDParam(0, SPECSTR_SONGNAME);
 
					SetDParam(1, _music_wnd_cursong);
 
				}
 
				DrawString(r.left, r.right, r.top + 1, str, TC_FROMSTRING, SA_CENTER);
 
			} break;
 

	
 
			case MW_MUSIC_VOL: case MW_EFFECT_VOL: {
 
				DrawString(r.left, r.right, r.top + 1, (widget == MW_MUSIC_VOL) ? STR_MUSIC_MUSIC_VOLUME : STR_MUSIC_EFFECTS_VOLUME, TC_FROMSTRING, SA_CENTER);
 
				int y = (r.top + r.bottom - slider_bar_height) / 2;
 
				DrawFrameRect(r.left, y, r.right, y + slider_bar_height, COLOUR_GREY, FR_LOWERED);
 
				DrawString(r.left, r.right, r.bottom - FONT_HEIGHT_SMALL, STR_MUSIC_MIN_MAX_RULER, TC_FROMSTRING, SA_CENTER);
 
				y = (r.top + r.bottom - slider_height) / 2;
 
				byte volume = (widget == MW_MUSIC_VOL) ? msf.music_vol : msf.effect_vol;
 
				int x = r.left + (volume * (r.right - r.left) / 127);
 
				DrawFrameRect(x, y, x + slider_width, y + slider_height, COLOUR_GREY, FR_NONE);
 
			} break;
 
		}
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		this->DrawWidgets();
 

	
 
		DrawString(108, 174, 15, STR_MUSIC_MUSIC_VOLUME, TC_FROMSTRING, SA_CENTER);
 
		DrawString(108, 174, 29, STR_MUSIC_MIN_MAX_RULER, TC_FROMSTRING, SA_CENTER);
 
		DrawString(214, 280, 15, STR_MUSIC_EFFECTS_VOLUME, TC_FROMSTRING, SA_CENTER);
 
		DrawString(214, 280, 29, STR_MUSIC_MIN_MAX_RULER, TC_FROMSTRING, SA_CENTER);
 

	
 
		DrawFrameRect(108, 23, 174, 26, COLOUR_GREY, FR_LOWERED);
 
		DrawFrameRect(214, 23, 280, 26, COLOUR_GREY, FR_LOWERED);
 

	
 
		DrawFrameRect(
 
			108 + msf.music_vol / 2, 22, 111 + msf.music_vol / 2, 28, COLOUR_GREY, FR_NONE
 
		);
 

	
 
		DrawFrameRect(
 
			214 + msf.effect_vol / 2, 22, 217 + msf.effect_vol / 2, 28, COLOUR_GREY, FR_NONE
 
		);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		switch (widget) {
 
			case MW_PREV: // skip to prev
 
				if (!_song_is_active) return;
 
				SkipToPrevSong();
 
				break;
 

	
 
			case MW_NEXT: // skip to next
 
				if (!_song_is_active) return;
 
				SkipToNextSong();
 
				break;
 

	
 
			case MW_STOP: // stop playing
 
				msf.playing = false;
 
				break;
 

	
 
			case MW_PLAY: // start playing
 
				msf.playing = true;
 
				break;
 

	
 
			case MW_MUSIC_VOL: case MW_EFFECT_VOL: { // volume sliders
 
				int x = pt.x - 88;
 
				if (x < 0) return;
 
				int x = pt.x - this->nested_array[widget]->pos_x;
 

	
 
				byte *vol = &msf.music_vol;
 
				if (x >= 106) {
 
					vol = &msf.effect_vol;
 
					x -= 106;
 
				}
 
				byte *vol = (widget == MW_MUSIC_VOL) ? &msf.music_vol : &msf.effect_vol;
 

	
 
				byte new_vol = min(max(x - 21, 0) * 2, 127);
 
				byte new_vol = x * 127 / this->nested_array[widget]->current_x;
 
				if (new_vol != *vol) {
 
					*vol = new_vol;
 
					if (vol == &msf.music_vol) MusicVolumeChanged(new_vol);
 
					if (widget == MW_MUSIC_VOL) MusicVolumeChanged(new_vol);
 
					this->SetDirty();
 
				}
 

	
 
				_left_button_clicked = false;
 
			} break;
 

	
 
			case MW_SHUFFLE: // toggle shuffle
 
				msf.shuffle ^= 1;
 
				this->SetWidgetLoweredState(MW_SHUFFLE, msf.shuffle);
 
				this->InvalidateWidget(MW_SHUFFLE);
 
				StopMusic();
 
				SelectSongToPlay();
 
				break;
 

	
 
			case MW_PROGRAMME: // show track selection
 
				ShowMusicTrackSelection();
 
				break;
 

	
 
			case MW_ALL: case MW_OLD: case MW_NEW:
 
			case MW_EZY: case MW_CUSTOM1: case MW_CUSTOM2: // playlist
 
				this->RaiseWidget(msf.playlist + MW_ALL);
 
				msf.playlist = widget - MW_ALL;
 
				this->LowerWidget(widget);
 
				this->SetDirty();
 
@@ -549,52 +543,52 @@ struct MusicWindow : public Window {
 
				break;
 
		}
 
	}
 

	
 
#if 0
 
	virtual void OnTick()
 
	{
 
		this->InvalidateWidget(MW_GAUGE);
 
	}
 
#endif
 
};
 

	
 
static const NWidgetPart _nested_music_window_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY, MW_CLOSE),
 
		NWidget(WWT_CAPTION, COLOUR_GREY, MW_CAPTION), SetDataTip(STR_MUSIC_JAZZ_JUKEBOX_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
	EndContainer(),
 

	
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, MW_PREV), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_SKIP_TO_PREV, STR_MUSIC_TOOLTIP_SKIP_TO_PREVIOUS_TRACK),
 
		NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, MW_NEXT), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_SKIP_TO_NEXT, STR_MUSIC_TOOLTIP_SKIP_TO_NEXT_TRACK_IN_SELECTION),
 
		NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, MW_STOP), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_STOP_MUSIC, STR_MUSIC_TOOLTIP_STOP_PLAYING_MUSIC),
 
		NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, MW_PLAY), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_PLAY_MUSIC, STR_MUSIC_TOOLTIP_START_PLAYING_MUSIC),
 
		NWidget(WWT_PANEL, COLOUR_GREY, MW_SLIDERS),
 
			NWidget(NWID_HORIZONTAL),
 
				NWidget(WWT_EMPTY, COLOUR_GREY, MW_MUSIC_VOL), SetMinimalSize(98, 22), SetDataTip(0x0, STR_MUSIC_TOOLTIP_DRAG_SLIDERS_TO_SET_MUSIC),
 
			NWidget(NWID_HORIZONTAL), SetPIP(20, 11, 20),
 
				NWidget(WWT_EMPTY, COLOUR_GREY, MW_MUSIC_VOL), SetMinimalSize(67, 22), SetDataTip(0x0, STR_MUSIC_TOOLTIP_DRAG_SLIDERS_TO_SET_MUSIC),
 
				NWidget(WWT_PANEL, COLOUR_GREY, MW_GAUGE), SetMinimalSize(16, 20), SetPadding(1, 0, 1, 0), EndContainer(),
 
				NWidget(WWT_EMPTY, COLOUR_GREY, MW_EFFECT_VOL), SetMinimalSize(98, 22), SetDataTip(0x0, STR_MUSIC_TOOLTIP_DRAG_SLIDERS_TO_SET_MUSIC),
 
				NWidget(WWT_EMPTY, COLOUR_GREY, MW_EFFECT_VOL), SetMinimalSize(67, 22), SetDataTip(0x0, STR_MUSIC_TOOLTIP_DRAG_SLIDERS_TO_SET_MUSIC),
 
			EndContainer(),
 
		EndContainer(),
 
		NWidget(NWID_SPACER), SetFill(true, false),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_GREY, MW_BACKGROUND),
 
		NWidget(NWID_HORIZONTAL),
 
			NWidget(WWT_TEXTBTN, COLOUR_GREY, MW_SHUFFLE), SetMinimalSize(50, 8), SetDataTip(STR_MUSIC_SHUFFLE, STR_MUSIC_TOOLTIP_TOGGLE_PROGRAM_SHUFFLE), SetPadding(6, 3, 8, 6),
 
			NWidget(NWID_VERTICAL),
 
				NWidget(NWID_SPACER), SetMinimalSize(0, 9),
 
				NWidget(WWT_PANEL, COLOUR_GREY, MW_INFO), SetMinimalSize(182, 9), SetFill(false, false), EndContainer(),
 
				NWidget(NWID_SPACER), SetFill(false, true),
 
			EndContainer(),
 
			NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, MW_PROGRAMME), SetMinimalSize(50, 8), SetDataTip(STR_MUSIC_PROGRAM, STR_MUSIC_TOOLTIP_SHOW_MUSIC_TRACK_SELECTION), SetPadding(6, 0, 8, 3),
 
			NWidget(NWID_SPACER), SetFill(true, false),
 
		EndContainer(),
 
	EndContainer(),
 
	NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
 
		NWidget(WWT_TEXTBTN, COLOUR_GREY, MW_ALL), SetMinimalSize(50, 8), SetDataTip(STR_MUSIC_PLAYLIST_ALL, STR_MUSIC_TOOLTIP_SELECT_ALL_TRACKS_PROGRAM),
 
		NWidget(WWT_TEXTBTN, COLOUR_GREY, MW_OLD), SetMinimalSize(50, 8), SetDataTip(STR_MUSIC_PLAYLIST_OLD_STYLE, STR_MUSIC_TOOLTIP_SELECT_OLD_STYLE_MUSIC),
 
		NWidget(WWT_TEXTBTN, COLOUR_GREY, MW_NEW), SetMinimalSize(50, 8), SetDataTip(STR_MUSIC_PLAYLIST_NEW_STYLE, STR_MUSIC_TOOLTIP_SELECT_NEW_STYLE_MUSIC),
 
		NWidget(WWT_TEXTBTN, COLOUR_GREY, MW_EZY), SetMinimalSize(50, 8), SetDataTip(STR_MUSIC_PLAYLIST_EZY_STREET, STR_MUSIC_TOOLTIP_SELECT_EZY_STREET_STYLE),
 
		NWidget(WWT_TEXTBTN, COLOUR_GREY, MW_CUSTOM1), SetMinimalSize(50, 8), SetDataTip(STR_MUSIC_PLAYLIST_CUSTOM_1, STR_MUSIC_TOOLTIP_SELECT_CUSTOM_1_USER_DEFINED),
 
		NWidget(WWT_TEXTBTN, COLOUR_GREY, MW_CUSTOM2), SetMinimalSize(50, 8), SetDataTip(STR_MUSIC_PLAYLIST_CUSTOM_2, STR_MUSIC_TOOLTIP_SELECT_CUSTOM_2_USER_DEFINED),
 
	EndContainer(),
0 comments (0 inline, 0 general)