atomes 1.1.16
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-2024 by CNRS and University of Strasbourg */
15
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
134void prep_axis_data (project * this_proj, int rid, int cid, int ax)
135{
136 dogrid = this_proj -> curves[rid][cid] -> show_grid[ax];
137 x_shift = this_proj -> curves[rid][cid] -> labels_shift_x[ax];
138 y_shift = this_proj -> curves[rid][cid] -> labels_shift_y[ax];
139 mticks = this_proj -> curves[rid][cid] -> majt[ax];
140 nticks = this_proj -> curves[rid][cid] -> mint[ax];
141 if (this_proj -> curves[rid][cid] -> ticks_io[ax] == 1)
142 {
143 amint = this_proj -> curves[rid][cid] -> mint_size[ax];
144 amajt = this_proj -> curves[rid][cid] -> majt_size[ax];
145 }
146 else
147 {
148 amint = - this_proj -> curves[rid][cid] -> mint_size[ax];
149 amajt = - this_proj -> curves[rid][cid] -> majt_size[ax];
150 }
151 tickpos = this_proj -> curves[rid][cid] -> ticks_pos[ax];
152 labpos = this_proj -> curves[rid][cid] -> labels_pos[ax];
153}
154
165void draw_frame (cairo_t * cr, project * this_proj, int rid, int cid)
166{
167 show_frame (cr,
168 this_proj -> curves[rid][cid] -> frame_type,
169 this_proj -> curves[rid][cid] -> frame_dash,
170 resol,
171 this_proj -> curves[rid][cid] -> frame_thickness,
172 this_proj -> curves[rid][cid] -> frame_pos[0],
173 this_proj -> curves[rid][cid] -> frame_pos[1],
174 this_proj -> curves[rid][cid] -> frame_color);
175
176// X axis
177
178// Draw X axis ticks and labels
179 pango_layout_set_font_description (layout, pango_font_description_from_string (this_proj -> curves[rid][cid] -> labels_font[0]));
180 prep_axis_data (this_proj, rid, cid, 0);
181 if (this_proj -> curves[rid][cid] -> scale[0] == 0)
182 {
183 setup_xaxis_linear (cr, this_proj, rid, cid);
184 }
185 else
186 {
187 setup_xaxis_log (cr, this_proj, rid, cid, TRUE);
188 }
189
190// Draw X axis title
191 cairo_move_to (cr,
192 x_min + XDRAW / 2.0 + this_proj -> curves[rid][cid] -> axis_title_x[0],
193 y_min + this_proj -> curves[rid][cid] -> axis_title_y[0]);
194 pango_layout_set_font_description (layout, pango_font_description_from_string (this_proj -> curves[rid][cid] -> axis_title_font[0]));
195 pango_layout_set_text (layout, this_proj -> curves[rid][cid] -> axis_title[0], -1);
196 pango_cairo_update_layout (cr, layout);
197 pango_cairo_show_layout (cr, layout);
198 cairo_stroke(cr);
199
200// Y axis
201
202// Draw Y axis ticks and labels
203 pango_layout_set_font_description (layout, pango_font_description_from_string (this_proj -> curves[rid][cid] -> labels_font[1]));
204 prep_axis_data (this_proj, rid, cid, 1);
205 if (this_proj -> curves[rid][cid] -> scale[1] == 0)
206 {
207 setup_yaxis_linear (cr, this_proj, rid, cid);
208 }
209 else
210 {
211 setup_yaxis_log (cr, this_proj, rid, cid, TRUE);
212 }
213 cairo_move_to (cr,
214 x_min - this_proj -> curves[rid][cid] -> axis_title_x[1],
215 y_min + YDRAW/2 - this_proj -> curves[rid][cid] -> axis_title_y[1]);
216 pango_layout_set_font_description (layout, pango_font_description_from_string (this_proj -> curves[rid][cid] -> axis_title_font[1]));
217 pango_layout_set_text (layout, this_proj -> curves[rid][cid] -> axis_title[1], -1);
218 cairo_rotate (cr, -pi/2.0);
219 pango_cairo_update_layout (cr, layout);
220 pango_cairo_show_layout (cr, layout);
221 cairo_stroke (cr);
222 cairo_rotate (cr, pi/2.0);
223 pango_cairo_update_layout (cr, layout);
224}
int tickpos
Definition curve.c:83
int labpos
Definition curve.c:83
double scale(double axe)
find appropriate major tick spacing based on axis length
Definition curve.c:204
int resol[2]
Definition curve.c:64
double YDRAW
Definition curve.c:65
curve_dash * selectdash(int iddash)
setup dash pointer
Definition curve.c:134
double mticks
Definition curve.c:72
double XDRAW
Definition curve.c:65
int amajt
Definition curve.c:82
gboolean dogrid
Definition curve.c:80
double ax
Definition curve.c:70
double y_min
Definition curve.c:69
int nticks
Definition curve.c:73
PangoLayout * layout
Definition curve.c:79
int x_shift
Definition curve.c:81
int amint
Definition curve.c:82
double x_min
Definition curve.c:68
int y_shift
Definition curve.c:81
Variable declarations for the curve widget Functions for interactions with the curve widget.
void setup_yaxis_log(cairo_t *cr, project *this_proj, int rid, int cid, gboolean draw_it)
setup y axis using a log scale
Definition yaxis.c:231
GtkWidget * majt
Definition tab-4.c:103
void setup_yaxis_linear(cairo_t *cr, project *this_proj, int rid, int cid)
setup y axis using a linear scale
Definition yaxis.c:121
void setup_xaxis_log(cairo_t *cr, project *this_proj, int rid, int cid, gboolean draw_it)
setup x axis using a log scale
Definition xaxis.c:163
void setup_xaxis_linear(cairo_t *cr, project *this_proj, int rid, int cid)
setup x axis using a linear scale
Definition xaxis.c:54
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 draw_frame(cairo_t *cr, project *this_proj, int rid, int cid)
draw frame and axis data
Definition frame.c:165
void prep_frame(cairo_t *fr, int da, double ti, ColRGBA dcol)
draw frame line
Definition frame.c:56
void prep_axis_data(project *this_proj, int rid, int cid, int ax)
prepare axis data
Definition frame.c:134
double pi
Definition global.c:195
Global variable declarations Global convenience function declarations Global data structure defin...
double y
Definition ogl_draw.c:57
double x
Definition ogl_draw.c:57
float blue
Definition global.h:124
float alpha
Definition global.h:125
float red
Definition global.h:122
float green
Definition global.h:123
int b
Definition tab-1.c:95
int a
Definition tab-1.c:95
GtkWidget * axis_title_font
Definition tab-4.c:102
GtkWidget * show_grid
Definition tab-4.c:98
GtkWidget * axis_title
Definition tab-4.c:101
GtkWidget * res[2]
Definition w_encode.c:212