diff --git a/src/buttons.c b/src/buttons.c index 13fafa0b..e5f81ec9 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -4942,6 +4942,20 @@ void Button_Text() Change_paintbrush_shape(PAINTBRUSH_SHAPE_COLOR_BRUSH); else Change_paintbrush_shape(PAINTBRUSH_SHAPE_MONO_BRUSH); + // Activate alpha mode + if (antialias && TrueType_font(selected_font_index)) + { + Shade_mode=0; + Quick_shade_mode=0; + Smooth_mode=0; + Tiling_mode=0; + Smear_mode=0; + Colorize_mode=1; + Colorize_current_mode=3; + Effect_function=Effect_alpha_colorize; + + Draw_menu_button(BUTTON_EFFECTS,BUTTON_PRESSED); + } Select_button(BUTTON_DRAW,LEFT_SIDE); if (Config.Auto_discontinuous) diff --git a/src/buttons_effects.c b/src/buttons_effects.c index eb62b93d..19870249 100644 --- a/src/buttons_effects.c +++ b/src/buttons_effects.c @@ -553,6 +553,9 @@ void Button_Colorize_mode(void) break; case 2 : Effect_function=Effect_substractive_colorize; + break; + case 3 : + Effect_function=Effect_alpha_colorize; } Shade_mode=0; Quick_shade_mode=0; @@ -588,6 +591,9 @@ void Button_Colorize_display_selection(int mode) break; case 2 : // Méthode soustractive y_pos=74; + break; + case 3 : // Méthode alpha + y_pos=91; } Print_in_window(4,y_pos,"\020",MC_Black,MC_Light); Print_in_window(129,y_pos,"\021",MC_Black,MC_Light); @@ -600,7 +606,7 @@ void Button_Colorize_menu(void) short clicked_button; char str[4]; - Open_window(140,118,"Transparency"); + Open_window(140,135,"Transparency"); Print_in_window(16,23,"Opacity:",MC_Dark,MC_Light); Window_set_input_button(87,21,3); // 1 @@ -610,9 +616,10 @@ void Button_Colorize_menu(void) Window_set_normal_button(16,54,108,14,"Additive" ,2,1,SDLK_d); // 3 Window_set_normal_button(16,71,108,14,"Subtractive",1,1,SDLK_s); // 4 + Window_set_normal_button(16,88,108,14,"Alpha",1,1,SDLK_a); // 4 - Window_set_normal_button(16,94, 51,14,"Cancel" ,0,1,KEY_ESC); // 5 - Window_set_normal_button(73,94, 51,14,"OK" ,0,1,SDLK_RETURN); // 6 + Window_set_normal_button(16,111, 51,14,"Cancel" ,0,1,KEY_ESC); // 5 + Window_set_normal_button(73,111, 51,14,"OK" ,0,1,SDLK_RETURN); // 6 Num2str(Colorize_opacity,str,3); Window_input_content(Window_special_button_list,str); @@ -643,9 +650,10 @@ void Button_Colorize_menu(void) } Display_cursor(); break; - case 2: // Méthode interpolée - case 3: // Méthode additive - case 4: // Méthode soustractive + case 2: // Interpolated method + case 3: // Additive method + case 4: // Substractive method + case 5: // Alpha method selected_mode=clicked_button-2; Hide_cursor(); Button_Colorize_display_selection(selected_mode); @@ -654,13 +662,13 @@ void Button_Colorize_menu(void) if (Is_shortcut(Key,0x100+BUTTON_HELP)) Window_help(BUTTON_EFFECTS, "TRANSPARENCY"); else if (Is_shortcut(Key,SPECIAL_COLORIZE_MENU)) - clicked_button=6; + clicked_button=7; } - while (clicked_button<5); + while (clicked_button<6); Close_window(); - if (clicked_button==6) // OK + if (clicked_button==7) // OK { Colorize_opacity =chosen_opacity; Colorize_current_mode=selected_mode; diff --git a/src/misc.c b/src/misc.c index bc750078..ffc268d6 100644 --- a/src/misc.c +++ b/src/misc.c @@ -499,6 +499,22 @@ byte Effect_substractive_colorize(word x,word y,byte color) blueTimer_start) Timer_state=1; diff --git a/src/misc.h b/src/misc.h index 523f143d..9e99dbda 100644 --- a/src/misc.h +++ b/src/misc.h @@ -86,6 +86,7 @@ void Replace_colors_within_limits(byte * replace_table); byte Effect_interpolated_colorize (word x,word y,byte color); byte Effect_additive_colorize (word x,word y,byte color); byte Effect_substractive_colorize(word x,word y,byte color); +byte Effect_alpha_colorize(word x,word y,byte color); byte Effect_sieve(word x,word y); /// diff --git a/src/special.c b/src/special.c index 4f7a60cc..6e3dc579 100644 --- a/src/special.c +++ b/src/special.c @@ -431,6 +431,9 @@ void Transparency_set(byte amount) break; case 2 : Effect_function=Effect_substractive_colorize; + break; + case 3 : + Effect_function=Effect_alpha_colorize; } Shade_mode=0; Quick_shade_mode=0; diff --git a/src/text.c b/src/text.c index 1a6ce573..7ff4019f 100644 --- a/src/text.c +++ b/src/text.c @@ -377,8 +377,8 @@ byte *Render_text_TTF(const char *str, int font_number, int size, int antialias, int index; int style; - SDL_Color Couleur_Avant; - SDL_Color Couleur_Arriere; + SDL_Color fg_color; + SDL_Color bg_color; // Chargement de la fonte font=TTF_OpenFont(Font_name(font_number), size); @@ -386,6 +386,7 @@ byte *Render_text_TTF(const char *str, int font_number, int size, int antialias, { return NULL; } + // Style style=0; if (italic) @@ -393,24 +394,18 @@ byte *Render_text_TTF(const char *str, int font_number, int size, int antialias, if (bold) style|=TTF_STYLE_BOLD; TTF_SetFontStyle(font, style); + // Couleurs - if (antialias) - { - Couleur_Avant = Color_to_SDL_color(Fore_color); - Couleur_Arriere = Color_to_SDL_color(Back_color); - } - else - { - Couleur_Avant = Color_to_SDL_color(MC_White); - Couleur_Arriere = Color_to_SDL_color(MC_Black); - } - + fg_color.r=fg_color.g=fg_color.b=255; + bg_color.r=bg_color.g=bg_color.b=0; + // The following is alpha, supposedly unused + bg_color.unused=fg_color.unused=255; // Rendu du texte: crée une surface SDL RGB 24bits if (antialias) - TexteColore=TTF_RenderText_Shaded(font, str, Couleur_Avant, Couleur_Arriere ); + TexteColore=TTF_RenderText_Shaded(font, str, fg_color, bg_color ); else - TexteColore=TTF_RenderText_Solid(font, str, Couleur_Avant); + TexteColore=TTF_RenderText_Solid(font, str, fg_color); if (!TexteColore) { TTF_CloseFont(font); @@ -431,13 +426,17 @@ byte *Render_text_TTF(const char *str, int font_number, int size, int antialias, } if (!antialias) { - // Mappage des couleurs + // Map colors: white->fg, black->bg for (index=0; index < Texte8Bit->w * Texte8Bit->h; index++) { - if (*(new_brush+index) == MC_Black) - *(new_brush+index)=Back_color; - else if (*(new_brush+index) == MC_White) - *(new_brush+index)=Fore_color; + int sum; + sum = Main_palette[*(new_brush+index)].R + + Main_palette[*(new_brush+index)].G + + Main_palette[*(new_brush+index)].B; + if (sum < 128 * 3) + *(new_brush+index)=Back_color; + else + *(new_brush+index)=Fore_color; } } *width=Texte8Bit->w;