]> git.pld-linux.org Git - packages/dia.git/blob - dia-state.patch
- version 0.92 pre4
[packages/dia.git] / dia-state.patch
1 diff -Nur dia-0.91-pre3.orig/objects/UML/state.c dia-0.91-pre3/objects/UML/state.c
2 --- dia-0.91-pre3.orig/objects/UML/state.c      Sun Jan 26 07:44:52 2003
3 +++ dia-0.91-pre3/objects/UML/state.c   Mon Feb 24 10:46:59 2003
4 @@ -1,6 +1,9 @@
5  /* Dia -- an diagram creation/manipulation program
6   * Copyright (C) 1998 Alexander Larsson
7   *
8 + * State type for UML diagrams
9 + * Copyright (C) 2003 Alejandro Sierra <asierra@servidor.unam.mx>
10 + * 
11   * This program is free software; you can redistribute it and/or modify
12   * it under the terms of the GNU General Public License as published by
13   * the Free Software Foundation; either version 2 of the License, or
14 @@ -51,9 +54,12 @@
15    ConnectionPoint connections[8];
16  
17    Text *text;
18 -  int state_type;
19 +  int state_type;  
20  
21    TextAttributes attrs;
22 +
23 +  int show_internals;
24 +  Text *internals;
25  };
26  
27  
28 @@ -126,13 +132,15 @@
29        Warning: break this and you'll get angry UML users after you. */
30    { "type", PROP_TYPE_INT, PROP_FLAG_NO_DEFAULTS|PROP_FLAG_LOAD_ONLY,
31      "hack", NULL, NULL },
32 -  
33    PROP_STD_TEXT_FONT,
34    PROP_STD_TEXT_HEIGHT,
35    PROP_STD_TEXT_COLOUR,
36 -  { "text", PROP_TYPE_TEXT, 0, N_("Text"), NULL, NULL }, 
37 -  
38 -  PROP_DESC_END
39 +  { "text", PROP_TYPE_TEXT, 0, N_("Text"), NULL, NULL },  
40 +  { "show_internals", PROP_TYPE_BOOL, PROP_FLAG_VISIBLE,
41 +    N_("Show internals"),NULL,NULL},
42 +  { "internals", PROP_TYPE_TEXT, 0, N_("Internals"), NULL, NULL },
43 +  { NULL, 0, 0, NULL, NULL, NULL, 0} 
44 +//  PROP_DESC_END
45  };
46  
47  static PropDescription *
48 @@ -142,7 +150,7 @@
49  }
50  
51  static PropOffset state_offsets[] = {
52 -  ELEMENT_COMMON_PROPERTIES_OFFSETS,
53 +  ELEMENT_COMMON_PROPERTIES_OFFSETS,     
54    {"text",PROP_TYPE_TEXT,offsetof(State,text)},
55    {"text_font",PROP_TYPE_FONT,offsetof(State,attrs.font)},
56    {"text_height",PROP_TYPE_REAL,offsetof(State,attrs.height)},
57 @@ -152,7 +160,8 @@
58        if sizeof(enum) != sizeof(int), we're toast.             -- CC
59        */
60    { "type", PROP_TYPE_INT, offsetof(State, state_type) },
61 -  
62 +  { "show_internals", PROP_TYPE_BOOL, offsetof(State, show_internals) },
63 +   {"internals",PROP_TYPE_TEXT,offsetof(State,internals)},
64    { NULL, 0, 0 },
65  };
66  
67 @@ -167,9 +176,14 @@
68  static void
69  state_set_props(State *state, GPtrArray *props)
70  {
71 +   TextAttributes attrs;
72 +   
73    object_set_props_from_offsets(&state->element.object,
74                                  state_offsets,props);
75    apply_textattr_properties(props,state->text,"text",&state->attrs);
76 +  attrs = state->attrs;
77 +  attrs.alignment = ALIGN_LEFT;
78 +  apply_textattr_properties(props,state->internals,"internals",&attrs);
79    state_update_data(state);
80  }
81  
82 @@ -184,8 +198,12 @@
83  state_select(State *state, Point *clicked_point,
84                DiaRenderer *interactive_renderer)
85  {
86 -  text_set_cursor(state->text, clicked_point, interactive_renderer);
87 -  text_grab_focus(state->text, &state->element.object);
88 +  Text *text = (state->show_internals && clicked_point->y >=
89 +       state->internals->position.y - state->internals->height) ?
90 +        state->internals : state->text;
91 +   
92 +  text_set_cursor(text, clicked_point, interactive_renderer);
93 +  text_grab_focus(text, &state->element.object);
94    element_update_handles(&state->element);
95  }
96  
97 @@ -229,27 +247,7 @@
98    renderer_ops->set_linewidth(renderer, STATE_LINEWIDTH);
99    renderer_ops->set_linestyle(renderer, LINESTYLE_SOLID);
100  
101 -  if (state->state_type!=STATE_NORMAL) {
102 -      p1.x = x + w/2;
103 -      p1.y = y + h/2;
104 -      if (state->state_type==STATE_END) {
105 -         r = STATE_ENDRATIO;
106 -         renderer_ops->fill_ellipse(renderer, 
107 -                                     &p1,
108 -                                     r, r,
109 -                                     &color_white);
110 -         
111 -         renderer_ops->draw_ellipse(renderer, 
112 -                                     &p1,
113 -                                     r, r,
114 -                                     &color_black);
115 -      }  
116 -      r = STATE_RATIO;
117 -      renderer_ops->fill_ellipse(renderer, 
118 -                                 &p1,
119 -                                 r, r,
120 -                                 &color_black);
121 -  } else {
122 +  if (state->state_type==STATE_NORMAL) {
123        p1.x = x;
124        p1.y = y;
125        p2.x = x + w;
126 @@ -257,14 +255,28 @@
127        renderer_ops->fill_rounded_rect(renderer, &p1, &p2, &color_white, 0.5);
128        renderer_ops->draw_rounded_rect(renderer, &p1, &p2, &color_black, 0.5);
129        text_draw(state->text, renderer);
130 -  }
131 +      if (state->show_internals) {
132 +        p1.x = x; p2.x = x + w;
133 +        p1.y = p2.y = state->internals->position.y - state->internals->ascent
134 +          - 0.5*STATE_MARGIN_Y;
135 +      
136 +        renderer_ops->set_linewidth(renderer, 0.1);
137 +        renderer_ops->draw_line(renderer,
138 +                                &p1, &p2,
139 +                                &color_black);
140 +        
141 +        text_draw(state->internals, renderer);
142 +      }     
143 +  } else {
144 +     message_warning(_("Please use initial/final state instead"));
145 +  } 
146  }
147  
148  
149  static void
150  state_update_data(State *state)
151  {
152 -  real w, h;
153 +  real w=0, h=0, x=0;
154  
155    Element *elem = &state->element;
156    Object *obj = &elem->object;
157 @@ -274,13 +286,24 @@
158    if (state->state_type==STATE_NORMAL) { 
159        w = state->text->max_width + 2*STATE_MARGIN_X;
160        h = state->text->height*state->text->numlines +2*STATE_MARGIN_Y;
161 -      if (w < STATE_WIDTH)
162 -         w = STATE_WIDTH;
163 +     
164 +      x = (state->show_internals) ? 
165 +          state->internals->max_width + 2*STATE_MARGIN_X:
166 +          STATE_WIDTH;
167 +     
168 +      if (w < x)
169 +         w = x;
170        p.x = elem->corner.x + w/2.0;
171 -      p.y = elem->corner.y + STATE_MARGIN_Y + state->text->ascent;
172 +      p.y = elem->corner.y + state->text->ascent +
173 +       ((state->show_internals) ? STATE_MARGIN_Y/2.0: STATE_MARGIN_Y);     
174 +      
175        text_set_position(state->text, &p);
176 -  } else {
177 -      w = h = (state->state_type==STATE_END) ? STATE_ENDRATIO: STATE_RATIO;
178 +      if (state->show_internals) {
179 +        p.x = elem->corner.x + STATE_MARGIN_X;
180 +        p.y += STATE_MARGIN_Y + state->internals->height;
181 +         h += state->internals->height*state->internals->numlines;
182 +        text_set_position(state->internals, &p);
183 +      }     
184    }
185  
186    elem->width = w;
187 @@ -339,11 +362,14 @@
188    p.y += STATE_HEIGHT/2.0;
189    
190    state->text = new_text("", font, 0.8, &p, &color_black, ALIGN_CENTER);
191 -  text_get_attributes(state->text,&state->attrs);
192 +  text_get_attributes(state->text,&state->attrs);   
193 +  state->internals = new_text("", font, 0.8, &p, &color_black, ALIGN_LEFT);
194  
195    dia_font_unref(font);
196    
197    state->state_type = STATE_NORMAL;
198 +  state->show_internals = 0;
199 +   
200    element_init(elem, 8, 8);
201    
202    for (i=0;i<8;i++) {
203 @@ -367,7 +393,7 @@
204  state_destroy(State *state)
205  {
206    text_destroy(state->text);
207 -
208 +  text_destroy(state->internals);
209    element_destroy(&state->element);
210  }
211  
This page took 0.097804 seconds and 3 git commands to generate.