WhipExamples/Visibility.cpp

00001 //
00002 //  Copyright (c) 2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED,
00008 //  AS TO THE CORRECTNESS OF THIS CODE OR ANY DERIVATIVE
00009 //  WORKS WHICH INCORPORATE IT.
00010 //
00011 //  AUTODESK PROVIDES THE CODE ON AN "AS-IS" BASIS
00012 //  AND EXPLICITLY DISCLAIMS ANY LIABILITY, INCLUDING
00013 //  CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00014 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00015 //
00016 //  Use, duplication, or disclosure by the U.S. Government is subject to
00017 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00018 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00019 //  Data and Computer Software), as applicable.
00020 //
00021 
00022 #include "whiptk/whip_toolkit.h"
00023 #include "whiptk/w2d_class_factory.h"
00024 
00025 extern WT_File *whip_file; //Assume this has been opened for writing elsewhere.
00026 
00027 WT_Result Visibility()
00028 {
00029     WT_W2D_Class_Factory cf;
00030 
00031     //Store the current visibility and color.
00032     WT_Boolean previous_visibility = whip_file->desired_rendition().visibility().visible();
00033     WT_Color *previous_color = cf.Create_Color(whip_file->desired_rendition().color());
00034     if (previous_color == NULL)
00035         return WT_Result::Out_Of_Memory_Error;
00036     //Define a polygon to be used as an invisible link target.
00037     int x=0,y=0;
00038     WT_Logical_Point vP[4];
00039     vP[0] = WT_Logical_Point(x-100,y-100);
00040     vP[1] = WT_Logical_Point(x-100,y+100);
00041     vP[2] = WT_Logical_Point(x+100,y+100);
00042     vP[3] = WT_Logical_Point(x+100,y-100);
00043     WT_Polygon *polygon = cf.Create_Polygon(4, vP, WD_True);
00044     if (polygon == NULL)
00045         return WT_Result::Out_Of_Memory_Error;
00046 
00047     //Set the current visibility to off, and the color to transparent black.
00048     whip_file->desired_rendition().visibility() = WD_False;
00049     whip_file->desired_rendition().color().set(0,0,0,0);
00050     //Add a hyperlink and serialize the invisible polygon.
00051     WT_URL_Item  url(0, "http://www.autodesk.com/viewers", "Autodesk Viewers Page");
00052     whip_file->desired_rendition().url().add_url_optimized(url, *whip_file);
00053     WD_CHECK(polygon->serialize(*whip_file));
00054     cf.Destroy( polygon );
00055     whip_file->desired_rendition().url().clear();
00056 
00057     //Draw something on top of the invisible polygon.
00058     //Set the visibility and color back.
00059     whip_file->desired_rendition().visibility() = previous_visibility;
00060     whip_file->desired_rendition().color() = *previous_color;
00061     //Create a text object.
00062     WT_Text *text = cf.Create_Text(WT_Logical_Point(x-10, y), WT_String("CLICK"));
00063     if (text == NULL)
00064         return WT_Result::Out_Of_Memory_Error;
00065     WD_CHECK(text->serialize(*whip_file));
00066     cf.Destroy( text );
00067     cf.Destroy( previous_color );
00068 
00069     return WT_Result::Success;
00070 }

Generated on Tue Jan 6 22:41:12 2009 for Autodesk DWF Whip 2D Toolkit by  doxygen 1.4.5