atomes 1.1.16
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-2024 by CNRS and University of Strasbourg */
15
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
44extern DataLayout * get_extra_layout (int i);
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
66 x = this_proj -> curves[rid][cid] -> legend_pos[0] * resol[0];
67 y = this_proj -> curves[rid][cid] -> legend_pos[1] * resol[1];
68
69 pango_layout_set_font_description (layout, pango_font_description_from_string (this_proj -> curves[rid][cid] -> legend_font));
70 CurveExtra * ctmp;
71 ctmp = this_proj -> curves[rid][cid] -> extrac -> first;
72 for ( j=this_proj -> curves[rid][cid] -> extrac -> extras ; j >= 0 ; j-- )
73 {
74 y = y + 4.0*z/3.0;
75 if (this_proj -> curves[rid][cid] -> draw_id == j)
76 {
77 if (this_proj -> curves[rid][cid] -> layout -> dash > 0)
78 {
79 dasht = selectdash (this_proj -> curves[rid][cid] -> layout -> dash);
80 cairo_set_dash(cr, dasht -> a, dasht -> b, 0.0);
81 cairo_set_source_rgba (cr, this_proj -> curves[rid][cid] -> layout -> datacolor.red,
82 this_proj -> curves[rid][cid] -> layout -> datacolor.green,
83 this_proj -> curves[rid][cid] -> layout -> datacolor.blue,
84 this_proj -> curves[rid][cid] -> layout -> datacolor.alpha);
85 cairo_set_line_width (cr, this_proj -> curves[rid][cid] -> layout -> thickness);
86 cairo_move_to (cr, x-5, y);
87 cairo_line_to (cr, x+20, y);
88 cairo_stroke(cr);
89 g_free (dasht);
90 }
91 z = x-5;
92 draw_glyph (cr, this_proj -> curves[rid][cid] -> layout -> glyph, z, y,
93 this_proj -> curves[rid][cid] -> layout -> datacolor,
94 this_proj -> curves[rid][cid] -> layout -> gsize);
95 z = x+20;
96 draw_glyph (cr, this_proj -> curves[rid][cid] -> layout -> glyph, z, y,
97 this_proj -> curves[rid][cid] -> layout -> datacolor,
98 this_proj -> curves[rid][cid] -> layout -> gsize);
99 cairo_set_source_rgba (cr, this_proj -> curves[rid][cid] -> legend_color.red,
100 this_proj -> curves[rid][cid] -> legend_color.green,
101 this_proj -> curves[rid][cid] -> legend_color.blue,
102 this_proj -> curves[rid][cid] -> legend_color.alpha);
103 str = g_strdup_printf ("%s - %s", prepare_for_title(this_proj -> name), this_proj -> curves[rid][cid] -> name);
104 }
105 else
106 {
107 DataLayout * lay = ctmp -> layout;
108 if (lay -> dash > 0)
109 {
110 dasht = selectdash (lay -> dash);
111 cairo_set_dash(cr, dasht -> a, dasht -> b, 0.0);
112 cairo_set_source_rgba (cr, lay -> datacolor.red,
113 lay -> datacolor.green,
114 lay -> datacolor.blue,
115 lay -> datacolor.alpha);
116 cairo_set_line_width (cr, lay -> thickness);
117 cairo_move_to (cr, x-5, y);
118 cairo_line_to (cr, x+20, y);
119 cairo_stroke(cr);
120 g_free (dasht);
121 }
122 z = x-5;
123 draw_glyph (cr, lay -> glyph, z, y, lay -> datacolor, lay -> gsize);
124 z = x+20;
125 draw_glyph (cr, lay -> glyph, z, y, lay -> datacolor, lay -> gsize);
126 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
127 k = ctmp -> id.a;
128 l = ctmp -> id.b;
129 m = ctmp -> id.c;
130 str = g_strdup_printf ("%s - %s", prepare_for_title(get_project_by_id(k) -> name),
131 get_project_by_id(k) -> curves[l][m] -> name);
132 if (ctmp -> next != NULL) ctmp = ctmp -> next;
133 }
134 pango_layout_set_text (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_proj -> curves[rid][cid] -> show_legend_box)
147 {
148 dasht = selectdash (this_proj -> curves[rid][cid] -> legend_box_dash);
149 cairo_set_dash(cr, dasht -> a, dasht -> b, 0.0);
150 cairo_set_source_rgba (cr, this_proj -> curves[rid][cid] -> legend_box_color.red,
151 this_proj -> curves[rid][cid] -> legend_box_color.green,
152 this_proj -> curves[rid][cid] -> legend_box_color.blue,
153 this_proj -> curves[rid][cid] -> legend_box_color.alpha);
154 cairo_set_line_width (cr, this_proj -> curves[rid][cid] -> legend_box_thickness);
155 x = this_proj -> curves[rid][cid] -> legend_pos[0] * resol[0] - 25;
156 th = ih + fh + (y - this_proj -> curves[rid][cid] -> legend_pos[1] * resol[1]);
157 y = this_proj -> curves[rid][cid] -> 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:64
curve_dash * selectdash(int iddash)
setup dash pointer
Definition curve.c:134
PangoLayout * layout
Definition curve.c:79
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:80
DataLayout * get_extra_layout(int i)
retrieve the i data layout
Definition tab-2.c:195
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:57
double y
Definition ogl_draw.c:57
double x
Definition ogl_draw.c:57
int b
Definition tab-1.c:95
int a
Definition tab-1.c:95