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

Generated by: LCOV version 1.16