~ubuntu-branches/debian/wheezy/gtk2-engines-murrine/wheezy

« back to all changes in this revision

Viewing changes to src/murrine_style.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez
  • Date: 2007-10-17 19:28:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071017192800-0anhivnr6cybvfk5
Tags: 0.53.1-1
* New upstream release.
* debian/control: correct description since there is no theme included with
  it.                                                        closes: #428874
* debian/patches: add a patch from Steve Langasek to use the correct free()
  function and avoid a segfault in gimp.                     closes: #447008

Show diffs side-by-side

added added

removed removed

Lines of Context:
858
858
murrine_style_draw_option (DRAW_ARGS)
859
859
{
860
860
        MurrineStyle *murrine_style = MURRINE_STYLE (style);
861
 
        MurrineRGB *border;
862
 
        MurrineRGB *dot;
 
861
        MurrineColors *colors = &murrine_style->colors;
 
862
        cairo_t *cr;
 
863
        WidgetParameters params;
 
864
 
 
865
        cr = murrine_begin_paint (window, area);
 
866
 
 
867
        murrine_sanitize_size (window, &width, &height);
 
868
 
 
869
        murrine_set_widget_parameters (widget, style, state_type, &params);
 
870
 
 
871
        params.hilight_ratio = murrine_style->hilight_ratio;
 
872
        params.glazestyle = murrine_style->glazestyle;
 
873
        params.gradients = murrine_style->gradients;
 
874
 
 
875
        OptionParameters option;
 
876
 
 
877
        option.draw_bullet = ((shadow_type == GTK_SHADOW_IN) || (shadow_type == GTK_SHADOW_ETCHED_IN));
 
878
        option.inconsistent = (shadow_type == GTK_SHADOW_ETCHED_IN);
863
879
        double trans = 1.0;
864
 
        gboolean draw_bullet = (shadow_type == GTK_SHADOW_IN);
865
 
 
866
 
        cairo_t *cr = murrine_begin_paint (window, area);
867
 
        cairo_pattern_t *pt;
868
 
 
869
 
#ifdef HAVE_ANIMATION
870
 
        if (murrine_style->animation)
871
 
                murrine_animation_connect_checkbox (widget);
872
 
#endif
873
 
 
874
 
        if (state_type == GTK_STATE_INSENSITIVE)
875
 
        {
876
 
                border = &murrine_style->colors.shade[3];
877
 
                dot    = &murrine_style->colors.shade[3];
878
 
        }
879
 
        else
880
 
        {
881
 
                border = &murrine_style->colors.shade[5];
882
 
                if (draw_bullet)
883
 
                        border = &murrine_style->colors.spot[2];
884
 
                dot    = &murrine_style->colors.text[state_type];
885
 
        }
886
 
        MurrineRGB shadow; 
887
 
        murrine_shade (border, &shadow, 0.9);
888
 
        
889
 
        cairo_translate (cr, x, y);
890
 
        
891
 
        cairo_set_line_width (cr, 2);
892
 
        cairo_arc (cr, 7, 7, 6, 0, M_PI*2);     
893
 
        cairo_set_source_rgba (cr, shadow.r, shadow.g, shadow.b, 0.15);
894
 
        cairo_stroke (cr);
895
 
 
896
 
        cairo_set_line_width (cr, 1);
897
 
 
898
 
        cairo_arc (cr, 7, 7, 5.5, 0, M_PI*2);   
899
 
 
900
 
        if (state_type != GTK_STATE_INSENSITIVE)
901
 
        {
902
 
                MurrineRGB *bg = &murrine_style->colors.base[0];
903
 
                if (draw_bullet)
904
 
                        bg = &murrine_style->colors.spot[1];
905
 
                if (murrine_style->glazestyle != 2) {
906
 
                                MurrineRGB hilight;
907
 
                                murrine_shade (bg, &hilight, 1.1*murrine_style->hilight_ratio);
908
 
                                murrine_set_gradient (cr, &hilight, 1.1, 0, 14, murrine_style->gradients, FALSE);
 
880
 
 
881
        #ifdef HAVE_ANIMATION
 
882
                if (murrine_style->animation)
 
883
                        murrine_animation_connect_checkbox (widget);
 
884
 
 
885
                if (murrine_style->animation && GTK_IS_CHECK_BUTTON (widget) && murrine_animation_is_animated (widget) && !gtk_toggle_button_get_inconsistent (GTK_TOGGLE_BUTTON (widget)))
 
886
                {
 
887
                        gfloat elapsed = murrine_animation_elapsed (widget);
 
888
                        trans = sqrt (sqrt (MIN(elapsed / CHECK_ANIMATION_TIME, 1.0)));
909
889
                }
910
 
                else
911
 
                        murrine_set_gradient (cr, bg, 1.1, 0, 14, murrine_style->gradients, FALSE);
912
 
                cairo_fill_preserve (cr);
913
 
        }
914
 
 
915
 
        cairo_set_source_rgb (cr, border->r, border->g, border->b);
916
 
        cairo_stroke (cr);
917
 
 
918
 
        cairo_arc (cr, 7, 7, 5, 0, M_PI*2);     
919
 
        cairo_clip(cr);
920
 
 
921
 
        if (state_type != GTK_STATE_INSENSITIVE)
922
 
        {
923
 
                MurrineRGB *bg = &murrine_style->colors.base[0];
924
 
                if (draw_bullet)
925
 
                        bg = &murrine_style->colors.spot[1];
926
 
 
927
 
                cairo_rectangle (cr, 0, 7, width, height);
928
 
                if (murrine_style->glazestyle == 2) {
929
 
                        MurrineRGB hilight;
930
 
                        murrine_shade (bg, &hilight, 1.1*murrine_style->hilight_ratio);
931
 
                        murrine_set_gradient (cr, &hilight, 1.1, 0, 14, murrine_style->gradients, FALSE);
932
 
                }               
933
 
                else
934
 
                        murrine_set_gradient (cr, bg, 1.1, 0, 14, murrine_style->gradients, FALSE);
935
 
                cairo_fill (cr);
936
 
        }       
937
 
 
938
 
 
939
 
#ifdef HAVE_ANIMATION
940
 
        if (murrine_style->animation && GTK_IS_CHECK_BUTTON (widget) &&
941
 
        murrine_animation_is_animated (widget) &&
942
 
        !gtk_toggle_button_get_inconsistent (GTK_TOGGLE_BUTTON (widget)))
943
 
        {
944
 
                gfloat elapsed = murrine_animation_elapsed (widget);
945
 
        
946
 
                if (draw_bullet)
947
 
                        trans = sqrt (sqrt (MIN(elapsed / CHECK_ANIMATION_TIME, 1.0))); 
948
 
                else
949
 
                        trans = 1.0 - sqrt (sqrt (MIN(elapsed / CHECK_ANIMATION_TIME, 1.0)));
950
 
                
951
 
                draw_bullet = TRUE;
952
 
        }
953
 
#endif
954
 
 
955
 
        /* inconsistent state is missing? */
956
 
        if (draw_bullet)
957
 
        {
958
 
                cairo_arc (cr, 7, 7, 2, 0, M_PI*2);
959
 
                //cairo_set_source_rgb (cr, dot->r, dot->g, dot->b);
960
 
                cairo_set_source_rgba (cr, dot->r, dot->g, dot->b,trans);
961
 
                cairo_fill (cr);
962
 
        }
 
890
        #endif
 
891
 
 
892
        murrine_draw_radiobutton (cr, colors, &params, &option, x, y, width, height, trans);
963
893
 
964
894
        cairo_destroy (cr);
965
895
}
968
898
murrine_style_draw_check (DRAW_ARGS)
969
899
{
970
900
        MurrineStyle *murrine_style = MURRINE_STYLE (style);
971
 
        MurrineRGB *border;
972
 
        MurrineRGB *dot;
 
901
        MurrineColors *colors = &murrine_style->colors;
 
902
        cairo_t *cr;
 
903
        WidgetParameters params;
 
904
 
 
905
        cr = murrine_begin_paint (window, area);
 
906
 
 
907
        murrine_sanitize_size (window, &width, &height);
 
908
 
 
909
        murrine_set_widget_parameters (widget, style, state_type, &params);
 
910
 
 
911
        params.hilight_ratio = murrine_style->hilight_ratio;
 
912
        params.glazestyle = murrine_style->glazestyle;
 
913
        params.gradients = murrine_style->gradients;
 
914
 
 
915
        OptionParameters option;
 
916
 
 
917
        option.draw_bullet = ((shadow_type == GTK_SHADOW_IN) || (shadow_type == GTK_SHADOW_ETCHED_IN));
 
918
        option.inconsistent = (shadow_type == GTK_SHADOW_ETCHED_IN);
973
919
        double trans = 1.0;
974
 
        gboolean draw_bullet = (shadow_type == GTK_SHADOW_IN || shadow_type == GTK_SHADOW_ETCHED_IN);
975
 
 
976
 
        cairo_t *cr = murrine_begin_paint (window, area);
977
 
        cairo_pattern_t *pt;
978
 
 
979
 
#ifdef HAVE_ANIMATION
980
 
        if (murrine_style->animation)
981
 
                murrine_animation_connect_checkbox (widget);
982
 
#endif
983
 
        
984
 
        if (state_type == GTK_STATE_INSENSITIVE)
985
 
        {
986
 
                border = &murrine_style->colors.shade[3];
987
 
                dot    = &murrine_style->colors.shade[3];
988
 
        }
989
 
        else
990
 
        {
991
 
                border = &murrine_style->colors.shade[5];
992
 
                if (draw_bullet)
993
 
                        border = &murrine_style->colors.spot[2];
994
 
                dot    = &murrine_style->colors.text[state_type];
995
 
        }
996
 
        MurrineRGB shadow; 
997
 
        murrine_shade (border, &shadow, 0.9);
998
 
 
999
 
        cairo_translate (cr, x, y);
1000
 
        cairo_set_line_width (cr, 1);
1001
 
        
1002
 
        if (style->xthickness > 2 && style->ythickness > 2)
1003
 
        {               
1004
 
                cairo_rectangle (cr, 0.5, 0.5, width-1, height-1);
1005
 
                cairo_set_source_rgba (cr, shadow.r, shadow.g, shadow.b, 0.15);
1006
 
                cairo_stroke (cr);
1007
 
                
1008
 
                /* Draw the rectangle for the checkbox itself */
1009
 
                cairo_rectangle (cr, 1.5, 1.5, width-3, height-3);
1010
 
        }
1011
 
        else
1012
 
        {
1013
 
                cairo_rectangle (cr, 0.5, 0.5, width-1, height-1);
1014
 
        }
1015
 
        
1016
 
 
1017
 
        if (state_type != GTK_STATE_INSENSITIVE)
1018
 
        {
1019
 
                MurrineRGB *bg = &murrine_style->colors.base[0];
1020
 
                if (draw_bullet)
1021
 
                        bg = &murrine_style->colors.spot[1];
1022
 
 
1023
 
                if (murrine_style->glazestyle == 2) {
1024
 
                        MurrineRGB hilight;
1025
 
                        murrine_shade (bg, &hilight, 1.1*murrine_style->hilight_ratio);
1026
 
                        murrine_set_gradient (cr, &hilight, 1.1, 0, 14, murrine_style->gradients, FALSE);
1027
 
                }               
1028
 
                else
1029
 
                        murrine_set_gradient (cr, bg, 1.1, 0, 14, murrine_style->gradients, FALSE);
1030
 
                cairo_fill_preserve (cr);
1031
 
        }
1032
 
 
1033
 
        cairo_set_source_rgb (cr, border->r, border->g, border->b);
1034
 
        cairo_stroke (cr);
1035
 
 
1036
 
        if (state_type != GTK_STATE_INSENSITIVE)
1037
 
        {
1038
 
                MurrineRGB *bg = &murrine_style->colors.base[0];
1039
 
                if (draw_bullet)
1040
 
                        bg = &murrine_style->colors.spot[1];
1041
 
 
1042
 
                MurrineRGB hilight;
1043
 
                murrine_shade (bg, &hilight, 1.1*murrine_style->hilight_ratio);
1044
 
                if (style->xthickness > 2 && style->ythickness > 2)
1045
 
                        cairo_rectangle (cr, 2, 2, width-4, (height-4)/2);
1046
 
                else
1047
 
                        cairo_rectangle (cr, 1, 1, width-2, (height-2)/2);
1048
 
                
1049
 
                if (murrine_style->glazestyle != 2) {
1050
 
                        MurrineRGB hilight;
1051
 
                        murrine_shade (bg, &hilight, 1.1*murrine_style->hilight_ratio);
1052
 
                        murrine_set_gradient (cr, &hilight, 1.1, 0, 14, murrine_style->gradients, FALSE);
1053
 
                }
1054
 
                else
1055
 
                        murrine_set_gradient (cr, bg, 1.1, 0, 14, murrine_style->gradients, FALSE);
1056
 
                cairo_fill (cr);
1057
 
        }               
1058
 
 
1059
 
#ifdef HAVE_ANIMATION
1060
 
        if (murrine_style->animation && GTK_IS_CHECK_BUTTON (widget) &&
1061
 
            murrine_animation_is_animated(widget) &&
1062
 
            !gtk_toggle_button_get_inconsistent (GTK_TOGGLE_BUTTON (widget)))
1063
 
        {
1064
 
                gfloat elapsed = murrine_animation_elapsed (widget);
1065
 
        
1066
 
                if (draw_bullet)
 
920
 
 
921
        #ifdef HAVE_ANIMATION
 
922
                if (murrine_style->animation)
 
923
                        murrine_animation_connect_checkbox (widget);
 
924
 
 
925
                if (murrine_style->animation && GTK_IS_CHECK_BUTTON (widget) && murrine_animation_is_animated (widget) && !gtk_toggle_button_get_inconsistent (GTK_TOGGLE_BUTTON (widget)))
 
926
                {
 
927
                        gfloat elapsed = murrine_animation_elapsed (widget);
1067
928
                        trans = sqrt (sqrt (MIN(elapsed / CHECK_ANIMATION_TIME, 1.0)));
1068
 
                else
1069
 
                        trans = 1.0 - sqrt (sqrt (MIN(elapsed / CHECK_ANIMATION_TIME, 1.0)));
1070
 
                
1071
 
                draw_bullet = TRUE;
1072
 
        }
1073
 
#endif
 
929
                }
 
930
        #endif
 
931
        
 
932
        murrine_draw_checkbutton (cr, colors, &params, &option, x, y, width, height, trans);
1074
933
 
1075
 
        cairo_scale (cr, width / 13.0, height / 13.0);
1076
 
        if (draw_bullet)
1077
 
        {
1078
 
                if (shadow_type == GTK_SHADOW_ETCHED_IN) /* Inconsistent */
1079
 
                {
1080
 
                        cairo_set_line_width (cr, 2.0);
1081
 
                        cairo_move_to (cr, 3, height*0.5);
1082
 
                        cairo_line_to (cr, width-3, height*0.5);
1083
 
                }
1084
 
                else {
1085
 
                        cairo_translate (cr, -2, 0);
1086
 
/*
1087
 
                        if (widget && widget->parent && GTK_IS_MENU(widget->parent))
1088
 
                                cairo_translate (cr, 0, 0);
1089
 
*/
1090
 
                        cairo_move_to (cr, 4, 8);
1091
 
                        cairo_rel_line_to (cr,   5,   4);
1092
 
                        cairo_rel_curve_to (cr,  1.4,  -5,   -1,  -1,   5.7,  -12.5);
1093
 
                        cairo_rel_curve_to (cr, -4,   4,  -4,   4,  -6.7,    9.3);
1094
 
                        cairo_rel_line_to (cr,  -2.3,  -2.5);
1095
 
                }
1096
 
                
1097
 
                cairo_set_source_rgba (cr, dot->r, dot->g, dot->b, trans);
1098
 
                cairo_fill (cr);
1099
 
        }
1100
934
        cairo_destroy (cr);
1101
935
}
1102
936
 
1147
981
}
1148
982
 
1149
983
static void
1150
 
murrine_style_draw_hline                      (GtkStyle               *style,
 
984
murrine_style_draw_hline  (GtkStyle               *style,
1151
985
                                 GdkWindow              *window,
1152
986
                                 GtkStateType            state_type,
1153
987
                                 GdkRectangle           *area,
1302
1136
}
1303
1137
 
1304
1138
static void
 
1139
murrine_style_draw_layout (GtkStyle * style,
 
1140
             GdkWindow * window,
 
1141
             GtkStateType state_type,
 
1142
             gboolean use_text,
 
1143
             GdkRectangle * area,
 
1144
             GtkWidget * widget,
 
1145
             const gchar * detail, gint x, gint y, PangoLayout * layout)
 
1146
{
 
1147
  GdkGC *gc;
 
1148
 
 
1149
  g_return_if_fail (GTK_IS_STYLE (style));
 
1150
  g_return_if_fail (window != NULL);
 
1151
 
 
1152
  gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
 
1153
 
 
1154
  if (area)
 
1155
    gdk_gc_set_clip_rectangle (gc, area);
 
1156
 
 
1157
  if (state_type == GTK_STATE_INSENSITIVE) {
 
1158
    MurrineStyle *murrine_style = MURRINE_STYLE (style);
 
1159
    MurrineColors *colors = &murrine_style->colors;
 
1160
 
 
1161
    WidgetParameters params;
 
1162
 
 
1163
    murrine_set_widget_parameters (widget, style, state_type, &params);
 
1164
 
 
1165
    GdkColor etched;
 
1166
    MurrineRGB temp;
 
1167
 
 
1168
    if (GTK_WIDGET_NO_WINDOW (widget))
 
1169
      murrine_shade (&params.parentbg, &temp, 1.2);
 
1170
    else
 
1171
      murrine_shade (&colors->bg[widget->state], &temp, 1.2);
 
1172
    etched.red = (int) (temp.r * 65535);
 
1173
    etched.green = (int) (temp.g * 65535);
 
1174
    etched.blue = (int) (temp.b * 65535);
 
1175
 
 
1176
    gdk_draw_layout_with_colors (window, style->text_gc[state_type], x + 1, y + 1, layout, &etched, NULL);
 
1177
    gdk_draw_layout (window, style->text_gc[state_type], x, y, layout);
 
1178
  }
 
1179
  else
 
1180
    gdk_draw_layout (window, gc, x, y, layout);
 
1181
 
 
1182
  if (area)
 
1183
    gdk_gc_set_clip_rectangle (gc, NULL);
 
1184
}
 
1185
 
 
1186
static void
1305
1187
murrine_style_init_from_rc (GtkStyle * style,
1306
1188
                               GtkRcStyle * rc_style)
1307
1189
{
1672
1554
        style_class->draw_hline       = murrine_style_draw_hline;
1673
1555
        style_class->draw_resize_grip = murrine_style_draw_resize_grip;
1674
1556
        style_class->draw_arrow       = murrine_style_draw_arrow;
1675
 
        style_class->render_icon                        = murrine_style_draw_render_icon;
 
1557
        style_class->draw_layout      = murrine_style_draw_layout;
 
1558
        style_class->render_icon                = murrine_style_draw_render_icon;
1676
1559
}
1677
1560
 
1678
1561
GType murrine_type_style = 0;