利用ShapeRenderer可进行矩形进度条的绘制,多变形的填充等操作。

这是根据角度获取矩形坐标的函数。

     public Vector2 GetPoint( float x, float y, float w, float h, float angle ){
Vector2 point = new Vector2();
while( angle >= 360 ){
angle -= 360;
}
while( angle < 0 ){
angle += 360;
} System.out.println( GetAtan( h/w ) ); if( angle>=0 && angle<GetAtan( h/w ) || angle>=360-GetAtan( h/w ) && angle<360 ){
point.x = x+w;
point.y = y+w*Change( angle );
}
else if( angle>=GetAtan( h/w ) && angle<180-GetAtan( h/w ) ){
point.x = x+h*Change( 90-angle );
point.y = y+h;
}
else if( angle>=180-GetAtan( h/w ) && angle<180+GetAtan( h/w ) ){
point.x = x-w;
point.y = y-w*Change( angle );
}
else if( angle>=180+GetAtan( h/w ) && angle<360-GetAtan( h/w ) ){
point.x = x-h*Change( 90-angle );
point.y = y-h;
} return point;
}

画部分矩形

     public void FillPartRect( float x, float y, float w, float h, float start, float angle, ShapeRenderer rend, Color color  )
{
rend.begin( ShapeType.Line );
rend.setColor( color );
rend.rect( x-w, y-h, 2*w, 2*h );
rend.end(); rend.begin( ShapeType.Filled ); for( int i=0; i<angle-1; i++ ){
Vector2 point1 = GetPoint( x, y, w, h, start+i );
Vector2 point2 = GetPoint( x, y, w, h, start+i+1 );
rend.triangle( x, y, point1.x, point1.y, point2.x, point2.y );
}
rend.end();
}

全部代码如下:

 package com.fxb.newtest;

 import sun.security.provider.certpath.Vertex;

 import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2; public class Lib012_CdDraw extends ApplicationAdapter{ ShapeRenderer rend; float[] vertexs; Pixmap pixmap;
float angle = 0; @Override
public void create() {
// TODO Auto-generated method stub
rend = new ShapeRenderer(); vertexs = new float[]{ 100, 100, 250, 100, 200, 200, 100, 250 }; } public void FillPolygon( float[] vertexs, ShapeRenderer rend, Color color ){
if( vertexs.length%2 != 0 ){
return;
}
rend.begin( ShapeType.Filled );
rend.setColor( color );
for( int i=2; i<=vertexs.length-4; i+=2 ){
rend.triangle( vertexs[0], vertexs[1], vertexs[i], vertexs[i+1], vertexs[i+2], vertexs[i+3] );
}
rend.end();
} public float Change( float angle0 ){
return (float)Math.tan( angle0*(float)Math.PI/180 );
} public void FillRect( float x, float y, float w, float h, float start, float angle, ShapeRenderer rend, Color color ){ rend.begin( ShapeType.Line );
rend.setColor( color );
rend.rect( x-w, y-h, 2*w, 2*h );
rend.end(); rend.begin( ShapeType.Filled );
rend.setColor( color );
//angle = angle*(float)Math.PI/180; if( angle <= 45 ){
rend.triangle( x, y, x+w, y, x+w, y+w*(float)Math.tan( angle*(float)Math.PI/180 ) );
}
else if( angle <= 135 ){
rend.triangle( x, y, x+w, y, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+h*(float)Math.tan( (90-angle)*(float)Math.PI/180 ), y+h );
}
else if( angle <= 135+90 ){
rend.triangle( x, y, x+w, y, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x-w, y+h );
rend.triangle( x, y, x-w, y+h, x-w, y-w*Change( angle ) );
}
else if( angle <= 135+180 ){
rend.triangle( x, y, x+w, y, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x-w, y+h );
rend.triangle( x, y, x-w, y+h, x-w, y-h );
rend.triangle( x, y, x-w, y-h, x-h*Change( 270-angle ), y-h );
}
else if( angle <= 360 ){
rend.triangle( x, y, x+w, y, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x-w, y+h );
rend.triangle( x, y, x-w, y+h, x-w, y-h );
rend.triangle( x, y, x-w, y-h, x+w, y-h );
rend.triangle( x, y, x+w, y-h, x+w, y+w*Change(angle) );
} rend.end();
} public float GetAtan( float angle ){
return (float)( 180*Math.atan( angle )/Math.PI );
} public Vector2 GetPoint( float x, float y, float w, float h, float angle ){
Vector2 point = new Vector2();
while( angle >= 360 ){
angle -= 360;
}
while( angle < 0 ){
angle += 360;
} System.out.println( GetAtan( h/w ) ); if( angle>=0 && angle<GetAtan( h/w ) || angle>=360-GetAtan( h/w ) && angle<360 ){
point.x = x+w;
point.y = y+w*Change( angle );
}
else if( angle>=GetAtan( h/w ) && angle<180-GetAtan( h/w ) ){
point.x = x+h*Change( 90-angle );
point.y = y+h;
}
else if( angle>=180-GetAtan( h/w ) && angle<180+GetAtan( h/w ) ){
point.x = x-w;
point.y = y-w*Change( angle );
}
else if( angle>=180+GetAtan( h/w ) && angle<360-GetAtan( h/w ) ){
point.x = x-h*Change( 90-angle );
point.y = y-h;
} return point;
} public void FillRect1( float x, float y, float w, float h, float start, float angle, ShapeRenderer rend, Color color ){ rend.begin( ShapeType.Line );
rend.setColor( color );
rend.rect( x-w, y-h, 2*w, 2*h );
rend.end(); rend.begin( ShapeType.Filled );
rend.setColor( color );
//angle = angle*(float)Math.PI/180; if( angle <= 45 ){
rend.triangle( x, y, x, y+h, x+h*Change( angle ), y+h );
}
else if( angle <= 135 ){
rend.triangle( x, y, x, y+h, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+w, y+w*Change( 90-angle ) );
}
else if( angle <= 135+90 ){
rend.triangle( x, y, x, y+h, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+w, y-h );
rend.triangle( x, y, x+w, y-h, x-h*Change( angle ), y-h );
}
else if( angle <= 135+180 ){
rend.triangle( x, y, x, y+h, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+w, y-h );
rend.triangle( x, y, x+w, y-h, x-w, y-h );
rend.triangle( x, y, x-w, y-h, x-w, y-w*Change( 270-angle ) );
}
else if( angle <= 360 ){
rend.triangle( x, y, x, y+h, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+w, y-h );
rend.triangle( x, y, x+w, y-h, x-w, y-h );
rend.triangle( x, y, x-w, y-h, x-w, y+h );
rend.triangle( x, y, x-w, y+h, x+h*Change( angle ), y+h );
} rend.end();
} public void FillRect2( float x, float y, float w, float h, float start, float angle, ShapeRenderer rend, Color color ){ rend.begin( ShapeType.Line );
rend.setColor( color );
rend.rect( x-w, y-h, 2*w, 2*h );
rend.end(); rend.begin( ShapeType.Filled );
rend.setColor( color );
//angle = angle*(float)Math.PI/180;
rend.rect( x-w, y-h, 2*w, 2*h ); //rend.setColor( color.mul( 0.5f ) ); if( angle <= 45 ){
rend.triangle( x, y, x, y+h, x+h*Change( angle ), y+h );
}
else if( angle <= 135 ){
rend.triangle( x, y, x, y+h, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+w, y+w*Change( 90-angle ) );
}
else if( angle <= 135+90 ){
rend.triangle( x, y, x, y+h, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+w, y-h );
rend.triangle( x, y, x+w, y-h, x-h*Change( angle ), y-h );
}
else if( angle <= 135+180 ){
rend.triangle( x, y, x, y+h, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+w, y-h );
rend.triangle( x, y, x+w, y-h, x-w, y-h );
rend.triangle( x, y, x-w, y-h, x-w, y-w*Change( 270-angle ) );
}
else if( angle <= 360 ){
rend.triangle( x, y, x, y+h, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+w, y-h );
rend.triangle( x, y, x+w, y-h, x-w, y-h );
rend.triangle( x, y, x-w, y-h, x-w, y+h );
rend.triangle( x, y, x-w, y+h, x+h*Change( angle ), y+h );
} rend.end();
} public void FillPartRect( float x, float y, float w, float h, float start, float angle, ShapeRenderer rend, Color color )
{
rend.begin( ShapeType.Line );
rend.setColor( color );
rend.rect( x-w, y-h, 2*w, 2*h );
rend.end(); rend.begin( ShapeType.Filled ); for( int i=0; i<angle-1; i++ ){
Vector2 point1 = GetPoint( x, y, w, h, start+i );
Vector2 point2 = GetPoint( x, y, w, h, start+i+1 );
rend.triangle( x, y, point1.x, point1.y, point2.x, point2.y );
}
rend.end();
} public void FillCircle( ){ } @Override
public void render() {
// TODO Auto-generated method stub
Gdx.gl.glClearColor( 0, 1, 1, 1 );
Gdx.gl.glClear( GL10.GL_COLOR_BUFFER_BIT ); Gdx.gl.glEnable( GL10.GL_BLEND );
Gdx.gl.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA ); /* rend.begin( ShapeType.Filled );
rend.setColor( Color.BLUE );
//rend.polyline( vertexs );
//rend.line( 100, 100, 200, 200 );
//rend.triangle( 100, 100, 200, 100, 100, 200 ); rend.arc( 100, 100, 100, 0, 60 );
rend.circle( 300, 300, 100 );
rend.end();*/ //FillPolygon( vertexs, rend, Color.BLUE ); angle += 0.5f;
/* if( angle > 360 ){
angle -= 360;
}*/ //angle =
//FillRect( 300, 300, 100, 100, 0, angle, rend, Color.BLUE ); //FillRect1( 300, 300, 100, 100, 0, angle, rend, new Color( 1f, 0.7f, 0.7f, 0.5f ));
//FillRect( 300, 300, 100, 100, 0, 90, rend, new Color( 1, 1, 1, 0 ) );
//FillRect2( 300, 300, 100, 100, 0, angle, rend, Color.BLUE); FillPartRect( 300, 300, 100, 100, 90, 360-angle, rend, Color.BLUE);
} @Override
public void dispose() {
// TODO Auto-generated method stub
rend.dispose();
super.dispose();
} }

运行结果:

libgdx学习记录13——矩形CD进度条绘制的更多相关文章

  1. jQuery ajax 标准写法及进度条绘制

    jQuery ajax 标准写法及进度条绘制 $.ajax({ url: "http://www.microsoft.com", //请求的url地址 dataType: &quo ...

  2. ProgressBar学习笔记,自定义横向进度条的样式(包含ActionBar上面的进度条)

     点显示进度条后→   android:max="100" 进度条的最大值 android:progress  进度条已经完成的进度值 android:progressDrawab ...

  3. 【Flutter学习】基本组件之进度条(LinearProgressIndicator, CircularProgressIndicator)

    一,概述 基本有两种类型: 条形进度条(LinearProgressIndicator) new LinearProgressIndicator( backgroundColor: Colors.bl ...

  4. libgdx学习记录12——圆角矩形CircleRect

    libgdx提供了ShapeRenderer这个工具,用它可以画点.画线.画圆.画矩形.画椭圆.画扇形,但是没有提供画圆角矩形的方法. 刚开始自己尝试分成8端,4端画直线,4端画扇形,发现多了半径几部 ...

  5. libgdx学习记录24——九宫格NinePatch

    NinePatch用于图片纹理拉伸显示.当图片拉伸时,4个角不会拉伸,而只有中间的部分会拉伸,适合做圆角矩形类的Button. 简单示例: package com.fxb.newtest; impor ...

  6. libgdx学习记录16——资源加载器AssetManager

    AssetManager用于对游戏中的资源进行加载.当游戏中资源(图片.背景音乐等)较大时,加载时会需要较长时间,可能会阻塞渲染线程,使用AssetManager可以解决此类问题. 主要优点: 1. ...

  7. libgdx学习记录2——文字显示BitmapFont

    libgdx对中文支持不是太好,主要通过Hireo和ttf字库两种方式实现.本文简单介绍最基本的bitmapfont的用法. 代码如下: package com.fxb.newtest; import ...

  8. libgdx学习记录3——动画Animation

    libgdx动画采用Animation实现,即通过帧动画实现. 代码如下: package com.fxb.newtest; import com.badlogic.gdx.ApplicationAd ...

  9. libgdx学习记录27——线段与线段相交检测

    给定p1, p2, p3, p4四个点,p1,p2为一条线段,p3,p4为一条线段,检测其是否有交点. 可分为三种情况: 1. L2与x轴平行 2. L2与y轴平行 3. L2与坐标轴不平行. (L1 ...

随机推荐

  1. su、sudo、su - root的区别

    su和sudo的区别 共同点:都是root用户权限: 不同点:su只获得root权限,工作环境不变,还是在切换之前用户的工作环境:sudo是完全获得root的权限和root的工作环境. sudo:表示 ...

  2. Ionic 命令

    在WebStorm的设置中设置下面的命令后, 可以通过 工具 -->External Tools 中选中来执行指定脚本 C:\Windows\System32\WindowsPowerShell ...

  3. SQL Server复制入门(二)----复制的几种模式 (转载)

    简介本系列文章的上一篇对复制是什么做了一个概述.本篇文章根据发布服务器,分发服务器和订阅服务器的组织方式和复制类型来讲述常用复制的几种模式. 模式的选择选择复制的模式取决于多个方面.首先需要考虑具体的 ...

  4. js实现双向链表

    1.概念 上一个文章里我们已经了解到链表结构,链表的特点是长度不固定,不用担心插入新元素的时候新增位置的问题.插入一个元素的时候,只要找到插入点就可以了,不需要整体移动整个结构. 这里我们了解一下双向 ...

  5. 小程序码B接口生成出错:场景内容包含非法字符

    由于包含了非法字符,微信返回的字节不超过100字符,但是没有包含提示内容,因此很难识别发现问题所在

  6. C/C++控制Windows关机/注销/重启的正确姿势

    简介 说到代码控制Windows关机/注销/重启的方式,有很多种,最简单的不过就是控制命令行,使用system("pause")函数执行一个shutdown -s -t 0,关机就 ...

  7. jquery ajax 设置请求头header 参数

    $.ajax( { url:'http://127.0.0.1:30080/api-a/quasiCustom/selectCustomList', type:'post', dateType:'js ...

  8. [BUG] python实例化N次类,调用类函数log会输出N遍的bug 解决办法

    最近再写DOU用例时,采用的是 unittest测试框架,就涉及到将其它所有模块需要全部在一个 .py文件中进行实例化,然后再运行时发现在控制台中同一个日志信息会打印多次(实例化几次,同一消息就会打印 ...

  9. [Eclipse]如何往eclipse中导入单个python文件,其它类型代码文件也可以参照该方法

    实例:想从外部单独拷一个文件到项目中指定路径,如果直接拷到对应文件夹路径下,启动eslipse又识别不到该文件,下面介绍直接copy的方法至eclipse,复制成功后即会在项目中对应路径下产生文件,下 ...

  10. myeclipse10无法weblogic10.3的问题解决方案

    在完成了myec与wl10的基本配置后,启动报如下错误 Parsing Failure in config.xml: java.lang.AssertionError: java.lang.Class ...