"work AlphaTransparentCmd and RasterPeekFunc"

[email protected] Fri, 14 Jun 2002 16:10:09 -0700
Newsgroups gmane.comp.lib.ivtools.patches
Message-ID <[email protected]>
Patch:    ivtools-020614-johnston-052
For:      ivtools-1.0.3
Author:   [email protected]
Subject:  work AlphaTransparentCmd and RasterPeekFunc
Requires: 

This is an intermediate patch to ivtools-1.0.3.  To apply, cd to the
top-level directory of the ivtools source tree (the directory with src
and config subdirs), and apply like this:

	patch -p0 <ThisFile

Summary of Changes:

- work AlphaTransparentCmd and RasterPeekFunc

Index: OverlayUnidraw/ovclasses.h
diff -c OverlayUnidraw/ovclasses.h:1.1 OverlayUnidraw/ovclasses.h:1.2
*** OverlayUnidraw/ovclasses.h:1.1	Fri Nov  2 13:07:02 2001
--- src/OverlayUnidraw/ovclasses.h	Fri Jun 14 16:07:32 2002
***************
*** 93,98 ****
--- 93,99 ----
  #define OVPRECISEBRUSH_CMD    2060
  #define PUSH_CMD              2061
  #define PULL_CMD              2062
+ #define ALPHATRANSPARENT_CMD  2063
  
  #define OVERLAY_COMP          2150
  #define OVERLAYS_COMP         2151
Index: OverlayUnidraw/ovkit.c
diff -c OverlayUnidraw/ovkit.c:1.4 OverlayUnidraw/ovkit.c:1.5
*** OverlayUnidraw/ovkit.c:1.4	Tue May  7 13:26:24 2002
--- src/OverlayUnidraw/ovkit.c	Fri Jun 14 16:07:32 2002
***************
*** 64,69 ****
--- 64,70 ----
  #include <OverlayUnidraw/ovtext.h>
  #include <OverlayUnidraw/ovunidraw.h>
  #include <OverlayUnidraw/ovviewer.h>
+ #include <OverlayUnidraw/rastercmds.h>
  #include <OverlayUnidraw/setattrbyexpr.h>
  #include <OverlayUnidraw/slctbyattr.h>
  
***************
*** 1012,1028 ****
  	     "Precise Rotate   ");
      mbi->menu()->append_item(kit.menu_item_separator());
  
!     MenuItem* graymenu = kit.menu_item(kit.label("Graylevel Processing   "));
!     graymenu->menu(kit.pullright());
!     mbi->menu()->append_item(graymenu);
      
!     MakeMenu(graymenu, new ScaleGrayCmd(new ControlInfo("Scale GrayImage",
  					     "", "")),
  	     "Scale Gray Image   ");
!     MakeMenu(graymenu, new LogScaleCmd(new ControlInfo("LogScale GrayImage",
  					     "", "")),
  	     "Logscale Gray Image   ");
!     MakeMenu(graymenu, new PseudocolorCmd(new ControlInfo("PseudoColor GrayImage",
  					     "", "")),
  	     "Pseudocolor Gray Image   ");
  #ifdef CLIPPOLY
--- 1013,1032 ----
  	     "Precise Rotate   ");
      mbi->menu()->append_item(kit.menu_item_separator());
  
!     MenuItem* imagemenu = kit.menu_item(kit.label("Image Processing   "));
!     imagemenu->menu(kit.pullright());
!     mbi->menu()->append_item(imagemenu);
      
!     MakeMenu(imagemenu, new AlphaTransparentRasterCmd(new ControlInfo("Alpha Transparency",
  					     "", "")),
+ 	     "Alpha Transparency ");
+     MakeMenu(imagemenu, new ScaleGrayCmd(new ControlInfo("Scale GrayImage",
+ 					     "", "")),
  	     "Scale Gray Image   ");
!     MakeMenu(imagemenu, new LogScaleCmd(new ControlInfo("LogScale GrayImage",
  					     "", "")),
  	     "Logscale Gray Image   ");
!     MakeMenu(imagemenu, new PseudocolorCmd(new ControlInfo("PseudoColor GrayImage",
  					     "", "")),
  	     "Pseudocolor Gray Image   ");
  #ifdef CLIPPOLY
Index: OverlayUnidraw/ovraster.c
diff -c OverlayUnidraw/ovraster.c:1.5 OverlayUnidraw/ovraster.c:1.6
*** OverlayUnidraw/ovraster.c:1.5	Tue Jun 11 13:03:41 2002
--- src/OverlayUnidraw/ovraster.c	Fri Jun 14 16:07:32 2002
***************
*** 1389,1394 ****
--- 1389,1395 ----
    float rval, gval, bval, aval;
    peek(x, y, rval, gval, bval, aval);
    val.double_ref() = (double) (gval*(float)0xff); 
+   val.type(AttributeValue::DoubleType);
  }
  
  void OverlayRaster::graypoke(unsigned long x, unsigned long y, unsigned int i)
Index: OverlayUnidraw/rastercmds.c
diff -c OverlayUnidraw/rastercmds.c:1.1 OverlayUnidraw/rastercmds.c:1.2
*** OverlayUnidraw/rastercmds.c:1.1	Fri Nov  2 13:07:03 2001
--- src/OverlayUnidraw/rastercmds.c	Fri Jun 14 16:07:32 2002
***************
*** 1,4 ****
--- 1,5 ----
  /*
+  * Copyright (c) 2002 Scott E. Johnston
   * Copyright (c) 1997 Vectaport Inc. and R.B. Kissh & Associates
   *
   * Permission to use, copy, modify, distribute, and sell this software and
***************
*** 24,35 ****
--- 25,41 ----
  #include <OverlayUnidraw/ovclasses.h>
  #include <OverlayUnidraw/oved.h>
  #include <OverlayUnidraw/ovraster.h>
+ #include <OverlayUnidraw/ovselection.h>
  #include <OverlayUnidraw/ovviewer.h>
  #include <OverlayUnidraw/rastercmds.h>
  
  #include <Unidraw/unidraw.h>
  #include <Unidraw/iterator.h>
  
+ #include <IVGlyph/stredit.h>
+ 
+ #include <InterViews/window.h>
+ 
  // -----------------------------------------------------------------------
  
  
***************
*** 154,159 ****
--- 160,215 ----
  	OverlayRaster* raster = rastview->GetOverlayRaster();
  	if (raster) {
  	  raster->unhighlight();
+ 	}
+       }
+     }
+   }
+ }
+ 
+ /*-----------------------------------------------------------------*/
+ 
+ AlphaTransparentRasterCmd::AlphaTransparentRasterCmd(ControlInfo* ci) : Command(ci) {
+ }
+ 
+ Command* AlphaTransparentRasterCmd::Copy() {
+     Command* copy = new AlphaTransparentRasterCmd(GetControlInfo());
+     InitCopy(copy);
+     ((AlphaTransparentRasterCmd*)copy)->_alpha = _alpha;
+     return copy;
+ }
+ 
+ ClassId AlphaTransparentRasterCmd::GetClassId () { return ALPHATRANSPARENT_CMD; }
+ 
+ boolean AlphaTransparentRasterCmd::IsA (ClassId id) {
+     return ALPHATRANSPARENT_CMD == id || Command::IsA(id);
+ }
+ 
+ boolean AlphaTransparentRasterCmd::Reversible() {
+     return true;
+ }
+ 
+ void AlphaTransparentRasterCmd::Execute() {
+   // find the rasters in the current comp and unhighlight
+ 
+   char* newalpha = StrEditDialog::post
+     (GetEditor()->GetWindow(), 
+      "Enter alpha value", "0.5");
+   if (newalpha)
+     _alpha = atof(newalpha);
+   else
+     _alpha = 1.0;
+ 
+   OverlayEditor* ed = (OverlayEditor*)GetEditor();
+   OverlaySelection* sel = (OverlaySelection*) ed->GetSelection();
+   Iterator i;
+   for (sel->First(i); !sel->Done(i); sel->Next(i)) {
+     GraphicView* view = sel->GetView(i);
+     if (view->IsA(OVRASTER_VIEW)) {
+       RasterOvView* rastview = (RasterOvView*)view;
+       if (rastview) {
+ 	OverlayRasterRect* rr = rastview->GetOverlayRasterRect();
+ 	if (rr) {
+ 	  rr->alphaval(_alpha);
  	}
        }
      }
Index: OverlayUnidraw/rastercmds.h
diff -c OverlayUnidraw/rastercmds.h:1.1 OverlayUnidraw/rastercmds.h:1.2
*** OverlayUnidraw/rastercmds.h:1.1	Fri Nov  2 13:07:03 2001
--- src/OverlayUnidraw/rastercmds.h	Fri Jun 14 16:07:32 2002
***************
*** 1,4 ****
--- 1,5 ----
  /*
+  * Copyright (c) 2002 Scott E. Johnston
   * Copyright (c) 1999 Vectaport Inc.
   * Copyright (c) 1997 Vectaport Inc., R.B. Kissh & Associates
   *
***************
*** 69,74 ****
--- 70,94 ----
      virtual boolean IsA(ClassId);
  
      virtual boolean Reversible();
+ };
+ 
+ 
+ 
+ //: command to make raster alpha-transparent
+ class AlphaTransparentRasterCmd : public Command {
+ public:
+     AlphaTransparentRasterCmd(ControlInfo* ci); 
+ 
+     virtual void Execute();
+ 
+     virtual Command* Copy();
+     virtual ClassId GetClassId();
+     virtual boolean IsA(ClassId);
+ 
+     virtual boolean Reversible();
+ 
+ protected: 
+     float _alpha;
  };
  
  
Index: ComUnidraw/comeditor.c
diff -c ComUnidraw/comeditor.c:1.11 ComUnidraw/comeditor.c:1.12
*** ComUnidraw/comeditor.c:1.11	Tue Feb 19 16:18:19 2002
--- src/ComUnidraw/comeditor.c	Fri Jun 14 16:07:34 2002
***************
*** 216,221 ****
--- 216,222 ----
      comterp->add_command("gtod", new GraphicToDrawingFunc(comterp, this));
  
      comterp->add_command("poke", new PixelPokeFunc(comterp, this));
+     comterp->add_command("peek", new PixelPeekFunc(comterp, this));
      comterp->add_command("pcols", new PixelColsFunc(comterp, this));
      comterp->add_command("prows", new PixelRowsFunc(comterp, this));
      comterp->add_command("pflush", new PixelFlushFunc(comterp, this));
Index: ComUnidraw/pixelfunc.c
diff -c ComUnidraw/pixelfunc.c:1.3 ComUnidraw/pixelfunc.c:1.4
*** ComUnidraw/pixelfunc.c:1.3	Thu Jan 31 10:20:46 2002
--- src/ComUnidraw/pixelfunc.c	Fri Jun 14 16:07:34 2002
***************
*** 58,63 ****
--- 58,90 ----
  
  /*****************************************************************************/
  
+ PixelPeekFunc::PixelPeekFunc(ComTerp* comterp, Editor* ed) : UnidrawFunc(comterp, ed) {
+ }
+ 
+ void PixelPeekFunc::execute() {
+   Viewer* viewer = _ed->GetViewer();
+ 
+   ComValue rastcompv(stack_arg(0));
+   ComValue xv(stack_arg(1));
+   ComValue yv(stack_arg(2));
+   reset_stack();
+   
+   RasterOvComp* rastcomp = (RasterOvComp*) rastcompv.geta(RasterOvComp::class_symid());
+   OverlayRasterRect* rastrect = rastcomp ? rastcomp->GetOverlayRasterRect() : nil;
+   OverlayRaster* raster = rastrect ? rastrect->GetOriginal() : nil;
+ 
+   if (raster) {
+     ComValue retval;
+     raster->graypeek(xv.int_val(), yv.int_val(), retval);
+     push_stack(retval);
+   } else 
+     push_stack(ComValue::nullval());
+ 
+ 
+ }
+ 
+ /*****************************************************************************/
+ 
  PixelColsFunc::PixelColsFunc(ComTerp* comterp, Editor* ed) : UnidrawFunc(comterp, ed) {
  }
  
Index: ComUnidraw/pixelfunc.h
diff -c ComUnidraw/pixelfunc.h:1.3 ComUnidraw/pixelfunc.h:1.4
*** ComUnidraw/pixelfunc.h:1.3	Thu Jan 31 10:20:46 2002
--- src/ComUnidraw/pixelfunc.h	Fri Jun 14 16:07:34 2002
***************
*** 36,41 ****
--- 36,51 ----
  	return "%s(compview x y val) -- poke pixel value into raster"; }
  };
  
+ //: command to peek pixel values from raster
+ // val=peek(compview x y) -- peek pixel value into raster
+ class PixelPeekFunc : public UnidrawFunc {
+ public:
+     PixelPeekFunc(ComTerp*,Editor*);
+     virtual void execute();
+     virtual const char* docstring() { 
+ 	return "val=%s(compview x y) -- peek pixel value from raster"; }
+ };
+ 
  //: command to return number of columns in a raster
  // pcols(compview) -- number of columns in a raster
  class PixelColsFunc : public UnidrawFunc {
*** /dev/null	 Fri Jun 14 16:07:40 PDT 2002
--- patches/ivtools-020614-johnston-052
*************** patches/ivtools-020614-johnston-052
*** 0 ****
--- 1 ----
+ ivtools-020614-johnston-052

_______________________________________________________________

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas - http://devcon.sprintpcs.com/adp/index.cfm?source=osdntextlink