Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions demos/dragger.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ image create photo redptr -file [file join $images ptr-red.gif]
image create photo greenptr -file [file join $images ptr-green.gif]
image create photo doc -file [file join $images doc-img.gif]
set ptrxbm @[file join $images ptr-mask.xbm]
set docxbm @[file join $images doc-mask.xbm]

pack [label .l -justify l -text "Drag off this window to see a coloured\
cursor\n(implemented using a canvas and the non-rectangular\nwindow\
Expand All @@ -67,7 +66,7 @@ set image(doc) [.cursor.workarea create image 3 4 \
#pack [label .cursor.ptr -bd 0 -image greenptr]
update idletasks
shape set .cursor.workarea -offset 0 0 bitmap $ptrxbm
shape upd .cursor.workarea + -offset 3 4 bitmap $docxbm
shape upd .cursor.workarea + -offset 3 4 photo doc
shape set .cursor window .cursor.workarea

proc movecursor {x y} {
Expand Down
Binary file modified demos/images/doc-img.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 0 additions & 14 deletions demos/images/doc-mask.xbm

This file was deleted.

91 changes: 58 additions & 33 deletions generic/shape.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@

#include "shapeInt.h"

#ifdef __WIN32__
#define SUPPORTS_PHOTO_REGION
#else
#if (SHAPE_PHOTO == 1)
#define SUPPORTS_PHOTO_REGION
#endif
#endif

#ifdef SUPPORTS_PHOTO_REGION
#include <tkInt.h>
#endif
#include <X11/Xutil.h>

#define min(x,y) ((x)<(y) ? (x) : (y))
Expand Down Expand Up @@ -55,12 +44,9 @@ static int shapeText(Tk_Window tkwin, Tcl_Interp *interp,
static int shapeWindow(Tk_Window tkwin, Tcl_Interp *interp,
int x, int y, int op, int kind, int objc,
Tcl_Obj *const objv[]);
#ifdef SUPPORTS_PHOTO_REGION
static int shapePhoto(Tk_Window tkwin, Tcl_Interp *interp,
int x, int y, int op, int kind, int objc,
Tcl_Obj *const objv[]);
#endif

static int shapeCmd(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *const objv[]);

Expand Down Expand Up @@ -379,7 +365,6 @@ shapeWindow(
return Shape_CombineWindow(interp, tkwin, kind, op, x, y, srcwin);
}

#ifdef SUPPORTS_PHOTO_REGION
static int
shapePhoto(
Tk_Window tkwin,
Expand All @@ -393,36 +378,82 @@ shapePhoto(
{
char *imageName;
Tk_PhotoHandle handle;
Region region;
XImage *maskXImage;
GC maskGC;
Pixmap maskDrawable;
Tk_PhotoImageBlock block;
int result, i, j;
Display *dpy = Tk_Display(tkwin);
Window window = Tk_WindowId(tkwin);

if (objc != 1) {
Tcl_AppendResult(interp, "photo requires one argument; "
"a photo image name", NULL);
return TCL_ERROR;
}

imageName = Tcl_GetStringFromObj(objv[0], &NULL);
imageName = Tcl_GetString(objv[0]);
handle = Tk_FindPhoto(interp, imageName);
if (handle == NULL) {
return TCL_ERROR;
}

/*
* Deep implementation magic! Relies on knowing a TkRegion is
* implemented as a Region under X...
*/
Tk_PhotoGetImage(handle, &block);
maskDrawable = Tk_GetPixmap(dpy, window, block.width, block.height, 1);
if (maskDrawable == None) {
Tcl_AppendResult(interp, "Tk_GetPixmap failed for image ",
imageName, (char *)NULL);
return TCL_ERROR;
}

maskGC = XCreateGC(dpy, maskDrawable, 0ul, NULL);
if (maskGC == NULL) {
Tk_FreePixmap(dpy, maskDrawable);
Tcl_AppendResult(interp, "XCreateGC failed for image ",
imageName, (char *)NULL);
return TCL_ERROR;
}

region = (Region) TkPhotoGetValidRegion(handle);
maskXImage = XCreateImage(dpy, Tk_Visual(tkwin), 1u,
XYBitmap, 0, NULL, 1, 1, 32, 0);
if (maskXImage == NULL) {
XFreeGC(dpy, maskGC);
Tk_FreePixmap(dpy, maskDrawable);
Tcl_AppendResult(interp, "XCreateImage failed for image ",
imageName, (char *)NULL);
return TCL_ERROR;
}

if (region == None) {
Tcl_AppendResult(interp, "bad transparency info in photo image ",
imageName, NULL);
maskXImage->width = block.width;
maskXImage->height = block.height;
maskXImage->bytes_per_line = ((block.width + 31) >> 3) & ~3;
maskXImage->data = Tcl_Alloc(block.height * maskXImage->bytes_per_line);
if (maskXImage->data == NULL) {
XDestroyImage(maskXImage);
XFreeGC(dpy, maskGC);
Tk_FreePixmap(dpy, maskDrawable);
Tcl_AppendResult(interp, "failed to allocate mask XImage buffer for image ",
imageName, (char *)NULL);
return TCL_ERROR;
}

return Shape_CombineRegion(interp, tkwin, kind, op, x, y, region);
for (i = 0; i < block.height; i++) {
unsigned char *row = block.pixelPtr + i*block.pitch;
for (j = 0; j < block.width; j++) {
unsigned char *pixel = row + j*block.pixelSize;
XPutPixel(maskXImage, j, i, pixel[block.offset[3]] == 0);
}
}

XPutImage(dpy, maskDrawable, maskGC, maskXImage, 0, 0, 0, 0, block.width, block.height);
Tcl_Free(maskXImage->data);
maskXImage->data = NULL;
XDestroyImage(maskXImage);
XFreeGC(dpy, maskGC);
result = Shape_CombineBitmap(interp, tkwin, kind, op, x, y, maskDrawable);
Tk_FreePixmap(dpy, maskDrawable);
return result;
}
#endif

static int
shapeSetUpdateOps(
Expand All @@ -439,25 +470,19 @@ shapeSetUpdateOps(
"-offset",
"-bounding", "-clip", "-both",
"bitmap", "rectangles", "reset", "text", "window",
#ifdef SUPPORTS_PHOTO_REGION
"photo",
#endif
NULL
};
static enum optkind optk[] = {
offsetargs,
shapekind, shapekind, shapekind,
sourceargs, sourceargs, sourceargs, sourceargs, sourceargs
#ifdef SUPPORTS_PHOTO_REGION
, sourceargs
#endif
};
static shapeApplicator applicators[] = {
NULL, NULL, NULL, NULL,
shapeBitmap, shapeRects, shapeReset, shapeText, shapeWindow,
#ifdef SUPPORTS_PHOTO_REGION
shapePhoto,
#endif
NULL
};

Expand Down
2 changes: 1 addition & 1 deletion unix/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ GENERIC_DIR = $(TOP_DIR)/generic
UNIX_DIR = $(TOP_DIR)/unix
INCLUDE_DIR = $(TOP_DIR)/include
# ----------------------------------------------------------------------
CFLAGS = -g -DSHAPE_PHOTO=@SHAPE_PHOTO@
CFLAGS = -g
CC_SWITCHES = $(CFLAGS) ${CFLAGS_WARNING} ${SHLIB_CFLAGS} \
-I${INCLUDE_DIR} -I${GENERIC_DIR} -I${UNIX_DIR} \
-I${TK_INCLUDE_DIR} ${TK_XINCLUDES} -I${TCL_INCLUDE_DIR} \
Expand Down
47 changes: 0 additions & 47 deletions unix/configure
Original file line number Diff line number Diff line change
Expand Up @@ -492,52 +492,6 @@ else
fi


echo $ac_n "checking for TkPhotoGetValidRegion""... $ac_c" 1>&6
if eval "test \"`echo '$''{'ac_cv_func_TkPhotoGetValidRegion'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 501 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char TkPhotoGetValidRegion(); below. */
#include <assert.h>
/* Override any gcc2 internal prototype to avoid an error. */
char TkPhotoGetValidRegion();

int main() { return 0; }
int t() {

/* The GNU C library defines this for functions which it implements
to always fail with ENOSYS. Some functions are actually named
something starting with __ and the normal name is an alias. */
#if defined (__stub_TkPhotoGetValidRegion) || defined (__stub___TkPhotoGetValidRegion)
choke me
#else
TkPhotoGetValidRegion();
#endif

; return 0; }
EOF
if eval $ac_link; then
rm -rf conftest*
eval "ac_cv_func_TkPhotoGetValidRegion=yes"
else
rm -rf conftest*
eval "ac_cv_func_TkPhotoGetValidRegion=no"
fi
rm -f conftest*

fi
if eval "test \"`echo '$ac_cv_func_'TkPhotoGetValidRegion`\" = yes"; then
echo "$ac_t""yes" 1>&6
SHAPE_PHOTO=1
else
echo "$ac_t""no" 1>&6
SHAPE_PHOTO=0
fi



if test $TCL_SHARED_BUILD -eq 1; then
PRIMARY_TARGET='$(SOFILE)'
Expand Down Expand Up @@ -679,7 +633,6 @@ s%@LIBS@%$LIBS%g
s%@exec_prefix@%$exec_prefix%g
s%@prefix@%$prefix%g
s%@program_transform_name@%$program_transform_name%g
s%@SHAPE_PHOTO@%$SHAPE_PHOTO%g
s%@CC@%$CC%g
s%@PRIMARY_TARGET@%$PRIMARY_TARGET%g
s%@SHLIB_CFLAGS@%$SHLIB_CFLAGS%g
Expand Down
3 changes: 0 additions & 3 deletions unix/configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ TCL_BIN_DIR=$TK_EXEC_PREFIX/bin

AC_CHECK_LIB(Xext, XShapeQueryVersion, :, AC_MSG_ERROR(X extension library not available), $TK_XLIBSW)

AC_CHECK_FUNC(TkPhotoGetValidRegion, SHAPE_PHOTO=1, SHAPE_PHOTO=0)
AC_SUBST(SHAPE_PHOTO)

if test $TCL_SHARED_BUILD -eq 1; then
PRIMARY_TARGET='$(SOFILE)'
else
Expand Down