hinekure.net が http://hspdev-wiki.net/ から自動クローリングした結果を表示しています。画像やリソースなどのリンクが切れています。予めご了承ください。
eseobj/imgbtn2 - HSP開発wiki
トップ    編集凍結 差分バックアップ添付複製名前変更リロード   新規一覧単語検索最終更新   最終更新のRSS

画像を使ったボタン

eseobj/imgbtnとは違い、ウィンドウメッセージを利用していません。

mousex, mouseyをそのまま利用しているので、複数のscreenを利用しているときは 正しい動作をしないことがあります。

モジュール変数を利用したGraphicalBtn?モジュールと、それを管理・操作するgBtnCtrl?モジュールから構成されています。 ちょっと変わった方法ではありますが、いろいろと便利なので参考になるのではないでしょうか。

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
|
|
!
 
 
 
 
 
 
 
 
 
 
 
-
-
|
|
-
|
|
!
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
|
|
!
 
 
 
 
 
 
 
-
|
|
!
-
|
-
|
|
|
!
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/*
	GraphicalBtn 本体
	スクリプトからは直接利用しない
*/
#module GraphicalBtn x, y, w, h, gID, gx, gy, wID, oID
#modinit int _x, int _y, int _w, int _h, int _gID, int _gx, int _gy, int _wID, int _oID
    x = _x : y = _y                   // ボタンの位置
    w = _w : h = _h                   // ボタンの大きさ
    gID = _gID : gX = _gX : gY = _gY  // 画像のコピー元ウィンドウIDとその座標
    wID = _wID                        // ボタンのあるウィンドウID
    oID = _oID                        // 似非オブジェクトID
    return
 
// モードに従ってボタンを描画する
#modfunc draw_gbutton int mode
    gsel wID : pos x, y
    gcopy gID, gX, gY + h * ( mode != 0 ), w, h
    return
 
// 指定した座標がボタンの内側にあるか?
#modfunc inside int _x, int _y, local ret
    return ( x <= _x ) & ( y <= _y ) & ( _x < x + w ) & ( _y < y + h )
 
#modfunc get_oID
    return oID
 
#modfunc get_wID
    return wID
#global
 
/*
	GraphicalBtn をコントロールするためのモジュール
*/
#module gBtnCtrl
// 新しい似非オブジェクトIDを取得
#defcfunc new_oID@gBtnCtrl local iResult
    iResult = length( idlist )
    foreach idList
        if ( idList( cnt ) == 0 ) {
            iResult = cnt
            break
        }
    loop
    idList( iResult ) = 1
    return iResult
 
// マウス下にあるボタンのナンバーを取得
#defcfunc oID_pointed local iResult
    iResult = -1, -1
    foreach gbuttons
        get_wID gbuttons( cnt )
        gsel stat
        inside gbuttons( cnt ), mousex, mousey
        if ( stat ) {
            if ( stat != ginfo_act ) {
                // 候補ではあるが即決ではない
                iResult( 1 ) = cnt
            } else {
                iResult( 0 ) = cnt
                break
            }
        }
    loop
    return iResult( iResult( 0 ) == -1 )
 
// ボタンを作成する
#deffunc gbutton int gID, int gX, int gY, int w, int h, local oID
    oID = new_oID()
    newmod gbuttons, GraphicalBtn, ginfo_cx, ginfo_cy, w, h, gID, gX, gY, ginfo_sel, oID
    return oID
 
// すべてのボタンを描画する
#deffunc draw_gbuttons
    nPointed = oID_pointed()
    foreach gbuttons
        get_oID gbuttons( cnt )
        draw_gbutton gbuttons( cnt ), ( nPointed == stat )
    loop
    return
 
// 似非オブジェクトIDからgbuttonsのインデックスへ変換
#defcfunc get_num int id, local iResult
    iResult = -1
    foreach gbuttons
        get_oID gbuttons( cnt )
        if ( stat == id ) {
            iResult = cnt
            break
        }
    loop
    return iResult
 
// クリックされたボタンの似非オブジェクトIDを取得
#defcfunc oID_clicked local iResult
    iResult = -1
    getkey key, 1
    if ( oldKey == 0 ) & ( key == 1 ) {
        // クリック開始
        oID_clickstart = oID_pointed()
    }
    if ( oldKey == 1 ) & ( key == 0 ) {
        // クリック終了
        if ( oID_clickstart == oID_pointed() ) & ( 0 <= oID_clickstart ) {
            // クリック開始時とクリック終了時の
            // マウス下にあるボタンのナンバーが同じなら、クリックされたと判断
            iResult = oID_clickstart
        }
    }
    oldKey = key
    return iResult
 
// 指定した似非オブジェクトIDのボタンを削除
#deffunc del_gbutton int id
    delmod gbuttons( get_num( id ) )
    idList( id ) = 0
    return
 
// すべてのgbuttonを削除
#deffunc clear_gbuttons
    foreach gbuttons
        delmod gbuttons( cnt )
    loop
    dim idList, 1
    return
 
#global
    oID_clickstart@gBtnCtrl = -1

サンプルスクリプト

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
|
-
|
|
!
!
 
 
#const SIZE_GBUTTON 40
    // ボタン用画像を作成
    screen 2, 640, SIZE_GBUTTON * 2, SCREEN_TOOL
    title "ボタン用画像"
    repeat ginfo_winx / SIZE_GBUTTON
        hsvcolor 192 * cnt / 16, 255, 255
        boxf cnt * SIZE_GBUTTON, 0,            ( cnt + 1 ) * SIZE_GBUTTON, SIZE_GBUTTON
        hsvcolor 192 * cnt / 16, 128, 255
        boxf cnt * SIZE_GBUTTON, SIZE_GBUTTON, ( cnt + 1 ) * SIZE_GBUTTON, SIZE_GBUTTON * 2
        color
        pos cnt * SIZE_GBUTTON, 0            : mes cnt
        pos cnt * SIZE_GBUTTON, SIZE_GBUTTON : mes cnt
    loop
 
    // ボタンを配置
    repeat 2
        screen cnt, 320, 240, SCREEN_NORMAL
        title "ウィンドウID : " + cnt
        c = cnt
        repeat ginfo_winx / SIZE_GBUTTON
            pos cnt * SIZE_GBUTTON, ( ginfo_winy - SIZE_GBUTTON ) / 2
            gbutton 2, ( cnt + c * ginfo_winx / SIZE_GBUTTON ) * SIZE_GBUTTON, 0, SIZE_GBUTTON, SIZE_GBUTTON
        loop
    loop
 
*main
    gsel 0 : redraw 0 : color 255, 255, 255 : boxf
    gsel 1 : redraw 0 : color 255, 255, 255 : boxf
    draw_gbuttons
    gsel 0 : redraw 1
    gsel 1 : redraw 1
 
    if ( ginfo_act != 2 ) {
        nClicked = oID_clicked()
        if ( 0 <= nClicked ) {
            dialog "ナンバー" + nClicked + "のボタンが押されました。"
            del_gbutton nClicked // クリックされたボタンを削除
        }
    }
    wait 3
    goto *main

URL B I U SIZE Black Maroon Green Olive Navy Purple Teal Gray Silver Red Lime Yellow Blue Fuchsia Aqua White

トップ    編集凍結 差分バックアップ添付複製名前変更リロード   新規一覧単語検索最終更新   最終更新のRSS
Last-modified: 2007-07-23 (月) 09:04:38 (2330d)