New: Alpha drawing mode, in 'Translucency'. Drawing AA Text automatically activates it. Fixed a problem in non-AA text that made it pick wrong colors if the current skin wasn't using white and black.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1512 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2010-06-17 18:06:09 +00:00
parent ab657b018e
commit 95665a99df
6 changed files with 70 additions and 29 deletions

View File

@ -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)

View File

@ -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;

View File

@ -499,6 +499,22 @@ byte Effect_substractive_colorize(word x,word y,byte color)
blue<blue_under?blue:blue_under);
}
byte Effect_alpha_colorize (word x,word y,byte color)
{
byte color_under = Read_pixel_from_feedback_screen(x,y);
byte blue_under=Main_palette[color_under].B;
byte green_under=Main_palette[color_under].G;
byte red_under=Main_palette[color_under].R;
int factor=(Main_palette[color].R*76 +
Main_palette[color].G*151 +
Main_palette[color].B*28)/255;
return Best_color(
(Main_palette[Fore_color].R*factor + red_under*(255-factor))/255,
(Main_palette[Fore_color].G*factor + green_under*(255-factor))/255,
(Main_palette[Fore_color].B*factor + blue_under*(255-factor))/255);
}
void Check_timer(void)
{
if((SDL_GetTicks()/55)-Timer_delay>Timer_start) Timer_state=1;

View File

@ -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);
///

View File

@ -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;

View File

@ -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;