1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
|
/* File: gui_sketch_background.c; Copyright and License: see below */
#include "sketch/gui_sketch_background.h"
#include "meta/meta_info.h"
#include "u8/u8_trace.h"
#include <stdint.h>
#include "gui_gtk.h"
#include <assert.h>
void gui_sketch_background_init( gui_sketch_background_t *this_,
gui_resources_t *resources,
gui_sketch_texture_t *texture_downloader )
{
U8_TRACE_BEGIN();
assert( resources != NULL );
assert( texture_downloader != NULL );
shape_int_rectangle_init( &((*this_).bounds), 0, 0, 0, 0 );
(*this_).resources = resources;
(*this_).texture_downloader = texture_downloader;
U8_TRACE_END();
}
void gui_sketch_background_destroy( gui_sketch_background_t *this_ )
{
U8_TRACE_BEGIN();
shape_int_rectangle_destroy( &((*this_).bounds) );
(*this_).resources = NULL;
(*this_).texture_downloader = NULL;
U8_TRACE_END();
}
static const double BLACK_R = 0.0;
static const double BLACK_G = 0.0;
static const double BLACK_B = 0.0;
static const double BLACK_A = 1.0;
static const double DARK_R = 0.3;
static const double DARK_G = 0.3;
static const double DARK_B = 0.3;
static const double DARK_A = 1.0;
static const double D_GREY_R = 0.4;
static const double D_GREY_G = 0.4;
static const double D_GREY_B = 0.4;
static const double D_GREY_A = 1.0;
static const double GREY_R = 0.7;
static const double GREY_G = 0.7;
static const double GREY_B = 0.7;
static const double GREY_A = 1.0;
static const double ORANGE_R = 1.0;
static const double ORANGE_G = 0.8;
static const double ORANGE_B = 0.5;
static const double ORANGE_A = 1.0;
static const double LIGHT_R = 0.8;
static const double LIGHT_G = 0.8;
static const double LIGHT_B = 0.8;
static const double LIGHT_A = 1.0;
static const double BORDER = 8; /* border between text/icons and ground rectangle */
void gui_sketch_background_draw_introduction( gui_sketch_background_t *this_,
cairo_t *cr )
{
U8_TRACE_BEGIN();
assert( NULL != cr );
const int32_t left = shape_int_rectangle_get_left( &((*this_).bounds) );
const int32_t top = shape_int_rectangle_get_top( &((*this_).bounds) );
const uint32_t width = shape_int_rectangle_get_width( &((*this_).bounds) );
const uint32_t height = shape_int_rectangle_get_height( &((*this_).bounds) );
int32_t text_area_start;
/* if there is enough space, draw a nice picture bar on the left side */
if ( width > 192 )
{
GdkPixbuf *bg_img = gui_resources_get_background_column( (*this_).resources );
double icon_width = gdk_pixbuf_get_width ( bg_img );
double icon_height = gdk_pixbuf_get_height ( bg_img );
gdk_cairo_set_source_pixbuf( cr, bg_img, left, top );
cairo_rectangle ( cr, left, top, icon_width, icon_height );
cairo_fill (cr);
text_area_start = left+icon_width;
if ( height > icon_height )
{
cairo_set_source_rgba( cr, 0.0, 0.4, 0.3, 1.0 );
cairo_rectangle ( cr, left, top+icon_height, icon_width, height-icon_height );
cairo_fill (cr);
cairo_move_to( cr, left, top+icon_height );
cairo_line_to( cr, left+icon_width, top+icon_height );
cairo_line_to( cr, left, top+icon_height-(0.3*icon_width) );
cairo_fill (cr);
}
}
else
{
text_area_start = left;
}
cairo_set_source_rgba( cr, GREY_R, GREY_G, GREY_B, GREY_A );
cairo_rectangle ( cr, text_area_start, top, width-text_area_start, height );
cairo_fill (cr);
const int TAB_ROW0_Y = 48;
const int TAB_ROW1_Y = 96;
const int TAB_ROW2_Y = 192;
gui_sketch_background_private_draw_icon_and_message( this_,
gui_resources_get_crystal_facet_uml( (*this_).resources ),
"Welcome to",
META_INFO_PROGRAM_NAME_STR,
text_area_start+BORDER,
top+BORDER+TAB_ROW0_Y,
cr
);
gui_sketch_background_private_draw_icon_and_message( this_,
gui_resources_get_file_new( (*this_).resources ),
"To begin, please",
"create a new database file first.",
text_area_start+BORDER,
top+BORDER+TAB_ROW1_Y,
cr
);
gui_sketch_background_private_draw_icon_and_message( this_,
gui_resources_get_message_user_doc( (*this_).resources ),
"The user manual crystal-facet-uml_documentation.pdf is available",
#ifdef __linux__
"in the net and locally at /usr/share/doc/(packages/)crystal-facet-uml",
#else
"in the net",
#endif
text_area_start+BORDER,
top+BORDER+TAB_ROW2_Y,
cr
);
U8_TRACE_END();
}
void gui_sketch_background_draw_navigation( gui_sketch_background_t *this_,
unsigned int tree_depth,
unsigned int num_children,
cairo_t *cr )
{
U8_TRACE_BEGIN();
assert( NULL != cr );
const int32_t left = shape_int_rectangle_get_left( &((*this_).bounds) );
const int32_t top = shape_int_rectangle_get_top( &((*this_).bounds) );
const uint32_t width = shape_int_rectangle_get_width( &((*this_).bounds) );
const uint32_t height = shape_int_rectangle_get_height( &((*this_).bounds) );
if ( 0 == tree_depth )
{
cairo_set_source_rgba( cr, LIGHT_R, LIGHT_G, LIGHT_B, LIGHT_A );
}
else
{
cairo_set_source_rgba( cr, D_GREY_R, D_GREY_G, D_GREY_B, D_GREY_A );
}
cairo_rectangle ( cr, left, top, width, height );
cairo_fill (cr);
if ( ( 0 == tree_depth )&&( 0 == num_children ))
{
/* this is a new, empty database */
gui_sketch_background_private_draw_quick_introduction( this_, cr );
}
U8_TRACE_END();
}
void gui_sketch_background_draw_search( gui_sketch_background_t *this_, cairo_t *cr )
{
U8_TRACE_BEGIN();
assert( NULL != cr );
const int32_t left = shape_int_rectangle_get_left( &((*this_).bounds) );
const int32_t top = shape_int_rectangle_get_top( &((*this_).bounds) );
const uint32_t width = shape_int_rectangle_get_width( &((*this_).bounds) );
const uint32_t height = shape_int_rectangle_get_height( &((*this_).bounds) );
cairo_set_source_rgba( cr, DARK_R, DARK_G, DARK_B, DARK_A );
cairo_rectangle ( cr, left, top, width, height );
cairo_fill (cr);
U8_TRACE_END();
}
void gui_sketch_background_draw_edit( gui_sketch_background_t *this_, cairo_t *cr )
{
U8_TRACE_BEGIN();
assert( NULL != cr );
const int32_t left = shape_int_rectangle_get_left( &((*this_).bounds) );
const int32_t top = shape_int_rectangle_get_top( &((*this_).bounds) );
const uint32_t width = shape_int_rectangle_get_width( &((*this_).bounds) );
const uint32_t height = shape_int_rectangle_get_height( &((*this_).bounds) );
cairo_set_source_rgba( cr, DARK_R, DARK_G, DARK_B, DARK_A );
cairo_rectangle ( cr, left, top, width, height );
cairo_fill (cr);
U8_TRACE_END();
}
void gui_sketch_background_draw_create( gui_sketch_background_t *this_, cairo_t *cr )
{
U8_TRACE_BEGIN();
assert( NULL != cr );
const int32_t left = shape_int_rectangle_get_left( &((*this_).bounds) );
const int32_t top = shape_int_rectangle_get_top( &((*this_).bounds) );
const uint32_t width = shape_int_rectangle_get_width( &((*this_).bounds) );
const uint32_t height = shape_int_rectangle_get_height( &((*this_).bounds) );
cairo_set_source_rgba( cr, ORANGE_R, ORANGE_G, ORANGE_B, ORANGE_A );
cairo_rectangle ( cr, left, top, width, height );
cairo_fill (cr);
U8_TRACE_END();
}
void gui_sketch_background_private_draw_quick_introduction( gui_sketch_background_t *this_, cairo_t *cr )
{
U8_TRACE_BEGIN();
assert( NULL != cr );
const int32_t left = shape_int_rectangle_get_left( &((*this_).bounds) );
//const int32_t top = shape_int_rectangle_get_top( &((*this_).bounds) );
//const uint32_t width = shape_int_rectangle_get_width( &((*this_).bounds) );
const uint32_t height = shape_int_rectangle_get_height( &((*this_).bounds) );
const int32_t TAB_HEIGHT = 144 + BORDER;
const int32_t TAB_WIDTH = 640 + BORDER;
const int32_t TAB_X = left + 16;
const int32_t TAB_Y = height - TAB_HEIGHT - 16;
const int32_t TAB_COL0_X = TAB_X + BORDER + 14;
const int32_t TAB_COL1_X = TAB_X + BORDER + 112;
const int32_t TAB_COL2_X = TAB_X + BORDER + 340;
const int32_t TAB_ROW0_Y = TAB_Y + BORDER + 0;
const int32_t TAB_ROW1_Y = TAB_Y + BORDER + 48;
const int32_t TAB_ROW2_Y = TAB_Y + BORDER + 96;
cairo_set_source_rgba( cr, GREY_R, GREY_G, GREY_B, GREY_A );
cairo_rectangle ( cr, TAB_X, TAB_Y, TAB_WIDTH, TAB_HEIGHT );
cairo_fill (cr);
gui_sketch_background_private_draw_icon_and_message( this_,
gui_resources_get_message_user_doc( (*this_).resources ),
"Quick",
"Intro:",
TAB_COL0_X,
TAB_ROW0_Y,
cr
);
gui_sketch_background_private_draw_icon_and_message( this_,
gui_resources_get_view_navigate( (*this_).resources ),
"Click on a diagram to navigate,",
"on '+' to create a new diagram.",
TAB_COL1_X,
TAB_ROW0_Y,
cr
);
gui_sketch_background_private_draw_icon_and_message( this_,
gui_resources_get_view_edit( (*this_).resources ),
"Click on an element to edit",
"name, type and description.",
TAB_COL1_X,
TAB_ROW1_Y,
cr
);
gui_sketch_background_private_draw_icon_and_message( this_,
gui_resources_get_view_edit( (*this_).resources ),
"Drag an element to change",
"its position.",
TAB_COL2_X,
TAB_ROW1_Y,
cr
);
gui_sketch_background_private_draw_icon_and_message( this_,
gui_resources_get_view_create( (*this_).resources ),
"Click to create items.",
"Drag to create arrows.",
TAB_COL1_X,
TAB_ROW2_Y,
cr
);
gui_sketch_background_private_draw_icon_and_message( this_,
gui_resources_get_file_export( (*this_).resources ),
"Select the output folder",
"to export all diagrams.",
TAB_COL2_X,
TAB_ROW2_Y,
cr
);
U8_TRACE_END();
}
void gui_sketch_background_private_draw_icon_and_message( gui_sketch_background_t *this_,
GdkTexture *icon_1,
const char *text_1,
const char *text_2,
int x,
int y,
cairo_t *cr )
{
U8_TRACE_BEGIN();
assert( NULL != cr );
assert( NULL != icon_1 );
assert( NULL != text_1 );
assert( NULL != text_2 );
const double icon_width = gdk_texture_get_width ( icon_1 );
gui_sketch_texture_draw( (*this_).texture_downloader, icon_1, x, y, cr );
cairo_set_source_rgba( cr, BLACK_R, BLACK_G, BLACK_B, BLACK_A );
cairo_set_font_size ( cr, 12.0 );
cairo_move_to ( cr, x+icon_width+BORDER, y + 14 );
cairo_show_text ( cr, text_1 );
cairo_move_to ( cr, x+icon_width+BORDER, y + 2*14 );
cairo_show_text ( cr, text_2 );
U8_TRACE_END();
}
/*
Copyright 2017-2025 Andreas Warnke
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
|