atomes 1.1.16
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
labels.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2024 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'labels.c'
24*
25* Contains:
26*
27
28 - Function to draw the axis labels
29
30*
31* List of functions:
32
33 void label (cairo_t * cr, double val, int axe, int p, project * this_proj);
34
35*/
36
37#include <string.h>
38#include <math.h>
39#include <cairo.h>
40#include <pango/pangocairo.h>
41
42#include "global.h"
43#include "curve.h"
44
56void label (cairo_t * cr, double val, int axe, int p, project * this_proj)
57{
58 gchar * label;
59 gchar * lab;
60 gchar * tmp;
61 int i, j;
62 double u, v;
63
64 lab = g_strdup_printf ("%.10lf", val);
65 for (i=0; i < strlen(lab); i++)
66 {
67 tmp = g_strdup_printf ("%c", lab[i]);
68 if (g_strcmp0 ((char *)tmp, ".") == 0) j = i;
69 g_free (tmp);
70 }
71 for (i=0; i < j + this_proj -> curves[activer][activec] -> labels_digit[axe] + 1; i++)
72 {
73 if (i == 0)
74 {
75 label = g_strdup_printf ("%c", lab[i]);
76 }
77 else
78 {
79 tmp = g_strdup_printf ("%s%c", label, lab[i]);
80 g_free (label);
81 label = g_strdup_printf ("%s", tmp);
82 g_free (tmp);
83 }
84 }
85 pango_layout_set_text (layout, label, -1);
86 if (p == 1)
87 {
88 pango_layout_get_size (layout, & i, & j);
89 if (axe == 0)
90 {
91 u = sin (this_proj -> curves[activer][activec] -> labels_angle[axe]) * (double)i;
92 v = sin (pi / 2.0 - this_proj -> curves[activer][activec] -> labels_angle[axe]) * (double)j;
93 ay = ay - (u + v)/PANGO_SCALE;
94 }
95 else
96 {
97 u = sqrt (1.0*i*i + 1.0*j*j);
98 v = atan ((1.0*j) / (1.0*i));
99 u = u * cos (this_proj -> curves[activer][activec] -> labels_angle[axe] + v);
100 ax = ax - u / PANGO_SCALE;
101 }
102 }
103 cairo_move_to (cr, ax, ay);
104 cairo_rotate (cr, this_proj -> curves[activer][activec] -> labels_angle[axe]);
105 pango_cairo_update_layout (cr, layout);
106 pango_cairo_show_layout (cr, layout);
107 cairo_stroke (cr);
108 cairo_rotate (cr, -this_proj -> curves[activer][activec] -> labels_angle[axe]);
109 pango_cairo_update_layout (cr, layout);
110}
double ay
Definition curve.c:70
double ax
Definition curve.c:70
PangoLayout * layout
Definition curve.c:79
Variable declarations for the curve widget Functions for interactions with the curve widget.
int activer
Definition w_curve.c:74
int activec
Definition w_curve.c:73
float val
Definition dlp_init.c:117
double pi
Definition global.c:195
Global variable declarations Global convenience function declarations Global data structure defin...
void label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
Definition labels.c:56
GtkWidget * lab
Definition workspace.c:73