@@ -11,6 +11,7 @@ typedef struct {
1111 GList * layers_copy ;
1212 gboolean cinematic ;
1313 gboolean deepfry ;
14+ gboolean bw ;
1415} GifExportData ;
1516// async gif handling functions, fucking hell why is it so hard to do async
1617// work
@@ -81,7 +82,7 @@ static void export_gif_thread(GTask *task, gpointer source_object, gpointer task
8182 }
8283
8384 delay_ms = MAX ((int )MagickGetImageDelay (coalesced ) * 10 , 10 );
84- comp = meme_render_composite (frame , ctx -> layers_copy , ctx -> cinematic , ctx -> deepfry , FALSE);
85+ comp = meme_render_composite (frame , ctx -> layers_copy , ctx -> cinematic , ctx -> deepfry , ctx -> bw , FALSE);
8586 w = gdk_pixbuf_get_width (comp );
8687 h = gdk_pixbuf_get_height (comp );
8788 channels = gdk_pixbuf_get_n_channels (comp );
@@ -346,6 +347,7 @@ static void on_project_load_contents_finished(GObject *source_object, GAsyncResu
346347 gtk_widget_set_sensitive (GTK_WIDGET (self -> crop_mode_button ), TRUE);
347348 gtk_widget_set_sensitive (GTK_WIDGET (self -> save_project_button ), TRUE);
348349 gtk_widget_set_sensitive (GTK_WIDGET (self -> global_filters_button ), TRUE);
350+ gtk_widget_set_sensitive (GTK_WIDGET (self -> bw_button ), TRUE);
349351 gtk_widget_set_sensitive (GTK_WIDGET (self -> zoom_in ), TRUE);
350352 gtk_widget_set_sensitive (GTK_WIDGET (self -> zoom_out ), TRUE);
351353 gtk_widget_set_sensitive (GTK_WIDGET (self -> copy_clipboard_button ), TRUE);
@@ -403,6 +405,7 @@ static void on_load_image_response(GObject *s, GAsyncResult *r, gpointer d) {
403405 gtk_widget_set_sensitive (GTK_WIDGET (self -> add_image_button ), TRUE);
404406 gtk_widget_set_sensitive (GTK_WIDGET (self -> deep_fry_button ), TRUE);
405407 gtk_widget_set_sensitive (GTK_WIDGET (self -> cinematic_button ), TRUE);
408+ gtk_widget_set_sensitive (GTK_WIDGET (self -> bw_button ), TRUE);
406409 gtk_widget_set_sensitive (GTK_WIDGET (self -> crop_mode_button ), TRUE);
407410 gtk_widget_set_sensitive (GTK_WIDGET (self -> save_project_button ), TRUE);
408411 gtk_widget_set_sensitive (GTK_WIDGET (self -> global_filters_button ), TRUE);
@@ -488,6 +491,7 @@ static void on_export_file_response(GObject *s, GAsyncResult *r, gpointer d) {
488491 data -> layers_copy = meme_layer_list_copy (self -> layers );
489492 data -> cinematic = gtk_toggle_button_get_active (self -> cinematic_button );
490493 data -> deepfry = gtk_toggle_button_get_active (self -> deep_fry_button );
494+ data -> bw = gtk_toggle_button_get_active (self -> bw_button );
491495
492496 task = g_task_new (self , NULL , on_gif_export_ready , self );
493497 g_task_set_task_data (task , data , gif_export_data_free );
@@ -538,26 +542,39 @@ static void on_export_file_response(GObject *s, GAsyncResult *r, gpointer d) {
538542 g_object_unref (file );
539543}
540544
541- static void on_format_chosen (GObject * s , GAsyncResult * r , gpointer d ) {\
545+ static void on_format_chosen (GObject * s , GAsyncResult * r , gpointer d ) {
542546 char * filename ;
543547 GtkFileDialog * dialog ;
544548 const char * ext ;
549+ const char * format ;
550+ GtkDropDown * format_dropdown ;
551+ guint selected ;
545552 AdwAlertDialog * alert = ADW_ALERT_DIALOG (s );
546553 MemeWindow * self = MEME_WINDOW (d );
547554 const char * choice = adw_alert_dialog_choose_finish (alert , r );
548555
549- if (g_strcmp0 (choice , "cancel" ) == 0 || !choice ) return ;
556+ if (g_strcmp0 (choice , "export" ) != 0 ) return ;
557+
558+ format_dropdown = GTK_DROP_DOWN (g_object_get_data (G_OBJECT (alert ), "format-dropdown" ));
559+ selected = gtk_drop_down_get_selected (format_dropdown );
560+
561+ switch (selected ) {
562+ case 1 : format = "jpeg" ; break ;
563+ case 2 : format = "webp" ; break ;
564+ case 3 : format = "gif" ; break ;
565+ default : format = "png" ; break ;
566+ }
550567
551568 ext = ".png" ;
552- if (g_strcmp0 (choice , "jpeg" ) == 0 ) ext = ".jpg" ;
553- else if (g_strcmp0 (choice , "webp" ) == 0 ) ext = ".webp" ;
554- else if (g_strcmp0 (choice , "gif" ) == 0 ) ext = ".gif" ;
569+ if (g_strcmp0 (format , "jpeg" ) == 0 ) ext = ".jpg" ;
570+ else if (g_strcmp0 (format , "webp" ) == 0 ) ext = ".webp" ;
571+ else if (g_strcmp0 (format , "gif" ) == 0 ) ext = ".gif" ;
555572
556573 filename = g_strdup_printf ("meme%s" , ext );
557574 dialog = gtk_file_dialog_new ();
558575 gtk_file_dialog_set_initial_name (dialog , filename );
559576
560- g_object_set_data (G_OBJECT (dialog ), "export-format" , (gpointer )choice );
577+ g_object_set_data (G_OBJECT (dialog ), "export-format" , (gpointer )format );
561578
562579 gtk_file_dialog_save (dialog , GTK_WINDOW (self ), NULL , on_export_file_response , self );
563580
@@ -567,19 +584,29 @@ static void on_format_chosen(GObject *s, GAsyncResult *r, gpointer d) {\
567584
568585void on_export_clicked (MemeWindow * self ) {
569586 AdwAlertDialog * dialog ;
587+ GtkWidget * format_dropdown ;
588+ GtkStringList * model ;
589+ static const char * format_labels [] = { "PNG" , "JPG" , "WebP" , "GIF" , NULL };
570590
571591 if (!self -> final_meme ) return ;
592+
593+ model = gtk_string_list_new (format_labels );
594+ format_dropdown = gtk_drop_down_new (G_LIST_MODEL (model ), NULL );
595+ gtk_drop_down_set_selected (GTK_DROP_DOWN (format_dropdown ), 0 );
596+
572597 dialog = ADW_ALERT_DIALOG (adw_alert_dialog_new ("Export Format" , "Choose an image format." ));
598+ adw_alert_dialog_set_extra_child (dialog , format_dropdown );
599+ g_object_set_data (G_OBJECT (dialog ), "format-dropdown" , format_dropdown );
600+
573601 adw_alert_dialog_add_responses (dialog ,
574602 "cancel" , "Cancel" ,
575- "png" , "PNG" ,
576- "gif" , "GIF" ,
577- "jpeg" , "JPG" ,
578- "webp" , "WebP" ,
603+ "export" , "Export" ,
579604 NULL );
580605
581- adw_alert_dialog_set_response_appearance (dialog , "png " , ADW_RESPONSE_SUGGESTED );
606+ adw_alert_dialog_set_response_appearance (dialog , "export " , ADW_RESPONSE_SUGGESTED );
582607 adw_alert_dialog_set_response_appearance (dialog , "cancel" , ADW_RESPONSE_DESTRUCTIVE );
608+ adw_alert_dialog_set_default_response (dialog , "export" );
609+ adw_alert_dialog_set_close_response (dialog , "cancel" );
583610
584611 adw_alert_dialog_choose (dialog , GTK_WIDGET (self ), NULL , on_format_chosen , self );
585612}
0 commit comments