# drawChar()

フォントをスクリーン上に描画します。

以下の例では、Bボタンを押すたびに、事前に生成したフォントID=10のフォントを用いて固定の文字列を描画します。

```cpp
void loop() {
	if (M5.BtnB.wasReleased()) {
		static int idx = 0;
		const char msg[3][16] = {
		   	"ABCD1234", "あいうえ", "やあ世界" };
		
		auto&& font = queryFont(10); // use font ID=10
		
		drawChar(
			font,         // フォント指定
			0, 240 - 30,  // 左上座標 (X,Y)
			msg[idx],     // 文字列
			RED,          // 文字色
			BLACK,        // 背景色
			0x01);        // オプション 0x01:BOLD
		
		idx++; if (idx >= 3) idx = 0;
	}
}
```

## 関数定義

```cpp
int16_t drawChar(const FontDef& font, int32_t x, int32_t y, 
    uint16_t c, uint32_t color, uint32_t bg, uint8_t opt);
    
int16_t drawChar(const FontDef& font, int32_t x, int32_t y,
    const char *s, uint32_t color, uint32_t bg, uint8_t opt);
    
int16_t drawChar(const FontDef& font, int32_t x, int32_t y,
    const uint16_t* s, uint32_t color, uint32_t bg, uint8_t opt);
```

`font`を用い、左上座標(`x`,`y`)に、文字色`fg`、背景色`bg`、オプション`opt`で文字を描画します。

`uint16_t c`をパラメターとして与えた場合は、Unicode `c` に対応する文字を１文字描画します。

`const char *s`をパラメータとして与えた場合は、`s`をUTF-8としてデコードし、文字列として出力します。

`const uint16_t* s`をパラメータとして与えた場合は、Unicode文字列として描画します。

`opt`はオプションのビットマップです。以下の指定が可能です。

* `0x01` - 太字指定
* `0x02` - カーソルの描画

戻り値は、描画が行われればX(幅)方向に描画したピクセル数を返し、エラーなどが発生したときは0を返します。

## 実装について

実装時では以下のM5StackのAPIを利用しています。

* `M5.Lcd.startWrite()`
* `M5.Lcd.setWindow()`
* `M5.Lcd.endWrite()`
* `tft_Write_16()`
