1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

初めに

今回はDXライブラリに標準されている DrawBox関数を使って作っていきます
今回は自分で関数を作ります
今回のプログラムは自作なので見栄えしないし効率がいいものではないかもしれません

DrawBox関数

DrawBox関数とはDXライブラリ内の四角を描画する関数です
DrawBox関数は
int DrawBox( int x1 , int y1 , int x2 , int y2 ,unsigned int Color , int FillFlag ) ;

1 , y1 : 描画する四角形の左上の頂点座標
x2 , y2 : 描画する四角形の右下+1の頂点座標
Color  : 描画する四角形の色
FillFlag : 四角の中身を塗りつぶすか、のフラグ。TRUEで塗りつぶし、FALSEで塗りつぶさない

ゲージとは

増減するパーセンテージを可視化するもの
今回は左から右に増える関数です

ゲージの作成

static void DrawPercentBox(int sx ,int sy, int ex, int ey,float per, int bColor, int pColor);
という関数を定義します

引数は
sx,sy 枠部分の左上の座標
ex,ey 枠部分の右下の座標
per パーセンテージ
bColor 枠部分の色
pColor パーセンテージ部分の色

void DrawPercentBox(int sx, int sy, int ex, int ey, float per, int bColor, int pColor)
{
	int diff = ex - sx;
    if(per > 1.0f)
    {
        per = 1.0f;
    }
    if(per < 0.0f)
    {
        per = 0.0f;
    }
	DrawBox(sx, sy, ex, ey, bColor, true);
	DrawBox(sx, sy, sx + (diff * per), ey, pColor, true);
}

これで完成です。

1行目で枠の幅を求めています
2~5行目はパーセンテージが100%(1.0)より大きい場合100%(1.0)に固定する処理です
6~9行目はパーセンテージが0%(0.0)より小さい場合0%(0.0)に固定する処理です
10行目は枠部分の描画処理です
11行目はパーセンテージ部分の描画処理です

最後に

今回は左から右に増えるゲージの作り方でした
最初にもお話した通り今回の処理はDXライブラリを使用し自分でしたものです
効率が良くない可能性があります

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?