LCOV - code coverage report
Current view: top level - pencil/source - pencil_marker.c (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.57.0_covts Lines: 9 86 10.5 %
Date: 2024-04-07 11:14:42 Functions: 2 4 50.0 %

          Line data    Source code
       1             : /* File: pencil_marker.c; Copyright and License: see below */
       2             : 
       3             : #include "pencil_marker.h"
       4             : #include "u8/u8_trace.h"
       5             : #include <math.h>
       6             : #include <stdio.h>
       7             : #include <stdlib.h>
       8             : #include <assert.h>
       9             : 
      10           7 : void pencil_marker_init( pencil_marker_t *this_ )
      11             : {
      12           7 :     U8_TRACE_BEGIN();
      13             : 
      14           7 :     (*this_).dummy = 0;  /* prevent warnings on uninitialized usage */
      15             : 
      16           7 :     U8_TRACE_END();
      17           7 : }
      18             : 
      19           7 : void pencil_marker_destroy( pencil_marker_t *this_ )
      20             : {
      21           7 :     U8_TRACE_BEGIN();
      22             : 
      23           7 :     U8_TRACE_END();
      24           7 : }
      25             : 
      26           0 : void pencil_marker_mark_focused_rectangle ( const pencil_marker_t *this_, geometry_rectangle_t rect, cairo_t *cr )
      27             : {
      28           0 :     U8_TRACE_BEGIN();
      29           0 :     assert( NULL != cr );
      30             : 
      31             :     static const double YELLOW_BOX_SIZE = 8.0;
      32             :     static const double TOTAL_SIZE = 9.0;
      33             :     static const double LINE_WIDTH = 1.0;
      34             :     static const double GAP = 1.0;
      35             : 
      36           0 :     const double left = floor(geometry_rectangle_get_left ( &rect )); /* floor needed to position on pixel boundary*/
      37           0 :     const double top = floor(geometry_rectangle_get_top ( &rect ));
      38           0 :     const double right = floor(geometry_rectangle_get_right ( &rect ));
      39           0 :     const double bottom = floor(geometry_rectangle_get_bottom ( &rect ));
      40             : 
      41             :     /* gray lines */
      42           0 :     cairo_set_source_rgba( cr, 0.55, 0.55, 0.55, 1.0 );
      43             : 
      44           0 :     cairo_rectangle ( cr, left-GAP-LINE_WIDTH, top-GAP-TOTAL_SIZE, LINE_WIDTH, YELLOW_BOX_SIZE );
      45           0 :     cairo_rectangle ( cr, left-GAP-TOTAL_SIZE, top-GAP-LINE_WIDTH, TOTAL_SIZE, LINE_WIDTH );
      46           0 :     cairo_fill (cr);
      47             : 
      48           0 :     cairo_rectangle ( cr, right+GAP, top-GAP-TOTAL_SIZE, LINE_WIDTH, YELLOW_BOX_SIZE );
      49           0 :     cairo_rectangle ( cr, right+GAP, top-GAP-LINE_WIDTH, TOTAL_SIZE, LINE_WIDTH );
      50           0 :     cairo_fill (cr);
      51             : 
      52           0 :     cairo_rectangle ( cr, right+GAP, bottom+GAP+LINE_WIDTH, LINE_WIDTH, YELLOW_BOX_SIZE );
      53           0 :     cairo_rectangle ( cr, right+GAP, bottom+GAP, TOTAL_SIZE, LINE_WIDTH );
      54           0 :     cairo_fill (cr);
      55             : 
      56           0 :     cairo_rectangle ( cr, left-GAP-LINE_WIDTH, bottom+GAP+LINE_WIDTH, LINE_WIDTH, YELLOW_BOX_SIZE );
      57           0 :     cairo_rectangle ( cr, left-GAP-TOTAL_SIZE, bottom+GAP, TOTAL_SIZE, LINE_WIDTH );
      58           0 :     cairo_fill (cr);
      59             : 
      60             :     /* yellow box */
      61           0 :     cairo_set_source_rgba( cr, 0.95, 1.0, 0.0, 1.0 );
      62             : 
      63           0 :     cairo_rectangle ( cr, left-GAP-TOTAL_SIZE, top-GAP-TOTAL_SIZE, YELLOW_BOX_SIZE, YELLOW_BOX_SIZE );
      64           0 :     cairo_fill (cr);
      65             : 
      66           0 :     cairo_rectangle ( cr, right+GAP+LINE_WIDTH, top-GAP-TOTAL_SIZE, YELLOW_BOX_SIZE, YELLOW_BOX_SIZE );
      67           0 :     cairo_fill (cr);
      68             : 
      69           0 :     cairo_rectangle ( cr, left-GAP-TOTAL_SIZE, bottom+GAP+LINE_WIDTH, YELLOW_BOX_SIZE, YELLOW_BOX_SIZE );
      70           0 :     cairo_fill (cr);
      71             : 
      72           0 :     cairo_rectangle ( cr, right+GAP+LINE_WIDTH, bottom+GAP+LINE_WIDTH, YELLOW_BOX_SIZE, YELLOW_BOX_SIZE );
      73           0 :     cairo_fill (cr);
      74             : 
      75           0 :     U8_TRACE_END();
      76           0 : }
      77             : 
      78           0 : void pencil_marker_mark_selected_rectangle ( const pencil_marker_t *this_, geometry_rectangle_t rect, cairo_t *cr )
      79             : {
      80           0 :     U8_TRACE_BEGIN();
      81           0 :     assert( NULL != cr );
      82             : 
      83             :     static const double EXPAND_OVER_BORDER = 2.0;
      84             :     static const double INNER_EDGE = 8.0;
      85             : 
      86           0 :     const double left = floor(geometry_rectangle_get_left ( &rect )); /* floor needed to position on pixel boundary*/
      87           0 :     const double top = floor(geometry_rectangle_get_top ( &rect ));
      88           0 :     const double right = floor(geometry_rectangle_get_right ( &rect ));
      89           0 :     const double bottom = floor(geometry_rectangle_get_bottom ( &rect ));
      90             : 
      91           0 :     cairo_set_source_rgba( cr, 1.0, 0.3, 0.8, 1.0 );
      92             : 
      93           0 :     cairo_move_to( cr, left+INNER_EDGE, top-EXPAND_OVER_BORDER );
      94           0 :     cairo_line_to( cr, left-EXPAND_OVER_BORDER, top-EXPAND_OVER_BORDER );
      95           0 :     cairo_line_to( cr, left-EXPAND_OVER_BORDER, top+INNER_EDGE );
      96           0 :     cairo_close_path( cr );
      97           0 :     cairo_fill (cr);
      98             : 
      99           0 :     cairo_move_to( cr, right-INNER_EDGE, top-EXPAND_OVER_BORDER );
     100           0 :     cairo_line_to( cr, right+EXPAND_OVER_BORDER, top-EXPAND_OVER_BORDER );
     101           0 :     cairo_line_to( cr, right+EXPAND_OVER_BORDER, top+INNER_EDGE );
     102           0 :     cairo_close_path( cr );
     103           0 :     cairo_fill (cr);
     104             : 
     105           0 :     cairo_move_to( cr, right-INNER_EDGE, bottom+EXPAND_OVER_BORDER );
     106           0 :     cairo_line_to( cr, right+EXPAND_OVER_BORDER, bottom+EXPAND_OVER_BORDER );
     107           0 :     cairo_line_to( cr, right+EXPAND_OVER_BORDER, bottom-INNER_EDGE );
     108           0 :     cairo_close_path( cr );
     109           0 :     cairo_fill (cr);
     110             : 
     111           0 :     cairo_move_to( cr, left-EXPAND_OVER_BORDER, bottom-INNER_EDGE );
     112           0 :     cairo_line_to( cr, left-EXPAND_OVER_BORDER, bottom+EXPAND_OVER_BORDER );
     113           0 :     cairo_line_to( cr, left+INNER_EDGE, bottom+EXPAND_OVER_BORDER );
     114           0 :     cairo_close_path( cr );
     115           0 :     cairo_fill (cr);
     116             : 
     117           0 :     const double width = right-left;
     118             :     static const double LINE_LENGTH = 16.0;
     119             :     static const double LINE_WIDTH = 1.0;
     120           0 :     if ( width > 2.0*EXPAND_OVER_BORDER + LINE_LENGTH )
     121             :     {
     122           0 :         cairo_rectangle ( cr, left, bottom + EXPAND_OVER_BORDER - LINE_WIDTH, LINE_LENGTH, LINE_WIDTH );
     123           0 :         cairo_rectangle ( cr, right - LINE_LENGTH, bottom + EXPAND_OVER_BORDER - LINE_WIDTH, LINE_LENGTH, LINE_WIDTH );
     124           0 :         cairo_fill (cr);
     125           0 :         cairo_rectangle ( cr, left, top - EXPAND_OVER_BORDER, LINE_LENGTH, LINE_WIDTH );
     126           0 :         cairo_rectangle ( cr, right - LINE_LENGTH, top - EXPAND_OVER_BORDER, LINE_LENGTH, LINE_WIDTH );
     127           0 :         cairo_fill (cr);
     128             :     }
     129           0 :     const double height = bottom-top;
     130           0 :     if ( height > 2.0*EXPAND_OVER_BORDER + LINE_LENGTH )
     131             :     {
     132           0 :         cairo_rectangle ( cr, left - EXPAND_OVER_BORDER, top, LINE_WIDTH, LINE_LENGTH );
     133           0 :         cairo_rectangle ( cr, left - EXPAND_OVER_BORDER, bottom - LINE_LENGTH, LINE_WIDTH, LINE_LENGTH );
     134           0 :         cairo_fill (cr);
     135           0 :         cairo_rectangle ( cr, right + EXPAND_OVER_BORDER - LINE_WIDTH, top, LINE_WIDTH, LINE_LENGTH );
     136           0 :         cairo_rectangle ( cr, right + EXPAND_OVER_BORDER - LINE_WIDTH, bottom - LINE_LENGTH, LINE_WIDTH, LINE_LENGTH );
     137           0 :         cairo_fill (cr);
     138             :     }
     139             : 
     140           0 :     U8_TRACE_END();
     141           0 : }
     142             : 
     143             : 
     144             : /*
     145             : Copyright 2016-2024 Andreas Warnke
     146             : 
     147             : Licensed under the Apache License, Version 2.0 (the "License");
     148             : you may not use this file except in compliance with the License.
     149             : You may obtain a copy of the License at
     150             : 
     151             :     http://www.apache.org/licenses/LICENSE-2.0
     152             : 
     153             : Unless required by applicable law or agreed to in writing, software
     154             : distributed under the License is distributed on an "AS IS" BASIS,
     155             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     156             : See the License for the specific language governing permissions and
     157             : limitations under the License.
     158             : */

Generated by: LCOV version 1.16