本文整理汇总了C++中Canvas函数的典型用法代码示例。如果您正苦于以下问题:C++ Canvas函数的具体用法?C++ Canvas怎么用?C++ Canvas使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Canvas函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OvalToPoint
/* ARGSUSED */
static double
OvalToPoint(
Tk_Canvas canvas, /* Canvas containing item. */
Tk_Item *itemPtr, /* Item to check against point. */
double *pointPtr) /* Pointer to x and y coordinates. */
{
RectOvalItem *ovalPtr = (RectOvalItem *) itemPtr;
double width;
int filled;
Tk_State state = itemPtr->state;
if (state == TK_STATE_NULL) {
state = Canvas(canvas)->canvas_state;
}
width = (double) ovalPtr->outline.width;
if (Canvas(canvas)->currentItemPtr == itemPtr) {
if (ovalPtr->outline.activeWidth>width) {
width = (double) ovalPtr->outline.activeWidth;
}
} else if (state == TK_STATE_DISABLED) {
if (ovalPtr->outline.disabledWidth>0) {
width = (double) ovalPtr->outline.disabledWidth;
}
}
filled = ovalPtr->fillGC != None;
if (ovalPtr->outline.gc == None) {
width = 0.0;
filled = 1;
}
return TkOvalToPoint(ovalPtr->bbox, width, filled, pointPtr);
}
示例2: RectToArea
/* ARGSUSED */
static int
RectToArea(
Tk_Canvas canvas, /* Canvas containing item. */
Tk_Item *itemPtr, /* Item to check against rectangle. */
double *areaPtr) /* Pointer to array of four coordinates (x1,
* y1, x2, y2) describing rectangular area. */
{
RectOvalItem *rectPtr = (RectOvalItem *) itemPtr;
double halfWidth;
double width;
Tk_State state = itemPtr->state;
if (state == TK_STATE_NULL) {
state = Canvas(canvas)->canvas_state;
}
width = rectPtr->outline.width;
if (Canvas(canvas)->currentItemPtr == itemPtr) {
if (rectPtr->outline.activeWidth > width) {
width = rectPtr->outline.activeWidth;
}
} else if (state == TK_STATE_DISABLED) {
if (rectPtr->outline.disabledWidth > 0) {
width = rectPtr->outline.disabledWidth;
}
}
halfWidth = width/2.0;
if (rectPtr->outline.gc == None) {
halfWidth = 0.0;
}
if ((areaPtr[2] <= (rectPtr->bbox[0] - halfWidth))
|| (areaPtr[0] >= (rectPtr->bbox[2] + halfWidth))
|| (areaPtr[3] <= (rectPtr->bbox[1] - halfWidth))
|| (areaPtr[1] >= (rectPtr->bbox[3] + halfWidth))) {
return -1;
}
if ((rectPtr->fillGC == None) && (rectPtr->outline.gc != None)
&& (areaPtr[0] >= (rectPtr->bbox[0] + halfWidth))
&& (areaPtr[1] >= (rectPtr->bbox[1] + halfWidth))
&& (areaPtr[2] <= (rectPtr->bbox[2] - halfWidth))
&& (areaPtr[3] <= (rectPtr->bbox[3] - halfWidth))) {
return -1;
}
if ((areaPtr[0] <= (rectPtr->bbox[0] - halfWidth))
&& (areaPtr[1] <= (rectPtr->bbox[1] - halfWidth))
&& (areaPtr[2] >= (rectPtr->bbox[2] + halfWidth))
&& (areaPtr[3] >= (rectPtr->bbox[3] + halfWidth))) {
return 1;
}
return 0;
}
示例3: Canvas
void DebugRenderer::renderBlobs(unsigned char* image, Blobber* blobber, int width, int height) {
Canvas canvas = Canvas();
canvas.data = image;
canvas.width = width;
canvas.height = height;
for (int i = 0; i < blobber->getColorCount(); i++) {
Blobber::Color* color = blobber->getColor(i);
if (color == NULL) {
continue;
}
if (
strcmp(color->name, "ball") != 0
&& strcmp(color->name, "yellow-goal") != 0
&& strcmp(color->name, "blue-goal") != 0
) {
continue;
}
Blobber::Blob* blob = blobber->getBlobs(color->name);
while (blob != NULL) {
canvas.drawBoxCentered(
(int)blob->centerX, (int)blob->centerY,
blob->x2 - blob->x1, blob->y2 - blob->y1,
color->color.red, color->color.green, color->color.blue
);
blob = blob->next;
}
}
}
示例4: DisplayWindow
FullScreen::FullScreen()
{
#ifdef WIN32
clan::D3DTarget::set_current();
#else
clan::OpenGLTarget::set_current();
#endif
DisplayWindowDescription window_description;
window_description.set_title("ClanLib FullScreen Example");
window_description.set_size(Size(700, 600), true);
window_description.set_allow_resize(true);
window = DisplayWindow(window_description);
sc.connect(window.sig_window_close(), clan::bind_member(this, &FullScreen::on_window_close));
sc.connect(window.get_keyboard().sig_key_down(), clan::bind_member(this, &FullScreen::on_input_down));
canvas = Canvas(window);
spr_logo = Sprite(canvas, "../Basic2D/Resources/logo.png");
spr_background = Sprite(canvas, "../../Display/Path/Resources/lobby_background2.png");
font = clan::Font("tahoma", 24);
game_time.reset();
}
示例5: TextToPoint
static double
TextToPoint(
Tk_Canvas canvas, /* Canvas containing itemPtr. */
Tk_Item *itemPtr, /* Item to check against point. */
double *pointPtr) /* Pointer to x and y coordinates. */
{
TextItem *textPtr;
Tk_State state = itemPtr->state;
double value, px, py;
if (state == TK_STATE_NULL) {
state = Canvas(canvas)->canvas_state;
}
textPtr = (TextItem *) itemPtr;
px = pointPtr[0] - textPtr->drawOrigin[0];
py = pointPtr[1] - textPtr->drawOrigin[1];
value = (double) Tk_DistanceToTextLayout(textPtr->textLayout,
(int) (px*textPtr->cosine - py*textPtr->sine),
(int) (py*textPtr->cosine + px*textPtr->sine));
if ((state == TK_STATE_HIDDEN) || (textPtr->color == NULL) ||
(textPtr->text == NULL) || (*textPtr->text == 0)) {
value = 1.0e36;
}
return value;
}
示例6: SCOPED_DRAW_EVENT
void FRCPassPostProcessVisualizeLPV::Process(FRenderingCompositePassContext& Context)
{
SCOPED_DRAW_EVENT(Context.RHICmdList, VisualizeLPV);
const FSceneView& View = Context.View;
const FSceneViewFamily& ViewFamily = *(View.Family);
// const FSceneRenderTargetItem& DestRenderTarget = PassOutputs[0].RequestSurface(Context);
const TRefCountPtr<IPooledRenderTarget> RenderTarget = GetInput(ePId_Input0)->GetOutput()->PooledRenderTarget;
const FSceneRenderTargetItem& DestRenderTarget = RenderTarget->GetRenderTargetItem();
// Set the view family's render target/viewport.
SetRenderTarget(Context.RHICmdList, DestRenderTarget.TargetableTexture, FTextureRHIRef());
{
FRenderTargetTemp TempRenderTarget(View, (const FTexture2DRHIRef&)DestRenderTarget.TargetableTexture);
FCanvas Canvas(&TempRenderTarget, NULL, ViewFamily.CurrentRealTime, ViewFamily.CurrentWorldTime, ViewFamily.DeltaWorldTime, View.GetFeatureLevel());
float X = 30;
float Y = 28;
const float YStep = 14;
const float ColumnWidth = 250;
Canvas.DrawShadowedString( X, Y += YStep, TEXT("VisualizeLightPropagationVolume"), GetStatsFont(), FLinearColor(0.2f, 0.2f, 1));
Y += YStep;
const FLightPropagationVolumeSettings& Dest = View.FinalPostProcessSettings.BlendableManager.GetSingleFinalDataConst<FLightPropagationVolumeSettings>();
#define ENTRY(name)\
Canvas.DrawShadowedString( X, Y += YStep, TEXT(#name) TEXT(":"), GetStatsFont(), FLinearColor(1, 1, 1));\
Canvas.DrawShadowedString( X + ColumnWidth, Y, *FString::Printf(TEXT("%g"), Dest.name), GetStatsFont(), FLinearColor(1, 1, 1));
ENTRY(LPVIntensity)
ENTRY(LPVVplInjectionBias)
ENTRY(LPVSize)
ENTRY(LPVSecondaryOcclusionIntensity)
ENTRY(LPVSecondaryBounceIntensity)
ENTRY(LPVGeometryVolumeBias)
ENTRY(LPVEmissiveInjectionIntensity)
ENTRY(LPVDirectionalOcclusionIntensity)
ENTRY(LPVDirectionalOcclusionRadius)
ENTRY(LPVDiffuseOcclusionExponent)
ENTRY(LPVSpecularOcclusionExponent)
ENTRY(LPVDiffuseOcclusionIntensity)
ENTRY(LPVSpecularOcclusionIntensity)
#undef ENTRY
Canvas.Flush_RenderThread(Context.RHICmdList);
}
Context.RHICmdList.CopyToResolveTarget(DestRenderTarget.TargetableTexture, DestRenderTarget.ShaderResourceTexture, false, FResolveParams());
// to satify following passws
FRenderingCompositeOutput* Output = GetOutput(ePId_Output0);
Output->PooledRenderTarget = RenderTarget;
}
示例7: create_window
bool FullScreen::update()
{
const float virtual_screen_width = 800.0f;
const float virtual_screen_height = 600.0f;
game_time.update();
// Check for fullscreen switch
if (fullscreen_requested != is_fullscreen)
{
is_fullscreen = fullscreen_requested;
create_window();
}
if (window.get_gc() != canvas.get_gc())
{
canvas = Canvas(window); // Always get the graphic context, the window may have been recreated
}
canvas.clear(Colorf(0.0f,0.0f,0.2f));
int font_size = 28;
font_size *= canvas.get_width() / virtual_screen_width;
font.set_height(font_size);
canvas.set_transform(Mat4f::identity());
if (is_fullscreen)
{
font.draw_text(canvas, 16, font_size, "Full Screen Mode. Press 'F' to switch to resizable window.");
}
else
{
font.draw_text(canvas, 16, font_size, "Resizable Window. Press 'F' to switch to full screen mode.");
}
// Scale the drawing to the screen to a virtual screen size
Mat4f matrix = Mat4f::scale( (float) canvas.get_width() / virtual_screen_width, (float) canvas.get_height() /virtual_screen_height, 1.0f);
canvas.set_transform(matrix);
spr_logo.draw(canvas, virtual_screen_width-spr_logo.get_width(), virtual_screen_height-spr_logo.get_height());
spr_background.set_scale(0.5f, 0.5f);
spr_background.draw(canvas, 100, 100);
// Show a few alpha-blending moving rectangles that moves in circles
float x = cos(sin_count)*120.0f;
float y = sin(sin_count)*120.0f;
sin_count += 2.0f * game_time.get_time_elapsed();
canvas.fill_rect(Rectf( 320.0f + x -30.0f, 300.0f + y -30.0f, Sizef(60.0f, 60.0f)), Colorf(0.0f, 1.0f, 0.0, 0.5f));
x = cos(sin_count+3.14159f)*120.0f;
y = sin(sin_count+3.14159f)*120.0f;
canvas.fill_rect(Rectf( 320.0f + x -30.0f, 300 + y -30.0f, Sizef(60.0f, 60.0f)), Colorf(1.0f, 1.0f, 0.0, 0.5f));
window.flip(1);
return !quit;
}
示例8: DisplayImage
static void
DisplayImage(
Tk_Canvas canvas, /* Canvas that contains item. */
Tk_Item *itemPtr, /* Item to be displayed. */
Display *display, /* Display on which to draw item. */
Drawable drawable, /* Pixmap or window in which to draw item. */
int x, int y, int width, int height)
/* Describes region of canvas that must be
* redisplayed (not used). */
{
ImageItem *imgPtr = (ImageItem *) itemPtr;
short drawableX, drawableY;
Tk_Image image;
Tk_State state = itemPtr->state;
if (state == TK_STATE_NULL) {
state = Canvas(canvas)->canvas_state;
}
image = imgPtr->image;
if (Canvas(canvas)->currentItemPtr == itemPtr) {
if (imgPtr->activeImage != NULL) {
image = imgPtr->activeImage;
}
} else if (state == TK_STATE_DISABLED) {
if (imgPtr->disabledImage != NULL) {
image = imgPtr->disabledImage;
}
}
if (image == NULL) {
return;
}
/*
* Translate the coordinates to those of the image, then redisplay it.
*/
Tk_CanvasDrawableCoords(canvas, (double) x, (double) y,
&drawableX, &drawableY);
Tk_RedrawImage(image, x - imgPtr->header.x1, y - imgPtr->header.y1,
width, height, drawable, drawableX, drawableY);
}
示例9: return
RenderTechnique::PassElm RenderTechnique::addPass( NameID& name, unsigned int texCount, Effect* effect, int width, int height, bool flipH, bool flipV, bool renderToCanvas )
{
for( PassElm p = m_passes.FirstPointer(); !p.IsEmpty(); p.Next() )
if( p() && name == p()->name )
return( PassElm() );
if( static_cast<int>(texCount) > Global::use().engine->getTextureUnitsCount() )
return( PassElm() );
Engine::WindowRect wr;
Global::use().engine->getWindowRect( wr );
if( width <= 0 )
width = wr.width;
if( height <= 0 )
height = wr.height;
Pass* p = new Pass( name );
PassElm pass = m_passes.AddPointer( p );
if( pass.IsEmpty() )
{
DELETE_OBJECT( p );
return( PassElm() );
}
p->inputTextures.Reserve( texCount );
p->inputTexturesMine.Reserve( texCount );
for( unsigned int i = 0; i < p->inputTextures.Size(); i++ )
{
p->inputTextures[ i ] = 0;
p->inputTexturesMine[ i ] = false;
}
p->outputMaterial = xnew Material();
p->outputMaterial->setEffect( effect );
p->outputScene = xnew SpriteBatch( 1 );
p->outputScene->setCamera( xnew Camera2D( 0.0f, 0.0f, static_cast<float>(width), static_cast<float>(height), 0.0f ) );
p->outputQuad = xnew SpriteBatch::Sprite();
p->outputQuad->setMaterial( p->outputMaterial );
p->outputQuad->setWidth( static_cast<float>(width) );
p->outputQuad->setHeight( static_cast<float>(height) );
if( flipH )
p->outputQuad->flip( SpriteBatch::Sprite::ftHorizontal );
if( flipV )
p->outputQuad->flip( SpriteBatch::Sprite::ftVertical );
p->outputScene->attach( p->outputQuad );
if( renderToCanvas )
{
p->outputCanvas = xnew Canvas( width, height );
p->outputScene->setCanvas( p->outputCanvas );
p->outputCanvas->setClearOnActivate( true );
}
return( pass );
}
示例10: window_view
WindowView_Impl::WindowView_Impl(WindowView *view, const DisplayWindowDescription &desc) : window_view(view), window(desc)
{
canvas = Canvas(window);
slots.connect(window.sig_lost_focus(), clan::bind_member(this, &WindowView_Impl::on_lost_focus));
slots.connect(window.sig_got_focus(), clan::bind_member(this, &WindowView_Impl::on_got_focus));
slots.connect(window.sig_resize(), clan::bind_member(this, &WindowView_Impl::on_resize));
slots.connect(window.sig_paint(), clan::bind_member(this, &WindowView_Impl::on_paint));
slots.connect(window.sig_window_close(), clan::bind_member(this, &WindowView_Impl::on_window_close));
slots.connect(window.get_ic().get_keyboard().sig_key_down(), clan::bind_member(this, &WindowView_Impl::on_key_down));
slots.connect(window.get_ic().get_keyboard().sig_key_up(), clan::bind_member(this, &WindowView_Impl::on_key_up));
slots.connect(window.get_ic().get_mouse().sig_key_down(), clan::bind_member(this, &WindowView_Impl::on_mouse_down));
slots.connect(window.get_ic().get_mouse().sig_key_dblclk(), clan::bind_member(this, &WindowView_Impl::on_mouse_dblclk));
slots.connect(window.get_ic().get_mouse().sig_key_up(), clan::bind_member(this, &WindowView_Impl::on_mouse_up));
slots.connect(window.get_ic().get_mouse().sig_pointer_move(), clan::bind_member(this, &WindowView_Impl::on_mouse_move));
}
示例11: DisplayWindow
HSV::HSV()
{
clan::OpenGLTarget::set_current();
window = DisplayWindow("ClanLib HSV Sprite", 1024, 768);
sc.connect(window.sig_window_close(), clan::bind_member(this, &HSV::on_close));
sc.connect(window.get_keyboard().sig_key_up(), clan::bind_member(this, &HSV::on_input_up));
canvas = Canvas(window);
font = clan::Font("Tahoma", 11);
sprite_batcher = std::make_shared<HSVSpriteBatch>(canvas);
car1 = std::make_shared<HSVSprite>(canvas, sprite_batcher.get(), "Resources/spaceshoot_body_moving1.png");
car2 = std::make_shared<HSVSprite>(canvas, sprite_batcher.get(), "Resources/ferrari_maranello.png");
last_fps_update = System::get_time();
last_time = last_fps_update;
}
示例12: DisplayWindow
void FullScreen::create_window()
{
DisplayWindowDescription window_description;
window_description.set_title("ClanLib FullScreen Example");
window_description.set_size(Size(700, 600), true);
if (is_fullscreen)
{
window_description.set_fullscreen(true);
window_description.show_caption(false);
}
else
{
window_description.set_allow_resize(true);
}
window = DisplayWindow(window_description);
sc.connect(window.sig_window_close(), clan::bind_member(this, &FullScreen::on_window_close));
sc.connect(window.get_ic().get_keyboard().sig_key_down(), clan::bind_member(this, &FullScreen::on_input_down));
canvas = Canvas(window);
}
示例13: TextToArea
static int
TextToArea(
Tk_Canvas canvas, /* Canvas containing itemPtr. */
Tk_Item *itemPtr, /* Item to check against rectangle. */
double *rectPtr) /* Pointer to array of four coordinates
* (x1,y1,x2,y2) describing rectangular
* area. */
{
TextItem *textPtr;
Tk_State state = itemPtr->state;
if (state == TK_STATE_NULL) {
state = Canvas(canvas)->canvas_state;
}
textPtr = (TextItem *) itemPtr;
return TkIntersectAngledTextLayout(textPtr->textLayout,
(int) ((rectPtr[0] + 0.5) - textPtr->drawOrigin[0]),
(int) ((rectPtr[1] + 0.5) - textPtr->drawOrigin[1]),
(int) (rectPtr[2] - rectPtr[0] + 0.5),
(int) (rectPtr[3] - rectPtr[1] + 0.5),
textPtr->angle);
}
示例14: CenterButtonImage
//---------------------------------------------------------------------------
void __fastcall CenterButtonImage(TButton * Button)
{
UncenterButtonImage(Button);
// with themes disabled, the text seems to be drawn over the icon,
// so that the padding spaces hide away most of the icon
if (UseThemes())
{
Button->ImageAlignment = iaCenter;
int ImageWidth = Button->Images->Width;
std::unique_ptr<TControlCanvas> Canvas(new TControlCanvas());
Canvas->Control = Button;
UnicodeString Caption = Button->Caption;
UnicodeString Padding;
while (Canvas->TextWidth(Padding) < ImageWidth)
{
Padding += L" ";
}
Caption = Padding + Caption;
Button->Caption = Caption;
int CaptionWidth = Canvas->TextWidth(Caption);
// The margins seem to extend the area over which the image is centered,
// so we have to set it to a double of desired padding.
// Note that (CaptionWidth / 2) - (ImageWidth / 2)
// is approximatelly same as half of caption width before padding.
Button->ImageMargins->Left = - 2 * ((CaptionWidth / 2) - (ImageWidth / 2) + ScaleByTextHeight(Button, 2));
}
else
{
// at least do not draw it so near to the edge
Button->ImageMargins->Left = 1;
}
}
示例15: Canvas
Canvas
TopCanvas::Lock()
{
return Canvas(buffer);
}