mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Scale image according to current window size
This commit is contained in:
parent
c67bce4480
commit
540966a46c
@ -1962,7 +1962,6 @@ void
|
||||
win_pictest(ProfWin* window)
|
||||
{
|
||||
GdkPixbuf *file = gdk_pixbuf_new_from_file ("/home/michael/Pictures/test.png", NULL);
|
||||
//GdkPixbuf *file = gdk_pixbuf_new_from_file ("/home/michael/ask2.png", NULL);
|
||||
if (file == NULL) {
|
||||
win_println(window, THEME_ERROR, "!", "pictest");
|
||||
return;
|
||||
@ -1972,25 +1971,34 @@ win_pictest(ProfWin* window)
|
||||
ChafaSymbolMap *symbol_map;
|
||||
|
||||
symbol_map = chafa_symbol_map_new ();
|
||||
//chafa_symbol_map_add_by_tags (symbol_map, CHAFA_SYMBOL_TAG_ALL);
|
||||
chafa_symbol_map_add_by_tags (symbol_map, CHAFA_SYMBOL_TAG_ASCII);
|
||||
//chafa_symbol_map_add_by_tags (symbol_map, CHAFA_SYMBOL_TAG_ALL);
|
||||
//chafa_symbol_map_add_by_tags (symbol_map, CHAFA_SYMBOL_TAG_BRAILLE);
|
||||
//chafa_symbol_map_add_by_tags (symbol_map, CHAFA_SYMBOL_TAG_BLOCK | CHAFA_SYMBOL_TAG_BORDER);
|
||||
//chafa_symbol_map_add_by_tags (symbol_map, CHAFA_SYMBOL_TAG_BLOCK | CHAFA_SYMBOL_TAG_BORDER | CHAFA_SYMBOL_TAG_SPACE);
|
||||
|
||||
// TODO: use chafa_calc_canvas_geometry() to get recommended canvas size
|
||||
// calculate how much space we have on curent screen
|
||||
gint width = getmaxx(stdscr);
|
||||
gint height = screen_mainwin_row_end() - screen_mainwin_row_end();
|
||||
// get recommended canvas size. image will be scaled accordingly
|
||||
chafa_calc_canvas_geometry(gdk_pixbuf_get_width(file), gdk_pixbuf_get_height(file),
|
||||
&width,
|
||||
&height,
|
||||
0.5,
|
||||
TRUE,
|
||||
FALSE);
|
||||
|
||||
// TODO: could be a that a user shrinks its terminal. then we would need to redraw I guess?
|
||||
|
||||
config = chafa_canvas_config_new ();
|
||||
//chafa_canvas_config_set_geometry (config, 23, 12);
|
||||
chafa_canvas_config_set_geometry (config, 100, 65);
|
||||
chafa_canvas_config_set_geometry (config, width, height);
|
||||
chafa_canvas_config_set_symbol_map (config, symbol_map);
|
||||
|
||||
// mono for now (no escape code)
|
||||
chafa_canvas_config_set_canvas_mode (config, CHAFA_CANVAS_MODE_FGBG);
|
||||
|
||||
canvas = chafa_canvas_new (config);
|
||||
|
||||
//CHAFA_PIXEL_RGBA8_UNASSOCIATED,
|
||||
guchar *pixels = gdk_pixbuf_get_pixels (file);
|
||||
chafa_canvas_draw_all_pixels (canvas,
|
||||
CHAFA_PIXEL_ARGB8_UNASSOCIATED,
|
||||
@ -2000,5 +2008,5 @@ win_pictest(ProfWin* window)
|
||||
gdk_pixbuf_get_rowstride(file));
|
||||
|
||||
GString *gs = chafa_canvas_build_ansi (canvas);
|
||||
win_print(window, THEME_DEFAULT, "!", gs->str);
|
||||
win_println(window, THEME_DEFAULT, "!", gs->str);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user