スーパーpre記法

プログラムのソースコードを載せるのに超便利な pre 記法ですが、この度シンタックスカラー化に対応したそうです。せっかくなので、現在作成中の BayOS 用 BayGUI で bball を書き直した例を載せてみます。

#include "../baygui.h"

#define SCREEN_W 200
#define SCREEN_H 200

static int point[16][2] = {
    { 196, 100 }, { 187,  61 }, { 164,  29 }, { 129,   9 }, {  90,   5 },
    {  53,  17 }, {  23,  44 }, {   7,  81 }, {   7, 119 }, {  23, 156 },
    {  53, 183 }, {  90, 195 }, { 129, 191 }, { 164, 171 }, { 187, 139 },
    { 196, 100 }
};

static word color[16] = {
    0x0000, 0x8000, 0x0400, 0x8400, 0x0010, 0x8010, 0x0410, 0xc618,
    0x8410, 0xf800, 0x07e0, 0xffe0, 0x001f, 0xf81f, 0x07ff, 0xffff
};

class BBall : public Frame {
public:
    BBall()
    {
        setTitle("bball");
        setBounds(0, 0, SCREEN_W + INSETS_LEFT + INSETS_RIGHT, SCREEN_H + INSETS_TOP + INSETS_BOTTOM);
    }

    virtual void paint(Graphics* g)
    {
        /* 背景を塗りつぶす */
        g->setColor(0x0000);
        g->fillRect(0, 0, SCREEN_W, SCREEN_H);
        
        for (int i = 0; i < 15; i++) {
            int x0 = point[i][0];
            int y0 = point[i][1];
            for (int j = i + 1; j < 16; j++) {
                int dis = j - i; /* 2つの点の距離 */
                if (dis >= 8)
                dis = 15 - dis; /* 逆回りに数える */
                if (dis != 0) {
                    g->setColor(color[16 - dis]);
                    g->drawLine(x0, y0, point[j][0], point[j][1]);
                }
            }
        }
    }
};

void HariMain(void)
{
    BBall* bball = new BBall();
    Application::run(bball);
}