@@ -594,155 +594,67 @@ pub const Element = struct {
594594 if (self .type == .button ) {
595595 switch (self .type .button .style ) {
596596 .success = > {
597- _ = sdl .SDL_SetTextureColorMod (
598- texture ,
599- display .theme .success_button_colour .r ,
600- display .theme .success_button_colour .g ,
601- display .theme .success_button_colour .b ,
602- );
597+ tint_texture (texture , display .theme .success_button_colour );
603598 return ;
604599 },
605600 .failed = > {
606- _ = sdl .SDL_SetTextureColorMod (
607- texture ,
608- display .theme .failed_button_colour .r ,
609- display .theme .failed_button_colour .g ,
610- display .theme .failed_button_colour .b ,
611- );
601+ tint_texture (texture , display .theme .failed_button_colour );
612602 return ;
613603 },
614604 else = > {
615605 // Otherwise apply toggle colurs if needed
616606 },
617607 }
608+
618609 switch (self .type .button .toggle ) {
619- .off , .locked_off = > {
620- _ = sdl .SDL_SetTextureColorMod (
621- texture ,
622- display .theme .toggle_button .r ,
623- display .theme .toggle_button .g ,
624- display .theme .toggle_button .b ,
625- );
626- return ;
627- },
628- .on = > {
629- _ = sdl .SDL_SetTextureColorMod (
630- texture ,
631- display .theme .toggle_button_picked .r ,
632- display .theme .toggle_button_picked .g ,
633- display .theme .toggle_button_picked .b ,
634- );
635- return ;
636- },
637- .correct = > {
638- _ = sdl .SDL_SetTextureColorMod (
639- texture ,
640- display .theme .toggle_button_correct .r ,
641- display .theme .toggle_button_correct .g ,
642- display .theme .toggle_button_correct .b ,
643- );
644- return ;
645- },
646- .incorrect = > {
647- _ = sdl .SDL_SetTextureColorMod (
648- texture ,
649- display .theme .toggle_button_incorrect .r ,
650- display .theme .toggle_button_incorrect .g ,
651- display .theme .toggle_button_incorrect .b ,
652- );
653- return ;
654- },
655- .no_toggle = > {},
610+ .off , .locked_off = > tint_texture (texture , display .theme .toggle_button ),
611+ .on = > tint_texture (texture , display .theme .toggle_button_picked ),
612+ .correct = > tint_texture (texture , display .theme .toggle_button_correct ),
613+ .incorrect = > tint_texture (texture , display .theme .toggle_button_incorrect ),
614+ .no_toggle = > tint_texture (texture , engine .WHITE ),
656615 }
616+ return ;
657617 }
618+
658619 if (self .type == .panel ) {
659620 switch (self .type .panel .style ) {
660- .emphasised = > {
661- _ = sdl .SDL_SetTextureAlphaMod (texture , display .theme .emphasised_panel_colour .a );
662- _ = sdl .SDL_SetTextureColorMod (
663- texture ,
664- display .theme .emphasised_panel_colour .r ,
665- display .theme .emphasised_panel_colour .g ,
666- display .theme .emphasised_panel_colour .b ,
667- );
668- return ;
669- },
670- .success = > {
671- _ = sdl .SDL_SetTextureAlphaMod (texture , display .theme .success_panel_colour .a );
672- _ = sdl .SDL_SetTextureColorMod (
673- texture ,
674- display .theme .success_panel_colour .r ,
675- display .theme .success_panel_colour .g ,
676- display .theme .success_panel_colour .b ,
677- );
678- return ;
679- },
680- .failed = > {
681- _ = sdl .SDL_SetTextureAlphaMod (texture , display .theme .failed_panel_colour .a );
682- _ = sdl .SDL_SetTextureColorMod (
683- texture ,
684- display .theme .failed_panel_colour .r ,
685- display .theme .failed_panel_colour .g ,
686- display .theme .failed_panel_colour .b ,
687- );
688- return ;
689- },
690- .faded = > {
691- _ = sdl .SDL_SetTextureAlphaMod (texture , display .theme .faded_panel_colour .a );
692- _ = sdl .SDL_SetTextureColorMod (
693- texture ,
694- display .theme .faded_panel_colour .r ,
695- display .theme .faded_panel_colour .g ,
696- display .theme .faded_panel_colour .b ,
697- );
698- return ;
699- },
700- .background = > {
701- _ = sdl .SDL_SetTextureAlphaMod (texture , display .theme .background_colour .a );
702- _ = sdl .SDL_SetTextureColorMod (
703- texture ,
704- display .theme .background_colour .r ,
705- display .theme .background_colour .g ,
706- display .theme .background_colour .b ,
707- );
708- return ;
709- },
710- .normal = > {
711- _ = sdl .SDL_SetTextureAlphaMod (texture , display .theme .label_background_colour .a );
712- _ = sdl .SDL_SetTextureColorMod (
713- texture ,
714- display .theme .label_background_colour .r ,
715- display .theme .label_background_colour .g ,
716- display .theme .label_background_colour .b ,
717- );
718- return ;
719- },
621+ .emphasised = > tint_texture (texture , display .theme .emphasised_panel_colour ),
622+ .success = > tint_texture (texture , display .theme .success_panel_colour ),
623+ .failed = > tint_texture (texture , display .theme .failed_panel_colour ),
624+ .faded = > tint_texture (texture , display .theme .faded_panel_colour ),
625+ .background = > tint_texture (texture , display .theme .background_colour ),
626+ .normal = > tint_texture (texture , display .theme .label_background_colour ),
720627 else = > {
721628 warn (
722629 "unhandled panel tint option: {s}" ,
723630 .{@tagName (self .type .panel .style )},
724631 );
632+ tint_texture (texture , engine .WHITE );
725633 },
726634 }
635+ return ;
727636 }
637+
728638 if (self .type == .sprite ) {
729639 if (self .background .colour .a != 0 ) {
730- _ = sdl .SDL_SetTextureAlphaMod (texture , self .background .colour .a );
731- _ = sdl .SDL_SetTextureColorMod (
732- texture ,
733- self .background .colour .r ,
734- self .background .colour .g ,
735- self .background .colour .b ,
736- );
737- return ;
640+ tint_texture (texture , self .background .colour );
641+ } else {
642+ tint_texture (texture , engine .WHITE );
738643 }
644+ return ;
739645 }
740- _ = sdl .SDL_SetTextureColorMod (
741- texture ,
742- display .theme .label_background_colour .r ,
743- display .theme .label_background_colour .g ,
744- display .theme .label_background_colour .b ,
745- );
646+
647+ if (self .type == .label ) {
648+ tint_texture (texture , display .theme .label_background_colour );
649+ return ;
650+ }
651+
652+ tint_texture (texture , engine .WHITE );
653+ }
654+
655+ fn tint_texture (texture : * sdl.SDL_Texture , colour : Colour ) void {
656+ _ = sdl .SDL_SetTextureAlphaMod (texture , colour .a );
657+ _ = sdl .SDL_SetTextureColorMod (texture , colour .r , colour .g , colour .b );
746658 }
747659
748660 /// An icon may have different background textures for hovered,
@@ -1556,6 +1468,9 @@ pub const Element = struct {
15561468 }
15571469 }
15581470
1471+ /// Draw the foreground image `texture` of the sprite loaded from the
1472+ /// `texture_name` string. Does not draw the `background.image` texture.
1473+ /// The background image is drawn in the generic background drawing function.
15591474 inline fn draw_sprite (
15601475 element : * Element ,
15611476 display : * Display ,
@@ -1858,6 +1773,7 @@ pub const Element = struct {
18581773 /// Handle when a user chooses an element like a button, using
18591774 /// the mouse or the keyboard.
18601775 pub fn chosen (self : * Element , display : * Display , gpa : Allocator ) Allocator.Error ! void {
1776+ trace ("chosen element {s}" , .{self .name });
18611777 switch (self .type ) {
18621778 .button = > {
18631779 switch (self .type .button .toggle ) {
@@ -4962,9 +4878,8 @@ pub fn setup_sprite(
49624878) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || ResourcesError )! void {
49634879 element .texture = null ;
49644880 element .background .image = null ;
4965- if (element .focus == .unspecified ) {
4881+ if (element .focus == .unspecified )
49664882 element .focus = .accessibility_focus ;
4967- }
49684883
49694884 if (element .texture_name ) | image | {
49704885 if (try self .load_texture_resource (allocator , image )) | texture | {
@@ -4989,6 +4904,11 @@ pub fn setup_sprite(
49894904 err ("Failed to load sprite background image named \" {s}\" for button \" {s}\" " , .{ image , element .name });
49904905 }
49914906 }
4907+
4908+ if (element .texture_name != null )
4909+ trace ("sprite {s} fg {s}" , .{ element .name , element .texture_name .? });
4910+ if (element .background .image_name != null )
4911+ trace ("sprite {s} bg {s}" , .{ element .name , element .background .image_name .? });
49924912}
49934913
49944914fn select_font (fonts : []* FontInfo , name : ? []const u8 ) * FontInfo {
@@ -5292,7 +5212,6 @@ pub const SdlLogCategory = enum(c_int) {
52925212
52935213pub inline fn trace (comptime format : []const u8 , args : anytype ) void {
52945214 if (dev_build and dev_mode ) {
5295- std .log .debug (format , args );
52965215 log_output ("trace" , .engine , format , args );
52975216 }
52985217}
0 commit comments