goo

イメージリスト

イメージリスト

使用DLL: comctl32.DLL
同じサイズの画像を扱う。同DLLのツリービューなどのコントロールなどで利用できる。

単体でも利用可能。
HSPで簡単な動作テストを行った。時間単位での描画速度の結果は、
gcopy > ImageList.Draw() > ImageList.Draw() モジュール

で、左側の「gcopy」が速い。が、差はそれほどないので臨機応変にということで。

良いサンプルではないが、イメージリストを利用したマップ表示のサンプルを以下に書置きします。

実行結果



イメージリストを利用したマップ描画
/////////////////////////////////////////////////////////////
// 関数登録
// mod_ImageLists
#uselib "comctl32.dll"
#cfunc global ImageList_Create         "ImageList_Create"        int,int,int,int,int
#cfunc global ImageList_Remove         "ImageList_Remove"        int,int
#func  global ImageList_Destroy        "ImageList_Destroy"       int
#cfunc global ImageList_AddMasked      "ImageList_AddMasked"     int,int,int
#cfunc global ImageList_Draw           "ImageList_Draw"          int,int,int,int,int,int

#uselib "gdi32.dll"
#cfunc global BitBlt                   "BitBlt"                  int,int,int,int,int,int,int,int,int
#cfunc global CreateCompatibleDC       "CreateCompatibleDC"      int
#cfunc global CreateCompatibleBitmap   "CreateCompatibleBitmap"  int,int,int
#cfunc global SelectObject             "SelectObject"            int,int
#func  global DeleteDC                 "DeleteDC"                int
#func  global DeleteObject             "DeleteObject"            int

// メイン
#cfunc global CreatePolygonRgn         "CreatePolygonRgn"        int,int,int
#cfunc global PtInRegion               "PtInRegion"              int,int,int

/////////////////////////////////////////////////////////////
// mod_ImageLists
#module mod_ImageLists hImgList

#modfunc IL_Create int x, int y, int flag, int initial, int grow
	if( hImgList ) : ImageList_Destroy hImgList
	hImgList = ImageList_Create(x, y, flag, initial, grow)
	if( hImgList ) : return 1 : else : return 0

#modfunc IL_Draw int index, int hdcDest, int x, int y, int style
	if( hImgList == 0 ) : return 0
	return ImageList_Draw(hImgList, index, hdcDest, x, y, style)

#modfunc IL_AddMasked int x, int y, int w, int h, int hdcSrc, int c
	ret = -1
	if( hImgList == 0 ) : return ret
	hdcImg = CreateCompatibleDC(hdcSrc)
	if( hdcImg == 0 ) : return ret
	hBmpImg = CreateCompatibleBitmap(hdcSrc, w, h)
	if( hBmpImg ){
		if( SelectObject(hdcImg, hBmpImg) ){
			if( BitBlt(hdcImg, 0, 0, w, h, hdcSrc, x, y, 0xcc0020) ){
				DeleteDC hdcImg : hdcImg = 0
				ret = ImageList_AddMasked(hImgList, hBmpImg, c)
			}
		}
	}
	if( hdcImg ) : DeleteDC hdcImg
	DeleteObject hBmpImg
	return ret

#modfunc IL_Remove int index
	return ImageList_Remove(hImgList, index)

#modfunc IL_Destroy
	ImageList_Destroy hImgList : hImgList = 0
	return stat

#modinit
	hImgList = 0
	return

#modterm
	ImageList_Destroy hImgList
	return
#global

/////////////////////////////////////////////////////////////
// メイン
#define WINDOW_SIZE_X    350
#define WINDOW_SIZE_Y    350
#define GROUND_SIZE      24
#define GROUND_X         8
#define GROUND_Y         8
#define GROUND_FLOOR     4

*main
	screen 0, WINDOW_SIZE_X, WINDOW_SIZE_Y
	title "サンプル:イメージリスト"
	onclick *on_click
	ret = int(sqrt(3) * GROUND_SIZE / 2)
	buffer 2, ret * 4, GROUND_SIZE * 5 / 2 : color : boxf
	dim pt, 8
	pt(0) = 0, GROUND_SIZE / 2, ret, 0, ret * 2, GROUND_SIZE / 2, ret, GROUND_SIZE
	hRgn1 = CreatePolygonRgn(varptr(pt), 4, 2)
	pt(0) = ret*2, GROUND_SIZE / 2, ret*3, 0, ret * 4, GROUND_SIZE / 2, ret*3, GROUND_SIZE
	hRgn2 = CreatePolygonRgn(varptr(pt), 4, 2)
	pt(0) = 0, GROUND_SIZE, ret, GROUND_SIZE * 3 / 2
	pt(4) = ret, GROUND_SIZE * 5 / 2, 0, GROUND_SIZE * 2
	hRgn3 = CreatePolygonRgn(varptr(pt), 4, 2)
	pt(0) = ret, GROUND_SIZE * 3 / 2, ret * 2, GROUND_SIZE
	pt(4) = ret * 2, GROUND_SIZE * 2, ret, GROUND_SIZE * 5 / 2
	hRgn4 = CreatePolygonRgn(varptr(pt), 4, 2)
	repeat GROUND_SIZE * 5 / 2
		tmp = cnt
		repeat ret * 4
			if(PtInRegion(hRgn1, cnt, tmp)){
				color rnd(128), rnd(128) + 127, 0 : pset cnt, tmp
			}
			if(PtInRegion(hRgn2, cnt, tmp)){
				color rnd(64), rnd(64) + 127, 0 : pset cnt, tmp
			}
			if(PtInRegion(hRgn3, cnt, tmp)){
				color rnd(64) + 96, rnd(64) + 96, 0 : pset cnt, tmp
			}
			if(PtInRegion(hRgn4, cnt, tmp)){
				color rnd(64) + 64, rnd(64) + 64, 0 : pset cnt, tmp
			}
		loop
	loop
	DeleteObject hRgn1 : DeleteObject hRgn2
	DeleteObject hRgn3 : DeleteObject hRgn4
	newmod bg1Img, mod_ImageLists : newmod bg2Img, mod_ImageLists
	IL_Create bg1Img, ret * 2, GROUND_SIZE, 0x21, 1, 0
	IL_Create bg2Img, ret, GROUND_SIZE * 3 / 2, 0x21, 2, 0
	IL_AddMasked bg1Img, 0, 0, ret * 4, GROUND_SIZE, hdc, 0
	IL_AddMasked bg2Img, 0, GROUND_SIZE, ret * 2, GROUND_SIZE * 3 / 2, hdc, 0
	px = (GROUND_Y-GROUND_X-2)  * ret / 2 + (WINDOW_SIZE_X/2)
	py = (WINDOW_SIZE_Y/2) - (GROUND_X+GROUND_Y)*GROUND_SIZE/4

	buffer 1, WINDOW_SIZE_X, WINDOW_SIZE_Y
	repeat WINDOW_SIZE_Y
		tmp = cnt * 200 / WINDOW_SIZE_Y
		color tmp, tmp, 255 : line 0, cnt, WINDOW_SIZE_X, cnt
	loop

*on_click
	gsel 0 : redraw 0 : randomize gettime(7)
	pos 0, 0 : gcopy 1, 0, 0, WINDOW_SIZE_X, WINDOW_SIZE_Y
	repeat GROUND_X
		tmp = cnt
		pxTmp = px + (ret * cnt)
		pyTmp = py + (GROUND_SIZE * cnt / 2)
		repeat GROUND_Y
			f = rnd(GROUND_FLOOR)
			repeat f
				IL_Draw bg2img, 0, hdc, pxTmp, pyTmp-GROUND_SIZE/2-GROUND_SIZE*cnt, 0
				IL_Draw bg2img, 1, hdc, pxTmp+ret, pyTmp-GROUND_SIZE/2-GROUND_SIZE*cnt, 0
			loop
			if( f == GROUND_FLOOR -1 ){ IL_Draw bg1img, 0, hdc, pxTmp, pyTmp-GROUND_SIZE*f, 0 }
			else{ IL_Draw bg1img, 1, hdc, pxTmp, pyTmp-GROUND_SIZE*f, 0 }
			if(tmp == GROUND_X-1){
				IL_Draw bg2img, 1, hdc, pxTmp+ret, pyTmp+GROUND_SIZE/2, 0
			}
			pxTmp -= ret
			pyTmp += GROUND_SIZE / 2
		loop
		IL_Draw bg2img, 0, hdc, pxTmp+ret, pyTmp, 0
	loop

	font "MS ゴシック", 14, 17 : pos 10, 10
	txt  = "マップサイズ : " + GROUND_X + " x " + GROUND_Y
	txt += "¥n¥n高さ制限   : " + GROUND_FLOOR
	color 128, 128, 32 : x = 10 : y = 10
	repeat 8 : pos x + cos(0.79*cnt)*1.6 , y + sin(0.79*cnt)*1.6 : mes txt : loop
	color 255, 255, 64 : pos x, y : mes txt

	txt =  "マップをランダムに描画しています"
	txt += "¥n¥n画面をマウスでクリックすると再描画します"
	color 128, 32, 32 : x = 10 : y = WINDOW_SIZE_Y - 48
	repeat 8 : pos x + cos(0.79*cnt)*1.6 , y + sin(0.79*cnt)*1.6 : mes txt : loop
	color 255, 64, 64 : pos x, y : mes txt
	redraw 1

//	IL_Destroy bg1Img : IL_Destroy bg2Img
//	delmod bg1Img : delmod bg2Img
	stop

コメント ( 0 ) | Trackback ( 0 )