Panda3D
text_test.cxx
1 // Filename: text_test.cxx
2 // Created by:
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "eventHandler.h"
16 #include "chancfg.h"
17 #include "textNode.h"
18 #include "eggLoader.h"
19 #include "pnotify.h"
20 #include "pt_NamedNode.h"
21 
22 extern PT_NamedNode render;
23 extern PT_NamedNode egg_root;
24 extern EventHandler event_handler;
25 
26 extern int framework_main(int argc, char *argv[]);
27 extern void (*define_keys)(EventHandler&);
28 
29 PT(TextNode) text_node;
30 char *textStr;
31 
32 void event_p(CPT_Event) {
33  text_node->set_text("I'm a woo woo woo!");
34 
35  nout << "text is " << text_node->get_width() << " by "
36  << text_node->get_height() << "\n";
37 }
38 
39 void event_s(CPT_Event) {
40  text_node->set_wordwrap(5.0);
41 
42  nout << "text is " << text_node->get_width() << " by "
43  << text_node->get_height() << "\n";
44 }
45 
46 void text_keys(EventHandler& eh) {
47  eh.add_hook("p", event_p);
48  eh.add_hook("s", event_s);
49 
50  text_node = new TextNode("text_node");
51  PT_NamedNode font = loader.load_sync("cmr12");
52  text_node->set_font(font.p());
53  text_node->set_wordwrap(20.0);
54  text_node->set_card_as_margin(0.25, 0.25, 0.25, 0.25);
55  PT(Texture) tex = new Texture;
56  tex->set_name("genericButton.rgb");
57  tex->set_minfilter(SamplerState::FT_linear);
58  tex->set_magfilter(SamplerState::FT_linear);
59  tex->read("/beta/toons/textures/smGreyButtonUp.rgb");
60  text_node->set_card_texture( tex );
61  text_node->set_card_border(0.1, 0.1);
62  text_node->set_text( textStr );
63  text_node->set_text_color( 0.0, 0.0, 0.0, 1.0 );
64  if (text_node->has_card_texture())
65  nout << "I've got a texture!" << "\n";
66  else
67  nout << "I don't have a texture..." << "\n";
68  nout << "text is " << text_node->get_width() << " by "
69  << text_node->get_height() << "\n";
70 
71  new RenderRelation(egg_root, text_node);
72 }
73 
74 int main(int argc, char *argv[]) {
75  define_keys = &text_keys;
76  if (argc > 1)
77  textStr = argv[1];
78  else
79  textStr = argv[0];
80  return framework_main(argc, argv);
81 }
A class to monitor events from the C++ side of things.
Definition: eventHandler.h:41
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:75
bool add_hook(const string &event_name, EventFunction *function)
Adds the indicated function to the list of those that will be called when the named event is thrown...
The primary interface to this module.
Definition: textNode.h:52
A ConstPointerTo is similar to a PointerTo, except it keeps a const pointer to the thing...
Definition: pointerTo.h:144