WhipExamples/ColorMap.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 ColorMap()
00028 {
00029     WT_W2D_Class_Factory cf;
00030 
00031     //Store the old color map.
00032     WT_Color_Map *old_color_map = cf.Create_Color_Map( whip_file->desired_rendition().color_map() );
00033     if (old_color_map == NULL)
00034         return WT_Result::Out_Of_Memory_Error;
00035     
00036     //Create the new color map.
00037     WT_RGB rgb[3];
00038     rgb[0] = WT_RGB(255,0,0); //red
00039     rgb[1] = WT_RGB(0,255,0); //green
00040     rgb[2] = WT_RGB(0,0,255); //blue
00041 
00042     //Set the new color map active.
00043     whip_file->desired_rendition().color_map().set(3, rgb, *whip_file);
00044     //Draw some geometry with the new color map.
00045     whip_file->desired_rendition().color().set(0, whip_file->desired_rendition().color_map());
00046     WT_Text *text = cf.Create_Text(WT_Logical_Point(0, 0), WT_String("Red"));
00047     if (text == NULL)
00048         return WT_Result::Out_Of_Memory_Error;
00049     WD_CHECK(text->serialize(*whip_file));
00050     whip_file->desired_rendition().color().set(1, whip_file->desired_rendition().color_map());
00051     cf.Destroy( text );
00052     
00053     text = cf.Create_Text(WT_Logical_Point(150, 0), WT_String("Green"));
00054     if (text == NULL)
00055         return WT_Result::Out_Of_Memory_Error;
00056     WD_CHECK(text->serialize(*whip_file));
00057     whip_file->desired_rendition().color().set(2, whip_file->desired_rendition().color_map());
00058     cf.Destroy( text );
00059     
00060     text = cf.Create_Text(WT_Logical_Point(350, 0), WT_String("Blue"));
00061     WD_CHECK(text->serialize(*whip_file));
00062     cf.Destroy( text );
00063     //Resotre the old color map (using a different technique)
00064     whip_file->desired_rendition().color_map() = *old_color_map;
00065     
00066     cf.Destroy( old_color_map );
00067     
00068     return WT_Result::Success;
00069 }

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