MinGW是否影响编译 - 一个GTK程序 [英] Does MinGW influence compilation -- a GTK program
问题描述
旧MinGW新MinGW
gcc 3.4.5 4.7。 2
有什么想法?有人遇到这种情况吗?
另一个线索是关于GTK本身的。
g_signal_emit_by_name(G_OBJECT(g_object_get_data(G_OBJECT(window),plat_GA_canvas)),expose -event,G_TYPE_NONE);
根据不同情况绘制图像的画布。这里它只是发送一个信号来暴露画布。奇怪的是,它在旧的MinGW中起作用。所以我不怀疑这是问题的关键。只是一个线索。顺便说一下,我在家里的纯Linux环境中编译了GTK程序。它也很完美。
任何想法?请帮助。
@duskast,下面是代码的一部分。这是一个有点长。
++++++++++++++++++++++++++++++ ++++++++++++++++++++++
问题可能发生 - g_signal_emit_by_name
:
void ACC_platform_unit_num_changed(GtkWidget * box,GtkWidget * window)
{
int kind;
kind = gtk_option_menu_get_history((GtkOptionMenu *)box)+ 1;
if(plat.unit_num!= kind)
{
plat_GA_canvas_refresh(window);
g_signal_emit_by_name(G_OBJECT(g_object_get_data(G_OBJECT(window),plat_GA_canvas)),expose-event,G_TYPE_NONE);
plat.unit_num = kind;
if(plat.unit_num == 1)
{
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window),ACC_platform_if_gap),FALSE);
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window),ACC_platform_if_big_gap),FALSE);
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window),ACC_platform_gap_w),FALSE);
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window),ACC_platform_live_load_gap),FALSE);
}
else
{
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window),ACC_platform_if_gap),TRUE);
if(plat.has_gap)
{
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window),ACC_platform_if_big_gap),TRUE);
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window),ACC_platform_gap_w),TRUE);
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window),ACC_platform_live_load_gap),TRUE);
}
else
{
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window),ACC_platform_if_big_gap),FALSE);
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window),ACC_platform_gap_w),FALSE);
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window),ACC_platform_live_load_gap),FALSE);
gap_span_show(g_object_get_data(G_OBJECT(window),ACC_platform_gap_span_store));
核心绘图功能:
void ACC_GA_draw(cairo_t * cr,int width,int height)
{
/ * #define X_MARGIN 30
#define Y_MARGIN 30 * /
#define COLUMN_RADIUS_ASSUME 1.6
#define COLUMN_SQUARE_LEN_ASSUME 2.0
double x,y,x1,y1,x2,y2,scale,x_base,y_base,X_MARGIN,Y_MARGIN;
double x3,y3,downward_height = 0,downward_width = 0;
double x_one_unit,y_one_unit,x_total,y_total,gap_value;
double alpha = 60.0,arrow_side_length = 20.0,arrow_tail_length = 10.0;
ACC_AXIS * x_axis,* y_axis;
int i,j,unit_num,向下;
char * AX,* AY,* Wx_left,* Wx_right,* Wy_top,* Wy_bottom,* gap,* axis;
cairo_text_extents_t te;
AX = g_strdup_printf(%。0f,plat.fan_section_AX * 1000);
AY = g_strdup_printf(%。0f,plat.fan_section_AY * 1000);
Wx_left = g_strdup_printf(%。0f,plat.walkway_Wx_left * 1000);
Wx_right = g_strdup_printf(%。0f,plat.walkway_Wx_right * 1000);
Wy_bottom = g_strdup_printf(%。0f,plat.walkway_Wy_bottom * 1000);
Wy_top = g_strdup_printf(%。0f,plat.walkway_Wy_top * 1000);
x_one_unit = plat.fan_section_AX * plat.SDD_num;
x_total = x_one_unit * plat.unit_num + plat.gap_total + plat.walkway_Wx_left + plat.walkway_Wx_right;
y_one_unit = plat.fan_section_AY * plat.row_num;
y_total = y_one_unit + plat.walkway_Wy_bottom + plat.walkway_Wy_top;
scale = calcu_scale(width,height,x_total,y_total,Wx_left,Wy_top,cr,& X_MARGIN,& Y_MARGIN);
cairo_set_line_width(cr,NORMAL_LINE_WIDTH * 0.7); (unit_num = 1; unit_num< = plat.unit_num; unit_num ++)
{
if(unit_num == 1)
x_base = X_MARGIN;
else
{
double total_gap = 0; (i = 0; i total_gap + = strtod(g_list_nth(plat.gap_w,i) - > data,NULL);
。
x_base = X_MARGIN +(x_one_unit *(unit_num - 1)+ total_gap)* scale;
}
y_base = Y_MARGIN;
for(i = 0,x_axis = plat.X_axis; x_axis; x_axis = x_axis-> next,i ++)
{
if(i == 0)
x = x_base;
else
x + = plat.fan_section_AX * scale;
y = y_base;
cairo_move_to(cr,x,y);
y + = y_one_unit * scale;
cairo_line_to(cr,x,y); / *垂直网格* /
cairo_stroke(cr);
$ b $ * SDD * /
if(i!= plat.SDD_num)
{
cairo_arrow(cr,x + plat.fan_section_AX / 2 * scale,y + plat.walkway_Wy_bottom * scale,alpha,arrow_side_length,1,arrow_tail_length);
cairo_save(cr);
cairo_set_line_width(cr,BOLD_LINE_WIDTH);
cairo_set_line_cap(cr,CAIRO_LINE_CAP_SQUARE);
cairo_move_to(cr,x_base + plat.fan_section_AX / 2 * scale,y + plat.walkway_Wy_bottom * scale + arrow_side_length + arrow_tail_length);
cairo_rel_line_to(cr,(x_one_unit - plat.fan_section_AX)* scale,0);
cairo_stroke(cr);
cairo_restore(cr);
}
/ *暗线为A1,A2 ... * /
cairo_move_to(cr,x,y + plat.walkway_Wy_bottom * scale + arrow_side_length + arrow_tail_length + 10) ;
cairo_rel_line_to(cr,0,20);
cairo_get_current_point(cr,& x3,& y3);
if(i!= plat.SDD_num)
{
cairo_text_align_horizontal_center(cr,AX,0,1,plat.fan_section_AX / 2 * scale,-10);
}
else
{
if(plat.unit_num> 1& plat.has_gap& unit_num!= plat.unit_num)
{
gap_value = strtod(g_list_nth(plat.gap_w,unit_num_1) - > data,NULL);
gap = g_strdup_printf(%。0f,1000 * gap_value);
cairo_text_extents(cr,gap,& te);
if(gap_value * scale {
downward = 1;
downward_height = 11;
downward_width = gap_value *比例;
cairo_rel_move_to(cr,gap_value / 2 * scale - (te.x_bearing + te.width / 2),10);
}
else
{
downward = 0;
cairo_rel_move_to(cr,gap_value / 2 * scale - (te.x_bearing + te.width / 2),-10);
}
cairo_show_text(cr,gap);
g_free(gap);
}
else
下行= 0;
}
if(unit_num == 1&& i == 0)
{
cairo_move_to(cr,x - plat.walkway_Wx_left * scale,y + plat.walkway_Wy_bottom * scale + arrow_side_length + arrow_tail_length + 10);
cairo_rel_line_to(cr,0,20);
cairo_rel_move_to(cr,-25,-10);
cairo_show_text(cr,Wx_left);
if(unit_num == plat.unit_num&& i == plat.SDD_num)
{
cairo_move_to(cr,x + plat.walkway_Wx_right * scale,y + plat.walkway_Wy_bottom * scale + arrow_side_length + arrow_tail_length + 10);
cairo_rel_line_to(cr,0,20);
cairo_rel_move_to(cr,3,-10);
cairo_show_text(cr,Wx_right); (plat.axis_style_SDD == 0)/ *递增* /
轴= g_strdup_printf(A%d,plat.start_axis_SDD +(unit_num - 1)/
) *(plat.SDD_num + 1)+ i);
else
axis = g_strdup_printf(A%d,plat.start_axis_SDD +(unit_num - 1)*(plat.SDD_num + 1) - i);
cairo_text_extents(cr,axis,& te); ($!
)if(!upward ||((i!= plat.SDD_num)&&(unit_num!= 1&& i!= 0)))
cairo_move_to(cr,x3 - te .width / 2,y3 + te.height + 2);
else
{
if(te.width< downward_width)
cairo_move_to(cr,x3 - te.width / 2,y3 + te.height + downward_height);
else
{
if(i == plat.SDD_num)
cairo_move_to(cr,x3 - te.width,y3 + te.height + downward_height);
else
cairo_move_to(cr,x3,y3 + te.height + downward_height);
}
}
cairo_show_text(cr,axis);
g_free(axis);
cairo_stroke(cr);
for(j = 0,y_axis = plat.Y_axis; y_axis; y_axis = y_axis-> next,j ++)
{
x1 = x_base;
if(j == 0)
y1 = y_base + y_one_unit * scale;
else
y1 - = plat.fan_section_AY * scale;
if(i == 0)
{
cairo_move_to(cr,x1,y1);
x1 + = x_one_unit * scale;
cairo_line_to(cr,x1,y1); / *水平网格* /
cairo_stroke(cr);
}
if(i!= plat.SDD_num&& j!= plat.row_num)/ * fan ring * /
{
cairo_arc(cr ,x + plat.fan_section_AX / 2 * scale,y1-plat.fan_section_ay / 2 * scale,plat.fan_ring_opening_D / 2 * scale,0,2 * PI);
cairo_stroke(cr);
$ b $ *列* /
if(plat.col_type == 0)/ *砼悬臂住* /
{
if(plat .SDD_num%2 == 0)
{
if((i + 1)%2 == plat.SDD_col_first&&(j + 1)%2 == plat.row_col_first)
{
cairo_arc(cr,x,y1,COLUMN_RADIUS_ASSUME * scale,0,2 * PI);
cairo_fill(cr);
cairo_stroke(cr);
if(!plat.if_unit_symmetry || unit_num%2 == 1)
{
if( (i + 1)%2 == plat.SDD_col_first&(j + 1)%2 == plat.row_col_first)
{
cairo_arc(cr,x,y1,COLUMN_RADIUS_ASSUME * scale, 0,2 * PI);
cairo_fill(cr);
cairo_stroke(cr);
else
{
if((i)%2 == plat.SDD_col_first&&(j + 1)%2 == plat .row_col_first)
{
cairo_arc(cr,x,y1,COLUMN_RADIUS_ASSUME * scale,0,2 * PI);
cairo_fill(cr);
cairo_stroke(cr);
$ b else if(plat.col_type == 1)/ *钢柱* /
{
cairo_save (CR);
cairo_set_line_width(cr,2 * NORMAL_LINE_WIDTH);
cairo_move_to(cr,x,y1 - COLUMN_SQUARE_LEN_ASSUME / 2 * scale);
cairo_rel_line_to(cr,0,COLUMN_SQUARE_LEN_ASSUME * scale);
cairo_move_to(cr,x - COLUMN_SQUARE_LEN_ASSUME / 2 * scale,y1 - COLUMN_SQUARE_LEN_ASSUME / 2 * scale);
cairo_rel_line_to(cr,COLUMN_SQUARE_LEN_ASSUME * scale,0);
cairo_move_to(cr,x - COLUMN_SQUARE_LEN_ASSUME / 2 * scale,y1 + COLUMN_SQUARE_LEN_ASSUME / 2 * scale);
cairo_rel_line_to(cr,COLUMN_SQUARE_LEN_ASSUME * scale,0);
cairo_stroke(cr);
cairo_restore(cr);
}
else if(plat.col_type == 2)/ *砼框架柱* /
{
cairo_rectangle(cr,x - COLUMN_SQUARE_LEN_ASSUME / 2 * scale,y1 - COLUMN_SQUARE_LEN_ASSUME / 2 *比例,COLUMN_SQUARE_LEN_ASSUME *比例,COLUMN_SQUARE_LEN_ASSUME *比例);
cairo_fill(cr);
cairo_stroke(cr);
}
/ * AA,AB ... * /
的暗线如果(unit_num == plat.unit_num&& i == 0)
{
cairo_move_to(cr,x1 + plat.walkway_Wx_right * scale + 10,y1);
cairo_rel_line_to(cr,20,0);
if(j!= plat.row_num)
{
cairo_text_align_horizontal_center(cr,AY,1,1,-10,-plat.fan_section_AY / 2 * scale);
}
if(j == 0)
{
x2 = x1 + plat.walkway_Wx_right * scale + 10 + 20 - 5;
y2 = y1 + plat.walkway_Wy_bottom * scale;
cairo_move_to(cr,x1 + plat.walkway_Wx_right * scale + 10,y1);
cairo_rel_move_to(cr,0,plat.walkway_Wy_bottom * scale);
cairo_rel_line_to(cr,20,0);
cairo_rel_move_to(cr,-10,25);
cairo_save(cr);
cairo_rotate(cr, - PI / 2.0);
cairo_show_text(cr,Wy_bottom);
cairo_restore(cr);
if(j == plat.row_num)
{
cairo_move_to(cr,x1 + plat.walkway_Wx_right * scale + 10,y1);
cairo_rel_move_to(cr,0,-plat.walkway_Wy_top * scale);
cairo_rel_line_to(cr,20,0);
cairo_rel_move_to(cr,-10,-1);
cairo_save(cr);
cairo_rotate(cr, - PI / 2.0);
cairo_show_text(cr,Wy_top);
cairo_restore(cr);
}
cairo_stroke(cr);
if if(unit_num == 1&& i == 0)
{
if(plat.axis_style_row == 0)/ *递增* /
axis = g_strdup_printf(A%c,plat.start_axis_row + j);
else
axis = g_strdup_printf(A%c,plat.start_axis_row - j);
cairo_text_extents(cr,axis,& te);
cairo_move_to(cr,x_base - plat.walkway_Wx_left * scale - 20,y1 + te.height / 2);
cairo_show_text(cr,axis);
g_free(axis);
cairo_stroke(cr);
}
}
}
}
/ *走道线* /
x = X_MARGIN - plat.walkway_Wx_left *比例尺;
y = Y_MARGIN - plat.walkway_Wy_top * scale;
cairo_move_to(cr,x,y);
cairo_rel_line_to(cr,x_total * scale,0);
cairo_rel_line_to(cr,0,y_total * scale);
cairo_rel_line_to(cr,-x_total * scale,0);
cairo_rel_line_to(cr,0,-y_total * scale);
cairo_stroke(cr);
/ *暗淡A1,A2 ... * /
的总行数cairo_move_to(cr,X_MARGIN - plat.walkway_Wx_left * scale,Y_MARGIN +(y_one_unit + plat.walkway_Wy_bottom)* scale + arrow_side_length + arrow_tail_length + 10 + 20-5);
cairo_rel_line_to(cr,x_total * scale,0);
cairo_stroke(cr);
/ *暗淡AA,AB ... * /
的总行数cairo_move_to(cr,x2,y2);
cairo_rel_line_to(cr,0,-y_total * scale);
cairo_stroke(cr);
g_free(AX);
g_free(AY);
g_free(Wx_left);
g_free(Wx_right);
g_free(Wy_bottom);
g_free(Wy_top);
expose-event
signal:
static gboolean ACC_GA_expose(GtkWidget * canvas,GdkEventExpose * event,gpointer user_data)
{
cairo_t * cr;
cr = gdk_cairo_create(canvas-> window);
if(plat.if_GA_draw)
{
ACC_GA_draw(cr,canvas-> allocation.width,canvas-> allocation.height);
}
else
{
char * local = char_to_utf8(按下按钮\生成GA \更新!!);
cairo_select_font_face(cr,Sans,CAIRO_FONT_SLANT_NORMAL,CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size(cr,0.35);
cairo_move_to(cr,200,200);
cairo_show_text(cr,local);
g_free(local);
}
cairo_destroy(cr);
返回FALSE;
在main()函数中:
。
。
。
canvas = gtk_drawing_area_new();
g_object_set_data(G_OBJECT(窗口),plat_GA_canvas,canvas);
plat.if_GA_draw = 0;
gtk_widget_show(canvas);
gtk_box_pack_start(GTK_BOX(sub_main_box),canvas,TRUE,TRUE,0);
g_signal_connect(G_OBJECT(canvas),expose-event,G_CALLBACK(ACC_GA_expose),window);
。
。
。
+++++++++++++++++++++ ++++++++++++++++++++++++++++++
I compiled a GTK program in MinGW environment. It worked perfect. Recently, I updated MinGW and recompiled the GTK program, then the program always stopped with Segmentation fault. I have tried to use gdb to look for errors but I couldn't. The config of GTK is exactly same in the old and new MinGW. Therefore, I am suspicious of MinGW environment that influences compilation. I found the version of gcc is different in two environment:
old MinGW new MinGW
gcc 3.4.5 4.7.2
Any idea? Does anybody meet the situation?
Another clue is about GTK itself. I found the program stopped here:
g_signal_emit_by_name(G_OBJECT(g_object_get_data(G_OBJECT(window), "plat_GA_canvas")), "expose-event", G_TYPE_NONE);
It is a canvas to draw a image according to different situation. Here it just sends a signal to expose the canvas. The curious thing is that it worked in the old MinGW. So I don't doubt it is the point of the problem. Just maybe a clue. By the way, I compiled the GTK program in a pure Linux environment at home. It also worked perfect.
Any idea? Please help.
@duskast, below is the part of the code. It is a little lengthy.
+++++++++++++++++++++++++++++++++++++++++++++++++++
The problem maybe happened -- g_signal_emit_by_name
:
void ACC_platform_unit_num_changed (GtkWidget *box, GtkWidget *window)
{
int kind;
kind = gtk_option_menu_get_history((GtkOptionMenu *)box) + 1;
if(plat.unit_num != kind)
{
plat_GA_canvas_refresh (window);
g_signal_emit_by_name(G_OBJECT(g_object_get_data(G_OBJECT(window), "plat_GA_canvas")), "expose-event", G_TYPE_NONE);
plat.unit_num = kind;
if(plat.unit_num == 1)
{
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window), "ACC_platform_if_gap"), FALSE);
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window), "ACC_platform_if_big_gap"), FALSE);
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window), "ACC_platform_gap_w"), FALSE);
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window), "ACC_platform_live_load_gap"), FALSE);
}
else
{
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window), "ACC_platform_if_gap"), TRUE);
if(plat.has_gap)
{
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window), "ACC_platform_if_big_gap"), TRUE);
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window), "ACC_platform_gap_w"), TRUE);
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window), "ACC_platform_live_load_gap"), TRUE);
}
else
{
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window), "ACC_platform_if_big_gap"), FALSE);
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window), "ACC_platform_gap_w"), FALSE);
gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(window), "ACC_platform_live_load_gap"), FALSE);
}
}
gap_span_show (g_object_get_data(G_OBJECT(window), "ACC_platform_gap_span_store"));
}
}
The core drawing function:
void ACC_GA_draw (cairo_t *cr, int width, int height)
{
/* #define X_MARGIN 30
#define Y_MARGIN 30 */
#define COLUMN_RADIUS_ASSUME 1.6
#define COLUMN_SQUARE_LEN_ASSUME 2.0
double x, y, x1, y1, x2, y2, scale, x_base, y_base, X_MARGIN, Y_MARGIN;
double x3, y3, downward_height = 0, downward_width = 0;
double x_one_unit, y_one_unit, x_total, y_total, gap_value;
double alpha = 60.0, arrow_side_length = 20.0, arrow_tail_length = 10.0;
ACC_AXIS *x_axis, *y_axis;
int i, j, unit_num, downward;
char *AX, *AY, *Wx_left, *Wx_right, *Wy_top, *Wy_bottom, *gap, *axis;
cairo_text_extents_t te;
AX = g_strdup_printf("%.0f", plat.fan_section_AX * 1000);
AY = g_strdup_printf("%.0f", plat.fan_section_AY * 1000);
Wx_left = g_strdup_printf("%.0f", plat.walkway_Wx_left * 1000);
Wx_right = g_strdup_printf("%.0f", plat.walkway_Wx_right * 1000);
Wy_bottom = g_strdup_printf("%.0f", plat.walkway_Wy_bottom * 1000);
Wy_top = g_strdup_printf("%.0f", plat.walkway_Wy_top * 1000);
x_one_unit = plat.fan_section_AX * plat.SDD_num;
x_total = x_one_unit * plat.unit_num + plat.gap_total + plat.walkway_Wx_left + plat.walkway_Wx_right;
y_one_unit = plat.fan_section_AY * plat.row_num;
y_total = y_one_unit + plat.walkway_Wy_bottom + plat.walkway_Wy_top;
scale = calcu_scale (width, height, x_total, y_total, Wx_left, Wy_top, cr, &X_MARGIN, &Y_MARGIN);
cairo_set_line_width (cr, NORMAL_LINE_WIDTH * 0.7);
for(unit_num = 1; unit_num <= plat.unit_num; unit_num++)
{
if(unit_num == 1)
x_base = X_MARGIN;
else
{
double total_gap = 0;
for(i = 0; i < unit_num - 1; i++)
total_gap += strtod(g_list_nth(plat.gap_w, i)->data, NULL);
x_base = X_MARGIN + (x_one_unit * (unit_num - 1) + total_gap) * scale;
}
y_base = Y_MARGIN;
for(i = 0, x_axis = plat.X_axis; x_axis; x_axis = x_axis->next, i++)
{
if(i == 0)
x = x_base;
else
x += plat.fan_section_AX * scale;
y = y_base;
cairo_move_to(cr, x, y);
y += y_one_unit * scale;
cairo_line_to(cr, x, y); /* vertical grid */
cairo_stroke(cr);
/* SDD */
if(i != plat.SDD_num)
{
cairo_arrow (cr, x + plat.fan_section_AX / 2 * scale, y + plat.walkway_Wy_bottom * scale, alpha, arrow_side_length, 1, arrow_tail_length);
cairo_save(cr);
cairo_set_line_width (cr, BOLD_LINE_WIDTH);
cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE);
cairo_move_to(cr, x_base + plat.fan_section_AX / 2 * scale, y + plat.walkway_Wy_bottom * scale + arrow_side_length + arrow_tail_length);
cairo_rel_line_to(cr, (x_one_unit - plat.fan_section_AX) * scale, 0);
cairo_stroke(cr);
cairo_restore(cr);
}
/* dim line for A1, A2 ... */
cairo_move_to(cr, x, y + plat.walkway_Wy_bottom * scale + arrow_side_length + arrow_tail_length + 10);
cairo_rel_line_to(cr, 0, 20);
cairo_get_current_point(cr, &x3, &y3);
if(i != plat.SDD_num)
{
cairo_text_align_horizontal_center (cr, AX, 0, 1, plat.fan_section_AX / 2 * scale, -10);
}
else
{
if(plat.unit_num > 1 && plat.has_gap && unit_num != plat.unit_num)
{
gap_value = strtod(g_list_nth(plat.gap_w, unit_num - 1)->data, NULL);
gap = g_strdup_printf("%.0f", 1000 * gap_value);
cairo_text_extents(cr, gap, &te);
if(gap_value * scale < te.x_bearing + te.width)
{
downward = 1;
downward_height = 11;
downward_width = gap_value * scale;
cairo_rel_move_to(cr, gap_value / 2 * scale - (te.x_bearing + te.width / 2), 10);
}
else
{
downward = 0;
cairo_rel_move_to(cr, gap_value / 2 * scale - (te.x_bearing + te.width / 2), -10);
}
cairo_show_text(cr, gap);
g_free(gap);
}
else
downward = 0;
}
if(unit_num == 1 && i == 0)
{
cairo_move_to(cr, x - plat.walkway_Wx_left * scale, y + plat.walkway_Wy_bottom * scale + arrow_side_length + arrow_tail_length + 10);
cairo_rel_line_to(cr, 0, 20);
cairo_rel_move_to(cr, -25, -10);
cairo_show_text(cr, Wx_left);
}
if(unit_num == plat.unit_num && i == plat.SDD_num)
{
cairo_move_to(cr, x + plat.walkway_Wx_right * scale, y + plat.walkway_Wy_bottom * scale + arrow_side_length + arrow_tail_length + 10);
cairo_rel_line_to(cr, 0, 20);
cairo_rel_move_to(cr, 3, -10);
cairo_show_text(cr, Wx_right);
}
if(plat.axis_style_SDD == 0) /* 递增 */
axis = g_strdup_printf("A%d", plat.start_axis_SDD + (unit_num - 1) * (plat.SDD_num + 1) + i);
else
axis = g_strdup_printf("A%d", plat.start_axis_SDD + (unit_num - 1) * (plat.SDD_num + 1) - i);
cairo_text_extents(cr, axis, &te);
if(!downward || ((i != plat.SDD_num) && (unit_num != 1 && i != 0)))
cairo_move_to(cr, x3 - te.width / 2, y3 + te.height + 2);
else
{
if(te.width < downward_width)
cairo_move_to(cr, x3 - te.width / 2, y3 + te.height + downward_height);
else
{
if(i == plat.SDD_num)
cairo_move_to(cr, x3 - te.width, y3 + te.height + downward_height);
else
cairo_move_to(cr, x3, y3 + te.height + downward_height);
}
}
cairo_show_text(cr, axis);
g_free(axis);
cairo_stroke(cr);
for(j = 0, y_axis = plat.Y_axis; y_axis; y_axis = y_axis->next, j++)
{
x1 = x_base;
if(j == 0)
y1 = y_base + y_one_unit * scale;
else
y1 -= plat.fan_section_AY * scale;
if(i == 0)
{
cairo_move_to(cr, x1, y1);
x1 += x_one_unit * scale;
cairo_line_to(cr, x1, y1); /* horizontal grid */
cairo_stroke(cr);
}
if(i != plat.SDD_num && j != plat.row_num) /* fan ring */
{
cairo_arc(cr, x + plat.fan_section_AX / 2 * scale, y1 - plat.fan_section_AY / 2 * scale, plat.fan_ring_opening_D / 2 * scale, 0, 2 * PI);
cairo_stroke(cr);
}
/* columns */
if(plat.col_type == 0) /* 砼悬臂住 */
{
if(plat.SDD_num % 2 == 0)
{
if((i + 1) % 2 == plat.SDD_col_first && (j + 1) % 2 == plat.row_col_first)
{
cairo_arc(cr, x, y1, COLUMN_RADIUS_ASSUME * scale, 0, 2 * PI);
cairo_fill(cr);
cairo_stroke(cr);
}
}
else
{
if(!plat.if_unit_symmetry || unit_num % 2 == 1)
{
if((i + 1) % 2 == plat.SDD_col_first && (j + 1) % 2 == plat.row_col_first)
{
cairo_arc(cr, x, y1, COLUMN_RADIUS_ASSUME * scale, 0, 2 * PI);
cairo_fill(cr);
cairo_stroke(cr);
}
}
else
{
if((i) % 2 == plat.SDD_col_first && (j + 1) % 2 == plat.row_col_first)
{
cairo_arc(cr, x, y1, COLUMN_RADIUS_ASSUME * scale, 0, 2 * PI);
cairo_fill(cr);
cairo_stroke(cr);
}
}
}
}
else if(plat.col_type == 1) /* 钢柱 */
{
cairo_save(cr);
cairo_set_line_width (cr, 2 * NORMAL_LINE_WIDTH);
cairo_move_to(cr, x, y1 - COLUMN_SQUARE_LEN_ASSUME / 2 * scale);
cairo_rel_line_to(cr, 0, COLUMN_SQUARE_LEN_ASSUME * scale);
cairo_move_to(cr, x - COLUMN_SQUARE_LEN_ASSUME / 2 * scale, y1 - COLUMN_SQUARE_LEN_ASSUME / 2 * scale);
cairo_rel_line_to(cr, COLUMN_SQUARE_LEN_ASSUME * scale, 0);
cairo_move_to(cr, x - COLUMN_SQUARE_LEN_ASSUME / 2 * scale, y1 + COLUMN_SQUARE_LEN_ASSUME / 2 * scale);
cairo_rel_line_to(cr, COLUMN_SQUARE_LEN_ASSUME * scale, 0);
cairo_stroke(cr);
cairo_restore(cr);
}
else if(plat.col_type == 2) /* 砼框架柱 */
{
cairo_rectangle(cr, x - COLUMN_SQUARE_LEN_ASSUME / 2 * scale, y1 - COLUMN_SQUARE_LEN_ASSUME / 2 * scale, COLUMN_SQUARE_LEN_ASSUME * scale, COLUMN_SQUARE_LEN_ASSUME * scale);
cairo_fill(cr);
cairo_stroke(cr);
}
/* dim line of AA, AB ... */
if(unit_num == plat.unit_num && i == 0)
{
cairo_move_to(cr, x1 + plat.walkway_Wx_right * scale + 10, y1);
cairo_rel_line_to(cr, 20, 0);
if(j != plat.row_num)
{
cairo_text_align_horizontal_center (cr, AY, 1, 1, -10, -plat.fan_section_AY / 2 * scale);
}
if(j == 0)
{
x2 = x1 + plat.walkway_Wx_right * scale + 10 + 20 - 5;
y2 = y1 + plat.walkway_Wy_bottom * scale;
cairo_move_to(cr, x1 + plat.walkway_Wx_right * scale + 10, y1);
cairo_rel_move_to(cr, 0, plat.walkway_Wy_bottom * scale);
cairo_rel_line_to(cr, 20, 0);
cairo_rel_move_to(cr, -10, 25);
cairo_save(cr);
cairo_rotate(cr, - PI / 2.0);
cairo_show_text(cr, Wy_bottom);
cairo_restore(cr);
}
if(j == plat.row_num)
{
cairo_move_to(cr, x1 + plat.walkway_Wx_right * scale + 10, y1);
cairo_rel_move_to(cr, 0, -plat.walkway_Wy_top * scale);
cairo_rel_line_to(cr, 20, 0);
cairo_rel_move_to(cr, -10, -1);
cairo_save(cr);
cairo_rotate(cr, - PI / 2.0);
cairo_show_text(cr, Wy_top);
cairo_restore(cr);
}
cairo_stroke(cr);
}
else if(unit_num == 1 && i == 0)
{
if(plat.axis_style_row == 0) /* 递增 */
axis = g_strdup_printf("A%c", plat.start_axis_row + j);
else
axis = g_strdup_printf("A%c", plat.start_axis_row - j);
cairo_text_extents(cr, axis, &te);
cairo_move_to(cr, x_base - plat.walkway_Wx_left * scale - 20, y1 + te.height / 2);
cairo_show_text(cr, axis);
g_free(axis);
cairo_stroke(cr);
}
}
}
}
/* walkway line */
x = X_MARGIN - plat.walkway_Wx_left * scale;
y = Y_MARGIN - plat.walkway_Wy_top * scale;
cairo_move_to(cr, x, y);
cairo_rel_line_to(cr, x_total * scale, 0);
cairo_rel_line_to(cr, 0, y_total * scale);
cairo_rel_line_to(cr, -x_total * scale, 0);
cairo_rel_line_to(cr, 0, -y_total * scale);
cairo_stroke(cr);
/* dim total line for A1, A2 ... */
cairo_move_to(cr, X_MARGIN - plat.walkway_Wx_left * scale, Y_MARGIN + (y_one_unit + plat.walkway_Wy_bottom) * scale + arrow_side_length + arrow_tail_length + 10 + 20 - 5);
cairo_rel_line_to(cr, x_total * scale, 0);
cairo_stroke(cr);
/* dim total line for AA, AB ... */
cairo_move_to(cr, x2, y2);
cairo_rel_line_to(cr, 0, -y_total * scale);
cairo_stroke(cr);
g_free(AX);
g_free(AY);
g_free(Wx_left);
g_free(Wx_right);
g_free(Wy_bottom);
g_free(Wy_top);
}
The expose-event
signal:
static gboolean ACC_GA_expose (GtkWidget *canvas, GdkEventExpose *event, gpointer user_data)
{
cairo_t *cr;
cr = gdk_cairo_create (canvas->window);
if(plat.if_GA_draw)
{
ACC_GA_draw (cr, canvas->allocation.width, canvas->allocation.height);
}
else
{
char *local = char_to_utf8 ("Press button \"生成GA\" to update!!");
cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size(cr, 0.35);
cairo_move_to(cr, 200, 200);
cairo_show_text(cr, local);
g_free(local);
}
cairo_destroy (cr);
return FALSE;
}
In main() function:
.
.
.
canvas = gtk_drawing_area_new();
g_object_set_data(G_OBJECT(window), "plat_GA_canvas", canvas);
plat.if_GA_draw = 0;
gtk_widget_show(canvas);
gtk_box_pack_start(GTK_BOX(sub_main_box), canvas, TRUE, TRUE, 0);
g_signal_connect(G_OBJECT(canvas), "expose-event", G_CALLBACK(ACC_GA_expose), window);
.
.
.
+++++++++++++++++++++++++++++++++++++++++++++++++++
GCC 3.4.5 and GCC 4.7.2 are ABI incompatible. You need to rebuild all your code.
这篇关于MinGW是否影响编译 - 一个GTK程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!