Panda3D
 All Classes Functions Variables Enumerations
text_test.cxx
00001 // Filename: text_test.cxx
00002 // Created by:  
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "eventHandler.h"
00016 #include "chancfg.h"
00017 #include "textNode.h"
00018 #include "eggLoader.h"
00019 #include "pnotify.h"
00020 #include "pt_NamedNode.h"
00021 
00022 extern PT_NamedNode render;
00023 extern PT_NamedNode egg_root;
00024 extern EventHandler event_handler;
00025 
00026 extern int framework_main(int argc, char *argv[]);
00027 extern void (*define_keys)(EventHandler&);
00028 
00029 PT(TextNode) text_node;
00030 char *textStr;
00031 
00032 void event_p(CPT_Event) {
00033   text_node->set_text("I'm a woo woo woo!");
00034 
00035   nout << "text is " << text_node->get_width() << " by "
00036        << text_node->get_height() << "\n";
00037 }
00038 
00039 void event_s(CPT_Event) {
00040   text_node->set_wordwrap(5.0);
00041 
00042   nout << "text is " << text_node->get_width() << " by "
00043        << text_node->get_height() << "\n";
00044 }
00045 
00046 void text_keys(EventHandler& eh) {
00047   eh.add_hook("p", event_p);
00048   eh.add_hook("s", event_s);
00049 
00050   text_node = new TextNode("text_node");
00051   PT_NamedNode font = loader.load_sync("cmr12");
00052   text_node->set_font(font.p());
00053   text_node->set_wordwrap(20.0);
00054   text_node->set_card_as_margin(0.25, 0.25, 0.25, 0.25);
00055   PT(Texture) tex = new Texture;
00056   tex->set_name("genericButton.rgb");
00057   tex->set_minfilter(Texture::FT_linear);
00058   tex->set_magfilter(Texture::FT_linear);
00059   tex->read("/beta/toons/textures/smGreyButtonUp.rgb");
00060   text_node->set_card_texture( tex );
00061   text_node->set_card_border(0.1, 0.1);
00062   text_node->set_text( textStr );
00063   text_node->set_text_color( 0.0, 0.0, 0.0, 1.0 );
00064   if (text_node->has_card_texture())
00065     nout << "I've got a texture!" << "\n";
00066   else
00067     nout << "I don't have a texture..." << "\n";
00068   nout << "text is " << text_node->get_width() << " by "
00069        << text_node->get_height() << "\n";
00070 
00071   new RenderRelation(egg_root, text_node);
00072 }
00073 
00074 int main(int argc, char *argv[]) {
00075   define_keys = &text_keys;
00076         if (argc > 1)
00077                 textStr = argv[1];
00078         else
00079                 textStr = argv[0];
00080   return framework_main(argc, argv);
00081 }
 All Classes Functions Variables Enumerations