Win32 API 日本語リファレンス
ホームGraphics.Direct2D.Common › D2D1_GRADIENT_STOP

D2D1_GRADIENT_STOP

構造体
サイズx64: 20 バイト / x86: 20 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
positionFLOAT4+0+0グラデーション内の停止位置。通常0.0〜1.0。
colorD2D1_COLOR_F16+4+4その位置の色を表すD2D1_COLOR_F。

各言語での定義

#include <windows.h>

// D2D1_COLOR_F  (x64 16 / x86 16 バイト)
typedef struct D2D1_COLOR_F {
    FLOAT r;
    FLOAT g;
    FLOAT b;
    FLOAT a;
} D2D1_COLOR_F;

// D2D1_GRADIENT_STOP  (x64 20 / x86 20 バイト)
typedef struct D2D1_GRADIENT_STOP {
    FLOAT position;
    D2D1_COLOR_F color;
} D2D1_GRADIENT_STOP;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct D2D1_COLOR_F
{
    public float r;
    public float g;
    public float b;
    public float a;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct D2D1_GRADIENT_STOP
{
    public float position;
    public D2D1_COLOR_F color;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure D2D1_COLOR_F
    Public r As Single
    Public g As Single
    Public b As Single
    Public a As Single
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure D2D1_GRADIENT_STOP
    Public position As Single
    Public color As D2D1_COLOR_F
End Structure
import ctypes
from ctypes import wintypes

class D2D1_COLOR_F(ctypes.Structure):
    _fields_ = [
        ("r", ctypes.c_float),
        ("g", ctypes.c_float),
        ("b", ctypes.c_float),
        ("a", ctypes.c_float),
    ]

class D2D1_GRADIENT_STOP(ctypes.Structure):
    _fields_ = [
        ("position", ctypes.c_float),
        ("color", D2D1_COLOR_F),
    ]
#[repr(C)]
pub struct D2D1_COLOR_F {
    pub r: f32,
    pub g: f32,
    pub b: f32,
    pub a: f32,
}

#[repr(C)]
pub struct D2D1_GRADIENT_STOP {
    pub position: f32,
    pub color: D2D1_COLOR_F,
}
import "golang.org/x/sys/windows"

type D2D1_COLOR_F struct {
	r float32
	g float32
	b float32
	a float32
}

type D2D1_GRADIENT_STOP struct {
	position float32
	color D2D1_COLOR_F
}
type
  D2D1_COLOR_F = record
    r: Single;
    g: Single;
    b: Single;
    a: Single;
  end;

  D2D1_GRADIENT_STOP = record
    position: Single;
    color: D2D1_COLOR_F;
  end;
const D2D1_COLOR_F = extern struct {
    r: f32,
    g: f32,
    b: f32,
    a: f32,
};

const D2D1_GRADIENT_STOP = extern struct {
    position: f32,
    color: D2D1_COLOR_F,
};
type
  D2D1_COLOR_F {.bycopy.} = object
    r: float32
    g: float32
    b: float32
    a: float32

  D2D1_GRADIENT_STOP {.bycopy.} = object
    position: float32
    color: D2D1_COLOR_F
struct D2D1_COLOR_F
{
    float r;
    float g;
    float b;
    float a;
}

struct D2D1_GRADIENT_STOP
{
    float position;
    D2D1_COLOR_F color;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; D2D1_GRADIENT_STOP サイズ: 20 バイト(x64)
dim st, 5    ; 4byte整数×5(構造体サイズ 20 / 4 切り上げ)
; position : FLOAT (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; color : D2D1_COLOR_F (+4, 16byte)  varptr(st)+4 を基点に操作(16byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global D2D1_COLOR_F
    #field float r
    #field float g
    #field float b
    #field float a
#endstruct

#defstruct global D2D1_GRADIENT_STOP
    #field float position
    #field D2D1_COLOR_F color
#endstruct

stdim st, D2D1_GRADIENT_STOP        ; NSTRUCT 変数を確保
st->position = 100
mes "position=" + st->position