LCOV - code coverage report
Current view: top level - gui/source/sketch - gui_sketch_background.c (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.65.6_covts Lines: 0 160 0.0 %
Date: 2025-09-25 21:07:53 Functions: 0 9 0.0 %

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

Generated by: LCOV version 1.16