Commit 896672cc authored by Youness Alaoui's avatar Youness Alaoui
Browse files

Add --text-size option and change default size to 20

parent da306967
......@@ -229,6 +229,7 @@ void print_usage (int exit_code)
printf ("\t--background-png <file>\t\tDisplay PNG image as background\n");
printf ("\t--background-gradient <start red> <start green> <start blue> <end red> <end green> <end blue>\n");
printf ("\t\t\t\t\tGenerate a linear gradient background from left to right\n");
printf ("\t--text-size <size>\t\tSet the text font size\n");
exit (exit_code);
}
......@@ -250,6 +251,7 @@ int parse_whiptail_args (int argc, char **argv, whiptail_args *args)
args->background_grad_rgb[3] = 0.6;
args->background_grad_rgb[4] = 0.6;
args->background_grad_rgb[5] = 0.6;
args->text_size = 20;
for (i = 1; i < argc; i++) {
if (end_of_args == 0 && strcmp (argv[i], "-h") == 0) {
......@@ -362,6 +364,11 @@ int parse_whiptail_args (int argc, char **argv, whiptail_args *args)
args->background_grad_rgb[4] = (float) atoi (argv[i+5]) / 256;
args->background_grad_rgb[5] = (float) atoi (argv[i+6]) / 256;
i += 6;
} else if (strcmp (argv[i], "--text-size") == 0) {
// FBwhiptail specific arguments
if (i + 1 >= argc)
goto missing_value;
args->text_size = atoi (argv[++i]);
} else {
printf ("Unknown argument : '%s'\n", argv[i]);
goto error;
......@@ -555,7 +562,8 @@ int main(int argc, char **argv)
*/
if (args.mode == MODE_MENU) {
menu = standard_menu_create (args.title, args.text, xres, yres, -1, 1);
menu = standard_menu_create (args.title, args.text, args.text_size,
xres, yres, -1, 1);
for (i = 0; i < args.num_items; i++) {
char *text;
......@@ -579,11 +587,13 @@ int main(int argc, char **argv)
}
}
} else if (args.mode == MODE_YESNO) {
menu = standard_menu_create (args.title, args.text, xres, yres, 1, -1);
menu = standard_menu_create (args.title, args.text, args.text_size,
xres, yres, 1, -1);
standard_menu_add_item (menu, args.yes_button, 20);
standard_menu_add_item (menu, args.no_button, 20);
} else if (args.mode == MODE_MSGBOX) {
menu = standard_menu_create (args.title, args.text, xres, yres, -1, 1);
menu = standard_menu_create (args.title, args.text, args.text_size,
xres, yres, -1, 1);
standard_menu_add_item (menu, args.ok_button, 20);
}
if (args.background_png)
......
......@@ -29,6 +29,8 @@
#include "fbwhiptail_menu.h"
#define TEXT_PAD 5
cairo_surface_t *
create_gradient_background (int width, int height,
float start_r, float start_g, float start_b,
......@@ -189,7 +191,7 @@ refresh_text_surface (Menu *menu)
y = 0;
line = menu->text.lines;
while (*line != NULL && y + 20 < height) {
while (*line != NULL && y + menu->text_size < height) {
if (cnt > 0) {
cnt--;
line++;
......@@ -204,13 +206,13 @@ refresh_text_surface (Menu *menu)
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size (cr, 15);
cairo_set_font_size (cr, menu->text_size);
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_move_to (cr, x, y + 20);
cairo_move_to (cr, x, y + menu->text_size + TEXT_PAD);
cairo_show_text (cr, *line);
cairo_restore (cr);
y += 20;
y += menu->text_size;
line++;
}
......@@ -343,7 +345,7 @@ load_text_from_file (char *filename)
}
void
create_text_suface (Menu *menu, char *text)
create_text_suface (Menu *menu, char *text, int text_size)
{
char *ptr, *ptr2;
int filesize;
......@@ -384,13 +386,14 @@ create_text_suface (Menu *menu, char *text)
*ptr++ = 0;
}
menu->text.lines[menu->text.nlines] = NULL;
menu->text_size = text_size;
menu->text.surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
STANDARD_MENU_WIDTH, 10 + 20 * menu->text.nlines);
STANDARD_MENU_WIDTH, 10 + (text_size + TEXT_PAD) * menu->text.nlines);
}
Menu *
standard_menu_create (const char *title, char * text,
standard_menu_create (const char *title, char * text, int text_size,
int width, int height, int rows, int columns)
{
cairo_surface_t *surface;
......@@ -412,7 +415,7 @@ standard_menu_create (const char *title, char * text,
menu->width = width;
menu->height = height;
create_text_suface (menu, text);
create_text_suface (menu, text, text_size);
text_height = cairo_utils_get_surface_height (menu->text.surface);
background = create_standard_background (button_width, button_height, 0, 0, 0);
selected_background = create_standard_background (button_width, button_height,
......
......@@ -41,6 +41,7 @@ struct Menu_s {
int height;
const char *title;
MenuText text;
int text_size;
cairo_surface_t *frame;
void (*callback) (Menu *menu, int accepted);
void (*draw) (Menu *menu, cairo_t *cr);
......@@ -82,6 +83,7 @@ typedef struct {
// FBwhiptail arguments
char *background_png;
float background_grad_rgb[6];
int text_size;
} whiptail_args;
......@@ -133,7 +135,7 @@ cairo_surface_t *create_gradient_background (int width, int height,
float end_r, float end_g, float end_b);
cairo_surface_t *load_image_and_scale (char *path, int width, int height);
void draw_background (Menu *menu, cairo_t *cr);
Menu *standard_menu_create (const char *title, char * text,
Menu *standard_menu_create (const char *title, char * text, int text_size,
int width, int height, int rows, int columns);
int standard_menu_add_item (Menu *menu, const char *title, int fontsize);
int standard_menu_add_tag (Menu *menu, const char *title, int fontsize);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment