LoginSignup
0
0

More than 5 years have passed since last update.

C++ Builder / TCanvas > Chordを描いて中の色を塗る

Last updated at Posted at 2017-03-28
動作環境
C++ Builder XE4

関連 http://qiita.com/7of9/items/a5c05ddddd268d8e82e7

塗りつぶしを試す。

TCanvas.FloodFill Method

Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TRect R = GetClientRect();
    //            X1      Y1     X2       Y2        X3       Y3     X4      Y4
    Canvas->Chord(R.Left, R.Top, R.Right, R.Bottom, R.Right, R.Top, R.Left, R.Top);

    Canvas->Brush->Color = clBlue;

    long hormid = (R.Left + R.Right) / 2;
    Canvas->FloodFill(hormid, R.top - 100, clBlack, fsBorder);

}
//---------------------------------------------------------------------------

qiita.png

  • ボタンを2回押さないと中の色を塗らない
  • 他のウィンドウで隠された後、描画されない

参考 http://stackoverflow.com/questions/24931706/how-to-repaint-canvas-just-in-time

描画をきちんとするにはFormPaint()で実装するようだ。

Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
{
    TRect R = GetClientRect();
    //            X1      Y1     X2       Y2        X3       Y3     X4      Y4
    Canvas->Chord(R.Left, R.Top, R.Right, R.Bottom, R.Right, R.Top, R.Left, R.Top);

    Canvas->Brush->Color = clBlue;

    long hormid = (R.Left + R.Right) / 2;
    Canvas->FloodFill(hormid, R.Top + 50, clBlack, fsBorder);
}
//---------------------------------------------------------------------------

こちらでは、他のウィンドウで隠してから表示してもきちんと描画される。

0
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
0
0