Esempio n. 1
0
//----------------------------------------------------------------------------
//
//	InsertImage() - method to insert image into micro manager buffer pool
//
//----------------------------------------------------------------------------
int CScionCamera::InsertImage()
{
const unsigned char* img;

#ifdef	LOG_ENABLED
//sLogMessage("insert image in micro manager pool\r\n");
#endif

// call to GetImageBuffer will complete any pending capture
img = GetImageBuffer();
if (img == 0) 
	{	
	return DEVICE_ERR;
	}

int ret = GetCoreCallback()->InsertImage(this, img, GetImageWidth(), 
								GetImageHeight(), GetImageBytesPerPixel());

if (!stopOnOverflow_ && ret == DEVICE_BUFFER_OVERFLOW)
	{
	// do not stop on overflow - just reset the buffer
	GetCoreCallback()->ClearImageBuffer(this);
	return(GetCoreCallback()->InsertImage(this, img, 
				GetImageWidth(), GetImageHeight(), GetImageBytesPerPixel()));
	} 
else
	{
	return ret;
	}
}
Esempio n. 2
0
void CameraObject::VideoUpdatedSlot()
{
    if( IsRecording() && GetState() == Ok )
    {
        m_recordingCamera->AddFrame( GetVideoOutput(), GetUncalibratedTransform()->GetMatrix() );
    }

    // Update representation if image size changed
    if( GetImageWidth() != m_cachedImageSize[0] || GetImageHeight() != m_cachedImageSize[1] )
        UpdateGeometricRepresentation();

    // Get the position of the transparency center from projection of the tracked pointer
    if( m_trackedTransparencyCenter )
    {
        Q_ASSERT( this->GetManager() );
        PointerObject * navPointer = this->GetManager()->GetNavigationPointerObject();
        if( navPointer )
        {
            // Get world space position of the tip
            double * tip = navPointer->GetTipPosition();
            double cx, cy;
            WorldToImage( tip, cx, cy );

            // Set new center for transparency
            SetTransparencyCenter( cx / GetImageWidth(), cy / GetImageHeight() );
        }
    }

    UpdateVtkCamera();

    emit VideoUpdatedSignal();
    emit ObjectModified();
}
Esempio n. 3
0
void CameraObject::WorldToImage( double * worldPos, double & xIm, double & yIm )
{
    double p4[4];
    p4[0] = worldPos[0];
    p4[1] = worldPos[1];
    p4[2] = worldPos[2];
    p4[3] = 1.0;

    vtkMatrix4x4 * mat = vtkMatrix4x4::New();
    mat->DeepCopy( m_opticalCenterTransform->GetMatrix() );
    mat->Invert();
    double pCam[4] = { 0.0, 0.0, 0.0, 1.0 };
    mat->MultiplyPoint( p4, pCam );
    mat->Delete();

    double centerPix[2] = { 0.0, 0.0 };
    GetImageCenterPix( centerPix[0], centerPix[1] );
    double focalPix[2] = { 0.0, 0.0 };
    GetFocalPix( focalPix[0], focalPix[1] );

    xIm = centerPix[0] + pCam[0] / pCam[2] * focalPix[0];
    yIm = centerPix[1] + pCam[1] / pCam[2] * focalPix[1];
    xIm = GetImageWidth() - xIm - 1.0;
    yIm = GetImageHeight() - yIm - 1.0;
}
Esempio n. 4
0
void DrawSdk::Image::Draw(HDC hdc, double offX, double offY, ZoomManager *pZm)
{
   Gdiplus::Graphics graphics(hdc);
   graphics.TranslateTransform(offX, offY);
   if (pZm != NULL)
   {
      double zoom = pZm->GetZoomFactor();
      graphics.ScaleTransform(zoom, zoom);
   }
   
   if (gdipImage_)
   {
      Gdiplus::Status status;

      Gdiplus::RectF boundRect;
      Gdiplus::Unit boundUnit;
      gdipImage_->GetBounds(&boundRect, &boundUnit);

      Gdiplus::RectF destRect;
      destRect.X = x_;
      destRect.Y = y_;
      destRect.Width = width_;
      destRect.Height = height_;

     
      graphics.SetCompositingQuality(Gdiplus::CompositingQualityHighSpeed);
      graphics.SetCompositingMode(Gdiplus::CompositingModeSourceOver);
      graphics.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);

      status = graphics.DrawImage(gdipImage_, destRect, 
         boundRect.X, boundRect.Y, GetImageWidth(), GetImageHeight(), Gdiplus::UnitPixel);
   }
}
Esempio n. 5
0
int CScionCamera::StartSequenceAcquisition(long numImages, 
				double interval_ms, bool stopOnOverflow)
{
#ifdef	LOG_ENABLED
sLogMessage("start seqquence acquisition\r\n");
#endif

if (Busy() || sequenceRunning_)
	{return DEVICE_CAMERA_BUSY_ACQUIRING;}

// prepare core
int ret = GetCoreCallback()->PrepareForAcq(this);
if (ret != DEVICE_OK)
	{return ret;}

// make sure the circular buffer is properly sized
GetCoreCallback()->InitializeImageBuffer(1, 1, GetImageWidth(), 
							GetImageHeight(), GetImageBytesPerPixel());

stopOnOverflow_ = stopOnOverflow;
interval_ms = interval_ms;
sequenceLength_ = numImages;
image_counter_ = 0;

ctp->SetLength(numImages);
ctp->Start();

sequenceRunning_ = true;

return DEVICE_OK;
}
Esempio n. 6
0
void CameraObject::Setup( View * view )
{
    if( view->GetType() == THREED_VIEW_TYPE )
    {
        // turn on live video acquisition
        AddClient();

        // Make sure we receive interaction event from this view
        view->AddInteractionObject( this, 0.5 );

        PerViewElements perView;
        perView.cameraBackup = nullptr;

        vtkPolyDataMapper * camMapper = vtkPolyDataMapper::New();
        camMapper->SetInputData( m_cameraPolyData );
        perView.cameraActor = vtkActor::New();
        perView.cameraActor->SetMapper( camMapper );
        camMapper->Delete();
        perView.cameraActor->SetUserTransform( m_opticalCenterTransform );
        view->GetRenderer()->AddActor( perView.cameraActor );

        perView.cameraAxesActor = vtkAxesActor::New();
        perView.cameraAxesActor->SetTotalLength( 50, 50, 50 );
        perView.cameraAxesActor->AxisLabelsOff();
        perView.cameraAxesActor->SetUserTransform( m_opticalCenterTransform );
        view->GetRenderer()->AddActor( perView.cameraAxesActor );

        perView.cameraTrackerAxesActor = vtkAxesActor::New();
        perView.cameraTrackerAxesActor->SetTotalLength( 50, 50, 50 );
        perView.cameraTrackerAxesActor->AxisLabelsOff();
        perView.cameraTrackerAxesActor->SetUserTransform( this->m_uncalibratedWorldTransform );
        view->GetRenderer()->AddActor( perView.cameraTrackerAxesActor );

        perView.cameraImageActor = vtkSimpleProp3D::New();
        perView.cameraImageActor->SetUserTransform( m_imageTransform );

        perView.cameraImageMapper = vtkIbisImagePlaneMapper::New();
        perView.cameraImageMapper->SetGlobalOpacity( m_globalOpacity );
        perView.cameraImageMapper->SetImageCenter( m_intrinsicParams.m_center[0] * GetImageWidth(), m_intrinsicParams.m_center[1] * GetImageHeight() );
        perView.cameraImageMapper->SetLensDistortion( m_intrinsicParams.m_distorsionK1 );
        perView.cameraImageMapper->SetUseTransparency( m_useTransparency );
        perView.cameraImageMapper->SetUseGradient( m_useGradient );
        perView.cameraImageMapper->SetShowMask( m_showMask );
        perView.cameraImageMapper->SetTransparencyPosition( m_transparencyCenter[0], m_transparencyCenter[1] );
        perView.cameraImageMapper->SetTransparencyRadius( m_transparencyRadius[0], m_transparencyRadius[1] );
        perView.cameraImageActor->SetMapper( perView.cameraImageMapper );
        perView.cameraImageMapper->SetInputConnection( m_videoInputSwitch->GetOutputPort() );
        view->GetRenderer()->AddViewProp( perView.cameraImageActor );

        this->m_perViewElements[ view ] = perView;

        if( IsHidden() )
            Hide();

        connect( this, SIGNAL(ObjectModified()), view, SLOT(NotifyNeedRender()) );
    }
}
Esempio n. 7
0
/** \brief Handle updates in time of our fish
*
* This is called before we draw and allows us to
* move our fish. We add our speed times the amount
* of time that has elapsed.
* \param elapsed Time elapsed since the class call
*/
void CFish::Update(double elapsed)
{
	SetLocation(GetX() + mSpeedX * elapsed,
		GetY() + mSpeedY * elapsed);


	int reverseAtXLocation = BackgroundWidth - EdgeTolerance - (GetImageWidth() / 2);
	int reverseAtStart = BackgroundWidth - reverseAtXLocation;

	int HitTopYLocation = BackgroundHeight - 2 * EdgeTolerance - (GetImageHeight() / 2);
	int HitBottomYLocation = BackgroundHeight  - EdgeTolerance - HitTopYLocation;


	//Fish logic to stay inbounds
	if (mSpeedX > 0 && GetX() >= reverseAtXLocation)
	{
		mSpeedX = -mSpeedX;
		SetMirror(mSpeedX < 0);
	}
	else if (mSpeedX < 0 && GetX() <= reverseAtStart)
	{
		mSpeedX = abs(mSpeedX);
		SetMirror(false);
	}
	else if (mSpeedY > 0 && GetY() >= HitTopYLocation)
	{
		mSpeedY = -mSpeedY;
	}
	else if (mSpeedY < 0 && GetY() <= HitBottomYLocation)
	{
		mSpeedY = -mSpeedY;
	}

	BreedingUpdate(elapsed);
	AgeUpdate(elapsed);	

	//increases the time used to track feeding for fish
	mTimeFeeding++;

	//adjusts the fishes condtion based on the time since they were fed
	if (mTimeFeeding < TimeTillHungry)
	{
		mIsHungry = false;
		mIsDead = false;
		this->SetNotHungryImage();
	}
	else if (mTimeFeeding >= TimeTillHungry && mTimeFeeding < (TimeTillDead))
	{
		mIsHungry = true;
		this->SetHungryImage();
	}
	else if (mTimeFeeding >= TimeTillDead)
	{
		mIsDead = true;
	}
}
Esempio n. 8
0
bool CameraObject::OnMouseMoved( View * v, int x, int y, unsigned )
{
    if( m_mouseMovingTransparency )
    {
        double xIm, yIm;
        WindowToImage( x, y, v, xIm, yIm );
        SetTransparencyCenter( xIm / GetImageWidth(), yIm / GetImageHeight() );
        return true;
    }
    return false;
}
Esempio n. 9
0
bool CameraObject::OnLeftButtonPressed( View * v, int x, int y, unsigned )
{
    if( GetTrackCamera() && IsUsingTransparency() && v->GetType() == THREED_VIEW_TYPE && !m_trackedTransparencyCenter )
    {
        double xIm, yIm;
        WindowToImage( x, y, v, xIm, yIm );
        SetTransparencyCenter( xIm / GetImageWidth(), yIm / GetImageHeight() );
        m_mouseMovingTransparency = true;
        return true;
    }
    return false;
}
Esempio n. 10
0
void CameraObject::UpdateGeometricRepresentation()
{
    // Determine image size
    int width = GetImageWidth();
    int height = GetImageHeight();

    PerViewElementCont::iterator it = m_perViewElements.begin();
    while( it != m_perViewElements.end() )
    {
        PerViewElements & elem = (*it).second;
        elem.cameraImageMapper->SetImageCenter( m_intrinsicParams.m_center[0] * GetImageWidth(), m_intrinsicParams.m_center[1] * GetImageHeight() );
        elem.cameraImageMapper->SetLensDistortion( m_intrinsicParams.m_distorsionK1 );
        elem.cameraImageMapper->SetTransparencyPosition( m_transparencyCenter[0], m_transparencyCenter[1] );
        elem.cameraImageMapper->SetTransparencyRadius( m_transparencyRadius[0], m_transparencyRadius[1] );
        ++it;
    }
    m_camera->SetViewAngle( m_intrinsicParams.GetVerticalAngleDegrees() );

    double angleRad = 0.5 * m_intrinsicParams.GetVerticalAngleRad();
    double offsetY = m_imageDistance * tan( angleRad );
    double offsetX = width / ((double)height) * offsetY;
    double scaleFactor = ( 2 * offsetY ) / height;

    vtkPoints * pts = m_cameraPolyData->GetPoints();
    pts->SetPoint( 1, -offsetX, -offsetY, -m_imageDistance );
    pts->SetPoint( 2, offsetX, -offsetY, -m_imageDistance );
    pts->SetPoint( 3, offsetX, offsetY, -m_imageDistance );
    pts->SetPoint( 4, -offsetX, offsetY, -m_imageDistance );
    m_cameraPolyData->Modified();

    m_imageTransform->Identity();
    m_imageTransform->Translate( -offsetX, -offsetY, -m_imageDistance );
    m_imageTransform->Scale( scaleFactor, scaleFactor, scaleFactor );

    m_cachedImageSize[ 0 ] = width;
    m_cachedImageSize[ 1 ] = height;

    emit ParamsModified();
}
Esempio n. 11
0
/************************************************************************
 Function: void CreateAnimationDemo(void)
                                                                       
 Overview: Creates the animation screen.
 		                                                                          
 Input: none
                                                                       
 Output: none
************************************************************************/
void CreateAnimationDemo(void)
{
    SHORT   pixWidth, pixHeight;

	pixHeight = GetImageHeight((void *) &Engine1);
	pixWidth = GetImageWidth((void *) &Engine1);

    // free memory for the objects in the previous linked list and start new list
    GOLFree();

    pPicture = PictCreate
        (
            ID_PICTURE1,                        // ID
            PICTURE_XINDENT,
            PICTURE_YINDENT,
            PICTURE_XINDENT + PICTURE_WIDTH - 1,
            PICTURE_YINDENT + PICTURE_HEIGHT - 1,
            PICT_DRAW,                          // will be dislayed, has frame
            2,                                  // scale factor is x1
            (void *) &Engine1,                  // bitmap
            altScheme
        );                                      // default GOL scheme


    pMeter = MtrCreate
        (
            ID_METER1,
            (2 * PICTURE_XINDENT + PICTURE_WIDTH),
            PICTURE_YINDENT - 20,
            (2 * (PICTURE_XINDENT + PICTURE_WIDTH)),
            PICTURE_YINDENT + PICTURE_HEIGHT + 20,
            MTR_DRAW | MTR_RING | MTR_ACCURACY, // draw normal meter object
            MAX_METER_VALUE,                    // set initial value
            0,
            MAX_METER_VALUE,                    // set range
            (void *) &GOLFontDefault,           // Title font to be used
            (void *) &GOLMediumFont,            // Value font to be used
            MeterStr,                           //
            meterScheme
        );  // alternative GOL scheme

    CreateCtrlButtons(ExitStr, ScaleStr, DownStr, UpStr);

    // draw the colorful background 
    DrawBackgroundColorPalette();
}
Esempio n. 12
0
BOOL CPicapDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;

	if (!UpdateFileList(CString(lpszPathName)))
	{
		AfxMessageBox(UPDATE_FILE_LIST_FAILED_STR);
		return FALSE;
	}

	// TODO:  Add your specialized creation code here
	if (!LoadImage(CString(lpszPathName)))
	{
		AfxMessageBox(LOAD_IMAGE_FAILED_STR);
		return FALSE;
	}

    COptionsDlg::GetInstance()->SetImageSize(GetImageWidth(), GetImageHeight());

	return TRUE;
}
Esempio n. 13
0
/*********************************************************************
* Function: WORD PictDraw(PICTURE *pPict)
*
* Output: returns the status of the drawing
*		  0 - not completed
*         1 - done
*
* Overview: draws picture
*
********************************************************************/
WORD PictDraw(PICTURE *pPict)
{
    typedef enum
    {
        REMOVE,
        DRAW_IMAGE,
        DRAW_BACKGROUND1,
        DRAW_BACKGROUND2,
        DRAW_BACKGROUND3,
        DRAW_BACKGROUND4,
        DRAW_FRAME
    } PICT_DRAW_STATES;

    static PICT_DRAW_STATES state = REMOVE;
    static SHORT posleft;
    static SHORT postop;
    static SHORT posright;
    static SHORT posbottom;

    if(IsDeviceBusy())
        return (0);

    switch(state)
    {
        case REMOVE:
            if(GetState(pPict, PICT_HIDE))
            {
                SetColor(pPict->hdr.pGolScheme->CommonBkColor);
                if(!Bar(pPict->hdr.left, pPict->hdr.top, pPict->hdr.right, pPict->hdr.bottom))
                    return (0);
                return (1);
            }

            posleft = (pPict->hdr.left + pPict->hdr.right - pPict->scale * GetImageWidth(pPict->pBitmap)) >> 1;
            postop = (pPict->hdr.top + pPict->hdr.bottom - pPict->scale * GetImageHeight(pPict->pBitmap)) >> 1;
            posright = (pPict->hdr.right + pPict->hdr.left + pPict->scale * GetImageWidth(pPict->pBitmap)) >> 1;
            posbottom = (pPict->hdr.bottom + pPict->hdr.top + pPict->scale * GetImageHeight(pPict->pBitmap)) >> 1;
            state = DRAW_IMAGE;

        case DRAW_IMAGE:
            if(pPict->pBitmap != NULL)
            {
                if(IsDeviceBusy())
                    return (0);
                if(!PutImage(posleft, postop, pPict->pBitmap, pPict->scale))
                    return (0);
            }

            SetColor(pPict->hdr.pGolScheme->CommonBkColor);
            state = DRAW_BACKGROUND1;

        case DRAW_BACKGROUND1:
            if(!Bar(pPict->hdr.left + 1, pPict->hdr.top + 1, pPict->hdr.right - 1, postop - 1))
                return (0);
            state = DRAW_BACKGROUND2;

        case DRAW_BACKGROUND2:
            if(!Bar(pPict->hdr.left + 1, posbottom, pPict->hdr.right - 1, pPict->hdr.bottom - 1))
                return (0);
            state = DRAW_BACKGROUND3;

        case DRAW_BACKGROUND3:
            if(!Bar(pPict->hdr.left + 1, postop, posleft - 1, posbottom))
                return (0);
            state = DRAW_BACKGROUND4;

        case DRAW_BACKGROUND4:
            if(!Bar(posright, postop, pPict->hdr.right - 1, posbottom))
                return (0);
            state = DRAW_FRAME;

        case DRAW_FRAME:
            if(GetState(pPict, PICT_FRAME))
            {
                SetLineType(SOLID_LINE);
                SetColor(pPict->hdr.pGolScheme->TextColor0);
                if(!Rectangle(pPict->hdr.left, pPict->hdr.top, pPict->hdr.right, pPict->hdr.bottom))
                    return (0);
            }

            state = REMOVE;
            return (1);
    }

    return (1);
}
Esempio n. 14
0
void CameraObject::SetImageCenterPix( double x, double y )
{
    m_intrinsicParams.m_center[0] = x / GetImageWidth();
    m_intrinsicParams.m_center[1] = y / GetImageHeight();
    UpdateGeometricRepresentation();
}
Esempio n. 15
0
void CameraObject::GetImageCenterPix( double & x, double & y )
{
    x = m_intrinsicParams.m_center[0] * GetImageWidth();
    y = m_intrinsicParams.m_center[1] * GetImageHeight();
}
Esempio n. 16
0
// Add the droid order screen.
// Returns true if the form was displayed ok.
//
//changed to a BASE_OBJECT to accomodate the factories - AB 21/04/99
bool intAddOrder(BASE_OBJECT *psObj)
{
	bool Animate = true;
	SECONDARY_STATE State;
	UWORD OrdIndex;
	UWORD Height, NumDisplayedOrders;
	UWORD NumButs;
	UWORD NumJustifyButs, NumCombineButs, NumCombineBefore;
	bool  bLastCombine, bHidden;
	DROID *Droid;
	STRUCTURE *psStructure;

	if (bInTutorial)
	{
		// No RMB orders in tutorial!!
		return (false);
	}

	// Is the form already up?
	if (widgGetFromID(psWScreen, IDORDER_FORM) != NULL)
	{
		intRemoveOrderNoAnim();
		Animate = false;
	}
	// Is the stats window up?
	if (widgGetFromID(psWScreen, IDSTAT_FORM) != NULL)
	{
		intRemoveStatsNoAnim();
		Animate = false;
	}

	if (psObj)
	{
		if (psObj->type == OBJ_DROID)
		{
			Droid = (DROID *)psObj;
			psStructure =  NULL;
		}
		else if (psObj->type == OBJ_STRUCTURE)
		{
			Droid = NULL;
			psStructure = (STRUCTURE *)psObj;
			psSelectedFactory = psStructure;
			ASSERT_OR_RETURN(false, StructIsFactory(psSelectedFactory), "Trying to select a %s as a factory!",
			                 objInfo((BASE_OBJECT *)psSelectedFactory));
		}
		else
		{
			ASSERT(false, "Invalid object type");
			Droid = NULL;
			psStructure =  NULL;
		}
	}
	else
	{
		Droid = NULL;
		psStructure =  NULL;
	}

	setWidgetsStatus(true);

	AvailableOrders.clear();
	SelectedDroids.clear();

	// Selected droid is a command droid?
	if ((Droid != NULL) && (Droid->droidType == DROID_COMMAND))
	{
		// displaying for a command droid - ignore any other droids
		SelectedDroids.push_back(Droid);
	}
	else if (psStructure != NULL)
	{
		AvailableOrders = buildStructureOrderList(psStructure);
		if (AvailableOrders.empty())
		{
			return false;
		}
	}
	// Otherwise build a list of selected droids.
	else if (!BuildSelectedDroidList())
	{
		// If no droids selected then see if we were given a specific droid.
		if (Droid != NULL)
		{
			// and put it in the list.
			SelectedDroids.push_back(Droid);
		}
	}

	// Build a list of orders available for the list of selected droids. - if a factory has not been selected
	if (psStructure == NULL)
	{
		AvailableOrders = buildDroidOrderList();
		if (AvailableOrders.empty())
		{
			// If no orders then return;
			return false;
		}
	}

	WIDGET *parent = psWScreen->psForm;

	/* Create the basic form */
	IntFormAnimated *orderForm = new IntFormAnimated(parent, Animate);  // Do not animate the opening, if the window was already open.
	orderForm->id = IDORDER_FORM;
	orderForm->setGeometry(ORDER_X, ORDER_Y, ORDER_WIDTH, ORDER_HEIGHT);

	// Add the close button.
	W_BUTINIT sButInit;
	sButInit.formID = IDORDER_FORM;
	sButInit.id = IDORDER_CLOSE;
	sButInit.x = ORDER_WIDTH - CLOSE_WIDTH;
	sButInit.y = 0;
	sButInit.width = CLOSE_WIDTH;
	sButInit.height = CLOSE_HEIGHT;
	sButInit.pTip = _("Close");
	sButInit.pDisplay = intDisplayImageHilight;
	sButInit.UserData = PACKDWORD_TRI(0, IMAGE_CLOSEHILIGHT , IMAGE_CLOSE);
	if (!widgAddButton(psWScreen, &sButInit))
	{
		return false;
	}

	sButInit = W_BUTINIT();
	sButInit.formID = IDORDER_FORM;
	sButInit.id = IDORDER_CLOSE + 1;
	sButInit.pDisplay = intDisplayButtonHilight;
	sButInit.y = ORDER_BUTY;

	Height = 0;
	NumDisplayedOrders = 0;

	for (unsigned j = 0; j < AvailableOrders.size() && NumDisplayedOrders < MAX_DISPLAYABLE_ORDERS; ++j)
	{
		OrdIndex = AvailableOrders[j].OrderIndex;

		// Get current order state.
		State = GetSecondaryStates(OrderButtons[OrdIndex].Order);

		// Get number of buttons.
		NumButs = OrderButtons[OrdIndex].NumButs;
		// Set actual number of buttons.
		OrderButtons[OrdIndex].AcNumButs = NumButs;

		// Handle special case for factory -> command droid assignment buttons.
		switch (OrderButtons[OrdIndex].Class)
		{
		case ORDBUTCLASS_FACTORY:
			NumButs = countAssignableFactories((UBYTE)selectedPlayer, FACTORY_FLAG);
			break;
		case ORDBUTCLASS_CYBORGFACTORY:
			NumButs = countAssignableFactories((UBYTE)selectedPlayer, CYBORG_FLAG);
			break;
		case ORDBUTCLASS_VTOLFACTORY:
			NumButs = countAssignableFactories((UBYTE)selectedPlayer, VTOL_FLAG);
			break;
		default:
			break;
		}

		sButInit.id = OrderButtons[OrdIndex].ButBaseID;

		NumJustifyButs = NumButs;
		bLastCombine = false;

		switch (OrderButtons[OrdIndex].ButJustify & ORD_JUSTIFY_MASK)
		{
		case ORD_JUSTIFY_LEFT:
			sButInit.x = ORDER_BUTX;
			break;

		case ORD_JUSTIFY_RIGHT:
			sButInit.x = orderForm->width() - ORDER_BUTX -
			             (NumJustifyButs * GetImageWidth(IntImages, OrderButtons[OrdIndex].ButImageID[0]) +
			              (NumJustifyButs - 1) * ORDER_BUTGAP);
			break;

		case ORD_JUSTIFY_CENTER:
			sButInit.x = (orderForm->width() -
			              (NumJustifyButs * GetImageWidth(IntImages, OrderButtons[OrdIndex].ButImageID[0]) +
			               (NumJustifyButs - 1) * ORDER_BUTGAP)) / 2;
			break;

		case ORD_JUSTIFY_COMBINE:
			// see how many are on this line before the button
			NumCombineBefore = 0;
			for (unsigned i = 0; i < j; ++i)
			{
				if ((OrderButtons[AvailableOrders[i].OrderIndex].ButJustify & ORD_JUSTIFY_MASK)
				    == ORD_JUSTIFY_COMBINE)
				{
					NumCombineBefore += 1;
				}
			}
			NumCombineButs = (UWORD)(NumCombineBefore + 1);

			// now see how many in total
			for (unsigned i = j + 1; i < AvailableOrders.size(); ++i)
			{
				if ((OrderButtons[AvailableOrders[i].OrderIndex].ButJustify & ORD_JUSTIFY_MASK)
				    == ORD_JUSTIFY_COMBINE)
				{
					NumCombineButs += 1;
				}
			}

			// get position on line
			NumCombineButs = (UWORD)(NumCombineButs - (NumCombineBefore - (NumCombineBefore % ORD_MAX_COMBINE_BUTS)));

			if (NumCombineButs >= ORD_MAX_COMBINE_BUTS)
			{
				// the buttons will fill the line
				sButInit.x = (SWORD)(ORDER_BUTX +
				                     (GetImageWidth(IntImages, OrderButtons[OrdIndex].ButImageID[0]) + ORDER_BUTGAP) * NumCombineBefore);
			}
			else
			{
				// center the buttons
				sButInit.x = orderForm->width() / 2 -
				             (NumCombineButs * GetImageWidth(IntImages, OrderButtons[OrdIndex].ButImageID[0]) +
				              (NumCombineButs - 1) * ORDER_BUTGAP) / 2;
				sButInit.x = (SWORD)(sButInit.x +
				                     (GetImageWidth(IntImages, OrderButtons[OrdIndex].ButImageID[0]) + ORDER_BUTGAP) * NumCombineBefore);
			}

			// see if need to start a new line of buttons
			if ((NumCombineBefore + 1) == (NumCombineButs % ORD_MAX_COMBINE_BUTS))
			{
				bLastCombine = true;
			}

			break;
		}

		for (unsigned i = 0; i < OrderButtons[OrdIndex].AcNumButs; ++i)
		{
			sButInit.pTip = getDORDDescription(OrderButtons[OrdIndex].ButTips[i]);
			sButInit.width = (UWORD)GetImageWidth(IntImages, OrderButtons[OrdIndex].ButImageID[i]);
			sButInit.height = (UWORD)GetImageHeight(IntImages, OrderButtons[OrdIndex].ButImageID[i]);
			sButInit.UserData = PACKDWORD_TRI(OrderButtons[OrdIndex].ButGreyID[i],
			                                  OrderButtons[OrdIndex].ButHilightID[i],
			                                  OrderButtons[OrdIndex].ButImageID[i]);
			if (!widgAddButton(psWScreen, &sButInit))
			{
				return false;
			}

			// Set the default state for the button.
			switch (OrderButtons[OrdIndex].ButType)
			{
			case ORD_BTYPE_RADIO:
			case ORD_BTYPE_BOOLEAN:
				if ((State & OrderButtons[OrdIndex].StateMask) == (UDWORD)OrderButtons[OrdIndex].States[i])
				{
					widgSetButtonState(psWScreen, sButInit.id, WBUT_CLICKLOCK);
				}
				else
				{
					widgSetButtonState(psWScreen, sButInit.id, 0);
				}
				break;

			case ORD_BTYPE_BOOLEAN_DEPEND:
				if ((State & OrderButtons[OrdIndex].StateMask) == (UDWORD)OrderButtons[OrdIndex].States[i])
				{
					widgSetButtonState(psWScreen, sButInit.id, WBUT_CLICKLOCK);
				}
				else
				{
					if (i == 0)
					{
						widgSetButtonState(psWScreen, sButInit.id, 0);
					}
					else
					{
						widgSetButtonState(psWScreen, sButInit.id, WBUT_DISABLE);
					}
				}
				break;
			case ORD_BTYPE_BOOLEAN_COMBINE:
				if (State & (UDWORD)OrderButtons[OrdIndex].States[i])
				{
					widgSetButtonState(psWScreen, sButInit.id, WBUT_CLICKLOCK);
				}
				break;
			}

			// may not add a button if the factory doesn't exist
			bHidden = false;
			switch (OrderButtons[OrdIndex].Class)
			{
			case ORDBUTCLASS_FACTORY:
				if (!checkFactoryExists(selectedPlayer, FACTORY_FLAG, i))
				{
					widgHide(psWScreen, sButInit.id);
					bHidden = true;
				}
				break;
			case ORDBUTCLASS_CYBORGFACTORY:
				if (!checkFactoryExists(selectedPlayer, CYBORG_FLAG, i))
				{
					widgHide(psWScreen, sButInit.id);
					bHidden = true;
				}
				break;
			case ORDBUTCLASS_VTOLFACTORY:
				if (!checkFactoryExists(selectedPlayer, VTOL_FLAG, i))
				{
					widgHide(psWScreen, sButInit.id);
					bHidden = true;
				}
				break;
			default:
				break;
			}

			if (!bHidden)
			{

				sButInit.x = (SWORD)(sButInit.x + sButInit.width + ORDER_BUTGAP);
			}
			sButInit.id++;
		}

		if (((OrderButtons[OrdIndex].ButJustify & ORD_JUSTIFY_MASK) != ORD_JUSTIFY_COMBINE) ||
		    bLastCombine)
		{
			sButInit.y = (SWORD)(sButInit.y + sButInit.height + ORDER_BUTGAP);
			Height = (UWORD)(Height + sButInit.height + ORDER_BUTGAP);
		}
		NumDisplayedOrders ++;
	}

	// Now we know how many orders there are we can resize the form accordingly.
	int newHeight = Height + CLOSE_HEIGHT + ORDER_BUTGAP;
	orderForm->setGeometry(orderForm->x(), ORDER_BOTTOMY - newHeight, orderForm->width(), newHeight);

	OrderUp = true;

	return true;
}
Esempio n. 17
0
void CameraObject::GetFocalPix( double & x, double & y )
{
    x = m_intrinsicParams.m_focal[0] * GetImageWidth();
    y = m_intrinsicParams.m_focal[1] * GetImageHeight();
}
Esempio n. 18
0
/*********************************************************************
* Function: WORD WndDraw(WINDOW *pW)
*
* Overview: draws window
*
********************************************************************/
WORD WndDraw(WINDOW *pW){

typedef enum {
    WND_REMOVE,
	WND_TITLE_BAR_DRAW,
	WND_TITLE_BAR_BITMAP,
	WND_TITLE_BAR_TEXT,
	WND_TITLE_BAR_TEXT_DRAW,
    WND_CLIENT,
    WND_CLIENT_DRAW
} WND_DRAW_STATES;

SHORT temp;
static WND_DRAW_STATES state = WND_REMOVE;

    while(1){

        if(IsDeviceBusy())
            return 0;

        switch(state){

            case WND_REMOVE:
                if(GetState(pW,WND_HIDE)){
                    SetColor(pW->hdr.pGolScheme->CommonBkColor);
                    Bar(pW->hdr.left,pW->hdr.top,pW->hdr.right,pW->hdr.bottom);
                    return 1;                  
                }
                
if(GetState(pW,WND_DRAW_CLIENT)){

                state = WND_CLIENT;
                break;

            case WND_CLIENT:

                GOLPanelDraw(pW->hdr.left,pW->hdr.top,pW->hdr.right,pW->hdr.bottom, 0,
                         pW->hdr.pGolScheme->CommonBkColor,
                         pW->hdr.pGolScheme->EmbossLtColor,
                         pW->hdr.pGolScheme->EmbossDkColor,
                         NULL,
                         GOL_EMBOSS_SIZE);

                state = WND_CLIENT_DRAW;

            case WND_CLIENT_DRAW:

                if(!GOLPanelDrawTsk())
                    return 0;

}
                state = WND_TITLE_BAR_DRAW;
                break;

            case WND_TITLE_BAR_DRAW:

                if(!GetState(pW,WND_DISABLED)){
    	            if(GetState(pW,WND_FOCUSED)){
                        SetColor(pW->hdr.pGolScheme->Color1);
	                }else{

                        SetColor(pW->hdr.pGolScheme->Color0);
                    }
                }else{
                        SetColor(pW->hdr.pGolScheme->ColorDisabled);
                }

                Bar(pW->hdr.left+GOL_EMBOSS_SIZE, pW->hdr.top+GOL_EMBOSS_SIZE,
                    pW->hdr.right-GOL_EMBOSS_SIZE, pW->hdr.top+GOL_EMBOSS_SIZE+WND_TITLE_HEIGHT);

                state = WND_TITLE_BAR_BITMAP;
                
                break;
              
            case WND_TITLE_BAR_BITMAP:

        	    if (pW->pBitmap != NULL){
                    PutImage(pW->hdr.left+GOL_EMBOSS_SIZE,
                             pW->hdr.top+GOL_EMBOSS_SIZE+((WND_TITLE_HEIGHT-GetImageHeight(pW->pBitmap))>>1),
                             pW->pBitmap,IMAGE_NORMAL);
                }

if (pW->pText != NULL){

                state = WND_TITLE_BAR_TEXT;
                break;

            case WND_TITLE_BAR_TEXT:

                SetFont(pW->hdr.pGolScheme->pFont);

                if(!GetState(pW,WND_DISABLED)){

        	        if (GetState(pW,WND_FOCUSED)){
	        	        SetColor(pW->hdr.pGolScheme->TextColor1);
	                }else{
		                SetColor(pW->hdr.pGolScheme->TextColor0);
                    }

                }else{
		            SetColor(pW->hdr.pGolScheme->TextColorDisabled);
                }
                    
                temp = pW->hdr.left+GOL_EMBOSS_SIZE+WND_INDENT;

                if(pW->pBitmap != NULL){
                    temp += GetImageWidth(pW->pBitmap);
                }

                MoveTo(temp, pW->hdr.top+GOL_EMBOSS_SIZE+((WND_TITLE_HEIGHT-pW->textHeight)>>1));

                state = WND_TITLE_BAR_TEXT_DRAW;

            case WND_TITLE_BAR_TEXT_DRAW:
                if(!OutText(pW->pText))
                    return 0;	
}
                state = WND_REMOVE;
                return 1;

        }//end of switch
Esempio n. 19
0
/*********************************************************************
* Function: WORD GOLPanelDrawTsk(void) 
*
* PreCondition: parameters must be set with
*               GOLRndPanelDraw(x,y,radius,width,height,faceClr,embossLtClr,
*								embossDkClr,pBitmap,embossSize)
*
* Input: None
*
* Output: Output: non-zero if drawing is completed
*
* Overview: draws a rounded panel on screen. Must be called repeatedly. Drawing is done
*           when it returns non-zero. 
*
* Note: none
*
********************************************************************/
WORD GOLPanelDrawTsk(void)
{

#ifndef USE_NONBLOCKING_CONFIG

    WORD    counter;

    // check if we need to draw the panels and emboss sides
    if 	(
    		(_pRpnlBitmap == NULL) || 
    		(
    			((_rpnlX2 - _rpnlX1 + (_rpnlR<<1)) > GetImageWidth((void *)_pRpnlBitmap)) 	&& 
            	((_rpnlY2 - _rpnlY1 + (_rpnlR<<1)) > GetImageHeight((void *)_pRpnlBitmap))	&&
    			(_pRpnlBitmap != NULL)	
			)
        )
    {
	    if(_rpnlR)
	    {
	
	        // draw upper left portion of the embossed area
	        SetColor(_rpnlEmbossLtColor);
	        Arc(_rpnlX1, _rpnlY1, _rpnlX2, _rpnlY2, _rpnlR - _rpnlEmbossSize, _rpnlR, 0xE1);
	
	        // draw lower right portion of the embossed area
	        SetColor(_rpnlEmbossDkColor);
	        Arc(_rpnlX1, _rpnlY1, _rpnlX2, _rpnlY2, _rpnlR - _rpnlEmbossSize, _rpnlR, 0x1E);
	    }
	    else
	    {
	
	        // object is rectangular panel draw the embossed areas
	        counter = 1;
	        SetColor(_rpnlEmbossLtColor);
	        while(counter < _rpnlEmbossSize)
	        {
	            Bar(_rpnlX1 + counter, _rpnlY1 + counter, _rpnlX2 - counter, _rpnlY1 + counter);    // draw top
	            Bar(_rpnlX1 + counter, _rpnlY1 + counter, _rpnlX1 + counter, _rpnlY2 - counter);    // draw left
	            counter++;
	        }
	
	        counter = 1;
	        SetColor(_rpnlEmbossDkColor);
	        while(counter < _rpnlEmbossSize)
	        {
	            Bar(_rpnlX1 + counter, _rpnlY2 - counter, _rpnlX2 - counter, _rpnlY2 - counter);    // draw bottom
	            Bar(_rpnlX2 - counter, _rpnlY1 + counter, _rpnlX2 - counter, _rpnlY2 - counter);    // draw right	
	            counter++;
	        }
	    }
	
	    // draw the face color
	    SetColor(_rpnlFaceColor);
#ifdef USE_ALPHABLEND_LITE
        // set alpha value
        SetAlpha(_rpnlAlpha); 
#endif

	    if(_rpnlR)

#ifdef USE_GRADIENT
            if(_gradientScheme.gradientType != GRAD_NONE)
            {
                BevelGradient(_rpnlX1, _rpnlY1, _rpnlX2, _rpnlY2, _rpnlR - _rpnlEmbossSize,
                              _gradientScheme.gradientStartColor,_gradientScheme.gradientEndColor,
                              _gradientScheme.gradientLength,_gradientScheme.gradientType);
            }
            else
#endif
	        FillBevel(_rpnlX1, _rpnlY1, _rpnlX2, _rpnlY2, _rpnlR - _rpnlEmbossSize);
	    else
            { 

             Bar(_rpnlX1 + _rpnlEmbossSize, _rpnlY1 + _rpnlEmbossSize, _rpnlX2 - _rpnlEmbossSize, _rpnlY2 - _rpnlEmbossSize);
	        }
	            #if (COLOR_DEPTH == 1)
	    if(_rpnlFaceColor == _rpnlEmbossDkColor)
	    {
	        SetColor(_rpnlEmbossLtColor);
	        if(_rpnlR)
	            Bevel(_rpnlX1, _rpnlY1, _rpnlX2, _rpnlY2, _rpnlR - (_rpnlEmbossSize - 1));
	        else
	            Bevel
	            (
	                _rpnlX1 + (_rpnlEmbossSize - 1),
	                _rpnlY1 + (_rpnlEmbossSize - 1),
	                _rpnlX2 - (_rpnlEmbossSize - 1),
	                _rpnlY2 - (_rpnlEmbossSize - 1),
	                0
	            );
	    }
	
	            #endif
	} // end of check if we need to draw the panels and emboss sides
	
    // draw bitmap
    if(_pRpnlBitmap != NULL)
    {
        PutImage
        (
            (((_rpnlX2 + _rpnlX1) - (GetImageWidth((void *)_pRpnlBitmap))) >> 1) + 1,
            (((_rpnlY2 + _rpnlY1) - (GetImageHeight((void *)_pRpnlBitmap))) >> 1) + 1,
            _pRpnlBitmap,
            IMAGE_NORMAL
        );
   }
Esempio n. 20
0
    int main(void)
{
    SHORT       width, height;	// variables to store the height and width of the 16-bit bitmap image
    SHORT       counter;		// loop control variable for each shape that controls how many shapes are printed and their scale
    SHORT  		triangle[] = {160,120,160,120,160,120,160,120};		// triangle polygon points (start triangle in center of LCD)
    
    #if defined(__dsPIC33F__) || defined(__PIC24H__)

    // Configure Oscillator to operate the device at 40Mhz
    // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
    // Fosc= 8M*40(2*2)=80Mhz for 8M input clock
    PLLFBD = 38;                    // M=40
    CLKDIVbits.PLLPOST = 0;         // N1=2
    CLKDIVbits.PLLPRE = 0;          // N2=2
    OSCTUN = 0;                     // Tune FRC oscillator, if FRC is used

    // Disable Watch Dog Timer
    RCONbits.SWDTEN = 0;

    // Clock switching to incorporate PLL
    __builtin_write_OSCCONH(0x03);  // Initiate Clock Switch to Primary

    // Oscillator with PLL (NOSC=0b011)
    __builtin_write_OSCCONL(0x01);  // Start clock switching
    while(OSCCONbits.COSC != 0b011);

    // Wait for Clock switch to occur	
    // Wait for PLL to lock
    while(OSCCONbits.LOCK != 1)
    { };
    #elif defined(__PIC32MX__)
    INTEnableSystemMultiVectoredInt();
    SYSTEMConfigPerformance(GetSystemClock());
    #ifdef MULTI_MEDIA_BOARD_DM00123
    CPLDInitialize();
    CPLDSetGraphicsConfiguration(GRAPHICS_HW_CONFIG);
    CPLDSetSPIFlashConfiguration(SPI_FLASH_CHANNEL);
    #endif
    #endif

    #if defined (PIC24FJ256DA210_DEV_BOARD)
    
    // _ANSG8 = 0; /* S1 */
    // _ANSE9 = 0; /* S2 */
    // _ANSB5 = 0; /* S3 */
        
    #else

    /////////////////////////////////////////////////////////////////////////////
    // ADC Explorer 16 Development Board Errata (work around 2)
    // RB15 should be output
    /////////////////////////////////////////////////////////////////////////////
    LATBbits.LATB15 = 0;
    TRISBbits.TRISB15 = 0;

    #endif

    /////////////////////////////////////////////////////////////////////////////
    #if defined(__dsPIC33FJ128GP804__) || defined(__PIC24HJ128GP504__)
    AD1PCFGL = 0xffff;
    #endif
    InitGraph();

    while(1)
    {
	    /* Display the Kettering Logo bit image with the Welcome to the ECE in the center 
	    /* The image was taken from a JPEG and converted to a 16-bit bitmap in order to meet 
	    /* the display requirement of 16-bits per pixel. This can be done by resaving the
	    /* JPEG as 16-bit bitmap in a image editing program and then converting it using
	    /* the graphics library resource converter. The LCD only supports 4-bit, 8-bit, and
	    /* 16-bits per pixel images 
	    */
	    width = GetImageWidth((void *) &kulogo);
		SetFont((void *) &Font25);
	    WAIT_UNTIL_FINISH(PutImage(45, 20 , (void *) &kulogo,  1)); // image location is relative to the top left corner of the image
        SetColor(WHITE);
        Bar(45, 110, width + 45, 135);	// Draw a bar over the image to place the text over.
        SetColor(BLUE);
        OutTextXY(65, 110, "WELCOME TO THE ECE");
        
        DelayMs(DEMODELAY);	// delay for 1 sec and clear the screen
        SetColor(BLACK);
        ClearDevice();

		/* Display multiple circles, starting at the center and increasing in size at 
        /* each draw until the LCD borders are met. Increasing the counter value will 
        /* expand the shape size more quickly. */
        for(counter = 0; counter < MIN(GetMaxX(), GetMaxY()) >> 1; counter += 14)
        {
	        SetColor(BLACK);	// refresh the screen
	        ClearDevice();	
	        SetColor(BRIGHTRED);
	        SetFont((void *) &Font25);		// draw the name of the shape in the center
	        OutTextXY(135, 110, "Circle");
            WAIT_UNTIL_FINISH(Circle(GetMaxX() >> 1, GetMaxY() >> 1, counter + 5));	// draw the shape
            DelayMs(50);	// display for 50 ms
        }

        DelayMs(DEMODELAY);	// delay for 1 sec and clear the screen
        SetColor(BLACK);
        ClearDevice();

		/* Display multiple rectangles, starting at the center and increasing in size at 
        /* each draw until the LCD borders are met. Increasing the counter value will 
        /* expand the shape size more quickly. */
        for(counter = 0; counter < MIN(GetMaxX() / 2, GetMaxY() / 2) >> 1; counter += 5)
        {	
	        SetColor(BLACK);	// refresh the screen
	        ClearDevice();	
	        SetColor(BRIGHTBLUE);
	        OutTextXY(120, 110, "Rectangle");	// draw the name of the shape in the center
            WAIT_UNTIL_FINISH
            (
                Rectangle
                    (
                        GetMaxX() / 2 - counter * 3 + 6,	// x value of top left corner of rectangle
                        GetMaxY() / 2 - counter * 2 - 8,	// y value of top left corner of rectangle
                        GetMaxX() / 2 + counter * 3 - 6,	// x value of bottom right corner of rectangle
                        GetMaxY() / 2 + counter * 2 + 8     // y value of bottom right corner of rectangle        
                    )
            );
            DelayMs(20); // Display for 20 ms
            
        }

        DelayMs(DEMODELAY); // delay for 1 sec and clear the screen
        SetColor(BLACK);
        ClearDevice();
        
        /* Display multiple triangles, starting at the center and increasing in size at 
        /* each draw until the LCD borders are met. Increasing the counter value will 
        /* expand the shape size more quickly. */
        int i;
		for(counter = 0; counter < MIN(GetMaxX() / 2, GetMaxY() / 2) >> 1; counter += 10)
		{
			SetColor(BLACK);	// refresh the screen
			ClearDevice();
			SetColor(GREEN);	// draw the name of the shape at the center
			OutTextXY(125, 110, "Triangle");
			
			//{160,120,160,120,160,120,160,120} start in center of screen
			triangle[1] = triangle[1] - counter * 2 - 20; 	 // top point y
			triangle[7] = triangle[1];				 		 // top point y (close triangle)
			triangle[2] = triangle[2] - counter * 2 - 58; 	 // left corner point x
			triangle[3] = triangle[3] + counter * 2 + 16;	 // left corner point y
			triangle[4] = triangle[4] + counter * 2 + 58; 	 // right corner point x
			triangle[5] = triangle[5] + counter * 2 + 16;	 // right corner point y
			
			DrawPoly(4, triangle);	// draw the triangle (4 points to enclose it)
			
			// reset each of the triangle points to the center to prevent over expansion
			for (i = 0; i < 8; i++)
				if (i % 2 == 0)
					triangle[i] = 160;
				else
					triangle[i] = 120;
				
			DelayMs(50);	// display for 50 ms
		}
		
       
		DelayMs(DEMODELAY); // delay for 1 sec and clear the screen
    	SetColor(BLACK);
    	ClearDevice();
        
    }
}