d3module でマウス座標と重なっているセルを調べる

といっても、二次元座標から三次元座標に変換をするわけではありません。書き込んだバッファから pget してどのセルと重なっているか調べるだけです。

#include "d3m.hsp"

#const WINDOW_ID_MAIN 0
#const WINDOW_ID_WORK 1

#const PANEL_SIZE_X 1.0
#const PANEL_SIZE_Y 1.0

#const PANEL_DISTANCE_X PANEL_SIZE_X * 1.1
#const PANEL_DISTANCE_Y PANEL_SIZE_Y * 1.1

#const PANELS_NUM_X 10
#const PANELS_NUM_Y 10

#const PANELS_ALL_SIZE_X PANEL_DISTANCE_X * ( PANELS_NUM_X - 1 ) + PANEL_SIZE_X
#const PANELS_ALL_SIZE_Y PANEL_DISTANCE_Y * ( PANELS_NUM_Y - 1 ) + PANEL_SIZE_Y

#const PANELS_START_X 0.0 - PANELS_ALL_SIZE_X / 2
#const PANELS_START_Y 0.0 - PANELS_ALL_SIZE_Y / 2

    buffer WINDOW_ID_WORK
    screen WINDOW_ID_MAIN

    repeat
        d3setcam sin(0.01*cnt)*10, cos(0.01*cnt)*10, 10
        mx = mousex : my = mousey
        gsel WINDOW_ID_WORK
        cls
        gosub *draw
        pget mx, my
        select_x = ginfo_r : select_y = ginfo_g
        gsel WINDOW_ID_MAIN
        redraw 0
        color 255, 255, 255 : boxf
        gosub *draw
        redraw
        await 40
    loop
    stop


*draw
    repeat PANELS_NUM_Y
        y = cnt
        py = PANEL_DISTANCE_Y * y + PANELS_START_Y
        repeat PANELS_NUM_X
            x = cnt
            px = PANEL_DISTANCE_X * x + PANELS_START_X
            pxs = px, px + PANEL_SIZE_X, px + PANEL_SIZE_X, px
            pys = py, py, py + PANEL_SIZE_Y, py + PANEL_SIZE_Y
            pzs = 0, 0, 0, 0
            if ginfo_sel == WINDOW_ID_WORK {
                color x, y
            } else {
                color
                if select_x == x && select_y == y {
                    color 255
                }
            }
            d3square pxs, pys, pzs
        loop
    loop
    return

インフォメーション

公開日時
2008年2月5日 午前8時4分47秒
最終更新日時
2008年2月7日 午前6時42分43秒
カテゴリ
HSP