environment test
        uses "/mit/musedev/MuseLib/Muse.cdefs"
{

	Cfunc text_create(Cint) returns Cint;  -- makes text widget
	Cfunc make_tk_widget(Cint,Cint);

	Cint v_server;  -- pointer to the video server
	Cfunc GGetFrame(Cint,Cint) returns Cint;
	--use: put GGetFrame(v_server, Rpd) into framenumber;



	on OpenEnv
	{
                EnableDragWidget();
                EnableSizeWidget();
	}


	object BookSlideMaker
	{
	  var BEnumber;
	  var BEname;
	  var BIn;
	  var BOut;
	  var BIcon;
	  var BMinOne;
		on Initialize
		{
			put 0 into BEnumber;
			put "BSlide" into BEname;
			put 0 into Snumber;
			put 0 into nscreen;

			put 350 into BIn;
			put 350 into BOut;
			put 350 into BIcon;
			put 1 into BRpd;
			put (0 - 1) into BMinOne;
		 }

		on CreateSlide Recipient,Volume
			-- recipient is pck who gets slide
		{
		 -- Make a new element and set attributes:
			put (BEnumber + 1) into BEnumber;
			put (BEname & BEnumber) into BNewName;
			put CreateElement(BNewName) into BNewSlideID;
			 SetElementAttribute(BNewSlideID,"active",1);
			 SetElementAttribute(BNewSlideID,"type","still");

		 -- Add element to the Recipient package:
			put GetPackageID( Recipient ) into RecipientID;
			PackageAddElement(RecipientID,BNewSlideID);

		 -- Now make a screen and add it to element BNewSlideID:
			put CreateScreen(BNewName,"still","page",
			    25,50,160,120,0,0,97,BMinOne,BMinOne) into Screen;

			SetElementAttribute(BNewSlideID,"screen",Screen);

		 -- Now make a map, set pos_in, pos_out, set frame numbers:
			put CreateMap("still",0) into BNewMapID;

		 -- Get the page number from book->page
			put GetDimensionID(RecipientID,"page") into PageDim;
			put GetDimensionAttribute(PageDim, "current") into
			   PageNum;

			SetMapPosIn(BNewMapID,0,PageNum);
			SetMapPosOut(BNewMapID,0,PageNum);

		  -- Get the frame number
			put GGetFrame(v_server, BRpd) into BIn;

			SetMapAttribute(BNewMapID,"in",BIn);
			SetMapAttribute(BNewMapID,"out",BOut);
			SetMapAttribute(BNewMapID,"icon",BIcon);

			SetMapAttribute(BNewMapID,"rpd",BRpd);
			SetMapAttribute(BNewMapID,"key_dimension",0);

		 -- Following MUST be set:
			SetMapAttribute(BNewMapID,"label",Volume);

		 -- Add it to the element

			ElementAddMap(BNewSlideID,BNewMapID);

		 -- Activate the new element
			activate_element(BNewSlideID);
			refresh(BNewSlideID);
		}


	 }

	object TextMaker
	{
		var TextX;
		var TextY;
		var TextW;
		var TextH;
		var TextFont;
		var TextFG;
		var TextBG;
		var TextBD;
		var TextBW;
		var ScrID;
		var WndID;

		on Initialize
		{
			put 0 into Txtnumber;
			put "Text" into Txtname;
			put "*times-bold-r-normal--18-*" into TextFont;
			put 1 into TextBW;
			put 48 into TextBG;
			put 66 into TextFG;
			put 45 into TextBD;
		 }

		on CreateText Recipient
		{

		 -- Make a new element and set attributes:
			put (Txtnumber + 1) into Txtnumber;
			put (Txtname & Txtnumber) into NewName;
			put CreateElement(NewName) into NewSlideID;
			 SetElementAttribute(NewSlideID,"active",1);
			 SetElementAttribute(NewSlideID,"type","tkwidget");

		 -- Add element to the Recipient package:
			put GetPackageID( Recipient ) into RecipientID;
			PackageAddElement(RecipientID,NewSlideID);

			put GetScreenID(RecipientID, "page") into ScrID;
			SetElementAttribute(NewSlideID,"screen",ScrID);

		 -- Now make a map, set pos_in, pos_out, set frame numbers:

			put 0 into ptr;
			put text_create(ptr) into WgtID;

			put CreateMap("tktext",WgtID) into NewMapID;

			put WindowFromScreen(ScrID) into WndID;
			GetBox(WndID,TextX,TextY,TextW,TextH,1);


			put "*times-bold-r-normal--18-*" into TextFont;
			put 0 into TextBW;
			put 48 into TextBG;
			put 66 into TextFG;
			put 45 into TextBD;

			put 1 into options;
			SetWidgetAttribute(NewMapID, "options", options);
			SetWidgetAttribute(NewMapID, "edit_type", "edit");
			SetWidgetAttribute(NewMapID, "x", TextX);
			SetWidgetAttribute(NewMapID, "y", TextY);
			SetWidgetAttribute(NewMapID, "width", TextW);
			SetWidgetAttribute(NewMapID, "height", TextH);
			SetWidgetAttribute(NewMapID, "font", TextFont);
			SetWidgetAttribute(NewMapID, "foreground", TextFG);
			SetWidgetAttribute(NewMapID, "background", TextBG);
			SetWidgetAttribute(NewMapID, "border", TextBD);
			SetWidgetAttribute(NewMapID, "borderwidth", TextBW);

			make_tk_widget(NewSlideID,NewMapID);


		 -- Get the page number from book->page
			put GetDimensionID(RecipientID,"page") into PageDim;
			put GetDimensionAttribute(PageDim, "current") into
			   PageNum;

			SetMapPosIn(NewMapID,0,PageNum);
			SetMapPosOut(NewMapID,0,PageNum);

		 -- Add it to the element

			ElementAddMap(NewSlideID,NewMapID);

		 -- Activate the new element
			activate_element(NewSlideID);
			refresh(NewSlideID);
		}
	 }
}

