BRL-CAD
scale.c
Go to the documentation of this file.
1 /* S C A L E . C
2  * BRL-CAD
3  *
4  * Copyright (c) 1998-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file libdm/scale.c
21  *
22  * Functions -
23  * dm_draw_scale Draws the view scale.
24  *
25  */
26 
27 #include "common.h"
28 
29 #include <string.h>
30 #include <math.h>
31 
32 #include "vmath.h"
33 #include "bn.h"
34 #include "raytrace.h"
35 #include "dm.h"
36 #include "dm_private.h"
37 
38 void
40  fastf_t viewSize,
41  int *lineColor,
42  int *textColor)
43 {
44  int soffset;
45  fastf_t xpos1, xpos2;
46  fastf_t ypos1, ypos2;
47  struct bu_vls vls = BU_VLS_INIT_ZERO;
48  /* Save the line attributes */
49  int saveLineWidth = dmp->dm_lineWidth;
50  int saveLineStyle = dmp->dm_lineStyle;
51 
52  /* Draw solid lines */
53  dm_set_line_attr(dmp, dmp->dm_lineWidth, 0); /* solid lines */
54 
55  bu_vls_printf(&vls, "%g", viewSize*0.5);
56  soffset = (int)(strlen(bu_vls_addr(&vls)) * 0.5);
57 
58  xpos1 = -0.5;
59  xpos2 = 0.5;
60  ypos1 = -0.8;
61  ypos2 = -0.8;
62 
63  dm_set_fg(dmp,
64  (unsigned char)lineColor[0],
65  (unsigned char)lineColor[1],
66  (unsigned char)lineColor[2], 1, 1.0);
67  dm_draw_line_2d(dmp, xpos1, ypos1, xpos2, ypos2);
68  dm_draw_line_2d(dmp, xpos1, ypos1+0.01, xpos1, ypos1-0.01);
69  dm_draw_line_2d(dmp, xpos2, ypos1+0.01, xpos2, ypos1-0.01);
70 
71  dm_set_fg(dmp,
72  (unsigned char)textColor[0],
73  (unsigned char)textColor[1],
74  (unsigned char)textColor[2], 1, 1.0);
75  dm_draw_string_2d(dmp, "0", xpos1-0.005, ypos1 + 0.02, 1, 0);
76  dm_draw_string_2d(dmp, bu_vls_addr(&vls),
77  xpos2-(soffset * 0.015),
78  ypos1 + 0.02, 1, 0);
79 
80  bu_vls_free(&vls);
81 
82  /* Restore the line attributes */
83  dm_set_line_attr(dmp, saveLineWidth, saveLineStyle);
84 }
85 
86 
87 /*
88  * Local Variables:
89  * mode: C
90  * tab-width: 8
91  * indent-tabs-mode: t
92  * c-file-style: "stroustrup"
93  * End:
94  * ex: shiftwidth=4 tabstop=8
95  */
int dm_draw_string_2d(dm *dmp, const char *str, fastf_t x, fastf_t y, int size, int use_aspect)
Definition: dm-generic.c:735
Header file for the BRL-CAD common definitions.
void bu_vls_free(struct bu_vls *vp)
Definition: vls.c:248
int dm_set_fg(dm *dmp, unsigned char r, unsigned char g, unsigned char b, int strict, fastf_t transparency)
Definition: dm-generic.c:441
char * bu_vls_addr(const struct bu_vls *vp)
Definition: vls.c:111
int dm_lineWidth
Definition: dm_private.h:95
void dm_draw_scale(dm *dmp, fastf_t viewSize, int *lineColor, int *textColor)
Definition: scale.c:39
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
int dm_set_line_attr(dm *dmp, int width, int style)
Definition: dm-generic.c:617
#define BU_VLS_INIT_ZERO
Definition: vls.h:84
int dm_draw_line_2d(dm *dmp, fastf_t x1, fastf_t y1_2d, fastf_t x2, fastf_t y2)
Definition: dm-generic.c:741
Definition: vls.h:56
double fastf_t
Definition: defines.h:300
int dm_lineStyle
Definition: dm_private.h:96