[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

B&W Windows that are good for Color, Color windows that arent!



(sorry if below is long winded, but I've tried to be as clear as I can
and also provide all the code to make it easy to see this phenomenon.)
I'm having a puzzling problem. My setup is critical to this
problem so let me describe that first. I have an apple 2 page monitor *AND*
an 8 bit apple color monitor (with a GC*24 card (accelerator turned off),
I don't think that matters (...famous last words)).
CONTEXT:
    I do color animation via offscreen c grafports (always onto my color
 screen, whether it is the main monitor or not). The animation works fine
when my COLOR monitor is the main monitor but not when my  b&w monitor is
the 
main monitor. In that case even though projected onto the color monitor
it comes out b&w instead of color. 
   So I've figured out that this must be because the main graphics device
is now b&w instead of color. Accordingly, as suggested on page 125
("optimizing visual results") of Inside Mac V.5, I figure I've got to set
the current device temporarily to be the device associated with the color
screen (instead of main b&w device which is current device) while creating
these offscreen pixmaps. Right now the current (b&w) device 
is making them be b&w.  So I set off to learn to manipulate the current
device, and
on the way I uncovered some strange problems which seem to be connected, at
least
in part, & in some strange fashion, to MACL's color windows.
PROBLEM:
    if I create one a MACL color window within my color monitor screen  
it seems to perform correctly with regard to being filled with a color,
or even with regard to blitting in a color picture. So far fine and dandy.
But the weird thing is that in fact the pixmap record for the cgrafport
associated with that window doesn't look right! In fact it looks like
it was drawn from the b&w main monitor device. For example, its depth
(see pixmap variable "pixelsize") comes out 1 not 8!!!!! (Do you'all
setup on the basis of main device rather than maxdevice of window?).
  OK, this is weird enough but at least it works. I press ahead trying
to learn how to set current device to temporarily be that of the non-main
color monitor (in preperation for work on color offscreen cgrafports). I
seem to totally succeed in resetting the current device to be a color
one while creating one of MACL's color windows (see fn D3 below). Even
better,
the pixmap record associated with my window looks like that of a color one,

namely, it show "pixelsize" to be 8. BUT IT WON'T RESPOND TO VARIOUS COLOR
MANIPULATIONS!! 
  SO HERE IS THE BIZARRE SITUATION I FIND MYSELF IN:
   (remember setup is one where main monitor is b&w not color):
    (1) color manipulations (e.g., paint-rect, blitt in a pixmap) DO
     work on a standard MACL color window which DOESN'T seem to have a
     proper pixmap!
    (2) color manipulations DON'T work on a color window for which
     DOES seem to have a proper pixmap!

I am left scratching my head. Even our local guru is puzzled.
Enlightenment?

NOTE: also tried building my own window definition more from scratch
via :wptr keyword arg's to *window* exist, but this, again, while
seeming to have correct info in, doesn't allow color manipulations.

Below is appropriate code for seeing these phenomena:

; COLOR WINDOWS
(defobject *color-window* *color-window-mixin* *window*)

; FN FOR PAINTING WINDOW GREEN SO CAN SEE IF COLOR WORKING
(defobfun (PAINT-GREEN *COLOR-WINDOW*)()
   (set-fore-color *green-color*)
   (paint-rect (rref wptr window.portrect)))

;RETURN MAX DEVICE INTERSECTED BY AREA OF WINDOW
; I have tested below in a variety of ways and in some other active code
and
; really does seem to work fine...
(defobfun (GET-MAX-DEVICE *WINDOW*)()
  "void
Return the max device within a window's bounds."
  (ccl::with-rectangle-arg (r (window-position)
                         (add-points (window-position)
                                     (window-size)))
    (_GetMaxDevice :ptr r :ptr)))

(defun D3 ()
  (let ((max_dev (ask *top-listener* (get-max-device))) ;see comments
        (curr_dev (_getGDevice :ptr)))
    (print-db max_dev curr_dev)
    (_SetGDevice :ptr max_dev)     ;make current device = max device
    (print-db (_getgdevice :ptr))  ;confirm
    (setf cw (oneof *color-window*
                    :window-position #@(1200  40) ;positions on my color
monitor
                    :window-size #@(100 100)))
    (_SetGDevice :ptr curr_dev))  ;restore old current device
  )
#|{22-jan-91} I'm drawing the maxdevice from the listener so I can control
whether the current device will be set to a color device or a b&w one. All
I do is position the listener in either the color screen or b&w one. 
-- I setup local variables for curr device and for max device of listener
-- I set current to max
-- create a color window in new curr device context
-- restore former current device
 |#


; SOME INFO GATHERING DIAGNOSITICS

;DEFINITION OF GDEVICE so can peek at info on
 (defrecord (GDevice :handle)
    (gdRefNum :integer)
    (gdID :integer)
    (gdType :integer)
    (gdITable :handle)
    (gdResPref :integer)
    (gdSearchProc :handle)
    (gdCompProc :handle)
    (gdFlags :integer)
    (gdPMap :handle)
    (gdRefCon :longint)
    (gdNextGD :handle)
    (gdRect :Rect)
    (gdMode :longint)
    (gdCCBytes :integer)
    (gdCCDepth :integer)
    (gdCCXData :handle)
    (gdCCXMask :handle)
    (gdReserved :longint)
    )

; FN TO SHOW INFO OF MAIN DEVICE PMAP WHERE LISTENER CURRENTLY IS
(defun PEEK-LISTENER-MAX-DEVICE ()
  (print-record
   (rref (ask *top-listener* (get-max-device))
         :GDevice.gdPMap)
   :pixmap))

; FN TO LOOK AT ACTUAL PIXMAP INFO OF A GIVEN WINDOW, default is test
window "cw"
(defun PEEK (&optional (w cw))
  (print-record (rref (ask w wptr) cgrafport.portpixmap) :pixmap))

------------------------------
 ; HOW TO CONFIRM MY RESULTS:
(1) create a normal color window in color non-main screen and use
paint-green.
 Works. But now look at pixmap info via (peek...). Says that pixelsize is 1
(i.e. b&w!). Pixelsize = depth of pixmap.
TEST CODE: (WARNING: eval these one at a time else green flashes in only
temporarily)
       (setf cw (oneof *color-window* :window-size #@(100 100)
                                      :window-position #@(1200 40))) ;or
whatever
       (ask cw (paint-green))   ;works
       (peek cw)   ;pixelsize is 1 !!! (should be 8 for 256 color screen)

(2) use d3 with listener positioned IN NON-MAIN COLOR SCREEN ( This will
cause current device to be set to max device of listener which will
be color). WON'T be able to get paint-green to work yet will be able to
show proper pixmap (at least in terms of depth!!!).
TEST CODE: (eval these one at a time)
   (D3)  ;REMEMBER LISTENER SHOULD BE IN COLOR SCREEN
   (ask cw (paint-green))  ;doesn't work
   (peek cw) ;gives correct pixelsize of 8 !!!

(3) use d3 with listener in b&w main screen. Now will again get color
results
yet the pixmap definition will look wrong (e.g., opencport drew from max
device
of listener which was b&w main monitor, so was setup with pixelsize 1
etc.).
This last test indicates that my setting of device as b&w or color via
where place listener seems to work.

   
BTW: I tried out some manipulations with blitting in color pixmaps which
behave analagously to fn paint-green with respect to when work and when
don't work.  I also tried playing around with direct window setup. No
better success.  Here is a D4 for that:

(defun D4 ()
  (ccl::with-rectangle-arg 
   (wr #@(1200 40) #@(1300 100))   ;RECTANGLE OF WINDOW TO BE CREATED
   (with-pstrs ((wtitle "test"))
     (let ((max_dev (ask *top-listener* (get-max-device))) ;see comments
           (curr_dev (_getGDevice :ptr)))
       (print-db  max_dev  curr_dev)
       (_SetGDevice :ptr max_dev)     ;make current device = max device
       (print-db (_getgdevice :ptr))  ;confirm
       (L ((wptr (_newcwindow     ;MAKING WINDOW MYSELF
                  :ptr nil
                  :ptr wr
                  :ptr wtitle
                  :word -1
                  :word 0
                  :ptr (%int-to-ptr -1)
                  :word -1
                  :long 0
                  :ptr)))
          (setf cw (oneof *color-window*
                          :window-position #@(1200  40)
                          :window-size #@(100 100)
                          :wptr wptr))
          (_SetGDevice :ptr curr_dev))  ;restore old current device
       ))))

; to succeed have listener being in b&w main screen, to fail have listener
be in
;  color screen
(d4)
(ask cw (paint-green))
(peek cw)