--- nono/wx/wxtextscreen.cpp 2026/04/29 17:04:28 1.1 +++ nono/wx/wxtextscreen.cpp 2026/04/29 17:04:37 1.1.1.2 @@ -1,9 +1,9 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // -#include "wxheader.h" #include "wxtextscreen.h" #include "bitrev.h" #include "cgrom.h" @@ -19,13 +19,13 @@ wxBEGIN_EVENT_TABLE(WXTextScreen, inheri wxEND_EVENT_TABLE() // コンストラクタ -WXTextScreen::WXTextScreen(wxWindow *parent, int arg_col, int arg_row, - const uint16 *arg_textbuf) +WXTextScreen::WXTextScreen(wxWindow *parent, int col_, int row_, + const uint16 *textbuf_) : inherited(parent) { - col = arg_col; - row = arg_row; - textbuf = arg_textbuf; + col = col_; + row = row_; + textbuf = textbuf_; SetTextSize(col, row); } @@ -33,26 +33,18 @@ WXTextScreen::WXTextScreen(wxWindow *par // デストラクタ WXTextScreen::~WXTextScreen() { - if (bitmap) { - delete bitmap; - } - if (image) { - delete image; - } - if (bmpbuf) { - delete bmpbuf; - } - if (prevbuf) { - delete[] prevbuf; - } + bitmap.reset(); + image.reset(); + bmpbuf.reset(); + prevbuf.reset(); } // このパネルの(テキストでの)大きさを設定する。 void -WXTextScreen::SetTextSize(int acol, int arow) +WXTextScreen::SetTextSize(int col_, int row_) { - col = acol; - row = arow; + col = col_; + row = row_; int width = col * font_width; int height = row * font_height; @@ -61,12 +53,11 @@ WXTextScreen::SetTextSize(int acol, int } // サイズ変更イベント側でやるか - if (prevbuf) { - delete[] prevbuf; - prevbuf = NULL; + if ((bool)prevbuf) { + prevbuf.reset(); } - prevbuf = new uint16 [col * row]; - memset(prevbuf, 0xff, col * row * sizeof(*prevbuf)); + prevbuf.reset(new uint16 [col * row]); + memset(&prevbuf[0], 0xff, col * row * sizeof(prevbuf[0])); SetClientSize(width, height); SetMinSize(wxSize(width, height)); @@ -86,8 +77,8 @@ WXTextScreen::SetFontSize(fontsize_t new // 再描画を強制する。 // テキストの桁数行数は変わってないので再確保はしなくていい。 - assert(prevbuf); - memset(prevbuf, 0xff, col * row * sizeof(*prevbuf)); + assert((bool)prevbuf); + memset(&prevbuf[0], 0xff, col * row * sizeof(prevbuf[0])); // コントロールの大きさを変更 wxSize size = wxSize(col * font_width, row * font_height); @@ -110,25 +101,16 @@ WXTextScreen::OnSize(wxSizeEvent& event) view_height = size.y; // ビットマップを持っていれば一旦解放 - if (bitmap) { - delete bitmap; - bitmap = NULL; - } - if (image) { - delete image; - image = NULL; - } - if (bmpbuf) { - delete bmpbuf; - bmpbuf = NULL; - } + bitmap.reset(); + image.reset(); + bmpbuf.reset(); // ビットマップ作成 // 正しく描かれなかった時に分かりやすいよう初期値は濃いグレーにしておく - bmpbuf = new uint8 [view_width * view_height * 3]; - memset(bmpbuf, 0x70, view_width * view_height * 3); - image = new wxImage(view_width, view_height, bmpbuf, true); - bitmap = new wxBitmap(*image); + bmpbuf.reset(new uint8 [view_width * view_height * 3]); + memset(&bmpbuf[0], 0x70, view_width * view_height * 3); + image.reset(new wxImage(view_width, view_height, bmpbuf.get(), true)); + bitmap.reset(new wxBitmap(*image)); } // 描画イベント (UI スレッドから呼ばれる) @@ -138,7 +120,7 @@ WXTextScreen::OnPaint(wxPaintEvent& even // 更新があればメモリ DC に描画 wxMemoryDC memDC; memDC.SelectObject(*bitmap); - if (memcmp(textbuf, prevbuf, col * row * sizeof(*prevbuf)) != 0) { + if (memcmp(textbuf, &prevbuf[0], col * row * sizeof(prevbuf[0])) != 0) { Draw(memDC); } @@ -152,7 +134,7 @@ void WXTextScreen::Draw(wxDC& dc) { const uint16 *text = textbuf; - uint16 *prev = prevbuf; + uint16 *prev = &prevbuf[0]; int px = 0; int py = 0; for (int y = 0; y < row; y++, py += font_height) { @@ -174,7 +156,7 @@ WXTextScreen::Draw(wxDC& dc) } else { // マルチバイト文字は Shift_JIS として処理する uint code = (chr << 8) | (text[1] & 0xff); - if (*(uint32 *)prev != *(uint32 *)text) { + if (*(uint32 *)prev != *(const uint32 *)text) { DrawChar2(dc, px, py, code, attr); } *prev++ = *text++;