limj
2023-10-24 93652435728de839582440eefd5122c281181d35
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
Quintiq file version 2.0
#parent: CustomDrawComponentContainer/CustomDrawDataLayerComponent
Response OnDrawObject (
  LibOpt_Component object
) id:Response_CustomDrawComponentContainer_CustomDrawDataLayerComponent_OnDrawObject
{
  #keys: '[139164.3.945949135]'
  Body:
  [*
    scale_x := ValueHolderScaleX.Data();
    scale_y := ValueHolderScaleY.Data();
    
    image := object.UIImage();
    
    height := region.Height();
    
    DEFAULT_OFFSET := 5;
    
    color := Form.GetColor( object );
     
    surface.Brush().Color( color );
    
    surface.Draw( shape );
    
    surface.Brush().Color( Color::White() );
    
    offset := minvalue( 5, [Number] ( DEFAULT_OFFSET * maxvalue( scale_x, scale_y ) ) );
    diameter := [Number] ( ( object.UIGraphNode().Height() - offset * 2 ) * minvalue( scale_x, scale_y ) );
    circle_offset_y := [Number] ( ( height - diameter ) / 2 );
    circle_offset_x := minvalue( [Number] ( scale_x * DEFAULT_OFFSET ), circle_offset_y );
    surface.Pen().Width( 0 );
    surface.Circle( circle_offset_x, circle_offset_y, diameter );
    
    // Progress
    if( object.Task( relsize ) > 0 )
    {                          
      prog := object.Progress();
      
      if( prog < 1.0 )
      {
        surface.Brush().Color( color );
        surface.Circle( circle_offset_x + 2, circle_offset_y + 2, diameter - 4 );
      
        surface.Brush().Color( Color::Color( 255, 255, 255, 0.75 ) );
        surface.Circle( circle_offset_x + 2, circle_offset_y + 2, diameter - 4 );
      }                               
      surface.Brush().Color( color );
      if( prog < 0.0 )
      {
        surface.Brush().Color( Color::Red() );
      }
      surface.Pie( circle_offset_x + 2, circle_offset_y + 2, diameter - 4, diameter - 4, -90, [Number] ( 360 * prog ) );
      
      surface.Brush().Color( Color::White() );
      surface.Circle( circle_offset_x + 4, circle_offset_y + 4, diameter - 8 );
    }
    
    status := object.Run().Status();
    if( status = LibOpt_RunStatus::Loaded() )
    {
      image_size := [Number] ( diameter * sin( 0.25 * pi ) - 4 );
      image_offset := [Number] ( ( diameter - image_size ) / 2 );
      
      surface.Image( circle_offset_x + image_offset,
                     circle_offset_y + image_offset,
                     image_size, image_size, image );
    }
    else
    {
      nr_text := object.NrTimesCalled();                                       
      format := TextFormat::Construct();
      format.AlignMiddle();
      format.AlignCenter();
      font_size := surface.Font().Size();
      surface.Font().Size( 100 );
      surface.Font().Bold( true );
      surface.TextColor( color );
      surface.TextFit( circle_offset_x + 6, circle_offset_y + 6, diameter - 12, diameter - 12, [String] nr_text, font_size, format );
      surface.Font().Size( font_size );
      surface.TextColor( Color::Black() );
    }
    
    if( not object.CanBeCalled() )
    {
      overlaycolor := Color::Color( 255, 255, 255, 0.5 );
      surface.Brush().Color( overlaycolor );
      surface.Pen().Width( 1 );
      surface.Draw( shape );
    }
    
    format := TextFormat::Construct();
    format.WrapWords();
    
    surface.Font().Bold( true );
    
    text_region := region.CenterRect( region.Width() - offset * 2, region.Height() - offset * 2 );
    text_region := text_region.RightRect( text_region.Width() - diameter - circle_offset_x * 2 + offset, text_region.Height() );
    
    lines := text.TrimBoth().Tokenize( String::NewLine() );
    
    if( lines.Size() = 1 )
    {
      format.AlignMiddle();
      surface.TextFit( text_region, lines.Element( 0 ), 1, format );
    }
    else if( lines.Size() > 1 )
    {
      format.AlignBottom();
      line_offset := 2;
      line_height := [Number] ( ( text_region.Height() - line_offset * ( lines.Size() - 1 ) ) / lines.Size() );
      for( i := 0; i < lines.Size(); i++ )
      {
        if( i = lines.Size() - 1 )
        {
          format.AlignTop();
        }
        line_region := text_region.BottomRect( text_region.Width(), text_region.Height() - ( line_offset + line_height ) * i )
                                  .TopRect( text_region.Width(), line_height );
        surface.TextFit( line_region, lines.Element( i ), 1, format );
        surface.Font().Bold( false );
        format.AlignMiddle();
      }
    }
  *]
  CanBindMultiple: false
  DefinitionID: 'Responsedef_CustomDrawDataLayer_OnDrawObject'
}