home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 56 / CDPowerplay56Disc2.iso / demos / blade / data1.cab / Program_Executable_Files / Lib / Widgets / WidgetsExtra.py < prev    next >
Encoding:
Python Source  |  2000-10-27  |  4.6 KB  |  175 lines

  1.  
  2.  
  3.  
  4. import BUIx
  5. import BVideo
  6. import Raster
  7. import BBLibc
  8. import math
  9. import sys
  10.  
  11.  
  12. class B_VideoWidget(BUIx.B_RectWidget):
  13.   def __init__(self,Parent,Name,video):
  14.     self.Vid=BVideo.B_Video()
  15.     self.Vid.SetVideo(video)
  16.     self.vidw,self.vidh=self.Vid.GetDimension()
  17.     BUIx.B_RectWidget.__init__(self,Parent,Name,self.vidw,self.vidh)
  18.     self.Selected=0
  19.     self.Solid=0
  20.     self.Border=0
  21.     self.SetDrawFunc(self.Draw)
  22.  
  23.   def __del__(self):
  24.     pass
  25.  
  26.  
  27.   def Draw(self,x,y,time):
  28.     Raster.SetPosition(x,y)
  29.     Raster.DrawImage(self.vidw,self.vidh,"BGR","UpsideDown",self.Vid.GetData(time))
  30.     self.DefDraw(x,y,time)
  31.  
  32.  
  33.  
  34.  
  35. class B_ImageWidget(BUIx.B_RectWidget):
  36.   def __init__(self,Parent,Name,image):
  37.     self.Bitmap=BBLib.B_BitMap24()
  38.     self.Bitmap.ReadFromBMP(image)
  39.     self.vidw,self.vidh=self.Bitmap.GetDimension()
  40.     BUIx.B_RectWidget.__init__(self,Parent,Name,self.vidw,self.vidh)
  41.     self.Selected=0
  42.     self.Solid=0
  43.     self.Border=0
  44.     self.SetDrawFunc(self.Draw)
  45.  
  46.   def __del__(self):
  47.     pass
  48.  
  49.   def Draw(self,x,y,time):
  50.     Raster.SetPosition(x,y)
  51.     Raster.DrawImage(self.vidw,self.vidh,"RGB","Normal",self.Bitmap.GetData())
  52.     self.DefDraw(x,y,time)
  53.  
  54.  
  55. class B_FlashBitmapWidget(BUIx.B_BitmapWidget):
  56.   def __init__(self,Parent,Name,width,height,BitmapName,FileName):
  57.     BUIx.B_BitmapWidget.__init__(self,Parent,Name,width,height,BitmapName,FileName)
  58.     self.SetDrawFunc(self.Draw)
  59.     self.Flashing=0
  60.     self.MinAlpha= 0.0
  61.     self.MaxAlpha= 1.0
  62.     self.Continuous= 0
  63.  
  64.   def Draw(self,x,y,time):
  65.     if self.GetVisible()==0:
  66.       return
  67.  
  68.     if self.Flashing!=0:
  69.       alpha=self.GetAlpha()
  70.       alpha_range= self.MaxAlpha-self.MinAlpha
  71.       if self.Continuous:
  72.         self.SetAlpha(0.5+0.5*(math.cos(time*self.Flashing))*alpha_range+self.MinAlpha)
  73.       else:    
  74.         self.SetAlpha(max(0.0, math.cos(time*self.Flashing))*alpha_range+self.MinAlpha)
  75.       self.DefDraw(x,y,time)
  76.       self.SetAlpha(alpha)
  77.     else:
  78.       self.DefDraw(x,y,time)
  79.  
  80.  
  81.   def SetFlash(self,fl):
  82.     self.Flashing=fl
  83.  
  84.  
  85.   def GetFlash(self):
  86.     return self.Flashing
  87.  
  88. class B_FlashBarWidget(BUIx.B_BarWidget):
  89.   def __init__(self,Parent,Name,width,height):
  90.     BUIx.B_BarWidget.__init__(self,Parent,Name,width,height)
  91.     self.SetDrawFunc(self.Draw)
  92.     self.Flashing=0    
  93.     self.NormalColor= (0,0,0)
  94.     self.DeltaColor= (0,0,0)
  95.     self.Continuous= 0
  96.     
  97.   def Draw(self,x,y,time):
  98.     if self.GetVisible()==0:
  99.       return
  100.  
  101.     if self.Flashing!=0:      
  102.       if self.Continuous:
  103.         a= 0.5+0.5*math.cos(time*self.Flashing)
  104.       else:
  105.         a= max(0.0, math.cos(time*self.Flashing))
  106.       BUIx.B_BarWidget.SetColor(self,
  107.                                 self.NormalColor[0]+self.DeltaColor[0]*a, 
  108.                                 self.NormalColor[1]+self.DeltaColor[1]*a, 
  109.                                 self.NormalColor[2]+self.DeltaColor[2]*a)
  110.       self.DefDraw(x,y,time)
  111.       BUIx.B_BarWidget.SetColor(self,self.NormalColor[0], self.NormalColor[1], self.NormalColor[2])
  112.     else:
  113.       self.DefDraw(x,y,time)
  114.  
  115.   def SetFlash(self,fl):
  116.     self.Flashing=fl
  117.  
  118.   def GetFlash(self):
  119.     return self.Flashing
  120.  
  121.   def SetColor(self,r,g,b):
  122.     # change the delta to preserve the flash color    
  123.     #import pdb
  124.     #pdb.set_trace()
  125.     dc= (r-self.NormalColor[0],g-self.NormalColor[1],b-self.NormalColor[2])
  126.     self.DeltaColor= (min (self.DeltaColor[0]-dc[0], 255-r), 
  127.                       min (self.DeltaColor[1]-dc[1], 255-g), 
  128.                       min (self.DeltaColor[2]-dc[2], 255-b))
  129.     
  130.     self.NormalColor= (r,g,b)
  131.     BUIx.B_BarWidget.SetColor(self,r,g,b)
  132.     
  133.   def SetFlashColor(self,r,g,b):        
  134.     # Store as a delta
  135.     #import pdb
  136.     #pdb.set_trace()
  137.     self.DeltaColor= (r-self.NormalColor[0], g-self.NormalColor[1], b-self.NormalColor[2])
  138.  
  139.   def GetFlashColor(self):
  140.     return (self.NormalColor[0]+self.DeltaColor[0], 
  141.             self.NormalColor[1]+self.DeltaColor[1], 
  142.             self.NormalColor[2]+self.DeltaColor[2])
  143.  
  144.  
  145. class B_FlashTextWidget(BUIx.B_TextWidget):
  146.   def __init__(self,Parent,Name,Text,font_server,font):
  147.     BUIx.B_TextWidget.__init__(self,Parent,Name,Text,font_server,font)
  148.     self.SetDrawFunc(self.Draw)
  149.     self.Flashing=0
  150.  
  151.  
  152.   def Draw(self,x,y,time):
  153.     if self.GetVisible()==0:
  154.       return
  155.  
  156.     if self.Flashing!=0:
  157.       alpha=self.GetAlpha()
  158.       self.SetAlpha(math.cos(time*self.Flashing))
  159.       self.DefDraw(x,y,time)
  160.       self.SetAlpha(alpha)
  161.     else:
  162.       self.DefDraw(x,y,time)
  163.  
  164.  
  165.   def SetFlash(self,fl):
  166.     self.Flashing=fl
  167.  
  168.  
  169.   def GetFlash(self):
  170.     return self.Flashing
  171.  
  172.  
  173.  
  174.  
  175.