Exemple #1
0
// verify is there draw or mat
void Board::verifyState()
{
  if ( matState() || drawState() )
    return;

#ifndef NDEBUG
  Board board0(*this);
#endif

  MovesGenerator mg(*this);
  bool found = false;
  for ( ; !found; )
  {
    const Move & m = mg.move();
    if ( !m )
      break;

    if ( validateMove(m) )
      found = true;
  }

  if ( !found )
  {
    setNoMoves();

    // update move's state because it is last one
    if ( halfmovesCounter_ > 0 )
    {
      UndoInfo & undo = undoInfo(halfmovesCounter_-1);
      undo.state_ = state_;
    }
  }
}
Exemple #2
0
void ChessWidget::paintEvent(QPaintEvent * )
{
  cpos_.draw(this, curPt_);

  drawState();
  drawInfo();
}
Exemple #3
0
void Game2D::paint(QPainter &p){

    drawBackground (p);

    for (std::size_t i=0; i<evec_.size(); i++) drawUnit (evec_[i], p);//evec_[i].draw (p);

    if (state_==2) ship_.setType(1);
    else ship_.setType(0);

    drawUnit (ship_, p, direction_);

    drawLabels (p);

    drawState (p);

    /*
    typedef QSharedPointer <Unit> spUnit;
    QVector < spUnit>  units;

    Ship ship;
    Enemy e;

    units.push_back((spUnit)new Ship());
    //units.push_back((spUnit)&e);

    for (int i=0; i<units.size(); i++) drawUnit (*units[i].data(), p);

    */
}
/*------------------------------------------------------------------------------
| DrawingArea::button1DoubleClick                                              |
|                                                                              |
| Handle button 1 up double click events.  In the case of polyline and polygon |
| a double click indicates the user has finished adding data points to the     |
| object.                                                                      |
------------------------------------------------------------------------------*/
DrawingArea& DrawingArea::button1DoubleClick( const IPoint& point )
{
  if (drawState() == waitingForInput )
  {
    switch (currentObj)
    {
      case polyline:
      {
        iGraphic->drawOn( gc );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      }
      break;
      case polygon:
      {
        ((IGPolyline*)iGraphic)->IGPolyline::drawOn( gc );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      }
      break;
    }
  }
  return *this;
}
		Child* BaseTown::update(Parent* parent) {
			Child* next = this;
			//画面描画
			drawState();
			
			if ( CheckHitKey( KEY_INPUT_SPACE ) ) {
				switch ( mCursorPosition ) {
					case 0:
						next = new Dungeon;
						break;
					case 1:
						//TODO:ステータス表示
						break;
					case 2:
						next = new Shop;
						break;
					case 3:
						//TODO:スキル強化
						break;
					default:
						break; //何もしない
				}
			} else if ( CheckHitKey( KEY_INPUT_BACK ) ) {
				parent->moveTo( Parent::NEXT_TITLE );
			}
			return next;
		}
Exemple #6
0
void Hero::draw(void) {
   // this will hold the frame that the animation is to hold
   int state;

   // increments frameCount and updates currentFrame if necessary
   ++frameCount;

   if (frameCount == animationDelay) {
      frameCount = 0;
      ++currentFrame;
      // overflows currentFrame
      if (currentFrame == 4) 
         currentFrame = 0;
   }

   switch(currentFrame) {
      case 0:
         state = STANDING; break;
      case 1:
         state = RIGHT_STEP; break;
      case 2:
         state = STANDING; break;
      case 3:
         state = LEFT_STEP; break;
   }

   // `still' doesn't require animation
   if (movement == STILL) {
      // erases old image
      al_draw_filled_rectangle(x, y, x + 16, y + 16, al_map_rgb(0,0,0));

      // draws still guy
      drawState(dir, STANDING);
   }

   // animated movement
   else {
      // erases the old image
      al_draw_filled_rectangle(x, y, x + 16, y + 16, al_map_rgb(0,0,0));

      // moves the character
      move(movement);

      // draws the moved character
      drawState(movement, state);
   }
}
void _StateDraw(void)
{
	if (drawState == NULL | currentState == STATE_UNKNOW)
	{
		printf("[ERROR]\tdrawState() is NULL, no instance selected\n");
		//getc();
		exit(1);
	}
	else
		drawState();
}
void snakeEffect(int time, int drawTime) {
    emptyCube();

    //Snake* snake1 = new Snake(5, 0);
    Snake* snake2 = new Snake(6, 25);

    drawState(drawTime);

    NonBlockDelay timer;
    timer.delay(time);

    while(!timer.timeout()) {
        //snake1->update();
        snake2->update();

        drawState(drawTime);
    }

    //delete snake1;
    delete snake2;
}
Exemple #9
0
void GrGpu::onDrawPath(const GrPath* path, SkPath::FillType fill,
                       const GrDeviceCoordTexture* dstCopy) {
    this->handleDirtyContext();

    drawState()->setDefaultVertexAttribs();

    GrDrawState::AutoRestoreEffects are;
    if (!this->setupClipAndFlushState(kDrawPath_DrawType, dstCopy, &are, NULL)) {
        return;
    }

    this->onGpuDrawPath(path, fill);
}
/*------------------------------------------------------------------------------
| DrawingArea::button2Down                                                     |
|                                                                              |
| Determine the object under the mouse and start moving.                       |
------------------------------------------------------------------------------*/
DrawingArea& DrawingArea::button2Down( const IPoint& point )
{
  if (drawState() == notDrawing)
  {
    moveGraphic = graphicList()->topGraphicUnderPoint( point, gc );
    if ( moveGraphic )
    {
      moveRect.setEnclosingRect(moveGraphic->boundingRect( gc ));
      previousPt = point;
      startingPt = point;
      capturePointer();
    }
  }
  return *this;
}
Exemple #11
0
void GrGpu::onDrawPaths(size_t pathCount, const GrPath** paths,
                        const SkMatrix* transforms, SkPath::FillType fill,
                        SkStrokeRec::Style style,
                        const GrDeviceCoordTexture* dstCopy) {
    this->handleDirtyContext();

    drawState()->setDefaultVertexAttribs();

    GrDrawState::AutoRestoreEffects are;
    if (!this->setupClipAndFlushState(kDrawPaths_DrawType, dstCopy, &are, NULL)) {
        return;
    }

    this->onGpuDrawPaths(pathCount, paths, transforms, fill, style);
}
Exemple #12
0
void GrGpu::onDrawPaths(const GrPathRange* pathRange,
                        const uint32_t indices[], int count,
                        const float transforms[], PathTransformType transformsType,
                        SkPath::FillType fill, const GrDeviceCoordTexture* dstCopy) {
    this->handleDirtyContext();

    drawState()->setDefaultVertexAttribs();

    GrDrawState::AutoRestoreEffects are;
    if (!this->setupClipAndFlushState(kDrawPaths_DrawType, dstCopy, &are, NULL)) {
        return;
    }

    pathRange->willDrawPaths(indices, count);
    this->pathRendering()->drawPaths(pathRange, indices, count, transforms, transformsType, fill);
}
Exemple #13
0
// Main on-paint handler
void display(void) {

	// propagate system
	if(!pause)
		calculateEvolution(params, state, params.dt_evo);

	// fill vertex buffers with state graphs
	drawState(params, state, a_xy, b_xy, a_zy, b_zy);

	int t = (int)(state.t * params.t_rho * 1000.0); // time in ms
	if(t > 300)
	{
		exit(0);
	}

/*
	if(t % 5 == 0)
	{
		char fname[255];
		sprintf(fname, "screenshot%03d.bmp", t);
		createBitmap(fname, state.to_bmp, params.nvz, params.nvy);
	}
*/

	// draw graphs

	glEnable(GL_TEXTURE_2D);

	// clear screen
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
	glClearDepth(1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	float sizex = params.xmax / (params.xmax + params.zmax);
	float sizez = params.zmax / (params.xmax + params.zmax);
	a_xy.draw(0, 0, sizex, 0.5);
	b_xy.draw(0, 0.5, sizex, 0.5);
	a_zy.draw(sizex, 0, sizez, 0.5);
	b_zy.draw(sizex, 0.5, sizez, 0.5);

	glutSwapBuffers();
	glutPostRedisplay();

	char title[256];
	sprintf(title, "Two-component BEC evolution: %d ms", t);
	glutSetWindowTitle(title);
}
Exemple #14
0
bool Board::invalidate()
{
  Figure::Color ocolor = Figure::otherColor(color_);

  int ki_pos = kingPos(color_);
  int oki_pos = kingPos(ocolor);

  state_ = Ok;

  if ( isAttacked(color_, oki_pos) )
  {
    state_ = Invalid;
    return false;
  }

  if ( isAttacked(ocolor, ki_pos) )
    state_ |= UnderCheck;

  verifyChessDraw();

  if ( drawState() )
    return true;

  int cnum = findCheckingFigures(ocolor, ki_pos);
  if ( cnum > 2 )
  {
    state_ = Invalid;
    return false;
  }
  else if ( cnum > 0 )
  {
    state_ |= UnderCheck;
  }

  verifyState();

  return true;
}
/*------------------------------------------------------------------------------
| DrawingArea::button1Down                                                     |
|                                                                              |
| Handle button 1 down messages.  This event indicates a new graphic object is |
| to be created of additional data points to add to an existing graphic object.|
------------------------------------------------------------------------------*/
DrawingArea& DrawingArea::button1Down( const IPoint& point )
{
  switch (currentObj)
  {
    case move: // Button 1 drag
      if (drawState() == notDrawing)
      {
        moveGraphic = graphicList()->topGraphicUnderPoint( point, gc );
        if ( moveGraphic )
        {
          moveRect.setEnclosingRect(moveGraphic->boundingRect( gc ));
          previousPt = point;
          startingPt = point;
          capturePointer();
        }
      }
    break;
    case eraser:
      {
        // Delete the object under the pointer
        moveGraphic = graphicList()->topGraphicUnderPoint( point, gc );
        if ( moveGraphic )
        {
          moveRect.setEnclosingRect(moveGraphic->boundingRect( gc ));
          IGList::Cursor cursor( *graphicList(), gc, point );
          for (cursor.setToFirst(); cursor.isValid(); cursor.setToNext())
          {
             IGraphic* graphic(&(graphicList()->graphicAt(cursor)));
             if (graphic == moveGraphic)
             {
               graphicList()->removeAt(cursor);
               delete graphic;
               this->refresh( moveRect.boundingRect(gc).expandBy(2) );
               moveRect.resetTransformMatrix();
               moveGraphic = 0;
               break;
             }
          }
        }
      }
    break;
    case stylecan:
    {
      // Change all objects to the current pen and fill color.
      IRectangle tempRect;
      moveGraphic = graphicList()->topGraphicUnderPoint( point, gc );
      if( moveGraphic )
      {
        tempRect = moveGraphic->boundingRect( gc );
        moveGraphic->setGraphicBundle( currentBundle );
        moveGraphic->drawOn( gc );
        tempRect |= moveGraphic->boundingRect( gc );
        this->refresh( tempRect.expandBy(2) );
        moveGraphic = 0;
      }
    }
    break;
    case line:
      startingPt = point;
      previousPt = point;
      iGraphic = new IGLine( startingPt, previousPt );
      setDrawState();
    break;
    case freehand:
      iGraphic = new IGPolygon(IPointArray());
      ((IGPolygon*)iGraphic)->addPoint( point );
      setDrawState();
    break;
    case rectangle:
      startingPt = point;
      previousPt = point;
      iGraphic = new IGRectangle(IRectangle(startingPt, previousPt));
      setDrawState();
    break;
    case ellipse:
      startingPt = point;
      previousPt = point;
      iGraphic = new IGEllipse( startingPt, 0L );
      setDrawState();
    break;
    case polyline:
    case polygon:
      if (drawState() == notDrawing)
      {
        startingPt = point;
        previousPt = point;
        if (currentObj == polyline)
          iGraphic = new IGPolyline(IPointArray());
        else
          iGraphic = new IGPolygon(IPointArray());

        ((IGPolyline*)iGraphic)->addPoint( startingPt );
        ((IGPolyline*)iGraphic)->addPoint( previousPt );
        setDrawState();
      }
      else
      {
        ((IGPolyline*)iGraphic)->IGPolyline::drawOn( gc );
        ((IGPolyline*)iGraphic)->addPoint( point );
        ((IGPolyline*)iGraphic)->IGPolyline::drawOn( gc );
      }
    break;
    case arc:
      pointCount++;
      if (drawState() == notDrawing)
      {
        iGraphic = new IG3PointArc( point, IPoint(0,0), IPoint(0,0) );
        startingPt = point;
        previousPt = point;
      }
      else if ( pointCount == 2 )
      {
        previousPt = point;
        IGLine tempLine( ((IG3PointArc*)iGraphic)->startingPoint(), point );
        tempLine.drawOn( gc );
      }
      else if ( pointCount == 3 )
      {
        IGLine tempLine( ((IG3PointArc*)iGraphic)->startingPoint(), previousPt );
        tempLine.drawOn( gc );
        previousPt = point;
        ((IG3PointArc*)iGraphic)->setEndingPoint( point );
        iGraphic->drawOn( gc );
      }
      setDrawState();
    break;
    case pie:
    case chord:
      pointCount++;
      if (drawState() == notDrawing)
      {
        if (currentObj == pie)
          iGraphic = new IGPie( IRectangle(), 0, 0);
        else
          iGraphic = new IGChord( IRectangle(), 0, 0);

        ((IGPie*)iGraphic)->setEnclosingRect(
                             ((IGPie*)iGraphic)->enclosingRect().centerAt( point ));
        startingPt = point;
        previousPt = point;
      }
      else if ( pointCount == 2 )
      {
        previousPt = point;
        IGLine tempLine( ((IGPie*)iGraphic)->enclosingRect().center(), point );
        tempLine.drawOn( gc );
      }
      else if ( pointCount == 3 )
      {
        IGLine tempLine( ((IGPie*)iGraphic)->enclosingRect().center(), previousPt );
        tempLine.drawOn( gc );
        previousPt = point;
        double sweep(angleFromPoints( ((IGPie*)iGraphic)->enclosingRect().center(), point ));
        if ( sweep < ((IGPie*)iGraphic)->startAngle() )
          ((IGPie*)iGraphic)->setSweepAngle( 360.0 -
                                ( ((IGPie*)iGraphic)->startAngle() - sweep ));
        else
          ((IGPie*)iGraphic)->setSweepAngle( sweep -
                                            ((IGPie*)iGraphic)->startAngle());
        iGraphic->drawOn( gc );
      }
      setDrawState();
    break;
    case text:
      setDrawState();
    break;
    case bitmap:
      setDrawState();
    break;
  } /* endswitch */
  return *this;
}
/*------------------------------------------------------------------------------
| DrawingArea::mouseMoved                                                      |
|                                                                              |
| Handle button 1 down mouse move events.  This allows data points to be       |
| moved while the object is drawn with a rubber band effect.                   |
------------------------------------------------------------------------------*/
Boolean DrawingArea::mouseMoved( IMouseEvent& event )
{
  IPoint point(event.mousePosition());
  if ( hasPointerCaptured() )
  {
    IRectangle windowRect(this->rect());
    windowRect.moveTo(IPoint(0,0));
    if (!windowRect.contains(point))
    {
      if ((short)point.x() < (short)windowRect.left())
        point.setX(windowRect.left());
      else if ((short)point.x() > (short)windowRect.right())
        point.setX(windowRect.right());
      else if ((short)point.y() < (short)windowRect.bottom())
        point.setY(windowRect.bottom());
      else if ((short)point.y() > (short)windowRect.top())
        point.setY(windowRect.top());

      IPoint mapPt( IWindow::mapPoint( point,
                                       this->handle(),
                                       IWindow::desktopWindow()->handle()));

      IWindow::movePointerTo( mapPt );
    }
  }

  // If we're not moving an object
  if (!moveGraphic)
  {
    if (( drawState() == drawing ) || ( drawState() == waitingForInput ))
    {
      switch (currentObj)
      {
        case move:
        break;
        case eraser:
        break;
        case stylecan:
        break;
        case line:
          ((IGLine*)iGraphic)->drawOn( gc );
          ((IGLine*)iGraphic)->setEndingPoint( point );
          ((IGLine*)iGraphic)->drawOn( gc );
        break;
        case freehand:
          ((IGPolygon*)iGraphic)->addPoint( point );
          ((IGPolyline*)iGraphic)->IGPolyline::drawOn( gc );
        break;
        case rectangle:
        {
          IRectangle rc(((IGRectangle*)iGraphic)->enclosingRect());
          iGraphic->drawOn( gc );
          rc.sizeTo( rc.size() + point - previousPt );
          ((IGRectangle*)iGraphic)->setEnclosingRect( rc );
          iGraphic->drawOn( gc );
          previousPt = point;
        }
        break;
        case ellipse:
        {
          iGraphic->drawOn( gc );
          IRectangle rc(((IGEllipse*)iGraphic)->enclosingRect());
          rc.sizeTo( rc.size() + point - previousPt );
          ((IGEllipse*)iGraphic)->setEnclosingRect( rc );
          iGraphic->drawOn( gc );
          previousPt = point;
        }
        break;
        case polyline:
        case polygon:
          ((IGPolyline*)iGraphic)->IGPolyline::drawOn( gc );
          ((IGPolyline*)iGraphic)->setPoint(
                           ((IGPolyline*)iGraphic)->numberOfPoints()-1, point );
          ((IGPolyline*)iGraphic)->IGPolyline::drawOn( gc );
        break;
        case arc:
          if (drawState() != waitingForInput)
          {
            if ( pointCount == 2 )
            {
              IGLine tempLine( ((IG3PointArc*)iGraphic)->startingPoint(), previousPt );
              tempLine.drawOn( gc );
              tempLine.setEndingPoint( point );
              tempLine.drawOn( gc );
              previousPt = point;
            } else if ( pointCount == 3 ) {
              iGraphic->drawOn( gc );
              ((IG3PointArc*)iGraphic)->setEndingPoint( point );
              iGraphic->drawOn( gc );
            }
          } /* endif */
        break;
        case pie:
        case chord:
          if (drawState() != waitingForInput)
          {
            if ( pointCount == 2 )
            {
              IGLine tempLine( ((IGPie*)iGraphic)->enclosingRect().center(), previousPt );
              tempLine.drawOn( gc );
              tempLine.setEndingPoint( point );
              tempLine.drawOn( gc );
              previousPt = point;
            } else if ( pointCount == 3 ) {
              iGraphic->drawOn( gc );
              double sweep(angleFromPoints( ((IGPie*)iGraphic)->enclosingRect().center(), point ));
              if ( sweep < ((IGPie*)iGraphic)->startAngle() )
                ((IGPie*)iGraphic)->setSweepAngle( 360.0 -
                                    ( ((IGPie*)iGraphic)->startAngle() - sweep ));
              else
                ((IGPie*)iGraphic)->setSweepAngle( sweep -
                                                ((IGPie*)iGraphic)->startAngle());
              iGraphic->drawOn( gc );
            }
          } /* endif */
        break;
      } /* endswitch */
    }
  }
  else  // We are moving a graphic
  {
    moveRect.drawOn( gc );
    moveRect.translateBy( point - previousPt );
    moveRect.drawOn( gc );
    previousPt = point;
  }
  return false;
}
Exemple #17
0
void StarView::drawNodeStatus()
{
    QMap<unsigned int, HostItem*>::ConstIterator it;
    for (it = m_hostItems.constBegin(); it != m_hostItems.constEnd(); ++it)
        drawState(*it);
}
// Draw the screen
void LightScreen::draw(GLHandler* mgl, TextureAtlas* mAtlas){
	UIScreen::draw(mgl, mAtlas);
	
	// Set proj matrix 
	mgl->setProjectionMatrix(mgl->orthoMatrix);

	// Draw lights
	if (drawLight){
		float value = .5f * (1.0f - lightDarkness);
		mgl->lightBegin(value,value,value);
		lMap.drawMap(mgl);
		mgl->lightEnd();
	}
	
	// Bind UI Matrix's
	mAtlas->bindBuffers(mgl);
	mAtlas->bindTexture(mgl);

	// Enable light 
	if (drawLight) 
		mgl->enableLight(true);

	mgl->setFlatColor(0.875f, 0.875f, 0.875f, 1.0f);
	((UIAtlas*)mAtlas)->drawScale2(mgl, UII_REC, 0.0f,0.0f,screen_width, screen_height);
	// Draw boxes 
	bHand->draw(mgl, (UIAtlas*)mAtlas);
	mgl->enableLight(false);

	// State specific things 
	drawState(mgl, (UIAtlas*)mAtlas);

	//---------------------
	// Draw UI 
	
	// Map debug  
	lMap.drawDebug(mgl, (UIAtlas*)mAtlas);
	// Menu line 
	mgl->setFlatColor(.0f,.0f,.0f,bMove->getOpacity());
	((UIAtlas*)mAtlas)->drawScale2(mgl, UII_REC, 0.0f,0.0f,menuWidth+1.0f, screen_height);
	// Menu Background
	mgl->setFlatColor(.19f,.2f,.2f,bMove->getOpacity());
	((UIAtlas*)mAtlas)->drawScale2(mgl, UII_REC, 0.0f,0.0f,menuWidth, screen_height);
	// Draw method boxes 
	mgl->setFlatColor(.25f,.25f,.25f,bMove->getOpacity());
	((UIAtlas*)mAtlas)->drawScale2(mgl, UII_REC, method1Box.getX(), method1Box.getY(),
		method1Box.getWidth(), method1Box.getHeight());
	((UIAtlas*)mAtlas)->drawScale2(mgl, UII_REC, method2Box.getX(), method2Box.getY(),
		method2Box.getWidth(), method2Box.getHeight());

	// Draw buttons
	lTitle->draw(mgl, (UIAtlas*)mAtlas);
	bShow->draw(mgl, (UIAtlas*)mAtlas);
	bHide->draw(mgl, (UIAtlas*)mAtlas);
	bMove->draw(mgl, (UIAtlas*)mAtlas);
	bSetLight->draw(mgl, (UIAtlas*)mAtlas);
	bAdd->draw(mgl, (UIAtlas*)mAtlas);
	bRemove->draw(mgl, (UIAtlas*)mAtlas);
	bClear->draw(mgl, (UIAtlas*)mAtlas);
	cbShowLight->draw(mgl, (UIAtlas*)mAtlas);
	lLightSize->draw(mgl, (UIAtlas*)mAtlas);
	vsLightSize->draw(mgl, (UIAtlas*)mAtlas);
	lRayCount->draw(mgl, (UIAtlas*)mAtlas);
	vsRayCount->draw(mgl, (UIAtlas*)mAtlas);
	lDarkness->draw(mgl, (UIAtlas*)mAtlas);
	vsDarkness->draw(mgl, (UIAtlas*)mAtlas);
	cbMethod1->draw(mgl, (UIAtlas*)mAtlas);
	cbMethod2->draw(mgl, (UIAtlas*)mAtlas);
}
Exemple #19
0
int main(int argc, char *argv[])
{
    if(init()) return 1;

    if(argc < 2)
        WSreset();
    else
    {
        if(WSfread(argv[1]))
            WSreset();
    }

    int is_running = 1;
    int is_buttons_visible = 1;
    char keyst[0x200];
    memset(&keyst, 0, 0x200);
    int _drawRedScreen = 0;

    while(is_running)
    {
        if(_drawRedScreen) _drawRedScreen --;
        boxColor(screen, 0, 0, scr_w_-1, scr_h_-1, 0xff);
        WSdraw(screen);

        int i;
        if(is_buttons_visible)
        {
            for(i = 0; i < buttons_total; i++)
            {
                SCHbtnDraw(buttons[i],screen);
            }
        }

        int s; for(s = 0; s < 0x200; s++)
        {
            if(keyst[s] == KST_DOWN)
                keyst[s] = KST_PRESSED;
            if(keyst[s] == KST_UP)
                keyst[s] = KST_NONE;
        }

        SDL_Event ev;
        while(SDL_PollEvent(&ev))
        {
            if(!INisActive())
            {
                for(i = 0; i < buttons_total; i++)
                    SCHbtnLoop(buttons[i], &ev);
                WSloop(&ev);
            }

            /* Kbd handling */
            switch(ev.type)
            {
                case SDL_KEYDOWN: keyst[ev.key.keysym.sym] = KST_DOWN; break;
                case SDL_KEYUP: keyst[ev.key.keysym.sym] = KST_UP; break;

                /* Also we looking for quit signals */
                case SDL_QUIT: is_running = 0;
            }
        }

        if(INisActive())
        {

            int s,v;
            for(s = 0; s < 0x200; s++)
            {
                if(keyst[s] == KST_DOWN)
                {
                    if(!INsendKey(s))
                    {
                        for(v = 0; v < TOOLBUTTON; v++)
                        {
                            if(SCHgetBtnState(buttons[v])&BTNSTATE_CLICKED)
                            {
                                char *t = INgetResult();

                                if(v == BUTTON_LOAD)
                                {
                                    if(WSfread(t))
                                        _drawRedScreen = REDSCR_TIME;
                                }

                                else if(v == BUTTON_SAVE)
                                {
                                    if(WSfwrite(t))
                                        _drawRedScreen = REDSCR_TIME;
                                }

                                else if(v == BUTTON_RESIZE)
                                {
                                    int nw, nh;
                                    if(sscanf(t, "%u %u", &nw, &nh) == 2 && (nw > 0 && nh > 0))
                                        WSresize(nw, nh);
                                    else
                                        _drawRedScreen = REDSCR_TIME;
                                }

                                free(t);
                                SCHbtnLoop(buttons[v], NULL);
                            }
                        }
                    }
                }
            }

        }
        else
        {

            /* Workspace movement */
            if(keyst[SDLK_UP])      WSmove(DIR_UP);
            if(keyst[SDLK_RIGHT])   WSmove(DIR_RIGHT);
            if(keyst[SDLK_DOWN])    WSmove(DIR_DOWN);
            if(keyst[SDLK_LEFT])    WSmove(DIR_LEFT);

            /* Toggling buttons visibility */
            if(keyst[SDLK_p] == KST_DOWN)
                is_buttons_visible =! is_buttons_visible;

            if(is_buttons_visible)
            {

                /* SCHbuttons proc */
                if(SCHgetBtnState(buttons[BUTTON_QUIT])&BTNSTATE_CLICKED)
                    is_running = 0;

                if(SCHgetBtnState(buttons[BUTTON_NEW])&BTNSTATE_CLICKED)
                    WSreset();

                if(SCHgetBtnState(buttons[BUTTON_LOAD])&BTNSTATE_CLICKED)
                {
                    char *tmp = WSgetFileName();
                    INstart("Load a file:", tmp);
                    free(tmp);
                }

                if(SCHgetBtnState(buttons[BUTTON_SAVE])&BTNSTATE_CLICKED)
                {
                    char *tmp = WSgetFileName();
                    INstart("Save to file:", tmp);
                    free(tmp);
                }

                if(SCHgetBtnState(buttons[BUTTON_RESIZE])&BTNSTATE_CLICKED)
                {
                    char *tmp = WSgetFileName();
                    INstart("Resize (w h):", NULL);
                    free(tmp);
                }

                if(SCHgetBtnState(buttons[BUTTON_TOOL_ERASE])&BTNSTATE_CLICKED)
                    tool = -1;

                int a;
                for(a = 0; a < WSgetToolsCount(); a++)
                {
                    if(SCHgetBtnState(buttons[TOOLBUTTON+a])&BTNSTATE_CLICKED)
                        tool = a;
                }

                for(a = SDLK_0; a <= SDLK_9; a++)
                {
                    if(keyst[a] == KST_DOWN)
                        tool = a - SDLK_0;
                }

            }

        }

        drawState();
        if(INisActive())
            INdraw(screen, ui_font);

        if(_drawRedScreen)
            boxColor(screen, 0, 0, scr_w_-1, scr_h_-1, 0xcc0000aa);
        SDL_Flip(screen);

        /* FPS controller */
        static unsigned int fps = 0;
        static unsigned int now = 0;
        static unsigned int then = 0;
        static unsigned int frames = 0;

#define FPS 60 /* must be > 0 */

        now = SDL_GetTicks();
        if (now > then) fps = (++frames*1000)/(now-then);
        if (fps >= FPS) SDL_Delay(1000/FPS);

#undef FPS

    }

    printf("Shuttin` down.\n");

    SDL_Quit();
    return 0;
}
void TButton::handleEvent( TEvent& event )
{
    TPoint mouse;
    TRect clickRect;

    clickRect = getExtent();
    clickRect.a.x++;
    clickRect.b.x--;
    clickRect.b.y--;

    if( event.what == evMouseDown )
        {
        mouse = makeLocal( event.mouse.where );
        if( !clickRect.contains(mouse) )
            clearEvent( event );
        }
    TView::handleEvent(event);

    switch( event.what )
        {
        case evMouseDown:
            clickRect.b.x++;
            Boolean down = False;
            do  {
                mouse = makeLocal( event.mouse.where );
                if( down != clickRect.contains( mouse ) )
                    {
                    down = Boolean( !down );
                    drawState( down );
                    }
                } while( mouseEvent( event, evMouseMove ) );
            if( down )
                {
                press();
                drawState( False );
                }
            clearEvent( event );
            break;

        case evKeyDown:
            char c = hotKey( title );
            if( event.keyDown.keyCode == getAltCode(c) ||
                ( owner->phase == phPostProcess &&
                  c != 0 &&
                  toupper(event.keyDown.charScan.charCode) == c
                ) ||
                ( (state & sfFocused) != 0 &&
                  event.keyDown.charScan.charCode == ' '
                )
              )
                {
                press();
                clearEvent( event );
                }
            break;

        case evBroadcast:
            switch( event.message.command )
                {
                case cmDefault:
                    if( amDefault )
                        {
                        press();
                        clearEvent(event);
                        }
                    break;

                case cmGrabDefault:
                case cmReleaseDefault:
                    if( (flags & bfDefault) != 0 )
                        {
                        amDefault = Boolean(event.message.command == cmReleaseDefault);
                        drawView();
                        }
                    break;

                case cmCommandSetChanged:
                    setState(sfDisabled,Boolean(!commandEnabled(command)));
                    drawView();
                    break;
                }
        break;
        }
}
void TButton::draw()
{
    drawState(False);
}
/*------------------------------------------------------------------------------
| DrawingArea::button1Up                                                       |
|                                                                              |
| Handle button 1 up events.  This indicates a data points final location.     |
------------------------------------------------------------------------------*/
DrawingArea& DrawingArea::button1Up( const IPoint& point )
{
  if ( drawState() == drawing )
  {
    switch (currentObj)
    {
      case move:
      break;
      case eraser:
      break;
      case stylecan:
      break;
      case line:
        ((IGLine*)iGraphic)->setEndingPoint( point );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      break;
      case freehand:
        ((IGPolygon*)iGraphic)->addPoint( point );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      break;
      case rectangle:
      {
        IRectangle rc(((IGRectangle*)iGraphic)->enclosingRect());
        rc.sizeTo( rc.size() + point - previousPt );
        ((IGRectangle*)iGraphic)->setEnclosingRect( rc );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      }
      break;
      case ellipse:
      {
        IRectangle rc(((IGEllipse*)iGraphic)->enclosingRect());
        rc.sizeTo( rc.size() + point - previousPt );
        ((IGEllipse*)iGraphic)->setEnclosingRect( rc );

        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      }
      break;
      case polyline:
      case polygon:
        previousPt = point;
        ((IGPolyline*)iGraphic)->setPoint(
                         ((IGPolyline*)iGraphic)->numberOfPoints()-1, point );
        setDrawState( waitingForInput );
      break;
      case arc:
      if ( pointCount == 2 )
      {
        ((IG3PointArc*)iGraphic)->setIntermediatePoint( point );
        gc.setMixMode( IGraphicBundle::xor ).setPenColor( IColor::white );
        IGLine tempLine( ((IG3PointArc*)iGraphic)->startingPoint(), previousPt );
        tempLine.drawOn( gc );
        tempLine.setEndingPoint( point );
        tempLine.drawOn( gc );
        setDrawState( waitingForInput );
      }
      else if ( pointCount == 3 )
      {
        gc.setMixMode( IGraphicBundle::xor ).setPenColor( IColor::white );
        iGraphic->drawOn( gc );
        ((IG3PointArc*)iGraphic)->setEndingPoint( point );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
        pointCount = 0;
      }
      break;
      case pie:
      case chord:
      if ( pointCount == 2 )
      {
        gc.setMixMode( IGraphicBundle::xor ).setPenColor( IColor::white );
        setDrawState( waitingForInput );
        IPoint centerPt(((IGPie*)iGraphic)->enclosingRect().center());

        ((IGPie*)iGraphic)->setStartAngle( angleFromPoints( centerPt, point ));

        unsigned a(abs(centerPt.x()) - abs(point.x()));
        unsigned b(abs(centerPt.y()) - abs(point.y()));

        unsigned long radius((unsigned long)sqrtl(a*a + b*b));

        ((IGPie*)iGraphic)->setEnclosingRect(
           ((IGPie*)iGraphic)->enclosingRect().expandBy(radius));
      }
      else if ( pointCount == 3 )
      {
        gc.setMixMode( IGraphicBundle::xor ).setPenColor( IColor::white );
        iGraphic->drawOn( gc );

        double sweep(angleFromPoints(
                              ((IGPie*)iGraphic)->enclosingRect().center(), point ));

        if ( sweep < ((IGPie*)iGraphic)->startAngle() )
          ((IGPie*)iGraphic)->setSweepAngle( 360.0 -
                                ( ((IGPie*)iGraphic)->startAngle() - sweep ));
        else
          ((IGPie*)iGraphic)->setSweepAngle( sweep -
                                            ((IGPie*)iGraphic)->startAngle());

        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
        pointCount = 0;
      }
      break;
      case text:
      {
        IString input;

        IDynamicLinkLibrary reslib("CPPWV53R");

        if (point.x() % 2)
          input = reslib.loadString( STRING_SAMPLE1 );
        else if ((point.y() % 5)==1)
          input = reslib.loadString( STRING_SAMPLE3 );
        else if ((point.y() % 5)==3)
          input = reslib.loadString( STRING_SAMPLE4 );
        else
          input = reslib.loadString( STRING_SAMPLE2 );

        IGString* text = new IGString( input.x2c(), point, currentFont());
//      IGString* text = new IGString( "Doodle", point, currentFont());
        text->rotateBy( 10.0, point );
        text->setGraphicBundle( currentBundle );
        text->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *text );
      }
      break;
      case bitmap:
      {
        IGBitmap *bmp;
//      if (bitmapFileName().length() > 0)
//      {
//        bmp = new IGBitmap(bitmapFileName());
//      }

        // Select a bitmap to load
        IDynamicLinkLibrary reslib("CPPWV53R");

        if (point.x() % 2)
          bmp = new IGBitmap(reslib.loadBitmap( BITMAP_SAMPLE1 ));
        else if ((point.y() % 5)==1)
          bmp = new IGBitmap(reslib.loadBitmap( BITMAP_SAMPLE3 ));
        else if ((point.y() % 5)==3)
          bmp = new IGBitmap(reslib.loadBitmap( BITMAP_SAMPLE4 ));
        else
          bmp = new IGBitmap(reslib.loadBitmap( BITMAP_SAMPLE2 ));

        bmp->moveTo( point );
        bmp->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *bmp );
      }
      break;
    } /* endswitch */
  } /* endif */
  else  // not drawing
  {
    switch (currentObj)
    {
      case move:
        if (moveGraphic && capturePointer)
        {
          moveRect.translateBy( point - previousPt );
          moveRect.drawOn( gc );
          moveRect.resetTransformMatrix();
          this->refresh( moveRect.boundingRect(gc).expandBy(2) );
          moveGraphic->translateBy( point - startingPt );
          moveGraphic->drawOn( gc );
          moveGraphic = 0;
          capturePointer(false);
        }
      break;
    }
  }
  return *this;
}