atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
legend.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-2026 by CNRS and University of Strasbourg */
15
21
22/*
23* This file: 'legend.c'
24*
25* Contains:
26*
27
28 - The function to draw the legend
29
30*
31* List of functions:
32
33 void show_legend (cairo_t * cr, project * this_proj, int rid, int cid);
34
35*/
36
37#include <stdlib.h>
38#include <cairo.h>
39#include <pango/pangocairo.h>
40
41#include "global.h"
42#include "curve.h"
43
45
56void show_legend (cairo_t * cr, project * this_proj, int rid, int cid)
57{
58 double x, y, z;
59 double ih, fh;
60 double tw, th;
61 int w, h;
62 int j, k, l, m;
63 gchar * str;
64 curve_dash * dasht;
65 Curve * this_curve = this_proj -> analysis[rid] -> curves[cid];
66
67 x = this_curve -> legend_pos[0] * resol[0];
68 y = this_curve -> legend_pos[1] * resol[1];
69
70 pango_layout_set_font_description (layout, pango_font_description_from_string (this_curve -> legend_font));
71 CurveExtra * ctmp;
72 ctmp = this_curve -> extrac -> first;
73 for ( j=this_curve -> extrac -> extras ; j >= 0 ; j-- )
74 {
75 y = y + 4.0*z/3.0;
76 if (this_curve -> draw_id == j)
77 {
78 if (this_curve -> layout -> dash > 0)
79 {
80 dasht = selectdash (this_curve -> layout -> dash);
81 cairo_set_dash(cr, dasht -> a, dasht -> b, 0.0);
82 cairo_set_source_rgba (cr, this_curve -> layout -> datacolor.red,
83 this_curve -> layout -> datacolor.green,
84 this_curve -> layout -> datacolor.blue,
85 this_curve -> layout -> datacolor.alpha);
86 cairo_set_line_width (cr, this_curve -> layout -> thickness);
87 cairo_move_to (cr, x-5, y);
88 cairo_line_to (cr, x+20, y);
89 cairo_stroke(cr);
90 g_free (dasht);
91 }
92 z = x-5;
93 draw_glyph (cr, this_curve -> layout -> glyph, z, y,
94 this_curve -> layout -> datacolor,
95 this_curve -> layout -> gsize);
96 z = x+20;
97 draw_glyph (cr, this_curve -> layout -> glyph, z, y,
98 this_curve -> layout -> datacolor,
99 this_curve -> layout -> gsize);
100 cairo_set_source_rgba (cr, this_curve -> legend_color.red,
101 this_curve -> legend_color.green,
102 this_curve -> legend_color.blue,
103 this_curve -> legend_color.alpha);
104 str = g_strdup_printf ("%s - %s", prepare_for_title(this_proj -> name), this_curve -> name);
105 }
106 else
107 {
108 DataLayout * lay = ctmp -> layout;
109 if (lay -> dash > 0)
110 {
111 dasht = selectdash (lay -> dash);
112 cairo_set_dash(cr, dasht -> a, dasht -> b, 0.0);
113 cairo_set_source_rgba (cr, lay -> datacolor.red,
114 lay -> datacolor.green,
115 lay -> datacolor.blue,
116 lay -> datacolor.alpha);
117 cairo_set_line_width (cr, lay -> thickness);
118 cairo_move_to (cr, x-5, y);
119 cairo_line_to (cr, x+20, y);
120 cairo_stroke(cr);
121 g_free (dasht);
122 }
123 z = x-5;
124 draw_glyph (cr, lay -> glyph, z, y, lay -> datacolor, lay -> gsize);
125 z = x+20;
126 draw_glyph (cr, lay -> glyph, z, y, lay -> datacolor, lay -> gsize);
127 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
128 k = ctmp -> id.a;
129 l = ctmp -> id.b;
130 m = ctmp -> id.c;
131 str = g_strdup_printf ("%s - %s", get_project_by_id(k) -> name, get_project_by_id(k) -> analysis[l] -> curves[m] -> name);
132 if (ctmp -> next != NULL) ctmp = ctmp -> next;
133 }
134 pango_layout_set_markup (layout, str, -1);
135 pango_layout_get_size (layout, & w, & h);
136 z = (double) h / PANGO_SCALE;
137 if (j == 0) ih = z;
138 fh = z;
139 tw = max(tw, (double) w / PANGO_SCALE);
140 cairo_move_to (cr, x + 35.0, y - z/2);
141 pango_cairo_update_layout (cr, layout);
142 pango_cairo_show_layout (cr, layout);
143 cairo_stroke (cr);
144 g_free (str);
145 }
146 if (this_curve -> show_legend_box)
147 {
148 dasht = selectdash (this_curve -> legend_box_dash);
149 cairo_set_dash(cr, dasht -> a, dasht -> b, 0.0);
150 cairo_set_source_rgba (cr, this_curve -> legend_box_color.red,
151 this_curve -> legend_box_color.green,
152 this_curve -> legend_box_color.blue,
153 this_curve -> legend_box_color.alpha);
154 cairo_set_line_width (cr, this_curve -> legend_box_thickness);
155 x = this_curve -> legend_pos[0] * resol[0] - 25;
156 th = ih + fh + (y - this_curve -> legend_pos[1] * resol[1]);
157 y = this_curve -> legend_pos[1] * resol[1] - ih;
158 tw = tw + 80;
159 cairo_rectangle (cr, x, y, tw, th);
160 cairo_stroke(cr);
161 g_free (dasht);
162 }
163}
int resol[2]
Definition curve.c:65
curve_dash * selectdash(int iddash)
setup dash pointer
Definition curve.c:135
PangoLayout * layout
Definition curve.c:80
Variable declarations for the curve widget Functions for interactions with the curve widget.
void draw_glyph(cairo_t *in, int theglyph, double x, double y, ColRGBA gcolor, double size)
draw glyph at (x,y)
Definition glyph.c:88
Global variable declarations Global convenience function declarations Global data structure defin...
gchar * prepare_for_title(gchar *init)
prepare a string for a window title, getting rid of all markup
Definition tools.c:71
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
#define max(a, b)
Definition global.h:92
DataLayout * get_extra_layout(int i)
void show_legend(cairo_t *cr, project *this_proj, int rid, int cid)
draw legend
Definition legend.c:56
double z
Definition ogl_draw.c:63
double y
Definition ogl_draw.c:63
double x
Definition ogl_draw.c:63