[409] in java-interest

home help back first fref pref prev next nref lref last post

How To: Adding XOR graphics and mouse capture

daemon@ATHENA.MIT.EDU (Randy Gordon - Sun Victoria SE)
Tue Jun 20 13:42:17 1995

Date: Tue, 20 Jun 1995 10:28:26 -0700
From: randyg@Canada.Sun.COM (Randy Gordon - Sun Victoria SE)
To: java-interest@java.Eng.Sun.COM, java-porting@java.Eng.Sun.COM,
        hotjava-interest@java.Eng.Sun.COM


********* UNOFFICIAL UNOFFICIAL UNOFFICIAL UNOFFICIAL ***************

How to add XOR graphics and mouse capture to AWT
------------------------------------------------

I've had a few requests for my XOR graphics and mouse capture hacks so 
I will post info on these now.

Here are the changes I've currently done to add XOR graphics and 
mouse capture functions to my own version of AWT. These are unofficial 
although probably a future version of AWT will have similar  
functions added. You will need to have the alpha3 source and the 
Solaris C compiler to implement these extensions. Of course, these 
extensions are unsupported by me and are USE AT YOUR OWN RISK. They 
should also provide a starting point for others interested in hacking AWT.
I would be interested in hearing from anyone who has better approaches, 
or new functions to add to AWT. For example, one that comes to mind that 
I don't think is currently in AWT is being able to set the background 
mode of a window to OPAQUE or TRANSPARENT as in MS Windows.  If this 
functionality can be reasonably approximated in AWT, then I will 
probably add that for my own use too.

Of course, doing all of this violates the primary purpose of AWT which 
is to be an abstract and portable windowing API.  However, if you 
REALLY need these kinds of functions, and believe like I do that 
similar functions will eventually appear in AWT, then let's get on with 
it and build some really cool Java Window-based applications!
 
Cheers, Randy


Graphics XOR mode:

A graphics XOR mode function actually already exists in the libawt.so 
library for alpha3, although there is no reference to it in Graphics.java.
I can only speculate, but it may have been left out due to differences 
in the way XOR mode is handled by default in MS Windows and X11 (I think 
text drawing behaves differently) - if you stick to line drawing only you 
should be reasonably safe when/if this function is officially added.

Mouse capture:

The mouse capture is implemented with a brute force X server 
pointer grab. I'm not an X11 expert, so there are probably different 
or better ways to do this function. I've used the book "The X Toolkit 
Cookbook" by Paul E. Kimball (Prentice Hall) as my primary reference 
for implementing these extensions.  I would recommend this book for 
experienced developers that are X11 newbies. I believe the mouse capture 
I've implemented has similar semantics to the SetCapture() and 
ReleaseCapture() provided by the MS Windows API. Make sure to call 
releaseCapture() after a setCapture() or you're X server will "hang"! 
Most books on advanced Windows programming have examples on the techniques
used for mouse capture.


Below are the changes that must be made to the AWT source code:



1) Add the following code to the awt_Windows.c file in the alpha3 source:

/* Mouse capture stuff - Randy Gordon 950619 */
void
awt_WServer_windowSetCapture(Hawt_WServer *ws,
                             Hawt_Window *this)
{
    struct WindowData   *wdata;
 
    if (this == 0) {
        SignalError(0, JAVAPKG "NullPointerException", 0);
        return;
    }
 
    wdata = PDATA(WindowData,this);
    if (wdata == 0 || wdata->sw==0) {
        SignalError(0, JAVAPKG "NullPointerException", 0);
        return;
    }
 
    XtGrabPointer(wdata->w,
                  False,
                  PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
                  GrabModeAsync,
                  GrabModeAsync,
                  None,
                  None,
                  CurrentTime);
}                    
void
awt_WServer_windowReleaseCapture(Hawt_WServer *ws,
                                 Hawt_Window *this)
{
    struct WindowData   *wdata;
 
    if (this == 0) {
        SignalError(0, JAVAPKG "NullPointerException", 0);
        return;
    }
 
    wdata = PDATA(WindowData,this);
    if (wdata == 0 || wdata->sw==0) {
        SignalError(0, JAVAPKG "NullPointerException", 0);
        return;
    }
 
    XtUngrabPointer(wdata->w,
                    CurrentTime);
}                    
/* End Mouse capture */
 



2) Add to Window.java:

    /* Mouse capture - Randy Gordon 950619 */
    public void setCapture() {
        wServer.windowSetCapture(this);
    }
    public void releaseCapture() {
        wServer.windowReleaseCapture(this);
    }
    /* End mouse capture */ 




3) Add to Graphics.java:

    /* Graphics modes - Randy Gordon 950619 */
    public void xorMode() {
       wServer.graphicsXorMode(this);
    }
    public void paintMode() {
       wServer.graphicsPaintMode(this);
    }
    /* end graphics modes */




4) Add to WServer.java:

    /* Graphics modes - Randy Gordon 950619 */
    native synchronized void graphicsXorMode(Graphics g);
    native synchronized void graphicsPaintMode(Graphics g);
    /* end graphics modes */
    /* Mouse capture - Randy Gordon 950619 */
    native synchronized void windowSetCapture(Window w);
    native synchronized void windowReleaseCapture(Window w);
    /* end mouse capture */


-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post