menu entry for adding pictures, added alpha parameter for opacity

This commit is contained in:
Stefan Frederik 2022-01-22 04:55:59 +01:00
parent 320ad6e2aa
commit 81a612d5a3
5 changed files with 39 additions and 20 deletions

View File

@ -2417,11 +2417,11 @@ int draw_images_all(void)
{
#if HAS_CAIRO==1
int i, bbox_set = 0, w, h;
double x, y, rw, rh;
double sx1, sy1, sx2, sy2;
double x, y, rw, rh, rescaled = 0;
double sx1, sy1, sx2, sy2, alpha;
const char *ptr;
int save_bbx1, save_bby1, save_bbx2, save_bby2;
if(xctx->draw_single_layer==-1 || GRIDLAYER == xctx->draw_single_layer) {
if(xctx->enable_layer[GRIDLAYER]) for(i = 0; i < xctx->rects[GRIDLAYER]; i++) {
xRect *r = &xctx->rect[GRIDLAYER][i];
@ -2489,6 +2489,9 @@ int draw_images_all(void)
return 1;
}
if(cairo_surface_status(emb_ptr->image) != CAIRO_STATUS_SUCCESS) return 1;
ptr = get_tok_value(r->prop_ptr, "alpha", 0);
alpha = 1.0;
if(ptr[0]) alpha = atof(ptr);
w = cairo_image_surface_get_width (emb_ptr->image);
h = cairo_image_surface_get_height (emb_ptr->image);
dbg(1, "draw_images_all() w=%d, h=%d\n", w, h);
@ -2499,6 +2502,7 @@ int draw_images_all(void)
r->y2 = r->y1 + h;
scalex = xctx->mooz;
scaley = xctx->mooz;
rescaled = 1;
} else { /* resize image to fit in rectangle */
rw = abs(r->x2 - r->x1);
rh = abs(r->y2 - r->y1);
@ -2509,13 +2513,13 @@ int draw_images_all(void)
cairo_translate(xctx->cairo_save_ctx, x, y);
cairo_scale(xctx->cairo_save_ctx, scalex, scaley);
cairo_set_source_surface(xctx->cairo_save_ctx, emb_ptr->image, 0. , 0.);
cairo_paint(xctx->cairo_save_ctx);
cairo_paint_with_alpha(xctx->cairo_save_ctx, alpha);
}
if(xctx->draw_window) {
cairo_translate(xctx->cairo_ctx, x, y);
cairo_scale(xctx->cairo_ctx, scalex, scaley);
cairo_set_source_surface(xctx->cairo_ctx, emb_ptr->image, 0. , 0.);
cairo_paint(xctx->cairo_ctx);
cairo_paint_with_alpha(xctx->cairo_ctx, alpha);
}
cairo_restore(xctx->cairo_ctx);
cairo_restore(xctx->cairo_save_ctx);
@ -2525,6 +2529,7 @@ int draw_images_all(void)
xctx->bbx2 = save_bbx2;
xctx->bby2 = save_bby2;
xctx->sem = 1;
if(rescaled) bbox(ADD, r->x1, r->y1, r->x2, r->y2);
bbox(SET, 0.0, 0.0, 0.0, 0.0);
}
}

View File

@ -304,7 +304,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
unselect_all();
storeobject(-1, xctx->mousex_snap-400, xctx->mousey_snap-200, xctx->mousex_snap+400, xctx->mousey_snap+200,
xRECT, GRIDLAYER, SELECTED,
"flags=1\n"
"flags=graph\n"
"y1=0\n"
"y2=5\n"
"ypos1=0\n"
@ -327,6 +327,24 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
Tcl_ResetResult(interp);
}
if(!strcmp(argv[1],"add_png"))
{
char str[PATH_MAX+100];
cmd_found = 1;
unselect_all();
tcleval("tk_getOpenFile -filetypes { {{Png} {.png}} {{All files} *} }");
if(tclresult()[0]) {
my_snprintf(str, S(str), "flags=image,unscaled\nalpha=0.8\nimage=%s\n", tclresult());
storeobject(-1, xctx->mousex_snap-100, xctx->mousey_snap-100, xctx->mousex_snap+100, xctx->mousey_snap+100,
xRECT, GRIDLAYER, SELECTED, str);
xctx->need_reb_sel_arr=1;
rebuild_selected_array();
move_objects(START,0,0,0);
xctx->ui_state |= START_SYMPIN;
}
Tcl_ResetResult(interp);
}
else if(!strcmp(argv[1],"align"))
{
cmd_found = 1;
@ -2652,14 +2670,8 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
else if(argv[1][0] == 't') {
if(!strcmp(argv[1],"test"))
{
size_t len;
char *s;
cmd_found = 1;
if(argc > 2) {
Tcl_AppendResult(interp, (s = base64_from_file(argv[2], &len)), NULL);
my_free(1480, &s);
}
/* Tcl_ResetResult(interp); */
Tcl_ResetResult(interp);
}
else if(!strcmp(argv[1],"toggle_colorscheme"))

View File

@ -4525,6 +4525,7 @@ proc build_widgets { {topwin {} } } {
toolbar_create ToolInsertArc "xschem arc" "Insert Arc" $topwin
$topwin.menubar.tools.menu add command -label "Insert circle" -command "xschem circle" -accelerator Ctrl+Shift+C
toolbar_create ToolInsertCircle "xschem circle" "Insert Circle" $topwin
$topwin.menubar.tools.menu add command -label "Insert PNG image" -command "xschem add_png"
$topwin.menubar.tools.menu add command -label "Search" -accelerator Ctrl+F -command property_search
toolbar_create ToolSearch property_search "Search" $topwin
$topwin.menubar.tools.menu add command -label "Align to Grid" -accelerator Alt+U -command "xschem align"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long