Пример #1
0
void Graphics::onResize(int width, int height)
{
	if (width == 0 || height == 0)
		return;

	float w = static_cast<float>(width);
	float h = static_cast<float>(height);

	// calculate integer viewport coordinates
	float aspect = w / h;
	if (aspect < mMinAspect)
	{
		// add borders to the top and bottom
		float hn = w / mMinAspect;
		mViewport = CL_Rectf(0.0f, floor((h - hn) / 2.0f + 0.5f), w, floor((h + hn) / 2.0f + 0.5f));
	}
	else if (aspect > mMaxAspect)
	{
		// add borders to the left and right
		float wn = h * mMaxAspect;
		mViewport = CL_Rectf(floor((w - wn) / 2.0f + 0.5f), 0.0f, floor((w + wn) / 2.0f + 0.5f), h);
	}
	else
	{
		// don't add any borders
		mViewport = CL_Rectf(0.0f, 0.0f, w, h);
	}

	// determine the visible rectangle from the viewport aspect ratio
	float wn = mScreenSize.height * (mViewport.get_width() / mViewport.get_height());
	mVisibleRect = CL_Rectf((mScreenSize.width - wn) / 2.0f, 0.0f, (mScreenSize.width + wn) / 2.0f, mScreenSize.height);

	mWindow.get_gc().set_viewport(mViewport);
	mWindow.get_gc().set_projection(CL_Mat4f::ortho_2d(mVisibleRect.left, mVisibleRect.right, mVisibleRect.bottom, mVisibleRect.top));
}
Пример #2
0
void World::draw()
{
	// Draw background 
	CL_Rect window_rect = window.get_viewport();
	gc.set_texture(0, background);
	CL_Draw::texture(gc, window_rect);	
	gc.reset_texture(0);

	// Draw all gameobjects
	std::list<GameObject *>::iterator it;
	for(it = objects.begin(); it != objects.end(); ++it)
		(*it)->draw();

	// Draw drag area
	if(dragging)
	{
		float s = (sinf(CL_System::get_time() / 200.0f) + 3.0f) / 4.0f;

		
		CL_Draw::box(gc,
			CL_Rectf(dragArea.left - 1, dragArea.top - 1, dragArea.right + 1, dragArea.bottom + 1), 
			CL_Colorf(0.0f, 1.0f, 0.0f, (100.0f * s)/256.0f));
		CL_Draw::box(gc,
			CL_Rectf(dragArea.left, dragArea.top, dragArea.right, dragArea.bottom), 
			CL_Colorf(0.0f, 1.0f, 0.0f, (200.0f * s)/256.0f));
		CL_Draw::box(gc,
			CL_Rectf(dragArea.left + 1, dragArea.top + 1, dragArea.right - 1, dragArea.bottom - 1), 
			CL_Colorf(0.0f, 1.0f, 0.0f, (100.0f * s)/256.0f));
	}
}
Пример #3
0
void ClipRectManager::clamp(const CL_Vec2f& topleftBase, const CL_Size& sizeBase) {
    if (forceRepaint_) {
        CL_Rectf rect(topleftBase.x, topleftBase.y, CL_Sizef(sizeBase.width, sizeBase.height));
        rectangles_.clear();
        rectangles_.push_back(rect);
    } else if (rectangles_.empty()) {
        return;
    }
    
    std::vector<CL_Rectf> clamped;
    
    CL_Rectf clampRect(topleftBase.x, topleftBase.y, CL_Sizef(sizeBase.width, sizeBase.height));
    
    std::vector<CL_Rectf>::iterator iter = rectangles_.begin();
    std::vector<CL_Rectf>::iterator end = rectangles_.end();
    
    for (; iter != end; ++iter) {
        if (clampRect.is_overlapped(*iter)) {
            
            bool addedWithExpand = false;
            CL_Rectf curClamped = iter->clip(clampRect);
            
            float curClampedArea = curClamped.get_width() * curClamped.get_height();
            
            // check for overlaps to keep number of rectangles as small as possible
            std::vector<CL_Rectf>::iterator mergeIter = clamped.begin();
            std::vector<CL_Rectf>::iterator mergeEnd = clamped.end();
            
            for (; mergeIter != mergeEnd; ++mergeIter) {
                if (mergeIter->is_overlapped(curClamped)) {
                    CL_Rectf bounding = CL_Rectf(*mergeIter).bounding_rect(curClamped);
                    CL_Rectf overlap = CL_Rectf(*mergeIter).overlap(curClamped);
                    
                    // area of the bounding rectangle should not be too big. keep the rects seperate if joining them does not give a significant advantage
                    float unnecessaryIncluded = 
                            (bounding.get_width() * bounding.get_height())
                            - (mergeIter->get_width() * mergeIter->get_height() + curClampedArea)
                            + (overlap.get_width() * overlap.get_height());
                            
                    if (unnecessaryIncluded <= curClampedArea * 3) {
                                
                        mergeIter->bounding_rect(curClamped);
                        addedWithExpand = true;
                        break;
                    }
                }
            }
            
            if (!addedWithExpand) {
                clamped.push_back(curClamped);
            }
        }
    }
    
    rectangles_ = clamped;
}
Пример #4
0
void
CLVisualImage::draw(VisualContext &vc, float x, float y, int delta) {
  CL_GraphicContext &gc = ((CLVisualContext &)vc).getGraphicContext();
  if (rect_.isValid()) {
    image_.draw(gc, CL_Rectf((float) rect_.x, (float) rect_.y, 
                             (float) rect_.x + rect_.w, (float) rect_.y + rect_.h),
               CL_Rectf(x, y, x + rect_.w, y + rect_.h));
  } else {
    image_.draw(gc, x, y);
  }
}
Пример #5
0
void ScrollComponent::OnAdd(Entity *pEnt)
{
	EntityComponent::OnAdd(pEnt);

	//shared with the rest of the entity
	m_vecDisplacement = m_vecChildPos = CL_Vec2f(0,0);
	m_pPos2d = &GetParent()->GetVar("pos2d")->GetVector2();
	m_pSize2d = &GetParent()->GetVar("size2d")->GetVector2();
	//vars in our component namespace
	m_pBoundsRect = &GetVarWithDefault("boundsRect", CL_Rectf(0, 0, 0,0))->GetRect();
	m_pScrollStyle = &GetVarWithDefault("scrollStyle", uint32(STYLE_MOMENTUM))->GetUINT32();
	
	//only used for "momentum style"
	m_pFriction = &GetVarWithDefault("friction", 0.1f)->GetFloat();
	m_pMaxScrollSpeed = &GetVarWithDefault("maxScrollSpeed", float(7))->GetFloat();
	m_pPowerMod = &GetVarWithDefault("powerMod", float(0.15))->GetFloat();
	m_progressVar = GetVar("progress2d");
	m_pEnforceFingerTracking = &GetVarWithDefault("fingerTracking", uint32(0))->GetUINT32();
	m_pSwipeDetectDistance = &GetVarWithDefault("swipeDetectDistance", 25.0f)->GetFloat();
	m_pDontScrollUntilSwipeDetected = &GetVarWithDefault("dontScrollUntilSwipeDetected", uint32(0))->GetUINT32();
	m_pEatAllInput = &GetVarWithDefault("eatAllInput", uint32(0))->GetUINT32();

	GetParent()->GetFunction("OnOverStart")->sig_function.connect(1, boost::bind(&ScrollComponent::OnOverStart, this, _1));
	GetParent()->GetFunction("OnOverEnd")->sig_function.connect(1, boost::bind(&ScrollComponent::OnOverEnd, this, _1));
	GetParent()->GetFunction("OnOverMove")->sig_function.connect(1, boost::bind(&ScrollComponent::OnOverMove, this, _1));
	GetParent()->GetFunction("OnUpdate")->sig_function.connect(1, boost::bind(&ScrollComponent::OnUpdate, this, _1));
	GetFunction("SetProgress")->sig_function.connect(1, boost::bind(&ScrollComponent::SetProgress, this, _1));
}
Пример #6
0
void App::set_user_projection(CL_GraphicContext &gc, CL_Sizef &area_size, Options *options)
{
	gc.set_viewport(CL_Rectf(0, 0, area_size));

	float lens_zoom = 3.2f;
	float lens_near = 0.1f;
	float lens_far = 10000.0f;
	float lens_aspect = 1.0f;

	float fov = 2.0f * atan2(1.0f, lens_zoom);
	float aspect = 1.0f;

	aspect = ( area_size.width * lens_aspect) / area_size.height;

	fov = (fov * 180.0f) / CL_PI;
	CL_Mat4f projection_matrix = CL_Mat4f::perspective( fov, aspect, lens_near, lens_far);
	gc.set_projection(projection_matrix);

	CL_Mat4f modelview_matrix = CL_Mat4f::identity();

	modelview_matrix.scale_self(1.0f, 1.0f, -1.0f);	// So positive Z goes into the screen
	modelview_matrix.translate_self(-1.0f, 1.0, lens_zoom);
	modelview_matrix = modelview_matrix.multiply(CL_Mat4f::rotate(CL_Angle((float) -options->grid_angle, cl_degrees), 1.0f, 0.0f, 0.0f, false));
	modelview_matrix.scale_self(2.0f / area_size.width, -2.0f / area_size.height, 1.0f);
	modelview_matrix.translate_self(cl_pixelcenter_constant,cl_pixelcenter_constant, 0.0f);

	gc.set_modelview(modelview_matrix);
}
CL_Rectf
ObjMapSpriteObjectImpl::get_bound_rect() const
{
  CL_Point  align = CL_Point(0, 0);
  CL_Origin origin_e;
  
  sprite.get_alignment(origin_e, align.x, align.y);

  CL_Point origin = calc_origin(origin_e, CL_Size(sprite.get_width(),
                                                  sprite.get_height()));
  align.x = -align.x;

  // FIXME: This looks a bit hacky
  float scale_x, scale_y;
  sprite.get_scale(scale_x, scale_y);

  if (scale_x < 0)
    align.x += sprite.get_width();
  
  if (scale_y < 0)
    align.y += sprite.get_height();
      
  //  if (scale_x > 1.0f && scale_y > 1.0f)
  //    return CL_Rectf(pos - origin - align,
  //                   CL_Sizef(sprite.get_width() * scale_x, sprite.get_height() * scale_y));
  //  else
  return CL_Rectf(pos - origin - align,
                  CL_Sizef(sprite.get_width(), sprite.get_height()));  
}
Пример #8
0
// Zeichnen des Spielfeldes
void Board::draw()
{
	CL_Rectf fieldRect;
	CL_GraphicContext gc = world->get_gc();

	for(int i = 0; i < boardSize.height; ++i)
	{
		float yPos = (boardSize.height - 1 - i) * fieldSize.height;
		for(int j = 0; j < boardSize.width; ++j)
		{
			float xPos = j * fieldSize.width;
			fieldRect = CL_Rectf(xPos, yPos, fieldSize);

			CL_Draw::box(gc, fieldRect, CL_Colorf::white);

			switch(fields[i][j])
			{
				case none:
					break;
				case red:
					CL_Draw::circle(gc, xPos + fieldSize.width / 2, yPos + fieldSize.height / 2, fieldSize.height / 2 - 1, CL_Colorf::red);
					break;
				case white:
					CL_Draw::circle(gc, xPos + fieldSize.width / 2, yPos + fieldSize.height / 2, fieldSize.height / 2 - 1, CL_Colorf::white);
					break;
				default:
					break;
			}
		}
	}
}
Пример #9
0
void App::render_gaussian_blur(CL_GraphicContext &gc, float blur_amount, CL_Texture &source_texture, CL_ProgramObject &program_object, float dx, float dy)
{
	int sampleCount = 15;

	float *sampleWeights = new float[sampleCount];
	CL_Vec2f *sampleOffsets = new CL_Vec2f[sampleCount];

	sampleWeights[0] = compute_gaussian(0, blur_amount);
	sampleOffsets[0] = CL_Vec2f(0.0, 0.0);

	float totalWeights = sampleWeights[0];

	for (int i = 0; i < sampleCount / 2; i++)
	{
		float weight = compute_gaussian(i + 1.0f, blur_amount);

		sampleWeights[i * 2 + 1] = weight;
		sampleWeights[i * 2 + 2] = weight;

		totalWeights += weight * 2;

		float sampleOffset = i * 2 + 1.5f;

		CL_Vec2f delta = CL_Vec2f(dx * sampleOffset, dy * sampleOffset);

		sampleOffsets[i * 2 + 1] = delta;
		sampleOffsets[i * 2 + 2] = CL_Vec2f(-delta.x, -delta.y);
	}

	for (int i = 0; i < sampleCount; i++)
	{
		sampleWeights[i] /= totalWeights;
	}

	program_object.set_uniform1i("SourceTexture", 0);
	program_object.set_uniformfv("SampleOffsets", 2, sampleCount, (float *)sampleOffsets);
	program_object.set_uniformfv("SampleWeights", 1, sampleCount, sampleWeights);

	gc.set_texture(0, source_texture);
	gc.set_program_object(program_object, cl_program_matrix_modelview_projection);

	draw_texture(gc, CL_Rectf(0,0,gc.get_width(),gc.get_height()), CL_Colorf::white, CL_Rectf(0.0f, 0.0f, 1.0f, 1.0f));

	gc.reset_program_object();
	gc.reset_texture(0);
}
Пример #10
0
void AreaScene::render()
{
	// render underlying scene:
	m_topScene->render();

	// render fading shadow:
	auto renderer = m_manager->getRenderer();
	CL_Draw::fill(renderer->getGC(), CL_Rectf(renderer->getGCSize()), CL_Colorf(0.0f, 0.0f, 0.0f, m_percent));
}
bool GLFlashAdaptor_Initialize()
{
	LogMsg("initializing GLFlashAdaptor");
	g_projectionStack.reserve(2);
	g_projectionStack.push_back(CL_Mat4f::identity());

	g_modelStack.reserve(32);
	g_modelStack.push_back(CL_Mat4f::identity());
	g_scissorRect = CL_Rectf(0,0,GetScreenSizeXf(), GetScreenSizeYf());

	return true;
}
Пример #12
0
void RectRenderComponent::OnRender(VariantList *pVList)
{

	if (*m_pAlpha > 0.01)
	{
		CL_Vec2f vFinalPos = pVList->m_variant[0].GetVector2()+*m_pPos2d;
		uint32 color = ColorCombine(*m_pColor, *m_pColorMod, *m_pAlpha);

		if (GET_ALPHA(color) == 0) return;

		CL_Vec2f vRotationPt = vFinalPos;

		g_globalBatcher.Flush();

		if (*m_pRotation != 0)
		{
			SetupOrtho();
			PushRotationMatrix(*m_pRotation, vRotationPt);
			vFinalPos -= vRotationPt;
		}

			CL_Rectf r = CL_Rectf(vFinalPos.x, vFinalPos.y, vFinalPos.x+ m_pSize2d->x, vFinalPos.y+m_pSize2d->y); 
			if (*m_pVisualStyle != STYLE_BORDER_ONLY)
			{
				DrawFilledRect(r, color);
			}
			
			if (GET_ALPHA(*m_pBorderColor) > 0)
			{
				DrawRect(r, *m_pBorderColor, 1);
			}

			if (*m_pVisualStyle == STYLE_3D)
			{
				int shadedColor = ColorCombineMix(color, MAKE_RGBA(0,0,0,255), 0.4f);
				DrawLine(shadedColor, vFinalPos.x, vFinalPos.y+m_pSize2d->y, vFinalPos.x+m_pSize2d->x,vFinalPos.y+m_pSize2d->y, 1);
				DrawLine(shadedColor, vFinalPos.x+m_pSize2d->x, vFinalPos.y, vFinalPos.x+m_pSize2d->x,vFinalPos.y+m_pSize2d->y, 1);

				shadedColor = ColorCombineMix(color, MAKE_RGBA(255,255,255 ,255), 0.4f);
				DrawLine(shadedColor, vFinalPos.x, vFinalPos.y, vFinalPos.x,vFinalPos.y+m_pSize2d->y, 1);
				DrawLine(shadedColor, vFinalPos.x, vFinalPos.y, vFinalPos.x+m_pSize2d->x,vFinalPos.y, 1);
			}

			if (*m_pRotation != 0)
			{
				PopRotationMatrix();
			}

		
	}

}
Пример #13
0
/** Builds the screen.
*/
void
CASignUpScreen::buildScreen() 
{
    // Counter for cursor animation:
    static float cursorAnim = 0.0;

    // Backgroud:
    //
    CA_RES->menu_bg.draw ( *CA_APP->graphicContext, CL_Rect(0, 0, CA_APP->width, CA_APP->height) );

    // Title / help:
    //
    displayTitle();
    displayHelp();

    // Cursor:
    //
    CL_Draw::fill( *CA_APP->graphicContext, CL_Rectf(racePreview[cursor]->getLeft()-12, racePreview[cursor]->getTop()-12,
                           racePreview[cursor]->getRight()+12, racePreview[cursor]->getBottom()+12),
                           CL_Colorf (255, 216, 84, (int)((cursorAnim/2)*255) ));

    CA_RES->advanceAnimation( &cursorAnim, 1, 2.0, CAResources::Revolving );

    // Race previews:
    //
    for( int race=0; race<3; ++race )
    {
        if( racePreview[race] )
        {
            racePreview[race]->display();
            CA_RES->font_normal_14_white.draw_text( *CA_APP->graphicContext, racePreview[race]->getHCenter(),
                                                racePreview[race]->getTop()-22,
                                                (race==0 ? "Easy" : (race==1 ? "Medium" : "Hard")) );
        }
        if (m_selected == true)
        {
            for (unsigned int pl=0; pl<m_RacePlayer[race].size(); pl++)
            {
                CA_RES->font_normal_14_white.draw_text ( *CA_APP->graphicContext,racePreview[race]->getHCenter(),
                                                    racePreview[race]->getBottom()+22*(pl+1), m_StringRacePlayer[race][pl] );
            }
        }
    }

  
    //
    // UpgradesPanel
    UpgradesPanel uPanel(CA_APP->player[0], CA_RES->font_normal_14_white, CA_RES->font_lcd_13_green, racePreview[2]->getRight() + 32, racePreview[0]->getTop()-22);
    uPanel.display();
    
}
Пример #14
0
void CursorManager::drawDragObject(CL_GraphicContext& gc, const CL_Point& mousePos) const {
    if (isDragging_ && dragCandidate_) {
        boost::shared_ptr<ui::Texture> dragTex = dragCandidate_->getIngameTexture();
        if (dragTex && dragTex->isReadComplete()) {
            // TODO: load shader here for correct hueing
            CL_Draw::texture(gc, dragTex->getTexture(),
                    CL_Quadf(CL_Rectf(mousePos.x - dragTex->getWidth() / 2, mousePos.y - dragTex->getHeight() / 2, CL_Sizef(dragTex->getWidth(), dragTex->getHeight()))),
                    CL_Colorf::white, dragTex->getNormalizedTextureCoords()
            );
        } else {
            dragCandidate_->updateRenderData(0);
        }
    }
}
Пример #15
0
CL_Rectf RotateGUIRect(CL_Rectf vRect, CL_Rectf inputRect, float angle, CL_Vec2f destRectSize)
{
	CL_Vec2f vTopLeft =  RotateGUIPoint(vRect.get_top_left(), inputRect, angle, destRectSize);
	CL_Vec2f vBottomRight =  RotateGUIPoint(vRect.get_bottom_right(), inputRect, angle, destRectSize);

	if (angle == 90 ||angle == 270)
	{
		swap(vTopLeft.y, vBottomRight.y);
	}

    CL_Vec2f vTemp = vBottomRight-vTopLeft;
    
	return CL_Rectf(vTopLeft, *(CL_Sizef*)&(vTemp));
}
Пример #16
0
void ExampleText::draw_text(CL_GraphicContext &gc, CL_Texture &texture, CL_Angle angle)
{
	gc.set_texture(0, texture);

	gc.push_modelview();

	gc.mult_translate(gc.get_width()/2.0f, gc.get_height()/2.0f);
	gc.mult_rotate(angle, 0.0f, 0.0f, 1.0f);

	CL_Draw::texture(gc, CL_Rectf(-300.0f, -300.0f, 300.0f, 300.0f), CL_Colorf(1.0f, 1.0f, 1.0f, 0.7f));

	gc.pop_modelview();

	gc.reset_texture(0);
}
Пример #17
0
void App::render_night_vision(CL_GraphicContext &gc, CL_Texture &source_texture, CL_Texture &mask_texture, CL_Texture &noise_texture, CL_ProgramObject &program_object)
{
	program_object.set_uniform1i("sceneBuffer", 0);
	program_object.set_uniform1i("noiseTex", 1);
	program_object.set_uniform1i("maskTex", 2);

	program_object.set_uniform1f("elapsedTime", elapsedTime);
	program_object.set_uniform1f("luminanceThreshold", luminanceThreshold);
	program_object.set_uniform1f("colorAmplification", colorAmplification);
	program_object.set_uniform1f("effectCoverage", effectCoverage);

	gc.set_texture(0, source_texture);
	gc.set_texture(1, noise_texture);
	gc.set_texture(2, mask_texture);
	
	gc.set_program_object(program_object, cl_program_matrix_modelview_projection);

	draw_texture(gc, CL_Rectf(0,0,gc.get_width(),gc.get_height()), CL_Colorf::white, CL_Rectf(0.0f, 0.0f, 1.0f, 1.0f));

	gc.reset_program_object();
	gc.reset_texture(2);
	gc.reset_texture(1);
	gc.reset_texture(0);
}
Пример #18
0
//Zeichnen eines Menüeintrages, z.B.: Lebensanzeige (nicht für Baufelder)
void Menu::drawMenuItem(std::string outputString, int itemLength, CL_Texture texture, CL_Font font,
		int textOffsetY, int xPosition)
{
	CL_Rectf textureRectangle;
	CL_Quadf textureQuad;

	//Definieren eines Rechtecks für Position und Größe der Textur des Menüeintrages
	textureRectangle = CL_Rectf(
		(float)xPosition,
		viewPort.get_height() - menuHeight + ((menuHeight - itemLength) / 2.0f),
		CL_Sizex<float>((float)itemLength, (float)itemLength));
	textureQuad = CL_Quadf(textureRectangle);
	CL_Draw::texture(world->get_gc(), texture, textureRectangle);
	
	//Text zum Menüeintrag schreiben
	font.draw_text(world->get_gc(), textureRectangle.right + 5.0f,
		(float)(viewPort.get_height() - menuHeight + textOffsetY),
		outputString, CL_Colorf::white);
}
Пример #19
0
/** Displays the player view in the panel area.
    \param defaultPos default position if rank is 0 (race startup)
*/
void
CAPlayerView::display( const int defaultPos ) {
    // Maybe we need to re-render the button sprite:
    //
    if( currentColor!=player->getColor() ) {
        renderButton();
    }

    int lap = (int)( floor( player->getPosition() )+1.0 );
    int rank = (player->getRaceRank()==0 ? defaultPos : player->getRaceRank());
    int y = (rank-1) * 55 + 110 + 38; // The turbo jauge + the ammo jauge

    if( lap>5 ) lap=5;

    std::ostringstream ossLap, ossRank, ossNumLap;
    ossLap << lap;
    ossRank << rank;
    ossNumLap << CA_NUMLAPS;

    // Display color button:
    //
    button.draw ( *CA_APP->graphicContext,0, y);
    CA_RES->panel_life.draw ( *CA_APP->graphicContext, (int)((float)player->getLife() / 100.0 * 120.0), y );

    // Display name:
    //
    CA_RES->font_normal_11_white.draw_text( *CA_APP->graphicContext, 3, y+2, player->getName() );

    // Display laps and rank:
    //
    CA_RES->panel_infoview.draw ( *CA_APP->graphicContext,0, y+20);
    CA_RES->font_lcd_13_green.draw_text( *CA_APP->graphicContext, 50, y+22, ossLap.str() );
    CA_RES->font_lcd_13_green.draw_text( *CA_APP->graphicContext, 70, y+31, ossNumLap.str() );
    CA_RES->font_normal_11_white.draw_text( *CA_APP->graphicContext, 99, y+30, ossRank.str() );

    // Display cross for death players:
    //
    if( player->getLife()<0.1 ) {
        CL_Draw::fill( *CA_APP->graphicContext, CL_Rectf(0, y, 120, y+55), CL_Colorf(0, 0, 0, 85) );
        CA_RES->panel_death.draw ( *CA_APP->graphicContext,0, y);
    }
}
void TouchDragComponent::OnAdd(Entity *pEnt)
{
	EntityComponent::OnAdd(pEnt);
	m_lastPos = CL_Vec2f(-1,-1);
	m_pDisabled = &GetVarWithDefault("disabled", uint32(0))->GetUINT32();
	m_pVisualStyle = &GetVarWithDefault("visualStyle", uint32(STYLE_NONE))->GetUINT32();
	m_pOnTouchDragUpdate = GetFunction("OnTouchDragUpdate");
	m_pPos2d = &GetParent()->GetVar("pos2d")->GetVector2();
	m_pSize2d = &GetParent()->GetVar("size2d")->GetVector2();
	m_pSwapXAndY = &GetVar("swapXAndY")->GetUINT32();
	m_pReverseX = &GetVar("reverseX")->GetUINT32();
	m_pReverseY = &GetVar("reverseY")->GetUINT32();
	m_pDisabled = &GetVarWithDefault("disabled", uint32(0))->GetUINT32();

	m_pTouchPadding = &GetParent()->GetVarWithDefault(string("touchPadding"), Variant(CL_Rectf()))->GetRect();

	//this will only be set if TouchDragComponent is initted before the TouchHandler...
	//GetParent()->GetVarWithDefault(string("touchPadding"), Variant(CL_Rectf(0.0f, 0.0f, 0.0f, 0.0f)))->GetRect();

	//register to get updated every frame
	GetParent()->GetFunction("OnInput")->m_sig_function.connect(1, boost::bind(&TouchDragComponent::OnInput, this, _1));
}
Пример #21
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	CL_DisplayWindowDescription win_desc;
	win_desc.set_allow_resize(true);
	win_desc.set_stencil_size(8);
	// For simplicity this example does not use the depth components
	//win_desc.set_depth_size(16);
	win_desc.set_title("Stencil Example");
	win_desc.set_size(CL_Size( 900, 570 ), false);

	CL_DisplayWindow window(win_desc);
	CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);
	CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

	CL_String theme;
	if (CL_FileHelp::file_exists("../../../Resources/GUIThemeAero/theme.css"))
		theme = "../../../Resources/GUIThemeAero";
	else if (CL_FileHelp::file_exists("../../../Resources/GUIThemeBasic/theme.css"))
		theme = "../../../Resources/GUIThemeBasic";
	else
		throw CL_Exception("No themes found");

	CL_GUIWindowManagerTexture wm(window);
	CL_GUIManager gui(wm, theme);
	
	CL_GraphicContext gc = window.get_gc();

	// Deleted automatically by the GUI
	Options *options = new Options(gui, CL_Rect(0, 0, gc.get_size()));

	CL_Image image_grid(gc, "../Blend/Resources/grid.png");
	CL_Image image_ball(gc, "../Blend/Resources/ball.png");
	grid_space = (float) (image_grid.get_width() - image_ball.get_width());

	setup_balls();

	CL_BufferControl buffer_control;
	CL_BufferControl default_buffer_control;

	options->request_repaint();

	CL_Font font(gc, "Tahoma", 24);

	unsigned int time_last = CL_System::get_time();

	while (!quit)
	{
		unsigned int time_now = CL_System::get_time();
		float time_diff = (float) (time_now - time_last);
		time_last = time_now;

		wm.process();
		wm.draw_windows(gc);

		int num_balls = options->num_balls;
		if (num_balls > max_balls)
			num_balls = max_balls;

		if (options->is_moveballs_set)
			move_balls(time_diff, num_balls);

		gc.clear_stencil(0);

		// Draw the grid
		const float grid_xpos = 10.0f;
		const float grid_ypos = 10.0f;
		image_grid.draw(gc, grid_xpos, grid_ypos);

		// Draw the circle onto the stencil
		if (options->is_circle_set)
		{
			buffer_control.enable_logic_op(false);
			buffer_control.enable_stencil_test(true);
			buffer_control.set_stencil_compare_func(cl_comparefunc_always, cl_comparefunc_always);
			buffer_control.set_stencil_fail(cl_stencil_incr_wrap, cl_stencil_incr_wrap);
			buffer_control.set_stencil_pass_depth_fail(cl_stencil_incr_wrap, cl_stencil_incr_wrap);
			buffer_control.set_stencil_pass_depth_pass(cl_stencil_incr_wrap, cl_stencil_incr_wrap);
			buffer_control.enable_color_write(false);
			buffer_control.enable_depth_write(false);
			buffer_control.enable_depth_test(false);
			gc.set_buffer_control(buffer_control);
			CL_Draw::circle(gc, grid_xpos + image_grid.get_width()/2, grid_ypos + image_grid.get_height()/2, 100, CL_Colorf::white);
		}

		buffer_control.enable_color_write(true);
		buffer_control.enable_logic_op(false);

		buffer_control.enable_stencil_test(true);
		buffer_control.set_stencil_compare_func(options->compare_function, options->compare_function);
		buffer_control.set_stencil_compare_reference(options->compare_reference, options->compare_reference);
		buffer_control.set_stencil_write_mask(255, 255);
		buffer_control.set_stencil_compare_mask(255, 255);

		buffer_control.set_stencil_fail(options->stencil_fail, options->stencil_fail);;

		// Note, depth testing disabled for this example
		buffer_control.set_stencil_pass_depth_fail(options->stencil_pass, options->stencil_pass);
		buffer_control.set_stencil_pass_depth_pass(options->stencil_pass, options->stencil_pass);

		buffer_control.enable_depth_write(false);
		buffer_control.enable_depth_test(false);

		gc.set_buffer_control(buffer_control);

		for (int cnt=0; cnt<num_balls; cnt++)
		{
			image_ball.draw(gc, grid_xpos + balls[cnt].xpos, grid_ypos + balls[cnt].ypos);
		}

		gc.set_buffer_control(default_buffer_control);

		CL_Image stencil_image = get_stencil(gc, 
			CL_Rect(grid_xpos, grid_ypos, image_grid.get_width(), image_grid.get_height()));

		const float stencil_image_xpos = 400.0f;
		const float stencil_image_ypos = 30.0f;
		const float stencil_image_scale = 0.5f;
		stencil_image.set_scale(stencil_image_scale, stencil_image_scale);
		stencil_image.draw(gc, stencil_image_xpos, stencil_image_ypos);
		CL_Draw::box(gc, CL_Rectf(stencil_image_xpos, stencil_image_ypos, CL_Sizef(stencil_image.get_width() * stencil_image_scale, stencil_image.get_height() * stencil_image_scale)), CL_Colorf::white);
		font.draw_text(gc, stencil_image_xpos, stencil_image_ypos - 4.0f, "Stencil", CL_Colorf::black);

		// Add a note to avoid confusion
		font.draw_text(gc, 10.0f, 500.0, "(This example does not use the stencil depth buffer comparison or the stencil bitmask)", CL_Colorf::black);

		window.flip(1);

		CL_KeepAlive::process();
	}

	return 0;
}
Пример #22
0
	static int main(const std::vector<CL_String> &args)
	{
		CL_SetupCore setup_core; 
		CL_SetupDisplay setup_disp;
		CL_SetupGL setup_gl;

		CL_ConsoleWindow console("Console");

		try
		{
			CL_DisplayWindow window("über sprite test", 1024, 1024);
			CL_GraphicContext gc = window.get_gc();
			
			CL_BlendMode blend_mode1;
			blend_mode1.enable_blending(true);
			gc.set_blend_mode(blend_mode1);

			gc.set_map_mode(cl_map_2d_upper_left);

			CL_Sprite background(gc, "Images/background.png");
			CL_Sprite test1_facit(gc, "Images/test1_facit.png");

			CL_Sprite testsprite1(gc, "Images/testsprite1.png");

//			CL_PixelBuffer buffer = CL_ImageProviderFactory::load("Images/pacman.pcx");
//			int texture_width = buffer.get_width();
//			int texture_height = buffer.get_height();
//			CL_Texture texture(gc, texture_width, texture_height);
//			texture.set_image(buffer);
//			CL_SpriteDescription desc_pacman;
//			desc_pacman.add_gridclipped_frames(texture, 126, 93, 26, 30, 12, 2, 2, 2);
//			CL_Sprite spr_pacman(desc_pacman, gc);

			bool quit = false;

//			CL_SpriteRenderBatch batch(gc);

			while((!quit) && (!window.get_ic().get_keyboard().get_keycode(CL_KEY_ESCAPE)))
			{
				if(window.get_ic().get_keyboard().get_keycode(CL_KEY_SPACE))
				{
					test1_facit.draw(gc, 0, 0);
				}
				else
				{
					background.draw(gc, 0, 0);

					// Normal
					testsprite1.draw(gc, 56, 91);
//					testsprite1.draw(batch, 56, 91 + 128);
					testsprite1.draw(
						gc, 
						CL_Rectf(0,0,testsprite1.get_width(),testsprite1.get_height()),
						CL_Rectf(56, 91 + 256, 56 + testsprite1.get_width(), 91 + 256 + testsprite1.get_height()));
/*					testsprite1.draw(
						batch, 
						CL_Rectf(0,0,testsprite1.get_width(),testsprite1.get_height()),
						CL_Rectf(56, 91 + 384, 56 + testsprite1.get_width(), 91 + 384 + testsprite1.get_height()));
*/					testsprite1.draw(
						gc, 
						CL_Rectf(56, 91 + 512, 56 + testsprite1.get_width(), 91 + 512 + testsprite1.get_height()));
/*					testsprite1.draw(
						batch, 
						CL_Rectf(56, 91 + 640, 56 + testsprite1.get_width(), 91 + 640 + testsprite1.get_height()));
*/
					// Scale - Note: Src/Dest functions doesn't care about scale-settings
					testsprite1.set_scale(2.0, 2.0);
					testsprite1.draw(gc, 128 + 56, 91);
//					testsprite1.draw(batch, 128 + 56, 91 + 128);
					testsprite1.draw(	
						gc, 
						CL_Rectf(0,0,testsprite1.get_width(),testsprite1.get_height()),
						CL_Rectf(128 + 56, 91 + 256, 128 + 56 + testsprite1.get_width() * 2, 91 + 256 + testsprite1.get_height() * 2));
/*					testsprite1.draw(
						batch, 
						CL_Rectf(0,0,testsprite1.get_width(),testsprite1.get_height()),
						CL_Rectf(128 + 56, 91 + 384, 128 + 56 + testsprite1.get_width() * 2, 91 + 384 + testsprite1.get_height() * 2));
*/					testsprite1.draw(
						gc, 
						CL_Rectf(128 + 56, 91 + 512, 128 + 56 + testsprite1.get_width() * 2, 91 + 512 + testsprite1.get_height() * 2));
/*					testsprite1.draw(
						batch, 
						CL_Rectf(128 + 56, 91 + 640, 128 + 56 + testsprite1.get_width() * 2, 91 + 640 + testsprite1.get_height() * 2));
*/					testsprite1.set_scale(1.0, 1.0);

					// Rotate
					testsprite1.set_angle(CL_Angle(45.0, cl_degrees));
					testsprite1.draw(gc, 256 + 56, 91);
//					testsprite1.draw(batch, 256 + 56, 91 + 128);
					testsprite1.draw(	
						gc, 
						CL_Rectf(0,0,testsprite1.get_width(),testsprite1.get_height()),
						CL_Rectf(256 + 56, 91 + 256, 256 + 56 + testsprite1.get_width(), 91 + 256 + testsprite1.get_height()));
/*					testsprite1.draw(
						batch, 
						CL_Rectf(0,0,testsprite1.get_width(),testsprite1.get_height()),
						CL_Rectf(256 + 56, 91 + 384, 256 + 56 + testsprite1.get_width(), 91 + 384 + testsprite1.get_height()));
*/					testsprite1.draw(
						gc, 
						CL_Rectf(256 + 56, 91 + 512, 256 + 56 + testsprite1.get_width(), 91 + 512 + testsprite1.get_height()));
/*					testsprite1.draw(
						batch, 
						CL_Rectf(256 + 56, 91 + 640, 256 + 56 + testsprite1.get_width(), 91 + 640 + testsprite1.get_height()));
*/					testsprite1.set_angle(CL_Angle(0.0f, cl_degrees));

					// Scale / Rotate - default hotspot
					testsprite1.set_angle(CL_Angle(45.0f, cl_degrees));
					testsprite1.set_scale(2.0, 2.0);
					testsprite1.draw(gc, 384 + 56, 91);
//					testsprite1.draw(batch, 384 + 56, 91 + 128);
					testsprite1.draw(	
						gc, 
						CL_Rectf(0,0,testsprite1.get_width(),testsprite1.get_height()),
						CL_Rectf(384 + 56, 91 + 256, 384 + 56 + testsprite1.get_width() * 2, 91 + 256 + testsprite1.get_height() * 2));
/*					testsprite1.draw(
						batch, 
						CL_Rectf(0,0,testsprite1.get_width(),testsprite1.get_height()),
						CL_Rectf(384 + 56, 91 + 384, 384 + 56 + testsprite1.get_width() * 2, 91 + 384 + testsprite1.get_height() * 2));
*/					testsprite1.draw(
						gc, 
						CL_Rectf(384 + 56, 91 + 512, 384 + 56 + testsprite1.get_width() * 2, 91 + 512 + testsprite1.get_height() * 2));
/*					testsprite1.draw(
						batch, 
						CL_Rectf(384 + 56, 91 + 640, 384 + 56 + testsprite1.get_width() * 2, 91 + 640 + testsprite1.get_height() * 2));
*/					testsprite1.set_angle(CL_Angle(0.0f, cl_degrees));
					testsprite1.set_scale(1.0, 1.0);

					// Scale / Rotate - hotspot(0, 0)
					testsprite1.set_rotation_hotspot(origin_top_left, 0, 0);
					testsprite1.set_angle(CL_Angle(45.0f, cl_degrees));
					testsprite1.set_scale(2.0, 2.0);
					testsprite1.draw(gc, 512 + 56, 91);
//					testsprite1.draw(batch, 512 + 56, 91 + 128);
					testsprite1.draw(	
						gc, 
						CL_Rectf(0,0,testsprite1.get_width(),testsprite1.get_height()),
						CL_Rectf(512 + 56, 91 + 256, 512 + 56 + testsprite1.get_width() * 2, 91 + 256 + testsprite1.get_height() * 2));
/*					testsprite1.draw(
						batch, 
						CL_Rectf(0,0,testsprite1.get_width(),testsprite1.get_height()),
						CL_Rectf(512 + 56, 91 + 384, 512 + 56 + testsprite1.get_width() * 2, 91 + 384 + testsprite1.get_height() * 2));
*/					testsprite1.draw(
						gc, 
						CL_Rectf(512 + 56, 91 + 512, 512 + 56 + testsprite1.get_width() * 2, 91 + 512 + testsprite1.get_height() * 2));
/*					testsprite1.draw(
						batch, 
						CL_Rectf(512 + 56, 91 + 640, 512 + 56 + testsprite1.get_width() * 2, 91 + 640 + testsprite1.get_height() * 2));
*/					testsprite1.set_angle(CL_Angle(0.0f, cl_degrees));
					testsprite1.set_scale(1.0, 1.0);
					testsprite1.set_rotation_hotspot(origin_center, 0, 0);

					// Blend - TODO

					// Alignment - TODO
					testsprite1.set_alignment(origin_bottom_right, 0, 0);
					testsprite1.draw(gc, 768 + 56, 91);
//					testsprite1.draw(batch, 768 + 56, 91 + 128);
					testsprite1.draw(
						gc, 
						CL_Rectf(0,0,testsprite1.get_width(),testsprite1.get_height()),
						CL_Rectf(768 + 56, 91 + 256, 768 + 56 + testsprite1.get_width(), 91 + 256 + testsprite1.get_height()));
/*					testsprite1.draw(
						batch, 
						CL_Rectf(0,0,testsprite1.get_width(),testsprite1.get_height()),
						CL_Rectf(768 + 56, 91 + 384, 768 + 56 + testsprite1.get_width(), 91 + 384 + testsprite1.get_height()));
*/					testsprite1.draw(
						gc, 
						CL_Rectf(768 + 56, 91 + 512, 768 + 56 + testsprite1.get_width(), 91 + 512 + testsprite1.get_height()));
/*					testsprite1.draw(
						batch, 
						CL_Rectf(768 + 56, 91 + 640, 768 + 56 + testsprite1.get_width(), 91 + 640 + testsprite1.get_height()));
*/					testsprite1.set_color(CL_Color::white);
					testsprite1.set_alignment(origin_top_left, 0, 0);

					// Color
					testsprite1.set_color(CL_Color::yellow);
					testsprite1.draw(gc, 896 + 56, 91);
//					testsprite1.draw(batch, 896 + 56, 91 + 128);
					testsprite1.draw(
						gc, 
						CL_Rectf(0,0,testsprite1.get_width(),testsprite1.get_height()),
						CL_Rectf(896 + 56, 91 + 256, 896 + 56 + testsprite1.get_width(), 91 + 256 + testsprite1.get_height()));
/*					testsprite1.draw(
						batch, 
						CL_Rectf(0,0,testsprite1.get_width(),testsprite1.get_height()),
						CL_Rectf(896 + 56, 91 + 384, 896 + 56 + testsprite1.get_width(), 91 + 384 + testsprite1.get_height()));
*/					testsprite1.draw(
						gc, 
						CL_Rectf(896 + 56, 91 + 512, 896 + 56 + testsprite1.get_width(), 91 + 512 + testsprite1.get_height()));
/*					testsprite1.draw(
						batch, 
						CL_Rectf(896 + 56, 91 + 640, 896 + 56 + testsprite1.get_width(), 91 + 640 + testsprite1.get_height()));
*/					testsprite1.set_color(CL_Color::white);

//					batch.flush();
				}

				/*				CL_Draw::fill(gc, 
					0, 0, 
					640, 480, 
					CL_Color::green);

				CL_Draw::line(gc, 10,0,100,100, CL_Color::yellow);

				spr_pacman.set_frame(0);
				spr_pacman.draw(gc, 0, 0);

				CL_Draw::line(gc, 0,0,100,100, CL_Color::yellow);

				spr_pacman.set_frame(1);
				spr_pacman.draw(gc, 50, 0);

				spr_pacman.set_frame(2);
				spr_pacman.draw(gc, 100, 0);
*/
				window.flip(1);
				CL_KeepAlive::process();

				CL_System::sleep(10);
			}

			return 0;
		}
		catch(CL_Exception error)
		{
			CL_Console::write_line("Exception caught:");
			CL_Console::write_line(error.message);
			console.display_close_message();

			return -1;
		}

		return 0;
	}
void CL_InputBox_Silver::on_paint()
{
	bool has_focus = inputbox->is_enabled() && inputbox->has_focus();

	CL_Rectf rect = inputbox->get_screen_rect();
	int width = inputbox->get_width();

	// Outline
	if(has_focus)
	{
		// Fill
		CL_Display::fill_rect(
			CL_Rectf(rect.left + 1, rect.top + 1, rect.right - 1, rect.bottom - 1),
			CL_Color(245, 250, 255));

		// Main border
		CL_Display::draw_rect(
			rect,
			CL_Color(90, 118, 149));

		// Highlight
		CL_Display::draw_rect(
			CL_Rectf(rect.left - 1, rect.top - 1, rect.right + 1, rect.bottom + 1),
			CL_Color(206, 220, 233));
	}
	else
	{
		// Fill
		CL_Display::fill_rect(
			CL_Rectf(rect.left + 1, rect.top + 1, rect.right - 1, rect.bottom - 1),
			CL_Color::white);

		// Main border
		CL_Display::draw_rect(
			rect,
			CL_Color(128, 142, 159));
	}

	// For easy reference, put inputfield-text into local variable
	const char *text = inputbox->get_text().c_str();

	// Calculate offset for vertical centering
	int vert_center = (inputbox->get_height () - font->get_height ()) / 2;

	// Calculate scroll offset
	int character_offset = 0;
	int pixel_offset = 0;
	int text_width = (int) inputbox->in_password_mode() ? font->get_width('*')*strlen(text) : font->get_width(text);
	if (text_width > width - border_size * 2)
	{
		while (
			text_width >= width - border_size * 2 &&
			character_offset + 1 < inputbox->get_cursor_position())
		{
			int w = inputbox->in_password_mode() ? font->get_width('*') : font->get_width(text[character_offset]);
			character_offset++;
			pixel_offset += w;
			text_width -= w;
		}
	}

	// Display marked text, if any
	if(has_focus) 
	{
		if (inputbox->has_marked_text())
		{
			int start = inputbox->get_selection_start();
			int end = start + inputbox->get_selection_length();

			int mark_x1 = 0, mark_x2 = 0;

			int i;
			if (inputbox->in_password_mode())
			{
				int w = font->get_width('*');

				if (start > 0)
					mark_x1 += start*w;

				if (end > start)
					mark_x2 += (end-start)*w;
			}
			else
			{
				for(i = 0; i < start; i++)
					mark_x1 += font->get_width(text[i]);

				for(i = start; i < end; i++)
					mark_x2 += font->get_width(text[i]);
			}

			CL_Display::fill_rect(
				CL_Rect(
					inputbox->get_screen_x()+border_size + mark_x1 - 1,
					inputbox->get_screen_y() + vert_center,
					inputbox->get_screen_x()+border_size + mark_x1 + mark_x2,
					inputbox->get_screen_y() + font->get_height() + vert_center),
				CL_Color(204, 208, 232));
		}
	}

	// Display text
	if(inputbox->is_enabled() == false)
	{
		if (inputbox->in_password_mode())
			font_disabled->draw(inputbox->get_screen_x()+border_size, inputbox->get_screen_y()+vert_center, std::string(strlen(text+character_offset), '*'));
		else
			font_disabled->draw(inputbox->get_screen_x()+border_size, inputbox->get_screen_y()+vert_center, &text[character_offset]);
	}
	else
	{
		if (inputbox->in_password_mode())
			font->draw(inputbox->get_screen_x()+border_size, inputbox->get_screen_y()+vert_center, std::string(strlen(text+character_offset), '*'));
		else
			font->draw(inputbox->get_screen_x()+border_size, inputbox->get_screen_y()+vert_center, &text[character_offset]);
	}

	// Show blinking cursor
	if(has_focus) 
	{
		if (show_cursor)
		{
			int cursor_x = border_size - pixel_offset;

			if (inputbox->in_password_mode())
				cursor_x += inputbox->get_cursor_position() * font->get_width('*');
			else
				for(int i = 0; i < inputbox->get_cursor_position(); i++)
					cursor_x += font->get_width(text[i]);
			
			CL_Display::draw_line(
				inputbox->get_screen_x() + cursor_x,
				inputbox->get_screen_y() + vert_center,
				inputbox->get_screen_x() + cursor_x,
				inputbox->get_screen_y() + vert_center + font->get_height() - 1,
				CL_Color::black);
		}

		unsigned int cur_time = CL_System::get_time();
		if (cur_time >= cursor_blink_time)
		{
			cursor_blink_time = cur_time + 400;
			show_cursor = !show_cursor;
		}
	}
}
Пример #24
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	quit = false;

	// Create a console window for text-output if not available
	CL_ConsoleWindow console("Console", 80, 200);

	try
	{
		// Set the window
		// This opens a 640 x 480 window, including the frame size
		// If you want more control over the window, pass CL_DisplayWindowDescription to CL_DisplayWindow
		// (This is useful to create a borderless window of a specific size)
		// If you require target specific control over the window, use the derived CL_OpenGLWindowDescription
		// (This contains the multisampling options)
#ifdef USE_SWRENDER
		CL_DisplayWindowDescription desc;
#else
		CL_OpenGLWindowDescription desc;
//		desc.set_multisampling(4);
#endif
		desc.set_title("ClanLib 2D Test");
		desc.set_size(CL_Size(800, 600), true);
		CL_DisplayWindow window(desc);

		// Connect the Window close event
		CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);

		// Connect a keyboard handler to on_key_up()
		CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

		// Get the graphic context
		CL_GraphicContext gc = window.get_gc();

		CL_Texture texture_image(gc, "tux.png");
		texture_image.set_wrap_mode(cl_wrap_repeat, cl_wrap_repeat, cl_wrap_repeat);
		texture_image.set_min_filter(cl_filter_linear);
		texture_image.set_mag_filter(cl_filter_linear);

		CL_ResourceManager resources("resources.xml");
		CL_Sprite sprite(gc, "test", &resources);
		//sprite.set_linear_filter(true);

		CL_Font small_font = CL_Font(gc, "Tahoma", 12);

		float test_base_angle = 0.0f;
		float test_angle = 0.0f;
		float test_angle_pitch = 0.0f;
		float test_angle_yaw = 0.0f;
		float test_scale = 1.0f;
		bool test_scale_dir = false;

		// Run until someone presses escape
		while (!quit)
		{
			gc.clear(CL_Colorf(0.0f,0.0f,0.2f));

			gc.set_map_mode(CL_MapMode(cl_map_2d_upper_left));

	// CL_Draw::point()
			for (int xcnt=0; xcnt<8; xcnt++)
			{
				for (int ycnt=0; ycnt<6; ycnt++)
				{
					CL_Draw::point(gc, xcnt*2, ycnt*2, CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f));
				}
			}
			small_font.draw_text(gc, 32, 10, "8*6 Points (0 + 2x), (0 + 2y)");

	// CL_Draw::line()
			for (int xcnt=0; xcnt<4; xcnt++)
			{
				for (int ycnt=0; ycnt<3; ycnt++)
				{
					const int offset_y = 16;
					const int line_length = 6;
					const int spacing = 8;
					CL_Draw::line(gc, xcnt*spacing, (ycnt*spacing) + offset_y, line_length + (xcnt*spacing), (line_length + (ycnt*spacing)) + offset_y, CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f));
				}
			}
			small_font.draw_text(gc, 48, 30, "4*3 Lines (0 + 8x), (32 + 8y), (6 + 8x), (38 + 8y)");

	// CL_Draw::box()
			for (int xcnt=0; xcnt<4; xcnt++)
			{
				for (int ycnt=0; ycnt<3; ycnt++)
				{
					const int offset_y = 48;
					const int line_length = 6;
					const int spacing = 8;
					CL_Draw::box(gc, xcnt*spacing, (ycnt*spacing) + offset_y, line_length + (xcnt*spacing), (line_length + (ycnt*spacing)) + offset_y, CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f));
				}
			}
			small_font.draw_text(gc, 48, 66, "4*3 Box (0 + 8x), (32 + 8y), (6 + 8x), (38 + 8y)");

	// CL_Draw::fill()
			for (int xcnt=0; xcnt<4; xcnt++)
			{
				for (int ycnt=0; ycnt<3; ycnt++)
				{
					const int offset_y = 80;
					const int line_length = 6;
					const int spacing = 8;
					CL_Draw::fill(gc, xcnt*spacing, (ycnt*spacing) + offset_y, line_length + (xcnt*spacing), (line_length + (ycnt*spacing)) + offset_y, CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f));
				}
			}
			small_font.draw_text(gc, 48, 90, "4*3 Fill (0 + 8x), (32 + 8y), (6 + 8x), (38 + 8y)");

	// CL_Draw::gradient_fill()
			CL_Gradient gradient;
			gradient.top_left = CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f);
			gradient.top_right = CL_Colorf(1.0f, 0.0f, 0.0f, 1.0f);
			gradient.bottom_left = CL_Colorf(0.0f, 0.0f, 1.0f, 1.0f);
			gradient.bottom_right = CL_Colorf(0.0f, 1.0f, 0.0f, 1.0f);
			for (int xcnt=0; xcnt<4; xcnt++)
			{
				for (int ycnt=0; ycnt<3; ycnt++)
				{
					const int offset_y = 110;
					const int line_length = 6;
					const int spacing = 8;
					CL_Draw::gradient_fill(gc, xcnt*spacing, (ycnt*spacing) + offset_y, line_length + (xcnt*spacing), (line_length + (ycnt*spacing)) + offset_y, gradient);
				}
			}
			small_font.draw_text(gc, 48, 115, "4*3 GradientFill (0 + 8x), (32 + 8y), (6 + 8x), (38 + 8y)");
			small_font.draw_text(gc, 48, 125, "top left = white. top right = red");
			small_font.draw_text(gc, 48, 135, "bottom left = blue. bottom right = green");

	// CL_Draw::circle()
			{
				const int offset_y = 140;
				int radius = 5;
				CL_Draw::circle(gc, radius, offset_y + radius, radius, CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f));

				const int offset_x = 16;
				radius = 16;
				CL_Draw::circle(gc, offset_x + radius, offset_y + radius, radius, CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f));
			}
			small_font.draw_text(gc, 54, 149, "Circle (5, 145) Radius = 5");
			small_font.draw_text(gc, 54, 159, "Circle (32, 156) Radius = 16");

	// CL_Draw::gradient_circle()
			{
				CL_Gradient gradient;
				gradient.top_left = CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f);
				gradient.top_right = CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f);
				gradient.bottom_left = CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f);
				gradient.bottom_right = CL_Colorf(1.0f, 0.0f, 0.0f, 1.0f);

				const int offset_y = 180;
				float radius = 17.0;
				float xpos = radius;
				float ypos = offset_y + radius;
				CL_Draw::gradient_circle(gc, CL_Pointf( xpos, ypos ), CL_Pointf(radius/2.0, 0.0f), radius, gradient);

				const int offset_x = 40;
				radius = 17.0;
				xpos = offset_x + radius;
				ypos = offset_y + radius;
				CL_Draw::gradient_circle(gc, CL_Pointf( xpos, ypos), CL_Pointf(0.0f, radius/2.0), radius, gradient);
			}

			small_font.draw_text(gc, 80, 189, "Gradient Circle (16, 196) Radius = 17. Gradient right");
			small_font.draw_text(gc, 80, 199, "Gradient Circle (56, 196) Radius = 17. Gradient up");
			small_font.draw_text(gc, 80, 209, "centre = white, outer = red");

	// CL_Draw::triangle()
			{
				const float offset_y = 220.0f;
				const float size = 12.0f;
				CL_Draw::triangle(gc, CL_Pointf(0.0f, offset_y), CL_Pointf(0.0f, offset_y + size), CL_Pointf(size, offset_y + size), CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f));

				float offset_x = 16.0f;
				CL_Draw::triangle(gc, CL_Pointf(offset_x + 0.0f, offset_y + size), CL_Pointf(offset_x + size, offset_y + size), CL_Pointf(offset_x + 0.0f, offset_y), CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f));

				offset_x = 32.0f;
				CL_Draw::triangle(gc, CL_Pointf(offset_x + size, offset_y + size), CL_Pointf(offset_x + 0.0f, offset_y), CL_Pointf(offset_x + 0.0f, offset_y + size), CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f));
			}
			small_font.draw_text(gc, 48, 229, "3 Triangles (12 pixel size) (Left vertical edge).");
			small_font.draw_text(gc, 48, 239, "Top Left: (0,220)  (16,220)  (32,220)");

	// CL_Draw::texture()
			gc.set_texture(0, texture_image);
			{
				float offset_x = 0.0f;
				float offset_y = 250.0f;
				CL_Rectf src_rect(offset_x, offset_y, CL_Sizef(31, 47));
				CL_Rectf texture_coords(0.0, 0.0, 1.0f, 1.0f);
				CL_Colorf color(1.0f, 1.0f, 1.0f, 1.0f);
				CL_Draw::texture(gc, src_rect, color, texture_coords);

				offset_x = 33.0f;
				src_rect = CL_Rectf(offset_x, offset_y, CL_Sizef(31, 47));
				texture_coords = CL_Rectf(0.25f, 0.25f, 0.75f, 0.75f);
				color = CL_Colorf(1.0f, 0.0f, 0.0f, 1.0f);
				CL_Draw::texture(gc, src_rect, color, texture_coords);
			}
			gc.reset_texture(0);
			small_font.draw_text(gc, 76, 260, "Texture (0, 250) size=(31,47)");
			small_font.draw_text(gc, 76, 275, "Texture (33, 250) size=(31,47) (red, magnify*2)");

	// CL_RoundedRect
			{
				CL_RoundedRect roundedrect(CL_Sizef(64.0f, 32.0f), 15.0f);

				float offset_x = 0.0f;
				float offset_y = 300.0f;
				CL_Origin origin = origin_top_left;
				roundedrect.draw(gc, CL_Pointf(offset_x, offset_y), CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f), origin);

				offset_y = 340.0f;
				roundedrect.fill(gc, CL_Pointf(offset_x, offset_y), CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f), origin);

				offset_y = 380.0f;
				CL_Gradient gradient;
				gradient.top_left = CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f);
				gradient.top_right = CL_Colorf(1.0f, 0.0f, 0.0f, 1.0f);
				gradient.bottom_left = CL_Colorf(0.0f, 0.0f, 1.0f, 1.0f);
				gradient.bottom_right = CL_Colorf(0.0f, 1.0f, 0.0f, 1.0f);
				roundedrect.fill(gc, CL_Pointf(offset_x, offset_y), gradient, origin);

				offset_y = 420.0f;
				roundedrect.set_control_point_bl(CL_Pointf(0.4f, 0.8f));
				roundedrect.set_rounding_bottom_left(CL_Sizef(0.2f, 0.6f));

				roundedrect.set_control_point_tl(CL_Pointf(0.2f, 0.4f));
				roundedrect.set_rounding_top_left(CL_Sizef(0.4f, 0.2f));

				roundedrect.set_control_point_tr(CL_Pointf(0.6f, 0.2f));
				roundedrect.set_rounding_top_right(CL_Sizef(0.8f, 0.4f));
				roundedrect.set_control_point_br(CL_Pointf(0.6f, 0.8f));
				roundedrect.set_rounding_bottom_right(CL_Sizef(0.8f, 0.6f));

				roundedrect.fill(gc, CL_Pointf(offset_x, offset_y), gradient, origin);

			}
			small_font.draw_text(gc, 76, 310, "RoundedRect - draw (0, 300) size=(64,32)");
			small_font.draw_text(gc, 76, 325, "(RoundedRect - draw gradient - is not implemented)");
			small_font.draw_text(gc, 76, 350, "RoundedRect - fill (0, 340) size=(64,32)");
			small_font.draw_text(gc, 76, 390, "RoundedRect - fill gradient (0, 380) size=(64,32)");
			small_font.draw_text(gc, 76, 400, "top left = white. top right = red");
			small_font.draw_text(gc, 76, 410, "bottom left = blue. bottom right = green");
			small_font.draw_text(gc, 76, 430, "RoundedRect - fill gradient (0, 420) size=(64,32)");
			small_font.draw_text(gc, 76, 440, "Controling control / rounding points");

	// CL_Sprite
			{
				test_base_angle+=5.0f;
				if (test_base_angle >= 360.0f)
				{
					test_base_angle = 0.0f;
				}
#ifndef USE_SWRENDER
				clEnable(GL_MULTISAMPLE);
#endif
				sprite.set_base_angle(CL_Angle(test_base_angle, cl_degrees));
				sprite.draw(gc, 350, 20);
				sprite.set_base_angle(CL_Angle(0, cl_degrees));

#ifndef USE_SWRENDER
				clDisable(GL_MULTISAMPLE);
#endif
			}
			small_font.draw_text(gc, 370, 20, "Sprite - Base angle");
			small_font.draw_text(gc, 370, 35, "Multisampling enabled");

			{
				test_angle+=5.0f;
				if (test_angle >= 360.0f)
				{
					test_angle = 0.0f;
				}

				sprite.set_angle(CL_Angle(test_angle, cl_degrees));
				sprite.draw(gc, 350, 60);
				sprite.set_angle(CL_Angle(0, cl_degrees));
			}
			small_font.draw_text(gc, 370, 60, "Sprite - Angle");

			{
				test_angle_pitch+=5.0f;
				if (test_angle_pitch >= 360.0f)
				{
					test_angle_pitch = 0.0f;
				}

				sprite.set_angle_pitch(CL_Angle(test_angle_pitch, cl_degrees));
				sprite.draw(gc, 350, 100);
				sprite.set_angle_pitch(CL_Angle(0, cl_degrees));
			}
			small_font.draw_text(gc, 370, 100, "Sprite - Angle Pitch");

			{
				test_angle_yaw+=5.0f;
				if (test_angle_yaw >= 360.0f)
				{
					test_angle_yaw = 0.0f;
				}

				sprite.set_angle_yaw(CL_Angle(test_angle_yaw, cl_degrees));
				sprite.draw(gc, 350, 140);
				sprite.set_angle_yaw(CL_Angle(0, cl_degrees));
			}
			small_font.draw_text(gc, 370, 140, "Sprite - Angle Yaw");

			{
				if (test_scale_dir)
				{
					test_scale += 0.1f;
					if (test_scale >= 2.0f)
					{
						test_scale = 2.0f;
						test_scale_dir = false;
					}
				}else
				{
					test_scale -= 0.1f;
					if (test_scale <= -2.0f)
					{
						test_scale = -2.0f;
						test_scale_dir = true;
					}
				}

				sprite.set_scale(test_scale, 1.0f);
				sprite.draw(gc, 350, 180);
				sprite.set_scale(1.0f, test_scale);
				sprite.draw(gc, 390, 180);
				sprite.set_scale(1.0f, 1.0f);
			}
			small_font.draw_text(gc, 420, 180, "Sprite - Set Scale (x), (y)");

			// Flip the display, showing on the screen what we have drawed
			// since last call to flip()
			window.flip(1);

			// This call processes user input and other events
			CL_KeepAlive::process();
		}
		small_font = CL_Font();
	}
	catch(CL_Exception& exception)
	{
		CL_Console::write_line("Exception caught:");
		CL_Console::write_line(exception.message);

		// Display the stack trace (if available)
		std::vector<CL_String> stacktrace = exception.get_stack_trace();
		int size = stacktrace.size();
		if (size > 0)
		{
			CL_Console::write_line("Stack Trace:");
			for (int cnt=0; cnt < size; cnt++)
			{
				CL_Console::write_line(stacktrace[cnt]);
			}
		}

		console.display_close_message();

		return -1;
	}
	return 0;
}
Пример #25
0
void Level::loadTrackElement(const CL_DomNode &p_trackNode)
{
	// build block type map
	typedef std::map<CL_String, Common::GroundBlockType> blockMap_t;
	blockMap_t blockMap;
	blockMap_t::iterator blockMapItor;

	blockMap["vert"] = Common::BT_STREET_VERT;
	blockMap["horiz"] = Common::BT_STREET_HORIZ;
	blockMap["turn_bottom_right"] = Common::BT_TURN_BOTTOM_RIGHT;
	blockMap["turn_bottom_left"] = Common::BT_TURN_BOTTOM_LEFT;
	blockMap["turn_top_right"] = Common::BT_TURN_TOP_RIGHT;
	blockMap["turn_top_left"] = Common::BT_TURN_TOP_LEFT;
	blockMap["start_line_up"] = Common::BT_START_LINE_UP;

	// prepare level blocks
	const int blocksCount = m_width * m_height;
	m_blocks.clear();
	m_blocks.reserve(blocksCount);

	for (int i = 0; i < blocksCount; ++i) {
		m_blocks.push_back(CL_SharedPtr<Block>(new Block(Common::BT_GRASS)));
	}

	// create global resistance geometry
	CL_SharedPtr<RaceResistance::Geometry> globalResGeom(new RaceResistance::Geometry());
	globalResGeom->addRectangle(CL_Rectf(real(0), real(0), real(m_width), real(m_height)));

	m_resistanceMap.addGeometry(globalResGeom, 0.3f);

	// add sand resistance
	foreach (const Sandpit &sandpit, m_sandpits) {
		const unsigned circleCount = sandpit.getCircleCount();

		CL_SharedPtr<RaceResistance::Geometry> sandpitGeometry(new RaceResistance::Geometry());

		for (unsigned i = 0; i < circleCount; ++i) {
			// sandpit values are real
			const Sandpit::Circle &circle = sandpit.circleAt(i);
			sandpitGeometry->addCircle(CL_Circlef(circle.getCenter().x, circle.getCenter().y, circle.getRadius()));
		}

		m_resistanceMap.addGeometry(sandpitGeometry, 0.8f);
	}

	// read blocks
	const CL_DomNodeList blockList = p_trackNode.get_child_nodes();
	const int blockListSize = blockList.get_length();

	cl_log_event("debug", "Track node child count: %1", blockListSize);

	CL_Pointf lastCP; // last checkpoint

	for (int i = 0; i < blockListSize; ++i) {
		const CL_DomNode blockNode = blockList.item(i);

		if (blockNode.get_node_name() == "block") {
			CL_DomNamedNodeMap attrs = blockNode.get_attributes();

			const int x = CL_StringHelp::local8_to_int(attrs.get_named_item("x").get_node_value());
			const int y = CL_StringHelp::local8_to_int(attrs.get_named_item("y").get_node_value());
			const CL_String typeStr = attrs.get_named_item("type").get_node_value();

			if (x < 0 || y < 0 || x >= m_width || y >= m_height) {
				cl_log_event("debug", "coords x=%1, y=%2", x, y);
				throw CL_Exception("Blocks coords out of bounds");
			}

			blockMapItor = blockMap.find(typeStr);

			if (blockMapItor != blockMap.end()) {

				const Common::GroundBlockType blockType = blockMapItor->second;
				m_blocks[m_width * y + x]->setType(blockType);

				// add checkpoint to track
				if (blockType == Common::BT_START_LINE_UP) {
					lastCP = CL_Pointf((x + 0.5f) * Block::WIDTH, (y + 0.2f) * Block::WIDTH);
					const CL_Pointf firstCP((x + 0.5f) * Block::WIDTH, (y + 0.2 - 0.01f) * Block::WIDTH);

					m_track.addCheckpointAtPosition(firstCP);
				} else {
					const CL_Pointf checkPosition((x + 0.5f) * Block::WIDTH, (y + 0.5f) * Block::WIDTH);

					m_track.addCheckpointAtPosition(checkPosition);
				}

				// add resistance geometry based on block
				CL_SharedPtr<RaceResistance::Geometry> resGeom = buildResistanceGeometry(x, y, blockType);
				m_resistanceMap.addGeometry(resGeom, 0.0f);

			} else {
				cl_log_event("race", "Unknown block type: %1", typeStr);
			}

		} else {
			cl_log_event("race", "Unknown node '%1', ignoring", blockNode.get_node_name());
		}

	}

	m_track.addCheckpointAtPosition(lastCP);
	m_track.close();

}
Пример #26
0
CL_SharedPtr<RaceResistance::Geometry> Level::buildResistanceGeometry(int p_x, int p_y, Common::GroundBlockType p_blockType) const
{
	CL_SharedPtr<RaceResistance::Geometry> geom(new RaceResistance::Geometry());

	CL_Pointf p, q;
	CL_Pointf topLeft = real(CL_Pointf(p_x, p_y));
	CL_Pointf bottomRight = real(CL_Pointf(p_x + 1, p_y + 1));

	switch (p_blockType) {
		case Common::BT_GRASS:
			break;
		case Common::BT_STREET_HORIZ:
			p = real(CL_Pointf(p_x, p_y + 0.1f));
			q = real(CL_Pointf(p_x + 1, p_y + 0.9f));

			geom->addRectangle(CL_Rectf(p.x, p.y, q.x, q.y));
			break;
		case Common::BT_STREET_VERT:
			p = real(CL_Pointf(p_x + 0.1f, p_y));
			q = real(CL_Pointf(p_x + 0.9f, p_y + 1));

			geom->addRectangle(CL_Rectf(p.x, p.y, q.x, q.y));
			break;
		case Common::BT_TURN_BOTTOM_RIGHT:
			p = real(CL_Pointf(p_x + 1, p_y + 1));

			geom->addCircle(CL_Circlef(p, real(0.9f)));
			geom->subtractCircle(CL_Circlef(p, real(0.1f)));

			geom->andRect(CL_Rectf(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y));

			break;
		case Common::BT_TURN_BOTTOM_LEFT:
			p = real(CL_Pointf(p_x, p_y + 1));

			geom->addCircle(CL_Circlef(p, real(0.9f)));
			geom->subtractCircle(CL_Circlef(p, real(0.1f)));

			geom->andRect(CL_Rectf(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y));

			break;
		case Common::BT_TURN_TOP_RIGHT:
			p = real(CL_Pointf(p_x + 1, p_y));

			geom->addCircle(CL_Circlef(p, real(0.9f)));
			geom->subtractCircle(CL_Circlef(p, real(0.1f)));

			geom->andRect(CL_Rectf(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y));
			break;
		case Common::BT_TURN_TOP_LEFT:
			p = real(CL_Pointf(p_x, p_y));

			geom->addCircle(CL_Circlef(p, real(0.9f)));
			geom->subtractCircle(CL_Circlef(p, real(0.1f)));

			geom->andRect(CL_Rectf(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y));
			break;
		case Common::BT_START_LINE_UP:
			p = real(CL_Pointf(p_x + 0.1f, p_y));
			q = real(CL_Pointf(p_x + 0.9f, p_y + 1));

			geom->addRectangle(CL_Rectf(p.x, p.y, q.x, q.y));
			break;
		default:
			assert(0 && "unknown block type");
	}

	return geom;
}
Пример #27
0
//Zeichnet das Menü
void Menu::draw()
{
	CL_Font fontSmall;
	CL_Font fontBig;
	CL_Rect rectangle;
	std::stringstream sstream;
	std::string outputString;
	CL_Quadf textureQuad;
	CL_Rectf textureRectangle;
	CL_GraphicContext graphicContext;
	int space = 30;
	CL_Size textSize;
	int xPosition;

	//Ist die Menübreite gesetzt, wird der Anfang in x-Richtung
	//berechnet, damit das Menü zentriert ist
	if(menuWidth == -1)
		xPosition = 0;
	else
		xPosition = (viewPort.get_width() - menuWidth) / 2;

	graphicContext = world->get_gc();

	//Schriften setzen
	fontSmall = CL_Font(graphicContext, "Comic Sans MS", 10);
	fontBig = CL_Font(graphicContext, "Comic Sans MS", 20);

	//Die unterschiedlichen Turmtypen durchgehen
	for(unsigned int i = 0; i < towerTypes.size(); i++)
	{
		//Ein Rechteck für den Rahmen eines Baufeldes definieren
		rectangle = CL_Rect(
			i*menuHeight + xPosition,
			viewPort.get_height() - menuHeight,
			(i+1)*menuHeight + xPosition,
			viewPort.get_height()-1);
		//Den Rahmen des Baufeldes zeichnen
		CL_Draw::box(graphicContext, rectangle, CL_Colorf::white);
		
		//Ein Rechteck für die Anzeige der Turmtextur innerhalb des Baufeldes definieren
		textureRectangle = CL_Rectf(
			i * menuHeight + ((menuHeight - menuTowerLength) / 2.0f) + xPosition,
			viewPort.get_height() - menuHeight + 5.0f,
			CL_Sizex<float>((float)menuTowerLength, (float)menuTowerLength));
		textureQuad = CL_Quadf(textureRectangle);
		//Turmtextur zeichnen
		CL_Draw::texture(graphicContext, towerTypes[i]->texture, textureRectangle);
		
		//Nummer (=Shortcut auf Tastatur) des Baufeldes in der linken oberen Ecke zeichnen
		sstream << (i+1);
		sstream >> outputString;
		sstream.clear();
		fontSmall.draw_text(graphicContext, rectangle.left + 5, rectangle.top + 10,
			outputString,CL_Colorf::white);

		//Kosten des Turmes unterhalb der Textur und zentriert im Baufeld ausgeben
		sstream << towerTypes[i]->price;
		sstream >> outputString;
		sstream.clear();
		textSize = fontSmall.get_text_size(graphicContext, outputString);
		fontSmall.draw_text(graphicContext, ((menuHeight - textSize.width) / 2) + i * menuHeight + xPosition,
			viewPort.get_height() - textSize.height/2, outputString, CL_Colorf::white);
	}
	
	//x-Position weitersetzen für nächsten Menüeintrag
	xPosition += towerTypes.size()*menuHeight + space;

	//Geldanzeige
	sstream << world->getMoney();
	sstream >> outputString;
	sstream.clear();
	textSize = fontBig.get_text_size(world->get_gc(), outputString);

	Menu::drawMenuItem(outputString, menuCoinsLength, coinsTexture, fontBig, menuHeight/2, xPosition);

	xPosition += menuCoinsLength + textSize.width + space;

	//Zeitanzeige
	sstream << world->getCountdown();
	sstream >> outputString;
	sstream.clear();
	outputString = "Next Wave:\n" + outputString;
	textSize = fontBig.get_text_size(graphicContext, outputString);

	Menu::drawMenuItem(outputString, menuTimeLength, clockTexture, fontBig, menuHeight/2 - 10, xPosition);

	xPosition += menuTimeLength + textSize.width + space;

	//Lebensanzeige
	sstream << world->getLifes();
	sstream >> outputString;
	sstream.clear();
	
	Menu::drawMenuItem(outputString, menuLifeLength, heartTexture, fontBig, menuHeight/2, xPosition);

	//Beim ersten Aufruf wird die Menübreite errechnet
	if(menuWidth == -1)
	{
		textSize = fontBig.get_text_size(graphicContext, outputString);
		menuWidth = xPosition + menuLifeLength + textSize.width;
	}
}
void ScrollBarRenderComponent::OnRender(VariantList *pVList)
{
	//NOTE: We don't support drawing a horizontal scroll bar yet!
	CHECK_GL_ERROR();
	//LogMsg("Drawing progress bar: %.2f", progress);
	if (*m_pAlpha <= 0.07)
	{
		return; //not ready
	}

	float contentAreaRatio;
	
	GLboolean bScissorEnabled = false;
	glGetBooleanv(GL_SCISSOR_TEST, &bScissorEnabled);

	if (bScissorEnabled)
	{
		g_globalBatcher.Flush();
		//disable it temporarily
		glDisable(GL_SCISSOR_TEST);
	}
	float barHeight;
	float barWidth;
	CL_Vec2f vFinalPos;
	uint32 color = ColorCombine(*m_pColor, *m_pColorMod, *m_pAlpha);

	if (!m_pSurf) return; //can't do anything without the graphics loaded
	
	contentAreaRatio = (m_pBoundsRect->get_height()+m_pSize2d->y)/m_pSize2d->y;

	if (!m_bUsingScrollComponent && m_pBoundsRect->get_height() < (m_pSize2d->y+1)) //I don't really know why I need that +1..but it works..
	{
		contentAreaRatio = 0; //definitely don't need to scroll here
	}

	if (contentAreaRatio > 1)
	{
		//render vertical scroll bar
		m_pSurf->SetupAnim(1,2);

		barHeight = m_pSize2d->y/contentAreaRatio;
		
		if (barHeight < m_pSurf->GetFrameHeight()*2) barHeight = m_pSurf->GetFrameHeight()*2;
		
		barWidth = m_pSurf->GetFrameWidth();
		//LogMsg("percent scrolled is %.2f, contentAreaRation is %.2f", m_pProgress2d->y, contentAreaRatio);

		vFinalPos = pVList->m_variant[0].GetVector2()+ *m_pPos2d + CL_Vec2f(m_pSize2d->x, 0);

		if (vFinalPos.x >= GetScreenSizeXf())
		{
			//position on the inside, not the outside
			vFinalPos.x -= ( barWidth+(iPadMapX(8) )); //adjust the spacer with the screensize
		}
		//slide it down to the right position:
		vFinalPos.y += (m_pSize2d->y - barHeight)* m_pProgress2d->y;

		//draw the top of the capsule
		m_pSurf->BlitAnim(vFinalPos.x, vFinalPos.y,0,0, color);
		vFinalPos.y += m_pSurf->GetFrameHeight(); 
		barHeight -=  m_pSurf->GetFrameHeight()*2;
		//draw the bottom end cap
		m_pSurf->BlitAnim(vFinalPos.x, vFinalPos.y+barHeight,0,1, color);
		//first draw the first end cap
		CL_Rectf r = CL_Rectf(0, 0, barWidth, barHeight);
		ApplyOffset(&r, vFinalPos);
		DrawFilledRect(r, color);
	}

	contentAreaRatio = (m_pBoundsRect->get_width()+m_pSize2d->x)/m_pSize2d->x;

	if (!m_bUsingScrollComponent && m_pBoundsRect->get_width() < (m_pSize2d->x+1)) //I don't really know why I need that +1..but it works..
	{
		contentAreaRatio = 0; //definitely don't need to scroll here
	}
	
	if (contentAreaRatio > 1)
	{
		//render horizontal scroll bar
		m_pSurf->SetupAnim(2,1); //repurpose the graphics for horizontal...

		barWidth = m_pSize2d->x/contentAreaRatio;

		if (barWidth < m_pSurf->GetFrameWidth()*2) barWidth = m_pSurf->GetFrameWidth()*2;

		barHeight= m_pSurf->GetFrameHeight();
		//LogMsg("percent scrolled is %.2f, contentAreaRation is %.2f", m_pProgress2d->x, contentAreaRatio);

		vFinalPos = pVList->m_variant[0].GetVector2()+ *m_pPos2d + CL_Vec2f(0, m_pSize2d->y);

		if (vFinalPos.y >= GetScreenSizeYf())
		{
			//position on the inside, not the outside
			vFinalPos.y -= ( barHeight+(iPadMapY(6) )); //adjust the spacer with the screensize
		}
		//slide it down to the right position:
		vFinalPos.x += (m_pSize2d->x - barWidth)* m_pProgress2d->x;

		//draw the top of the capsule
		m_pSurf->BlitAnim(vFinalPos.x, vFinalPos.y,0,0, color);
		vFinalPos.x += m_pSurf->GetFrameWidth(); 
		barWidth -=  m_pSurf->GetFrameWidth()*2;
		//draw the bottom end cap
		m_pSurf->BlitAnim(vFinalPos.x+barWidth, vFinalPos.y,1,0, color);
		//first draw the first end cap
		CL_Rectf r = CL_Rectf(0, 0, barWidth, barHeight);
		ApplyOffset(&r, vFinalPos);
		DrawFilledRect(r, color);
		CHECK_GL_ERROR();

	}
	
	
	if (bScissorEnabled)
	{
		g_globalBatcher.Flush();
		glEnable(GL_SCISSOR_TEST);
	}
	CHECK_GL_ERROR();

}
void RenderScissorComponent::FilterOnRender(VariantList *pVList)
{

	CHECK_GL_ERROR()
	g_globalBatcher.Flush();

	GLboolean b = false;
	
	//Note: This fails when using the webOS emulation libs on Windows.. but works on the real device
	glGetBooleanv(GL_SCISSOR_TEST, &b);
	
#if defined(WIN32) && defined(RT_WEBOS) && defined(_DEBUG)
	//clear the error out so it doesn't flood our log
	glGetError();
#endif
	m_bOldScissorEnabled = b != 0;
	CHECK_GL_ERROR()
	if (m_bOldScissorEnabled)
	{
		//warning: Untested code...
		GLint nums[4];
		glGetIntegerv(GL_SCISSOR_BOX, &nums[0]);
		m_oldScissorPos = CL_Vec2f((float)nums[0],(float) nums[1]);
		m_oldScissorSize = CL_Vec2f((float)nums[2],(float) nums[3]);
		CHECK_GL_ERROR()
	}

	CL_Vec2f vFinalPos = pVList->m_variant[0].GetVector2()+*m_pPos2d;
	//vFinalPos -= GetAlignmentOffset(*m_pSize2d, eAlignment(*m_pAlignment));	

	CL_Rectf clipRect(vFinalPos.x, vFinalPos.y, vFinalPos.x+m_pSize2d->x, vFinalPos.y+m_pSize2d->y);
		
	//well, turns out we need to always do this on iOS, as this accounts for the screen being rotated as well, not just
	//the scaling issue

//	if (NeedToUseFakeScreenSize())
	{
		//Oh shit-sticks. We're stretching our content and using a fake screensize.  We'll need to convert
		//our glScissor rect to match the real gl surface size.
	
		float angle = OrientationToDegrees(GetOrientation());
		while (angle < 0)
		{
			angle+= 360;
		}
		rtRectf r = rtRectf(clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
		r = ConvertFakeScreenRectToReal(r);
		clipRect = CL_Rectf(r.left, r.top, r.right, r.bottom);

		float primaryX = (float)GetPrimaryGLX();
		float primaryY = (float)GetPrimaryGLY();
		
		if (InLandscapeGUIMode())
		{
			swap(primaryX, primaryY);
		}
		
		clipRect = RotateRect(clipRect, angle, CL_Vec2f(primaryX, primaryY));
	}

	//remember, glScissors x/y is the LOWER LEFT of the rect, not upper left. (and lower left is 0,0)
	glScissor((GLint)clipRect.left, (GLint)GetPrimaryGLY()-((GLint)clipRect.top+(GLint)clipRect.get_height()), (GLint)clipRect.get_width(),(GLint) clipRect.get_height());
	glEnable(GL_SCISSOR_TEST);

}
Пример #30
0
void CL_Window_Silver::on_paint()
{
	CL_Rectf rect = window->get_screen_rect();

	// Titlebar
	CL_Display::fill_rect(
		CL_Rectf(rect.left + 2, rect.top + 4, rect.right - 2, rect.top + titlebar_height - 3),
		CL_Color(206, 217, 228));

	CL_Display::draw_line(
		rect.left + 2,
		rect.top + 2,
		rect.right - 2,
		rect.top + 2,
		CL_Color(251, 253, 255));

	CL_Display::draw_line(
		rect.left + 2,
		rect.top + 3,
		rect.right - 2,
		rect.top + 3,
		CL_Color(236, 238, 240));

	CL_Display::draw_line(
		rect.left + 2,
		rect.top + titlebar_height - 3,
		rect.right - 2,
		rect.top + titlebar_height - 3,
		CL_Color(180, 202, 224));

	CL_Display::draw_line(
		rect.left + 2,
		rect.top + titlebar_height - 2,
		rect.right - 2,
		rect.top + titlebar_height - 2,
		CL_Color(144, 180, 218));

	CL_Display::draw_line(
		rect.left + 2,
		rect.top + titlebar_height - 1,
		rect.right - 2,
		rect.top + titlebar_height - 1,
		CL_Color(128, 142, 159));

	// Outer window frame
	CL_Display::draw_rect(
		rect,
		CL_Color(128, 142, 159));

	// Inner window frame
	CL_Display::draw_rect(
		CL_Rectf(rect.left + 1, rect.top + 1, rect.right - 1, rect.bottom - 1),
		CL_Color(161, 172, 185));

	// Client area
	CL_Display::fill_rect(
		CL_Rectf(rect.left + 2, rect.top + titlebar_height, rect.right - 2, rect.bottom - 2),
		CL_Gradient(
			CL_Color(255, 255, 255, 235),
			CL_Color(255, 255, 255, 235),
			CL_Color(224, 228, 232, 235),
			CL_Color(224, 228, 232, 235)));
		
	int y = (titlebar_height + 2 - font->get_height()) / 2;

	if(window->is_enabled() == false)
		font_disabled->draw(static_cast<int>(rect.left + 7),
								  static_cast<int>(rect.top + y), window->get_title());
	else
	{
		font->draw(static_cast<int>(rect.left + 7), 
					  static_cast<int>(rect.top + y), window->get_title());
		font->draw(static_cast<int>(rect.left + 8),
					  static_cast<int>(rect.top + y), window->get_title());
	}

/*	CL_Rect rect = window->get_screen_rect();

	int offx = window->get_screen_x();
	int offy = window->get_screen_y();

	int w_width = rect.get_width();
	int w_height = rect.get_height();

	// Vertical shadows
	CL_Display::draw_line(offx+w_width + 0, offy + 5, offx+w_width + 0, offy+w_height + 0, CL_Color(0, 0, 0, 64));
	CL_Display::draw_line(offx+w_width + 1, offy + 5, offx+w_width + 1, offy+w_height + 1, CL_Color(0, 0, 0, 51));
	CL_Display::draw_line(offx+w_width + 2, offy + 5, offx+w_width + 2, offy+w_height + 2, CL_Color(0, 0, 0, 38));
	CL_Display::draw_line(offx+w_width + 3, offy + 5, offx+w_width + 3, offy+w_height + 3, CL_Color(0, 0, 0, 25));
	CL_Display::draw_line(offx+w_width + 4, offy + 5, offx+w_width + 4, offy+w_height + 4, CL_Color(0, 0, 0, 13));

	// Horizontal shadows
	CL_Display::draw_line(offx + 5, offy+w_height + 0, offx+w_width + 1, offy+w_height + 0, CL_Color(0, 0, 0, 64));
	CL_Display::draw_line(offx + 5, offy+w_height + 1, offx+w_width + 2, offy+w_height + 1, CL_Color(0, 0, 0, 51));
	CL_Display::draw_line(offx + 5, offy+w_height + 2, offx+w_width + 3, offy+w_height + 2, CL_Color(0, 0, 0, 38));
	CL_Display::draw_line(offx + 5, offy+w_height + 3, offx+w_width + 4, offy+w_height + 3, CL_Color(0, 0, 0, 25));
	CL_Display::draw_line(offx + 5, offy+w_height + 4, offx+w_width + 5, offy+w_height + 4, CL_Color(0, 0, 0, 13));
*/
}