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.0f, 1.0f] の範囲内でなければなりません。
colorD2D1_COLOR_F16+4+4グラデーション ストップの色です。

公式ドキュメント

グラデーション ストップの位置と色を格納します。

解説(Remarks)

グラデーション ストップは、位置が異なる場合は任意の順序で指定できます。2 つのストップが同じ位置を共有することもあります。この場合、最初に指定されたストップが "low" (0.0f に近い) 側として扱われ、後続のストップが "higher" (1.0f に近い) 側として扱われます。この動作は、ストップの途中で瞬時に色を遷移させたい場合に便利です。

通常、コレクションには少なくとも 2 つのポイントが含まれますが、ストップを 1 つだけ指定して作成することも許可されています。たとえば、一方のポイントを位置 0.0f に、もう一方のポイントを位置 1.0f に配置し、追加のポイントを [0, 1] の範囲に分布させます。グラデーションの進行が [0, 1] の範囲を超える場合でも、それらのストップは保持され、グラデーションに影響を与えることがあります。

描画時には、[0, 1] の範囲の位置が、ブラシに依存した方法でブラシにマップされます。詳細については、ID2D1LinearGradientBrush および ID2D1RadialGradientBrush を参照してください。

[0, 1] の範囲外の位置にあるグラデーション ストップは明示的には表示されませんが、[0, 1] の範囲内で生成される色に影響を与えることがあります。たとえば、2 つのストップを持つグラデーション {{0.0f, Black}, {2.0f, White}} は、{{0.0f, Black}, {1.0f, Mid-level gray}} と視覚的に区別できません。また、色は補間の前にクランプされます。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での定義

#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