@@ -693,9 +693,7 @@ void on_mainapp_selection_received (GtkWidget *widget,
693
693
gchar * name , * copy ;
694
694
GromitPaintContext * context_template = NULL ;
695
695
696
- GromitPaintType type ;
697
- GdkRGBA * fg_color = NULL ;
698
- guint width , arrowsize , minwidth , maxwidth ;
696
+ GromitStyleDef style ;
699
697
700
698
if (token != G_TOKEN_EOF )
701
699
{
@@ -706,182 +704,18 @@ void on_mainapp_selection_received (GtkWidget *widget,
706
704
if (!name )
707
705
goto cleanup ;
708
706
709
- token = g_scanner_cur_token (scanner );
710
-
711
- if (token != G_TOKEN_EQUAL_SIGN )
712
- {
713
- g_scanner_unexp_token (scanner , G_TOKEN_EQUAL_SIGN , NULL ,
714
- NULL , NULL , "aborting" , TRUE);
715
- goto cleanup ;
716
- }
707
+ if (!parse_tool (data , scanner , & style ))
708
+ goto cleanup ;
717
709
718
- token = g_scanner_get_next_token (scanner );
719
-
720
- /* defaults */
721
- type = GROMIT_PEN ;
722
- width = 7 ;
723
- arrowsize = 0 ;
724
- minwidth = 1 ;
725
- maxwidth = G_MAXUINT ;
726
- fg_color = data -> red ;
710
+ token = g_scanner_cur_token (scanner );
727
711
728
- if (token == G_TOKEN_SYMBOL )
729
- {
730
- type = (GromitPaintType ) scanner -> value .v_symbol ;
731
- token = g_scanner_get_next_token (scanner );
732
- }
733
- else if (token == G_TOKEN_STRING )
712
+ if (token == G_TOKEN_LEFT_PAREN )
734
713
{
735
- copy = parse_name (scanner );
736
- if (!copy )
737
- goto cleanup ;
714
+ if (! parse_style (scanner , & style ))
715
+ goto cleanup ;
738
716
token = g_scanner_cur_token (scanner );
739
- context_template = g_hash_table_lookup (data -> tool_config , copy );
740
- if (context_template )
741
- {
742
- type = context_template -> type ;
743
- width = context_template -> width ;
744
- arrowsize = context_template -> arrowsize ;
745
- minwidth = context_template -> minwidth ;
746
- maxwidth = context_template -> maxwidth ;
747
- fg_color = context_template -> paint_color ;
748
- }
749
- else
750
- {
751
- g_printerr ("WARNING: Unable to copy \"%s\": "
752
- "not yet defined!\n" , copy );
753
- }
754
- }
755
- else
756
- {
757
- g_printerr ("Expected Tool-definition "
758
- "or name of template tool\n" );
759
- goto cleanup ;
760
717
}
761
718
762
- /* Are there any tool-options?
763
- */
764
-
765
- if (token == G_TOKEN_LEFT_PAREN )
766
- {
767
- GdkRGBA * color = NULL ;
768
- g_scanner_set_scope (scanner , 2 );
769
- scanner -> config -> int_2_float = 1 ;
770
- token = g_scanner_get_next_token (scanner );
771
- while (token != G_TOKEN_RIGHT_PAREN )
772
- {
773
- if (token == G_TOKEN_SYMBOL )
774
- {
775
- if ((intptr_t ) scanner -> value .v_symbol == 1 )
776
- {
777
- token = g_scanner_get_next_token (scanner );
778
- if (token != G_TOKEN_EQUAL_SIGN )
779
- {
780
- g_printerr ("Missing \"=\"... aborting\n" );
781
- goto cleanup ;
782
- }
783
- token = g_scanner_get_next_token (scanner );
784
- if (token != G_TOKEN_FLOAT )
785
- {
786
- g_printerr ("Missing Size (float)... aborting\n" );
787
- goto cleanup ;
788
- }
789
- width = (guint ) (scanner -> value .v_float + 0.5 );
790
- }
791
- else if ((intptr_t ) scanner -> value .v_symbol == 2 )
792
- {
793
- token = g_scanner_get_next_token (scanner );
794
- if (token != G_TOKEN_EQUAL_SIGN )
795
- {
796
- g_printerr ("Missing \"=\"... aborting\n" );
797
- goto cleanup ;
798
- }
799
- token = g_scanner_get_next_token (scanner );
800
- if (token != G_TOKEN_STRING )
801
- {
802
- g_printerr ("Missing Color (string)... "
803
- "aborting\n" );
804
- goto cleanup ;
805
- }
806
- color = g_malloc (sizeof (GdkRGBA ));
807
- if (gdk_rgba_parse (color , scanner -> value .v_string ))
808
- {
809
- fg_color = color ;
810
- }
811
- else
812
- {
813
- g_printerr ("Unable to parse color. "
814
- "Keeping default.\n" );
815
- g_free (color );
816
- }
817
- color = NULL ;
818
- }
819
- else if ((intptr_t ) scanner -> value .v_symbol == 3 )
820
- {
821
- token = g_scanner_get_next_token (scanner );
822
- if (token != G_TOKEN_EQUAL_SIGN )
823
- {
824
- g_printerr ("Missing \"=\"... aborting\n" );
825
- goto cleanup ;
826
- }
827
- token = g_scanner_get_next_token (scanner );
828
- if (token != G_TOKEN_FLOAT )
829
- {
830
- g_printerr ("Missing Arrowsize (float)... "
831
- "aborting\n" );
832
- goto cleanup ;
833
- }
834
- arrowsize = scanner -> value .v_float ;
835
- }
836
- else if ((intptr_t ) scanner -> value .v_symbol == 4 )
837
- {
838
- token = g_scanner_get_next_token (scanner );
839
- if (token != G_TOKEN_EQUAL_SIGN )
840
- {
841
- g_printerr ("Missing \"=\"... aborting\n" );
842
- goto cleanup ;
843
- }
844
- token = g_scanner_get_next_token (scanner );
845
- if (token != G_TOKEN_FLOAT )
846
- {
847
- g_printerr ("Missing Minsize (float)... "
848
- "aborting\n" );
849
- goto cleanup ;
850
- }
851
- minwidth = scanner -> value .v_float ;
852
- }
853
- else if ((intptr_t ) scanner -> value .v_symbol == 5 )
854
- {
855
- token = g_scanner_get_next_token (scanner );
856
- if (token != G_TOKEN_EQUAL_SIGN )
857
- {
858
- g_printerr ("Missing \"=\"... aborting\n" );
859
- goto cleanup ;
860
- }
861
- token = g_scanner_get_next_token (scanner );
862
- if (token != G_TOKEN_FLOAT )
863
- {
864
- g_printerr ("Missing Maxsize (float)... "
865
- "aborting\n" );
866
- goto cleanup ;
867
- }
868
- maxwidth = scanner -> value .v_float ;
869
- }
870
- else
871
- {
872
- g_printerr ("Unknown tool type ???\n" );
873
- }
874
- }
875
- else
876
- {
877
- g_printerr ("skipped unknown token: %d !!!\n" , token );
878
- }
879
- token = g_scanner_get_next_token (scanner );
880
- } // while (token != G_TOKEN_RIGHT_PAREN)
881
- g_scanner_set_scope (scanner , 0 );
882
- token = g_scanner_get_next_token (scanner );
883
- } // if (token == G_TOKEN_LEFT_PAREN)
884
-
885
719
// by now nothing should follow
886
720
if (token != G_TOKEN_EOF )
887
721
{
@@ -892,14 +726,16 @@ void on_mainapp_selection_received (GtkWidget *widget,
892
726
GromitPaintContext * context =
893
727
g_hash_table_lookup (data -> tool_config , name );
894
728
GromitPaintContext * new_context =
895
- paint_context_new (data , type , fg_color , width , arrowsize , minwidth , maxwidth );
729
+ paint_context_new (data , style .type , style .paint_color ,
730
+ style .width , style .arrowsize ,
731
+ style .minwidth , style .maxwidth );
896
732
* context = * new_context ;
897
733
898
734
g_free (new_context );
899
- } // if (token == G_TOKEN_STRING)
735
+ }
900
736
901
737
token = g_scanner_get_next_token (scanner );
902
- } // if (token != G_TOKEN_EOF)
738
+ }
903
739
904
740
cleanup :
905
741
0 commit comments