DI-Guy C++ SDK Reference  13.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
diguyViewLabel.h
Go to the documentation of this file.
1 
2 /*********************************************************************
3  ** Copyright (c) 1992-2014 VT MAK
4  ** All rights reserved.
5  *********************************************************************/
6 
7 /*********************************************************************/
13 #ifndef __diguyViewLabel_H
14 #define __diguyViewLabel_H
15 
16 #ifdef SWIG
17 %module diguyViewLabel
18 #else
19 #define CPLUSPLUS_ONLY
20 #endif
21 
22 #ifdef CPLUSPLUS_ONLY
23 class bdiGraphicsLabel;
24 
25 #include <stdio.h> // for NULL definition
26 #include <diguy_constants.h>
27 #include <diguy_typedefs.h>
28 class diguyViewLabel;
29 
30 
31 #endif
32 
33 
34 /****************************************************************************/
36 enum {
42 };
43 
44 #include <declspec_diguy.h>
45 
46 
47 /****************************************************************************/
48 class BDI_DECLSPEC_diguy diguyViewLabel
49 {
50 
51 public:
52 
53 /*****************************************************************************/
63  /*l
64  *b Description:
65  **
66  ** Returns the name of the object. This pointer will
67  ** never be NULL.
68  **
69  *b Returns:
70  **
71  ** name of the object
72  */
73  const char* get_name();
74 
75 
76 /*****************************************************************************/
86  /*l
87  *b Description:
88  **
89  ** Sets the text on the label.
90  */
91  void set_text(const char* text);
92 
93  /*l
94  *b Description:
95  **
96  ** Returns the text on the label.
97  **
98  *b Returns:
99  **
100  ** pointer to NULL-terminated string
101  */
102  const char* get_text();
103 
104  /*l
105  *b Description:
106  **
107  ** Similar to set_background_color(), but sets the color
108  ** of the label text.
109  **
110  ** Default color is solid white (1, 1, 1, 1).
111  */
112  void set_text_color(float r, float g, float b, float a,
113  float interp_time = 0.0f);
114 
115  /*l
116  *b Description:
117  **
118  ** Similar to set_background_color(), but sets the shadow color
119  ** of the label text.
120  **
121  ** Default color is solid black (0, 0, 0, 1).
122  */
123  void set_text_shadow_color(float r, float g, float b, float a,
124  float interp_time = 0.0f);
125 
126  /*l
127  *b Description:
128  **
129  ** Enables or disables text shadow. Default is 0 (disabled).
130  **
131  *b Arguments:
132  **
133  *a text_shadow_enabled - pass 1 to enable shadow, 0 to disable
134  */
135  void set_text_shadow_enabled(int text_shadow_enabled);
136 
137  /*l
138  *b Description:
139  **
140  ** Sets how the label text is justified, possible values are:
141  **
142  ** - DIGUY_GRAPHICS_LABEL_JUSTIFIED_LEFT
143  ** - DIGUY_GRAPHICS_LABEL_JUSTIFIED_RIGHT
144  ** - DIGUY_GRAPHICS_LABEL_JUSTIFIED_CENTER
145  **
146  ** Depending on how the flag is set the text will either draw flowing
147  ** to the right of the current x. The left of the current x or
148  ** centered above x.
149  */
150  void set_text_justification(diguyViewLabelJustification just);
151 
152  /*l
153  *b Description:
154  **
155  ** Returns how the text on the label is being justified.
156  **
157  *b Returns:
158  **
159  ** One of the following values:
160  **
161  *- - DIGUY_GRAPHICS_LABEL_JUSTIFIED_LEFT
162  *- - DIGUY_GRAPHICS_LABEL_JUSTIFIED_RIGHT
163  *- - DIGUY_GRAPHICS_LABEL_JUSTIFIED_CENTER
164  */
165  diguyViewLabelJustification get_text_justification();
166 
167  /*l
168  *b Description:
169  **
170  ** Adds an x offset to the text part of the label.
171  */
172  void set_text_offset_x(int offset);
173 
174  /*l
175  *b Returns:
176  **
177  ** returns the x offset of the text part of the label.
178  */
179  int get_text_offset_x();
180 
181  /*l
182  *b Description:
183  **
184  ** Adds a y offset to the text part of the label.
185  */
186  void set_text_offset_y(int offset);
187 
188  /*l
189  *b Returns:
190  **
191  ** returns the y offset of the text part of the label.
192  */
193  int get_text_offset_y();
194 
195 
196 /*****************************************************************************/
206  /*l
207  *b Description:
208  **
209  ** Sets the x location of the label. Positive numbers are
210  ** relative to the left side of the screen; negative numbers
211  ** are relative to the right side of the screen.
212  **
213  ** The optional interp_time argument will make the label
214  ** animate to its new location.
215  **
216  *b Arguments:
217  **
218  *a screen_x_offset - x offset in pixels
219  *a interp_time - amount of time in seconds used to
220  *a shift to new position
221  */
222  void set_x(float screen_x_offset,
223  float interp_time = 0.0f);
224 
225  /*l
226  *b Description:
227  **
228  ** Gets the x location of the label.
229  **
230  ** Note: this will return the current x value, not the desired one.
231  */
232  float get_x();
233 
234  /*l
235  *b Description:
236  **
237  ** Sets the y location of the label. Positive numbers are
238  ** relative to the bottom of the screen; negative numbers
239  ** are relative to the top of the screen.
240  **
241  ** The optional interp_time argument will make the label
242  ** animate to its new location.
243  **
244  *b Arguments:
245  **
246  *a screen_y_offset - y offset in pixels
247  *a interp_time - amount of time in seconds used to
248  *a shift to new position
249  */
250  void set_y(float screen_y_offset,
251  float interp_time = 0.0f);
252 
253  /*l
254  *b Description:
255  **
256  ** Gets the y location of the label.
257  **
258  ** Note: this will return the current y value, not the desired one.
259  */
260  float get_y();
261 
262  /*l
263  *b Description:
264  **
265  ** Sets if having a negative value wraps to the other side of the
266  ** viewport. Defaults to 1.
267  **
268  *b Arguments:
269  **
270  *a wrap - 1 if x should wrap; 0 if not
271  */
272  void set_negative_wraps_x(int wrap);
273 
274  /*l
275  *b Returns:
276  **
277  ** 1 if x wraps its offset when negative
278  */
279  int get_negative_wraps_x();
280 
281  /*l
282  *b Description:
283  **
284  ** Sets if having a negative value wraps to the other side of the
285  ** viewport. Defaults to 1.
286  **
287  *b Arguments:
288  **
289  *a wrap - 1 if y should wrap; 0 if not
290  */
291  void set_negative_wraps_y(int wrap);
292 
293  /*l
294  *b Returns:
295  **
296  ** 1 if y wraps its offset when negative
297  */
298  int get_negative_wraps_y();
299 
300  /*l
301  *b Description:
302  **
303  ** Sets how the label is positioned relative to the window, possible
304  ** values are:
305  **
306  *- - DIGUY_GRAPHICS_LABEL_JUSTIFIED_LEFT
307  *- - DIGUY_GRAPHICS_LABEL_JUSTIFIED_RIGHT
308  *- - DIGUY_GRAPHICS_LABEL_JUSTIFIED_CENTER
309  **
310  ** Depending on how the flag is set the x offset will be measured from
311  ** the right of the screen, the left or from the center of the window.
312  */
313  void set_window_justification_x(diguyViewLabelJustification just);
314 
315  /*l
316  *b Returns:
317  **
318  ** label's x positioning parameter described above
319  */
320  diguyViewLabelJustification get_window_justification_x();
321 
322  /*l
323  *b Description:
324  **
325  ** Sets how the label is positioned relative to the window. Possible
326  ** values are:
327  **
328  *- - DIGUY_GRAPHICS_LABEL_JUSTIFIED_BOTTOM
329  *- - DIGUY_GRAPHICS_LABEL_JUSTIFIED_TOP
330  *- - DIGUY_GRAPHICS_LABEL_JUSTIFIED_CENTER
331  **
332  ** Depending on how the flag is set the y offset will be measured from
333  ** the bottom of the screen, from the top or from the center of the
334  ** window.
335  */
336  void set_window_justification_y(diguyViewLabelJustification just);
337 
338  /*l
339  *b Returns:
340  **
341  ** label's y positioning parameter described above
342  */
343  diguyViewLabelJustification get_window_justification_y();
344 
345  /*l
346  *b Description:
347  **
348  ** Sets the minimum width of the label. The default is 0,
349  ** which will size the label width to fit the label text or bar
350  ** graph.
351  **
352  *b Arguments:
353  **
354  *a min_x - minimum width, in pixels
355  */
356  void set_minimum_width(int min_x);
357 
358  /*l
359  *b Returns:
360  **
361  ** minimum width of the label, as set by set_minimum_width()
362  */
363  int get_minimum_width();
364 
365  /*l
366  *b Description:
367  **
368  ** Similar to set_minimum_width(), but sets minimum label height.
369  */
370  void set_minimum_height(int min_y);
371 
372  /*l
373  *b Description:
374  **
375  ** Similar to set_minimum_height(), but returns minimum label height.
376  */
377  int get_minimum_height();
378 
379  /*l
380  *b Returns:
381  **
382  ** the current label width
383  */
384  int get_width();
385 
386  /*l
387  *b Returns:
388  **
389  ** the current label height
390  */
391  int get_height();
392 
393  /*l
394  *b Description:
395  **
396  ** Turns the label into a full-window overlay. This can be useful
397  ** for things like Heads-Up Displays (HUDs).
398  **
399  ** If there is a background image (see set_background_image()), the
400  ** image will be scaled to fit the entire screen.
401  **
402  ** Default is 0 (not full-window).
403  ** Note: turning a label into a full window will automatically make
404  ** it non-clickable.
405  **
406  *b Arguments:
407  **
408  *a full_window - pass 1 for full-window, 0 for not full-window
409  */
410  void set_full_window(int full_window);
411 
412  /*l
413  *b Returns:
414  **
415  ** whether label is full-window, as set by set_full_window()
416  */
417  int get_full_window();
418 
419  /*l
420  *b Description:
421  **
422  ** Resets the parameters of the label to the values from the
423  ** constructor.
424  */
425  void reset();
426 
427  /*l
428  *b Description:
429  **
430  ** Sets the visibility of a label. Default is 1 (visible).
431  **
432  *b Arguments:
433  **
434  *a visible - pass 1 to make label visible, 0 for invisible
435  */
436  void set_visible(int visible);
437 
438  /*l
439  *b Returns:
440  **
441  ** visibility of label, as set by set_visible()
442  */
443  int get_visible();
444 
445 
446 /*****************************************************************************/
456  /*l
457  *b Description:
458  **
459  ** Sets the color of the label background.
460  **
461  ** The optional interp_time argument will make the label gradually
462  ** shift to its new color.
463  **
464  *b Arguments:
465  **
466  *a r, g, b, a - RGBA values of new color, between 0.0 and 1.0
467  *a interp_time - amount of time in seconds used to shift to
468  *a new color
469  **
470  ** Default color is translucent blue (0, 0, 0.3, 0.7).
471  */
472  void set_background_color(float r, float g, float b, float a,
473  float interp_time = 0.0f);
474 
475  /*l
476  *b Description:
477  **
478  ** Sets the background image of the label. The file will
479  ** be looked for in $DIGUY/custom/geometry/rgb first,
480  ** then in $DIGUY/geometry/rgb.
481  **
482  ** The default is no background image.
483  */
484  void set_background_image(const char* filename);
485 
486  /*l
487  *b Description:
488  **
489  ** Enables or disables label background. Default is 1 (enabled).
490  **
491  *b Arguments:
492  **
493  *a background_enabled - pass 1 to enable shadow, 0 to disable
494  */
495  void set_background_enabled(int background_enabled);
496 
497 
498 /*****************************************************************************/
508  /*l
509  *b Description:
510  **
511  ** Similar to set_border_color(), but sets the border color of the
512  ** label background.
513  **
514  ** Default color is translucent white (1, 1, 1, 0.7).
515  *a r, g, b, a - RGBA values of new color, between 0.0 and 1.0
516  *a interp_time - amount of time in seconds used to shift to
517  *a new color
518  */
519  void set_border_color(float r, float g, float b, float a,
520  float interp_time = 0.0f);
521 
522  /*l
523  *b Description:
524  **
525  ** Sets the margin, of the label. Default is 6 pixels.
526  **
527  *b Arguments:
528  **
529  *a margin_size - margin size in pixels
530  */
531  void set_margin_size(int margin_size);
532 
533  /*l
534  *b Description:
535  **
536  ** Sets if the border should be visible. Default is 1 (enabled).
537  **
538  *b Arguments:
539  **
540  *a border_enabled - pass 1 to enable, 0 to disable
541  */
542  void set_border_enabled(int border_enabled);
543 
544 
545 /*****************************************************************************/
589  /*l
590  *b Description:
591  **
592  ** Enables bar graph functionality for this label. Note that this
593  ** doesn't automatically turn off text or background image.
594  **
595  ** Label position and minimum sizes should be set before this
596  ** is called.
597  **
598  *b Arguments:
599  **
600  *a num_lines - number of lines/bars that will be shown
601  *a lines_are_vertical - pass 1 for lines to go bottom to top,
602  *a 0 for lines to go left to right
603  *a line_thickness - line thickness, in pixels
604  *a space_between_lines - space between lines, in pixels
605  *a derive_minimum_label_size - derive and set the minimum label size,
606  *a as if set_minimum_width() and
607  *a set_minimum_height() were called to fit
608  *a this bar graph
609  */
610  void enable_bar_graph(int num_lines,
611  int lines_are_vertical = 1,
612  int line_thickness = 10,
613  int space_between_lines = 2,
614  int derive_minimum_label_size = 1);
615 
616  /*l
617  *b Description:
618  **
619  ** Disables bar graph functionality for this label. Bar graph lines
620  ** will no longer be visible.
621  */
622  void disable_bar_graph();
623 
624  /*l
625  *b Returns:
626  **
627  ** number of bars/lines in bar graph
628  */
629  int get_bar_graph_num_lines();
630 
631  /*l
632  *b Returns:
633  **
634  ** 1 if lines to go bottom to top, 0 if lines to go left to right
635  */
636  int get_bar_graph_lines_are_vertical();
637 
638  /*l
639  *b Description:
640  **
641  ** Sets the color of the specified line.
642  */
643  void set_bar_graph_line_color(int line_number,
644  float r, float g, float b, float a);
645 
646  /*l
647  *b Description:
648  **
649  ** Sets how much of the usable space (bottom to top for vertical
650  ** lines, left to right for horizontal lines) a line will take up
651  ** at its maximum length.
652  **
653  *b Arguments:
654  **
655  *a line_number - line to change
656  *a ratio - how much of the line to display, from 0 (none) to
657  *a 1 (all)
658  **
659  ** For example, if, based on the label height, the bar graph has at
660  ** most 20 pixels to show each line, passing 0.5 for ratio will
661  ** fill 10 pixels with the line color, while passing 1.0 for ratio
662  ** will fill all 20 pixels.
663  */
664  void set_bar_graph_line_magnitude_ratio(int line_number, float ratio);
665 
666  /*l
667  *b Description:
668  **
669  ** Similar to set_bar_graph_line_magnitude_ratio(), but sets the
670  ** length of the line based on absolute pixels.
671  **
672  ** Note that care should be taken to not overrun the current height
673  ** or width of the label when using this function.
674  **
675  *b Arguments:
676  **
677  *a line_number - line to change
678  *a pixels - line length in pixels
679  */
680  void set_bar_graph_line_magnitude_pixels(int line_number, int pixels);
681 
682 
683 /*****************************************************************************/
693  /*l
694  *b Description:
695  **
696  ** Sets if a label is temporary. Temporary labels are destroyed on
697  ** scenario reset, and will not re-appear unless they are recreated.
698  **
699  ** Pass 1 to make label temporary, 0 to make it permanent.
700  */
701  void set_is_temporary(int temporary);
702 
703  /*l
704  *b Returns:
705  **
706  ** 1 if a label is temporary, 0 if not; see set_is_temporary()
707  */
708  int get_is_temporary();
709 
710  /*l
711  *b Description:
712  **
713  ** Sets how far away the label will be drawn.
714  **
715  *b Arguments:
716  **
717  *a draw_limit - -1 to always draw, otherwise will draw till draw_limit
718  *a is reached
719  */
720  void set_draw_limit(float draw_limit);
721 
722  /*l
723  *b Description:
724  **
725  ** Gets how far away the label will be drawn.
726  ** Defaults to -1 which always draws.
727  */
728  float get_draw_limit();
729 
730  /*l
731  *b Description:
732  **
733  ** Sets if the label is clickable with the mouse.
734  **
735  ** For character labels this is the equivalent of clicking on the
736  ** character itself, and can trigger the CALLBACK_ID_IGUY_INTERACT
737  ** callback.
738  **
739  ** For screen labels it triggers CALLBACK_ID_USER_SELECTED on mouse
740  ** down, and CALLBACK_ID_USER_UNSELECTED on mouse up.
741  **
742  ** By default labels are clickable.
743  **
744  *b Arguments:
745  **
746  *a is_clickable - pass 1 to enable, 0 to disable
747  */
748  void set_is_clickable(int is_clickable);
749 
750  /*l
751  *b Returns:
752  **
753  ** 1 if label responds to mouse clicks, 0 if not; see
754  ** set_is_clickable()
755  */
756  int get_is_clickable();
757 
758  /*l
759  *b Description:
760  **
761  ** Sets if the label is "noise".
762  **
763  ** The textures of noise labels with be shifted every frame.
764  **
765  ** By default labels not noise.
766  **
767  *b Arguments:
768  **
769  *a is_noise - pass 1 to enable, 0 to disable
770  */
771  void set_is_noise(int is_noise);
772 
773  /*l
774  *b Returns:
775  **
776  ** 1 if label textures shift every frame, 0 if not; see
777  ** set_is_noise()
778  */
779  int get_is_noise();
780 
781  /*l
782  *b Resturs:
783  **
784  ** NULL-terminated string "label"
785  */
786  const char* get_type_name();
787 
788  /*l
789  *b Description:
790  **
791  ** This is an enumeration of the different callbacks that can be
792  ** registered with add_callback() and add_callback_script().
793  */
794  enum {
795  CALLBACK_ID_USER_SELECTED = 1,
796  CALLBACK_ID_USER_UNSELECTED,
797  CALLBACK_ID_IGUY_INTERACT
798  };
799 
800  /*l
801  *b Description:
802  **
803  ** This function adds a user callback script. Callback scripts can
804  ** be removed with remove_callback_script().
805  **
806  *b Arguments:
807  **
808  *a callback_id - integer id of the callback
809  *a callback_script - script text of callback to be added
810  *a callback_script_type - the type of script contained in
811  *a callback_script
812  **
813  ** If NULL is passed for callback_script_type, a default script type
814  ** will be derived based on the default script interpreter of the
815  ** scenario.
816  **
817  *i lua specific:
818  **
819  ** When the script is called, the object for which it is being called
820  ** will be in the callback_object global.
821  **
822  ** To pass NULL when calling from a lua script, use nil.
823  **
824  *b Returns:
825  **
826  ** 0 on success, -1 on failure
827  **
828  *b lua Example:
829  **
830  *e ------------------------------------------------------------------------------
831  *e local on_clicked_callback = [[
832  *e
833  *e local la_name = callback_object:get_name();
834  *e bdi_log_print(BDI_LOG_WARN, "Calling on_click for label ".. la_name .. "'.\n");
835  *e
836  *e ]]
837  *e ------------------------------------------------------------------------------
838  *e
839  *e label:add_callback_script(diguyViewLabel_CALLBACK_ID_USER_UNSELECTED,
840  *e on_clicked_callback,
841  *e "lua");
842  */
843  int add_callback_script(int callback_id,
844  const char* callback_script,
845  const char* callback_script_type = NULL);
846 
847  /*l
848  *b Description:
849  **
850  ** This function removes a user callback script previously added with
851  ** add_callback_script().
852  **
853  *b Arguments:
854  **
855  *a callback_id - integer id of the callback
856  *a callback_script - script text of callback previously added
857  *a callback_script_type - the type of script contained in
858  *a callback_script
859  **
860  ** If NULL is passed for callback_script, all callback
861  ** scripts whose ids match callback_id and whose types match
862  ** callback_script_type will be removed.
863  **
864  ** If NULL is passed for callback_script_type, a default script type
865  ** will be derived based on the default script interpreter of the
866  ** scenario.
867  **
868  *i lua specific:
869  **
870  ** To pass NULL when calling from a lua script, use nil.
871  **
872  *b Returns:
873  **
874  ** 0 on success, -1 on failure
875  **
876  *b Lua Example:
877  **
878  *e --
879  *e -- Remove all callback scripts with id
880  *e -- diguyViewLabel_CALLBACK_ID_USER_UNSELECTED
881  *e --
882  *e label:remove_callback_script(diguyViewLabel_CALLBACK_ID_USER_UNSELECTED,
883  *e nil,
884  *e "lua");
885  */
886  int remove_callback_script(int callback_id,
887  const char* callback_script,
888  const char* callback_script_type = NULL);
889 
890 
891 #ifdef CPLUSPLUS_ONLY
892 
893  /*l
894  *b Description:
895  **
896  ** This function adds a user callback. Callbacks can be removed
897  ** with remove_callback() or remove_callback_with_user_data().
898  **
899  *b Arguments:
900  **
901  *a callback - pointer to function with prototype
902  *a diguyViewLabelCallback (typedefed above)
903  *a callback_id - integer id of when this callback is to be called
904  *a callback_params - not currently used; pass NULL
905  *a callback_user_data - pointer for user's own use; DI-Guy will
906  *a do nothing to the contents of this pointer
907  *a beyond passing it back when the callback is
908  *a invoked
909  **
910  *b Returns:
911  **
912  ** 0 on success, -1 on failure
913  **
914  *b Callable From:
915  **
916  *- - C++
917  */
918  int add_callback(int callback_id,
919  diguyViewLabelCallback* callback,
920  void* callback_params = NULL,
921  void* callback_user_data = NULL);
922 
923  /*l
924  *b Description:
925  **
926  ** This function removes a user callback. All callbacks matching
927  ** the specified callback_id and callback function will be removed.
928  **
929  *b Arguments:
930  **
931  *a callback_id - integer id of when this callback is to be called
932  *a callback - pointer to function with prototype
933  *a diguyViewLabelCallback (typedefed above)
934  **
935  *b Returns:
936  **
937  ** 0 on success, -1 on failure
938  **
939  *b Callable From:
940  **
941  *- - C++
942  */
943  int remove_callback(int callback_id,
944  diguyViewLabelCallback* callback);
945 
946  /*b Description:
947  **
948  ** This function removes a user callback. All callbacks matching
949  ** the specified callback_id and callback_user_data pointer will
950  ** be removed.
951  **
952  *b Arguments:
953  **
954  *a callback_id - integer id of when this callback is to be called
955  *a callback_user_data - pointer for user's own use
956  **
957  *b Returns:
958  **
959  ** 0 on success, -1 on failure
960  **
961  *b Callable From:
962  **
963  *- - C++
964  */
965  int remove_callback_with_user_data(int callback_id,
966  void* callback_user_data);
967 
973  bdiGraphicsLabel* get_scripted_object() {return m_label;}
974 
975 private:
976 
977  /*l
978  ** A private constructor.
979  */
980  diguyViewLabel(bdiGraphicsLabel* label);
981 
982  /*l
983  ** A pointer to internal data.
984  */
985  bdiGraphicsLabel* m_label;
986 
987  friend class bdiGraphicsLabel;
988 
989 #endif
990 
991 };
992 
993 #endif /* __diguyViewFog_H */
994