diff options
Diffstat (limited to 'src/gtkext/gtkdisplaypanel.c')
-rw-r--r-- | src/gtkext/gtkdisplaypanel.c | 137 |
1 files changed, 116 insertions, 21 deletions
diff --git a/src/gtkext/gtkdisplaypanel.c b/src/gtkext/gtkdisplaypanel.c index b32adfa..76c18ec 100644 --- a/src/gtkext/gtkdisplaypanel.c +++ b/src/gtkext/gtkdisplaypanel.c @@ -28,6 +28,7 @@ #include "gtkdisplaypanel-int.h" +#include "../glibext/chrysamarshal.h" #include "../glibext/gbinarycursor.h" // REMME #include "../glibext/gloadedpanel-int.h" @@ -161,6 +162,16 @@ static void gtk_display_panel_class_init(GtkDisplayPanelClass *class) panel->compute_inc = gtk_display_panel_compute_scroll_inc; + /* Signaux */ + + g_signal_new("scaled", + GTK_TYPE_DISPLAY_PANEL, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(GtkDisplayPanelClass, scaled), + NULL, NULL, + g_cclosure_user_marshal_VOID__DOUBLE_DOUBLE, + G_TYPE_NONE, 2, G_TYPE_DOUBLE, G_TYPE_DOUBLE); + } @@ -181,6 +192,8 @@ static void gtk_display_panel_init(GtkDisplayPanel *panel) gtk_widget_set_has_window(GTK_WIDGET(panel), TRUE); gtk_widget_set_can_focus(GTK_WIDGET(panel), TRUE); + panel->scale = 1.0; + panel->export = false; } @@ -460,9 +473,14 @@ static void gtk_display_panel_size_allocate(GtkWidget *widget, GtkAllocation *al static void gtk_display_panel_get_preferred_height(GtkWidget *widget, gint *minimum, gint *natural) { + GtkDisplayPanel *panel; /* Autre version du composant */ gint req; /* Dimension requise */ - GTK_DISPLAY_PANEL_GET_CLASS(widget)->compute_size(GTK_DISPLAY_PANEL(widget), NULL, &req); + panel = GTK_DISPLAY_PANEL(widget); + + GTK_DISPLAY_PANEL_GET_CLASS(widget)->compute_size(panel, NULL, &req); + + req *= panel->scale; if (minimum != NULL) *minimum = req; if (natural != NULL) *natural = req; @@ -486,9 +504,14 @@ static void gtk_display_panel_get_preferred_height(GtkWidget *widget, gint *mini static void gtk_display_panel_get_preferred_width(GtkWidget *widget, gint *minimum, gint *natural) { + GtkDisplayPanel *panel; /* Autre version du composant */ gint req; /* Dimension requise */ - GTK_DISPLAY_PANEL_GET_CLASS(widget)->compute_size(GTK_DISPLAY_PANEL(widget), &req, NULL); + panel = GTK_DISPLAY_PANEL(widget); + + GTK_DISPLAY_PANEL_GET_CLASS(widget)->compute_size(panel, &req, NULL); + + req *= panel->scale; if (minimum != NULL) *minimum = req; if (natural != NULL) *natural = req; @@ -687,7 +710,7 @@ static void gtk_display_panel_update_adjustment(GtkDisplayPanel *panel, GtkOrien { adj = panel->hadjustment; - GTK_DISPLAY_PANEL_GET_CLASS(panel)->compute_size(panel, &req, NULL); + gtk_widget_get_preferred_width(GTK_WIDGET(panel), &req, NULL); allocated = allocation.width; } @@ -695,7 +718,7 @@ static void gtk_display_panel_update_adjustment(GtkDisplayPanel *panel, GtkOrien { adj = panel->vadjustment; - GTK_DISPLAY_PANEL_GET_CLASS(panel)->compute_size(panel, NULL, &req); + gtk_widget_get_preferred_height(GTK_WIDGET(panel), &req, NULL); allocated = allocation.height; } @@ -739,6 +762,73 @@ static void gtk_display_panel_adjustment_value_changed(GtkAdjustment *adj, GtkDi /****************************************************************************** * * * Paramètres : panel = composant GTK à mettre à jour. * +* * +* Description : Indique l'échelle appliquée à l'affichage du composant. * +* * +* Retour : Echelle appliquée à l'affichage. * +* * +* Remarques : - * +* * +******************************************************************************/ + +double gtk_display_panel_get_scale(const GtkDisplayPanel *panel) +{ + double result; /* Echelle à retourner */ + + result = panel->scale; + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : panel = composant GTK à mettre à jour. * +* scale = échelle appliquée à l'affichage. * +* * +* Description : Spécifie l'échelle à appliquer à l'affichage du composant. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void gtk_display_panel_set_scale(GtkDisplayPanel *panel, double scale) +{ + double old_scale; /* Echelle précédente */ + GtkDisplayPanelClass *class; /* Classe associée au composant*/ + + if (scale > 1.0) + scale = 1.0; + + else if (scale < 0.01) + scale = 0.01; + + if (panel->scale != scale) + { + old_scale = panel->scale; + + panel->scale = scale; + + class = GTK_DISPLAY_PANEL_GET_CLASS(panel); + + if (class->scale != NULL) + class->scale(panel, old_scale, scale); + + gtk_widget_queue_resize(GTK_WIDGET(panel)); + + g_signal_emit_by_name(panel, "scaled", old_scale, scale); + + } + +} + + +/****************************************************************************** +* * +* Paramètres : panel = composant GTK à mettre à jour. * * show = état de l'affichage auquel parvenir. * * * * Description : Définit si une bordure est à afficher. * @@ -785,9 +875,9 @@ void gtk_display_panel_prepare_export(GtkDisplayPanel *panel, bool export) /****************************************************************************** * * -* Paramètres : panel = composant GTK à venir consulter. * -* cr = contexte graphique associé à l'événement. * -* offset = décalage éventuel à appliquer. * +* Paramètres : panel = composant GTK à venir consulter. * +* cr = contexte graphique associé à l'événement. * +* area = surface à considérer. * * * * Description : Définit un chemin décrivant la bordure autour du panneau. * * * @@ -797,35 +887,32 @@ void gtk_display_panel_prepare_export(GtkDisplayPanel *panel, bool export) * * ******************************************************************************/ -void gtk_display_panel_define_border_path(GtkDisplayPanel *panel, cairo_t *cr, gint off_x, gint off_y) +void gtk_display_panel_define_border_path(GtkDisplayPanel *panel, cairo_t *cr, const GtkAllocation *area) { - GtkRequisition req; /* Taille allouée à l'élément */ double degrees; /* Conversion en degrés */ - gtk_widget_get_preferred_size(GTK_WIDGET(panel), NULL, &req); - degrees = M_PI / 180.0; cairo_new_sub_path(cr); cairo_arc(cr, - off_x + req.width - BORDER_CORNER_RADIUS - 0.5, - off_y + BORDER_CORNER_RADIUS + 0.5, + area->x + area->width - BORDER_CORNER_RADIUS - 0.5, + area->y + BORDER_CORNER_RADIUS + 0.5, BORDER_CORNER_RADIUS, -90 * degrees, 0 * degrees); cairo_arc(cr, - off_x + req.width - BORDER_CORNER_RADIUS - 0.5, - off_y + req.height - BORDER_CORNER_RADIUS - 0.5, + area->x + area->width - BORDER_CORNER_RADIUS - 0.5, + area->y + area->height - BORDER_CORNER_RADIUS - 0.5, BORDER_CORNER_RADIUS, 0 * degrees, 90 * degrees); cairo_arc(cr, - off_x + BORDER_CORNER_RADIUS + 0.5, - off_y + req.height - BORDER_CORNER_RADIUS - 0.5, + area->x + BORDER_CORNER_RADIUS + 0.5, + area->y + area->height - BORDER_CORNER_RADIUS - 0.5, BORDER_CORNER_RADIUS, 90 * degrees, 180 * degrees); cairo_arc(cr, - off_x + BORDER_CORNER_RADIUS + 0.5, - off_y + BORDER_CORNER_RADIUS + 0.5, + area->x + BORDER_CORNER_RADIUS + 0.5, + area->y + BORDER_CORNER_RADIUS + 0.5, BORDER_CORNER_RADIUS, 180 * degrees, 270 * degrees); cairo_close_path(cr); @@ -849,9 +936,10 @@ void gtk_display_panel_define_border_path(GtkDisplayPanel *panel, cairo_t *cr, g void gtk_display_panel_draw_border(GtkDisplayPanel *panel, cairo_t *cr) { GtkWidget *widget; /* Autre version du composant */ - GtkRequisition req; /* Taille allouée à l'élément */ GtkStyleContext *context; /* Contexte du thème actuel */ GdkRGBA color; /* Couleur de thème récupérée */ + GtkRequisition req; /* Taille allouée à l'élément */ + GtkAllocation area; /* Emplacement à considérer */ if (panel->show_border) { @@ -873,7 +961,14 @@ void gtk_display_panel_draw_border(GtkDisplayPanel *panel, cairo_t *cr) cairo_set_line_width(cr, 1.0); - gtk_display_panel_define_border_path(panel, cr, 0, 0); + gtk_widget_get_preferred_size(GTK_WIDGET(panel), NULL, &req); + + area.x = 0; + area.y = 0; + area.width = req.width; + area.height = req.height; + + gtk_display_panel_define_border_path(panel, cr, &area); cairo_stroke(cr); gtk_style_context_restore(context); |