<?mml version="0.5"?> 
<mml>
	<interface cosmetic_name="interfaceBrowser" unique_name="jmc/dev_remote/interfaceBrowser">
		<exports>
			<remote name="interface browser" window="interface_browser_popup" thumb_120="dss.red.jpg" thumb_60="dss.red.jpg"/>
		</exports>

		<FontStyle name="titlefont" size="+6" style="normal" />
		<FontStyle name="headerfont" size="+4" style="normal" />
		<FontStyle name="normalfont" style="normal" />

		<hitstyle name="MoodyFrame" default_hitcode="DRAG" >
			<hitcode type="LEFT"><shape><shape_rect alignment="0,0,0,1" offset="0,0,5,0" /></shape></hitcode>
			<hitcode type="BOTTOM"><shape><shape_rect alignment="0,1,1,1" offset="0,-5,-20,0" /></shape></hitcode>
			<hitcode type="TOP"><shape><shape_rect alignment="0,0,1,0" offset="0,0,0,5" /></shape></hitcode>
			<hitcode type="RIGHT"><shape><shape_rect alignment="1,0,1,1" offset="-5,0,0,-20" /></shape></hitcode>
			<hitcode type="BOTTOMRIGHT"><shape><shape_rect alignment="1,1,1,1" offset="-20,-20,0,0"	/></shape></hitcode>
		</hitstyle>
	
<!-- begin meat -->
		<!-- thumbnail window -->
		<window name="ThumbWindow" type="Sonique2_ThumbWindow" transparent="true">
			<imagestyle name="background" />
		</window>

		<!-- no thumbnail available -->
		<window name="NoThumb" transparent="true">
			<window name="title" transparent="true" type="textdisplay" offset="20,20,-20,-20" alignment="0,0,1,1" >
				<imagestyle name="background"> <color_fill color="0xFFFFFFFF"/> </imagestyle>
				<property font_style="normalfont" font_color="0xFFFF0000" font_justification="v_center|h_center"/>
				<script name="OnInit"> SetText("No Thumbnail Available"); </script>
			</window>
		</window>

		<!-- interface holder -->
		<window name="interface" transparent="true" hitstyle="ACTIVE">
			<imagestyle name="background">
				<color_fill color="0x80000080"/>
				<color_rect color="0xFF000000"/>
			</imagestyle>
			<script name="Launch"> 
				if (type == "remote") { :sonique.LaunchRemote(unique_name,name); }
				else { :sonique.LoadSkin(unique_name); }
			</script>
			<window name="remote_title" transparent="true" type="textdisplay" offset="0,0,0,22" alignment="0,0,1,0" >
				<property text_offset="5,1,-5,-1" font_style="headerfont" font_color="0xFF000000" font_justification="v_center" />
				<imagestyle name="background">
					<color_fill color="0xFFE7651A"/>
					<color_rect color="0xFF000000"/>
				</imagestyle>
			</window>
			<window name="skin_title" transparent="true" type="textdisplay" offset="0,0,0,22" alignment="0,0,1,0" >
				<property text_offset="5,1,-5,-1" font_style="headerfont" font_color="0xFF000000" font_justification="v_center" />
				<imagestyle name="background">
					<color_fill color="0xFFFF952A"/>
					<color_rect color="0xFF000000"/>
				</imagestyle>
			</window>
			<window name="name_window" transparent="true" type="button" offset="3,22,-3,42" alignment="0,0,1,0" hitstyle="ACTIVE">
				<property	font_style="titlefont" font_color="0xFFFFFF00" font_justification="h_center|v_center|trim_chars_w_ellipses" />
				<imagestyle name="state0" />
				<script name="OnClick">parent.Launch();</script>
			</window>
			<window name="author_window" transparent="true" type="textdisplay" offset="3,42,-3,62" alignment="0,0,1,0" >
				<property font_style="normalfont" font_color="0xFFFFFFFF" font_justification="h_center|v_center|trim_chars_w_ellipses"/>
			</window>
			<script name="Update">
				if (type == "skin")	
				{ 
					skin_title.SetText("Skin"); 
					skin_title.SetOpacity(1.0); 
					remote_title.SetOpacity(0.0);
					name_window.SetText(cosmetic_name); 
					name_window.SetHoverHint("Load " | cosmetic_name); 
				}
				else	
				{ 
					remote_title.SetText("Remote"); 
					skin_title.SetOpacity(0.0); 
					remote_title.SetOpacity(1.0);
					name_window.SetText(cosmetic_name | " | " | name);
					name_window.SetHoverHint("Launch " | cosmetic_name | " | " | name); 
				}

				$window = 0;
				if ( thumb_source )	{
					//$window = CreateWindow( "Sonique2_ThumbWindow", "ThumbWindow", "thumb", {90,70,210,190}, {0,0,0,0}, "true", 0, "false", 0, "true" );
					$window = CreateWindow( "Sonique2_ThumbWindow", "ThumbWindow", "thumb", {120,100,180,160}, {0,0,0,0}, "true", 0, "false", 0, "true" );
				}
				if ( !$window ) {
					$window = CreateWindow( "Generic", "NoThumb", "thumb", {90,70,210,190}, {0,0,0,0}, "true", 0, "false", 0, "true" );
				}
				else	{
					$window.SetThumbnail(unique_name,thumb_source);
				}

				if (author != :language.Translate("interfaces/default.author") ) { author_window.SetText("by " | author); }
				if (url)
				{
					url_window.SetText(url_title);
					url_window.SetHoverHint(url); 
				}
			</script>
			<window name="url_window" transparent="true" type="button" offset="0,-22,0,0" alignment="0,1,1,1" hitstyle="ACTIVE">
				<property text_offset="5,1,-5,-1" font_style="normalfont" font_color="0xFFFFFFFF" font_justification="left|bottom|trim_chars_w_ellipses" />
				<imagestyle name="state0">
				</imagestyle>
				<script name="OnClick">
					if (url)
					{
						:sonique.LaunchURL(url);
					}
				</script>
			</window>
		</window>


		<!-- actual popup -->
		<window name="interface_browser_popup" default_size="700,320" min_size="200,200" hitstyle="MoodyFrame" >
			<imagestyle name="background">
				<color_fill color="0x00000000"/>
				<color_rect color ="0xFFFFFFFF" alignment="entire" blendmode="COPY|RGB"/>
			</imagestyle>
			<window name="title" transparent="true" type="textdisplay" alignment="0,0,0,0" offset="6,6,150,20" >
				<property font_color="0xFFFFFFFF" />
				<script name="OnInit">SetText( :app.GetAppName()| " - " | :language.Translate("topmenu/view.interfacebrowser") );</script>
			</window>

			<window name="container" offset="3,21,-3,-28" alignment="0,0,1,1" transparent="false">
				<imagestyle name="background"><color_fill color="0x00000000"/></imagestyle>
				<window name="interfaces" offset="0,0,120,120" alignment="0,0,0,0">
					<imagestyle name="background"><color_fill color="0x00000000"/></imagestyle>
					<script name="OnInit">
						$interfaceArray = :sonique.GetInterfaceList();
						$n = $interfaceArray.ArraySize();

						SetOffset({0,0,$n*300,252});

						$offsetThumb = {2,2,302,232};

						for ( $i in 0 to $n-1 )
						{
							$window = 0;
							$name = "subwindow" | $i;
							$window = CreateWindow( "generic", "interface", $name, $offsetThumb, {0,0,0,0}, "true", 0, "false", 0, "true" );
							if ($window)
							{
								$window.cosmetic_name = $interfaceArray[$i]["cosmetic_name"];
								$window.unique_name = $interfaceArray[$i]["unique_name"];
								$window.name = $interfaceArray[$i]["name"];
								$window.window = $interfaceArray[$i]["window"];
								$window.type = $interfaceArray[$i]["type"];
								$window.author = $interfaceArray[$i]["author"];
								$window.url = $interfaceArray[$i]["url"];
								$window.url_title = $interfaceArray[$i]["url_title"];
								//$window.thumb_source = $interfaceArray[$i]["thumb_120"];
								$window.thumb_source = $interfaceArray[$i]["thumb_60"];
								$window.path = $interfaceArray[$i]["path"];
								$window.Update();
							}
							$offsetThumb += {300,0,300,0};
						}
						// use CompactMem cautiously!!
						:console.Echo("Compacting memory..."); 
						:sonique.CompactMem();
					</script>
				</window>
			</window>

			<window name="status" type="Sonique2_StatusBar" transparent="true" offset="3,-25,-3,-3" alignment="0,1,1,1" >
				<property 	scroll_mode="horizontal"
							scroll_speed="50"
							whitespace="40"
							rect_status_offset="5,5,-5,-5"
							font_color="0xFFFFFFFF"
							font_justification="left|v_center|single_line_only"
							rect_progress_offset="10,2,-10,-2"
				/>
				<imagestyle name="background">
					<color_fill color="0x00000000"/>
					<color_rect color ="0xFFFFFFFF" alignment="entire" blendmode="COPY|RGB"/>
				</imagestyle>
			</window>


<!-- scratch button -->
		<window type="button" transparent="false" alignment="upperright" offset="-36, 3, -21, 18" hitstyle="ACTIVE">
			<imagestyle name="state0">
				<color_fill color="0x00000000"/>
				<text color="0xFFffFFFF" justification="h_center|v_center|single_line_only">+</text>
				<color_rect color="0xFFffFFFF" alignment="entire" blendmode="COPY|RGB"/>
			</imagestyle>
			<script name="OnLeftButtonDown"> 	
// todo add test to make sure we don't go beyond edges
// todo - automate so holding down the button works.
				$offset = container.interfaces.GetOffset();
				$offset -= {150,0,150,0};
				container.interfaces.SetOffset($offset, 0, 500, "linear_smooth", false);
				:system.timer.SetTimer("hold down", 200, "OnLeftButtonDown();" , this);
			</script>
			<script name="OnLeftButtonUp">
				:system.timer.UnsetTimer("hold down", this);
			</script>
			<script name="OnMouseOut">
				:system.timer.UnsetTimer("hold down", this);
			</script>
		</window>
		<window type="button" transparent="false" alignment="upperright" offset="-54, 3, -39, 18" hitstyle="ACTIVE">
			<imagestyle name="state0">
				<color_fill color="0x00000000"/>
				<text color="0xFFffFFFF" justification="h_center|v_center|single_line_only">-</text>
				<color_rect color="0xFFffFFFF" alignment="entire" blendmode="COPY|RGB"/>
			</imagestyle>
			<script name="OnLeftButtonDown">
// todo add test to make sure we don't go beyond edges
				$offset = container.interfaces.GetOffset();
				$offset += {150,0,150,0};
				container.interfaces.SetOffset($offset, 0, 500, "linear_smooth", false);
				:system.timer.SetTimer("hold down", 200, "OnLeftButtonDown();" , this);
			</script>
			<script name="OnLeftButtonUp">
				:system.timer.UnsetTimer("hold down", this);
			</script>
			<script name="OnMouseOut">
				:system.timer.UnsetTimer("hold down", this);
			</script>
		</window>

			<window type="button" transparent="false" alignment="upperright" offset="-18, 3, -3, 18" hitstyle="ACTIVE">
				<imagestyle name="state0">
					<color_fill color="0x00000000"/>
					<text color="0xFFffFFFF" justification="h_center|v_center|single_line_only">X</text>
					<color_rect color="0xFFffFFFF" alignment="entire" blendmode="COPY|RGB"/>
				</imagestyle>
				<script name="OnClick"> parent.DestroyWindow(); </script>
				<property hoverhint="Close this window" default_delay="150" />
			</window>
		</window>

		<!-- end interface_browser_popup -->

	</interface>
</mml>
