# A test object. import ihEvent, ihApp, ihWidget class Bouncy(ihWidget.Widget): def __init__(self,parent,**args): apply(ihWidget.Widget.__init__,(self,parent),args) #print "Bouncy's widget:", self._Widget_ #print "Bouncy's drawable:", self._Drawable_ self.foreground = self.ForePen() self.background = self.BackPen() self.color = [self.MakeColor(.2,.1,.1), self.MakeColor(.5,.4,.2), self.MakeColor(.8,.5,.3)] self.color2 = [self.MakeColor(.1,.1,.2), self.MakeColor(.2,.4,.5), self.MakeColor(.3,.5,.8)] self.pm = self.MakePixmap(self.Dimensions()[2], self.Dimensions()[3]) self.pm.ForePen(self.BackPen) self.pm.FillRectangle(0,0,self.Dimensions()[2], self.Dimensions()[3]) self.splat_x = 0 self.splat_y = 0 self.splat_on = 1 self.splat_xvel = 5 self.splat_yvel = 3 self.wiper(0,0) def wiper(self,pos,col): nextcol = col if pos > 20: next = 0 if col >= 2: nextcol = 0 else: nextcol = col+1 else: next = pos + 1 self.FutureCall(.05,self.wiper,(next,nextcol)) i = pos x, y, w, h = self.Dimensions() self.pm.ForePen(self.background) while i < w: self.pm.DrawLine(i,0,i,h-1) i = i + 20 i = pos while i < h: self.pm.DrawLine(0,i,w-1,i) i = i + 10 if( self.splat_on ): x = self.splat_x y = self.splat_y x = x + self.splat_xvel if( x < 0 or (x+x) > w ): self.splat_xvel = -self.splat_xvel x = x + (2*self.splat_xvel) y = y + self.splat_yvel if( y < 0 or (y+y) > h ): self.splat_yvel = -self.splat_yvel y = y + (2*self.splat_yvel) self.pm.ForePen(self.color[0]) self.pm.FillArc(x,y,x+2,y+2) if( x > 5 and y > 5 ): self.pm.ForePen(self.color[1]) self.pm.FillArc(x+5,y+5,x-5,y-5) if( x > 10 and y > 10 ): self.pm.ForePen(self.color[2]) self.pm.FillArc(x+10,y+10,x-10,y-10) self.splat_x = x self.splat_y = y #print 'Bouncy has updated!' self.Paste(0,0,self.pm) def OnResize(self,ev,x,y,w,h): #print "Resizing Bouncy to (%d,%d,%d,%d)" % (x,y,w,h), \ # self._Widget_.Dimensions() try: self.OnRedraw(None,x,y,w,h) except: pass def OnRedraw(self,ev,x,y,w,h): #print "Redrawing Bouncy:", self self.Paste(x,y,self.pm,x,y,w,h) self.Flush() def OnMouse(self,ev,x,y,state,hit): if( ev.Code != ihEvent.CodeNames['MouseMove'] ): state = hit if( state ): self.pm.ForePen(self.color2[0]) self.pm.FillArc(x-15,y-15,x+15,y+15) self.pm.ForePen(self.color2[1]) self.pm.FillArc(x-10,y-10,x+10,y+10) self.pm.ForePen(self.color2[2]) self.pm.FillArc(x-5,y-5,x+5,y+5) self.Paste(0,0,self.pm) self.splat_xvel = x - self.splat_x self.splat_yvel = y - self.splat_y if( self.splat_xvel == 0 ): self.splat_xvel = 1 if( self.splat_yvel == 0 ): self.splat_yvel = 1 self.splat_x = x self.splat_y = y self.splat_on = 0 if( ev.Code == ihEvent.CodeNames['MouseRelease'] ): self.splat_on = 1 class Boxer(ihWidget.Widget): def __init__(self,parent,**args): apply(ihWidget.Widget.__init__,(self,parent),args) #print "Boxer's widget:", self._Widget_ #print "Boxer's drawable:", self._Drawable_ self.foreground = self.ForePen() self.background = self.BackPen() def OnResize(self,ev,x,y,w,h): #print "Resizing Boxer to (%d,%d,%d,%d)" % (x,y,w,h) try: self.OnRedraw(None,x,y,w,h) except: pass def OnRedraw(self,ev,x,y,w,h): # print "Redrawing Boxer:", self self.ForePen(self.background) self.FillRectangle(0,0,self.Width,self.Height) self.ForePen(self.foreground) self.DrawRectangle(0,0,self.Width,self.Height) self.Flush() class ihEmbed(ihApp.Application): def OnResize(self,ev,x,y,w,h): #print "Resizing Main to (%d,%d,%d,%d)" % (x,y,w,h) try: self.X = x self.Y = y self.Width = w self.Height = h self.bouncy.DoResize(0,0,w,h-10) self.boxer.DoResize(0,h-10,w,10) except: pass def OnRedraw(self,ev,x,y,w,h): #print "Redrawing Main:", self #print "Main dimens =", self._Widget_.Dimensions() #print "Bouncy dimens =", self.bouncy._Widget_.Dimensions() #print "Boxer dimens =", self.boxer._Widget_.Dimensions() pass def __init__(self,**args): #print "Initializing bouncy app!" apply(ihApp.Application.__init__,(self,),args) #print "Main's widget:", self._Widget_ #print "Main's drawable:", self._Drawable_ self.bouncy = Bouncy(self,Width=self.Width,Height=self.Height-10) self.boxer = Boxer(self) self.DoResize() __export__ = ['ihEmbed']
Dianne Kyra Hackborn <hackbod@angryredplanet.com> | Last modified: Wed Aug 14 14:33:51 PDT 1996 |