atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
frame.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: 'frame.c'
24*
25* Contains:
26*
27
28 - The functions to draw the frame
29
30*
31* List of functions:
32
33 void prep_frame (cairo_t * fr, int da, double ti, ColRGBA dcol);
34 void prep_axis_data (project * this_proj, int rid, int cid, int ax);
35 void draw_frame (cairo_t * cr, project * this_proj, int rid, int cid);
36
37*/
38
39#include <stdlib.h>
40#include <gdk/gdk.h>
41#include <cairo.h>
42
43#include "global.h"
44#include "curve.h"
45
56void prep_frame (cairo_t * fr, int da, double ti, ColRGBA dcol)
57{
58 curve_dash * tdash;
59
60 tdash = selectdash (da);
61 cairo_set_dash (fr, tdash -> a, tdash -> b, 0.0);
62 cairo_set_source_rgba (fr, dcol.red, dcol.green, dcol.blue, dcol.alpha);
63 cairo_set_line_width (fr, ti);
64 g_free (tdash);
65}
66
81void show_frame (cairo_t * cd, int tf, int da, int res[2], double ti, double x[2], double y[2], ColRGBA dcol)
82{
83 double x1, x2;
84 double y1, y2;
85
86 prep_frame (cd, da, ti, dcol);
87 x1 = x[0] * res[0];
88 x2 = x[1] * res[0];
89 y1 = y[0] * res[1];
90 y2 = y[1] * res[1];
91 switch (tf)
92 {
93 case 0:
94 cairo_move_to (cd, x1, y2);
95 cairo_line_to (cd, x2, y2);
96 cairo_line_to (cd, x2, y1);
97 cairo_line_to (cd, x1, y1);
98 cairo_line_to (cd, x1, y2);
99 break;
100 case 1:
101 cairo_move_to (cd, x1, y2);
102 cairo_line_to (cd, x1, y1);
103 cairo_line_to (cd, x2, y1);
104 cairo_line_to (cd, x2, y2);
105 break;
106 case 2:
107 cairo_move_to (cd, x1, y2);
108 cairo_line_to (cd, x1, y1);
109 cairo_line_to (cd, x2, y1);
110 break;
111 case 3:
112 cairo_move_to (cd, x2, y2);
113 cairo_line_to (cd, x2, y1);
114 cairo_line_to (cd, x1, y1);
115 break;
116 case 4:
117 cairo_move_to (cd, x1, y1);
118 cairo_line_to (cd, x2, y1);
119 break;
120 }
121 cairo_stroke (cd);
122}
123
132void prep_axis_data (Curve * this_curve, int ax)
133{
134 dogrid = this_curve -> show_grid[ax];
135 x_shift = this_curve -> labels_shift_x[ax];
136 y_shift = this_curve -> labels_shift_y[ax];
137 mticks = this_curve -> majt[ax];
138 nticks = this_curve -> mint[ax];
139 if (this_curve -> ticks_io[ax] == 1)
140 {
141 amint = this_curve -> mint_size[ax];
142 amajt = this_curve -> majt_size[ax];
143 }
144 else
145 {
146 amint = - this_curve -> mint_size[ax];
147 amajt = - this_curve -> majt_size[ax];
148 }
149 tickpos = this_curve -> ticks_pos[ax];
150 labpos = this_curve -> labels_pos[ax];
151}
152
163void draw_frame (cairo_t * cr, Curve * this_curve, int rid, int cid)
164{
165 show_frame (cr, this_curve -> frame_type, this_curve -> frame_dash, resol,
166 this_curve -> frame_thickness, this_curve -> frame_pos[0], this_curve -> frame_pos[1], this_curve -> frame_color);
167// X axis
168
169// Draw X axis ticks and labels
170 pango_layout_set_font_description (layout, pango_font_description_from_string (this_curve -> labels_font[0]));
171 prep_axis_data (this_curve, 0);
172 if (this_curve -> scale[0] == 0)
173 {
174 setup_xaxis_linear (cr, this_curve);
175 }
176 else
177 {
178 setup_xaxis_log (cr, this_curve, rid, cid, TRUE);
179 }
180
181// Draw X axis title
182 cairo_move_to (cr, x_min + XDRAW / 2.0 + this_curve -> axis_title_x[0], y_min + this_curve -> axis_title_y[0]);
183 pango_layout_set_font_description (layout, pango_font_description_from_string (this_curve -> axis_title_font[0]));
184 pango_layout_set_markup (layout, this_curve -> axis_title[0], -1);
185 // pango_layout_set_text (layout, this_curve -> axis_title[0], -1);
186 pango_cairo_update_layout (cr, layout);
187 pango_cairo_show_layout (cr, layout);
188 cairo_stroke(cr);
189
190// Y axis
191
192// Draw Y axis ticks and labels
193 pango_layout_set_font_description (layout, pango_font_description_from_string (this_curve -> labels_font[1]));
194 prep_axis_data (this_curve, 1);
195 if (this_curve -> scale[1] == 0)
196 {
197 setup_yaxis_linear (cr, this_curve);
198 }
199 else
200 {
201 setup_yaxis_log (cr, this_curve, TRUE);
202 }
203 cairo_move_to (cr, x_min - this_curve -> axis_title_x[1], y_min + YDRAW/2 - this_curve -> axis_title_y[1]);
204 pango_layout_set_font_description (layout, pango_font_description_from_string (this_curve -> axis_title_font[1]));
205 pango_layout_set_markup (layout, this_curve -> axis_title[1], -1);
206 cairo_rotate (cr, -pi/2.0);
207 pango_cairo_update_layout (cr, layout);
208 pango_cairo_show_layout (cr, layout);
209 cairo_stroke (cr);
210 cairo_rotate (cr, pi/2.0);
211 pango_cairo_update_layout (cr, layout);
212}
int tickpos
Definition curve.c:84
int labpos
Definition curve.c:84
double scale(double axe)
find appropriate major tick spacing based on axis length
Definition curve.c:205
int resol[2]
Definition curve.c:65
double YDRAW
Definition curve.c:66
curve_dash * selectdash(int iddash)
setup dash pointer
Definition curve.c:135
double mticks
Definition curve.c:73
double XDRAW
Definition curve.c:66
int amajt
Definition curve.c:83
gboolean dogrid
Definition curve.c:81
double ax
Definition curve.c:71
double y_min
Definition curve.c:70
int nticks
Definition curve.c:74
PangoLayout * layout
Definition curve.c:80
int x_shift
Definition curve.c:82
int amint
Definition curve.c:83
double x_min
Definition curve.c:69
int y_shift
Definition curve.c:82
Variable declarations for the curve widget Functions for interactions with the curve widget.
void setup_yaxis_linear(cairo_t *cr, Curve *this_curve)
setup y axis using a linear scale
Definition yaxis.c:118
GtkWidget * majt
void setup_xaxis_linear(cairo_t *cr, Curve *this_curve)
setup x axis using a linear scale
Definition xaxis.c:52
void setup_yaxis_log(cairo_t *cr, Curve *this_curve, gboolean draw_it)
setup y axis using a log scale
Definition yaxis.c:224
void setup_xaxis_log(cairo_t *cr, Curve *this_curve, int rid, int cid, gboolean draw_it)
setup x axis using a log scale
Definition xaxis.c:159
atom * tf
Definition d_measures.c:70
void show_frame(cairo_t *cd, int tf, int da, int res[2], double ti, double x[2], double y[2], ColRGBA dcol)
draw frame
Definition frame.c:81
void prep_frame(cairo_t *fr, int da, double ti, ColRGBA dcol)
draw frame line
Definition frame.c:56
void draw_frame(cairo_t *cr, Curve *this_curve, int rid, int cid)
draw frame and axis data
Definition frame.c:163
void prep_axis_data(Curve *this_curve, int ax)
prepare axis data
Definition frame.c:132
double pi
Definition global.c:202
Global variable declarations Global convenience function declarations Global data structure defin...
double y
Definition ogl_draw.c:63
double x
Definition ogl_draw.c:63
float blue
Definition global.h:138
float alpha
Definition global.h:139
float red
Definition global.h:136
float green
Definition global.h:137
GtkWidget * res[2]
Definition w_encode.c:342