檢視原始碼 wxGraphicsContext (wx v2.4.3)

wxGraphicsContext 實例是繪圖的物件。

它是由渲染器使用 wxGraphicsRenderer:createContext/2 建立的。這可以直接使用渲染器實例,或間接使用 wxGraphicsContext 的靜態便利 create/1 函式,這些函式總是將任務委派給預設渲染器。

注意:對於某些渲染器(如 Direct2D 或 Cairo),繪圖操作的處理可能會延遲(Direct2D 渲染目標通常會建立一批渲染命令,但會延遲這些命令的處理,而 Cairo 則在單獨的表面上操作),因此要使繪圖結果可見,您需要透過呼叫 wxGraphicsContext::Flush()(在 wx 中未實作)或銷毀上下文來更新上下文的內容。

參見

此類別衍生自,並且可以使用以下類別的函式

wxWidgets 文件:wxGraphicsContext

摘要

函式

將剪裁區域設定為給定區域與先前設定的剪裁區域的交集。

這是一個為了方便而提供的多載成員函式。它與上述函式的不同之處僅在於它接受的參數。

將傳入的變換與此上下文的當前變換串連。

建立一個輕量級上下文,該上下文只能用於測量文字。

wxBrush 建立原生筆刷。

wxFont 和文字顏色建立原生圖形字型。

建立具有指定屬性的字型物件。

這是一個為了方便而提供的多載成員函式。它與上述函式的不同之處僅在於它接受的參數。

使用線性漸層建立原生筆刷。筆刷從 (@a x1, @a y1) 開始,到 (@a x2, @a y2) 結束。可以指定起始和結束漸層顏色 (@a c1 和 @a c2),也可以指定完整的漸層 @a stops 集合。採用 wxGraphicsGradientStops 的版本是 wxWidgets 2.9.1 中的新功能。 matrix 參數已在 wxWidgets 3.1.3 中新增

從傳入的值建立原生仿射變換矩陣。

建立一個最初為空的原生圖形路徑。

wxPen 建立原生畫筆。

這是一個為了方便而提供的多載成員函式。它與上述函式的不同之處僅在於它接受的參數。

使用放射狀漸層建立原生筆刷。筆刷起源於 (@a startX, @a startY),並在以 (@a endX, @a endY) 為中心的圓上結束,並具有給定的 @a 半徑。可以透過其起始和結束顏色 @a oColor 和 @a cColor 或透過完整的漸層 @a stops 集合來指定漸層。採用 wxGraphicsGradientStops 的版本是 wxWidgets 2.9.1 中的新功能。 將變換矩陣應用於漸層的功能已在 3.1.3 中新增

銷毀物件

繪製多邊形。

先填滿然後描邊來繪製路徑。

在定義的位置繪製文字。

在定義的位置繪製文字。

在定義的位置繪製文字。

使用目前筆刷填滿路徑。

使用從 text 的開頭到 text 的對應字元的寬度來填寫 widths 陣列。

使用目前選定的字型取得字串的尺寸。

取得此上下文的當前變換矩陣。

將剪裁重設為原始形狀。

旋轉當前變換矩陣(以弧度為單位)。

縮放當前變換矩陣。

設定用於填滿路徑的筆刷。

設定用於繪製文字的字型。

設定用於繪製文字的字型。

設定用於描邊的畫筆。

設定此上下文的當前變換矩陣。

描繪單條線條。

描繪連接所有點的線條。

使用目前畫筆沿著路徑描邊。

平移當前變換矩陣。

型別

-type wxGraphicsContext() :: wx:wx_object().

函式

-spec clip(This, Region) -> ok when This :: wxGraphicsContext(), Region :: wxRegion:wxRegion().

將剪裁區域設定為給定區域與先前設定的剪裁區域的交集。

剪裁區域是限制繪圖的區域。

注意

  • 剪裁區域應以邏輯座標給定。

  • 呼叫此函式只能縮小剪裁區域,而不能擴大。

  • 如果您想將剪裁區域精確地設定為指定的區域,則需要先呼叫 resetClip/1

  • 如果產生的剪裁區域為空,則會剪裁掉上下文上的所有繪圖(繪圖操作所做的所有變更都會被遮罩掉)。

此函式連結

clip(This, X, Y, W, H)

檢視原始碼
-spec clip(This, X, Y, W, H) -> ok
              when
                  This :: wxGraphicsContext(),
                  X :: number(),
                  Y :: number(),
                  W :: number(),
                  H :: number().

這是一個為了方便而提供的多載成員函式。它與上述函式的不同之處僅在於它接受的參數。

此函式連結

concatTransform(This, Matrix)

檢視原始碼
-spec concatTransform(This, Matrix) -> ok
                         when This :: wxGraphicsContext(), Matrix :: wxGraphicsMatrix:wxGraphicsMatrix().

將傳入的變換與此上下文的當前變換串連。

-spec create() -> wxGraphicsContext().

建立一個輕量級上下文,該上下文只能用於測量文字。

-spec create(WindowDC) -> wxGraphicsContext()
                when
                    WindowDC ::
                        wxWindowDC:wxWindowDC() |
                        wxWindow:wxWindow() |
                        wxMemoryDC:wxMemoryDC() |
                        wxImage:wxImage().

wxWindowDC 建立 wxGraphicsContext

請參閱:wxGraphicsRenderer:createContext/2

此函式連結

createBrush(This, Brush)

檢視原始碼
-spec createBrush(This, Brush) -> wxGraphicsBrush:wxGraphicsBrush()
                     when This :: wxGraphicsContext(), Brush :: wxBrush:wxBrush().

wxBrush 建立原生筆刷。

此函式連結

createFont(This, Font)

檢視原始碼
-spec createFont(This, Font) -> wxGraphicsFont:wxGraphicsFont()
                    when This :: wxGraphicsContext(), Font :: wxFont:wxFont().

等同於 createFont(This, Font, [])

-spec createFont(This, SizeInPixels, Facename) -> wxGraphicsFont:wxGraphicsFont()
                    when
                        This :: wxGraphicsContext(),
                        SizeInPixels :: number(),
                        Facename :: unicode:chardata();
                (This, Font, [Option]) -> wxGraphicsFont:wxGraphicsFont()
                    when
                        This :: wxGraphicsContext(),
                        Font :: wxFont:wxFont(),
                        Option :: {col, wx:wx_colour()}.

wxFont 和文字顏色建立原生圖形字型。

注意:對於 Direct2D,圖形字型只能從 TrueType 字型建立。

-spec createFont(This, SizeInPixels, Facename, [Option]) -> wxGraphicsFont:wxGraphicsFont()
                    when
                        This :: wxGraphicsContext(),
                        SizeInPixels :: number(),
                        Facename :: unicode:chardata(),
                        Option :: {flags, integer()} | {col, wx:wx_colour()}.

建立具有指定屬性的字型物件。

建議使用採用 wxFont 的多載,詳情請參閱 wxGraphicsRenderer:createFont/4

注意:對於 Direct2D,圖形字型只能從 TrueType 字型建立。

自:2.9.3 起

此函式連結

createLinearGradientBrush(This, X1, Y1, X2, Y2, Stops)

檢視原始碼
-spec createLinearGradientBrush(This, X1, Y1, X2, Y2, Stops) -> wxGraphicsBrush:wxGraphicsBrush()
                                   when
                                       This :: wxGraphicsContext(),
                                       X1 :: number(),
                                       Y1 :: number(),
                                       X2 :: number(),
                                       Y2 :: number(),
                                       Stops :: wxGraphicsGradientStops:wxGraphicsGradientStops().

這是一個為了方便而提供的多載成員函式。它與上述函式的不同之處僅在於它接受的參數。

此函式連結

createLinearGradientBrush(This, X1, Y1, X2, Y2, C1, C2)

檢視原始碼
-spec createLinearGradientBrush(This, X1, Y1, X2, Y2, C1, C2) -> wxGraphicsBrush:wxGraphicsBrush()
                                   when
                                       This :: wxGraphicsContext(),
                                       X1 :: number(),
                                       Y1 :: number(),
                                       X2 :: number(),
                                       Y2 :: number(),
                                       C1 :: wx:wx_colour(),
                                       C2 :: wx:wx_colour().

使用線性漸層建立原生筆刷。筆刷從 (@a x1, @a y1) 開始,到 (@a x2, @a y2) 結束。可以指定起始和結束漸層顏色 (@a c1 和 @a c2),也可以指定完整的漸層 @a stops 集合。採用 wxGraphicsGradientStops 的版本是 wxWidgets 2.9.1 中的新功能。 matrix 參數已在 wxWidgets 3.1.3 中新增

-spec createMatrix(This) -> wxGraphicsMatrix:wxGraphicsMatrix() when This :: wxGraphicsContext().

等同於 createMatrix(This, [])

-spec createMatrix(This, [Option]) -> wxGraphicsMatrix:wxGraphicsMatrix()
                      when
                          This :: wxGraphicsContext(),
                          Option ::
                              {a, number()} |
                              {b, number()} |
                              {c, number()} |
                              {d, number()} |
                              {tx, number()} |
                              {ty, number()}.

從傳入的值建立原生仿射變換矩陣。

預設參數會產生單位矩陣。

-spec createPath(This) -> wxGraphicsPath:wxGraphicsPath() when This :: wxGraphicsContext().

建立一個最初為空的原生圖形路徑。

此函式連結

createPen(This, Pen)

檢視原始碼
-spec createPen(This, Pen) -> wxGraphicsPen:wxGraphicsPen()
                   when This :: wxGraphicsContext(), Pen :: wxPen:wxPen().

wxPen 建立原生畫筆。

除非您已經有 wxPen,否則請優先使用採用 wxGraphicsPenInfo 的多載(在 wx 中未實作),因為僅為了將其傳遞給此方法而建構一個畫筆是浪費的。

此函式連結

createRadialGradientBrush(This, StartX, StartY, EndX, EndY, Radius, Stops)

檢視原始碼
-spec createRadialGradientBrush(This, StartX, StartY, EndX, EndY, Radius, Stops) ->
                                   wxGraphicsBrush:wxGraphicsBrush()
                                   when
                                       This :: wxGraphicsContext(),
                                       StartX :: number(),
                                       StartY :: number(),
                                       EndX :: number(),
                                       EndY :: number(),
                                       Radius :: number(),
                                       Stops :: wxGraphicsGradientStops:wxGraphicsGradientStops().

這是一個為了方便而提供的多載成員函式。它與上述函式的不同之處僅在於它接受的參數。

此函式連結

createRadialGradientBrush(This, StartX, StartY, EndX, EndY, Radius, OColor, CColor)

檢視原始碼
-spec createRadialGradientBrush(This, StartX, StartY, EndX, EndY, Radius, OColor, CColor) ->
                                   wxGraphicsBrush:wxGraphicsBrush()
                                   when
                                       This :: wxGraphicsContext(),
                                       StartX :: number(),
                                       StartY :: number(),
                                       EndX :: number(),
                                       EndY :: number(),
                                       Radius :: number(),
                                       OColor :: wx:wx_colour(),
                                       CColor :: wx:wx_colour().

使用放射狀漸層建立原生筆刷。筆刷起源於 (@a startX, @a startY),並在以 (@a endX, @a endY) 為中心的圓上結束,並具有給定的 @a 半徑。可以透過其起始和結束顏色 @a oColor 和 @a cColor 或透過完整的漸層 @a stops 集合來指定漸層。採用 wxGraphicsGradientStops 的版本是 wxWidgets 2.9.1 中的新功能。 將變換矩陣應用於漸層的功能已在 3.1.3 中新增

-spec destroy(This :: wxGraphicsContext()) -> ok.

銷毀物件

此函式連結

drawBitmap(This, Bmp, X, Y, W, H)

檢視原始碼
-spec drawBitmap(This, Bmp, X, Y, W, H) -> ok
                    when
                        This :: wxGraphicsContext(),
                        Bmp :: wxBitmap:wxBitmap(),
                        X :: number(),
                        Y :: number(),
                        W :: number(),
                        H :: number().

繪製點陣圖。

在單色點陣圖的情況下,這會被視為遮罩,並且當前筆刷用於填滿。

此函式連結

drawEllipse(This, X, Y, W, H)

檢視原始碼
-spec drawEllipse(This, X, Y, W, H) -> ok
                     when
                         This :: wxGraphicsContext(),
                         X :: number(),
                         Y :: number(),
                         W :: number(),
                         H :: number().

繪製橢圓。

此函式連結

drawIcon(This, Icon, X, Y, W, H)

檢視原始碼
-spec drawIcon(This, Icon, X, Y, W, H) -> ok
                  when
                      This :: wxGraphicsContext(),
                      Icon :: wxIcon:wxIcon(),
                      X :: number(),
                      Y :: number(),
                      W :: number(),
                      H :: number().

繪製圖示。

此函式連結

drawLines(This, Points)

檢視原始碼
-spec drawLines(This, Points) -> ok
                   when This :: wxGraphicsContext(), Points :: [{X :: float(), Y :: float()}].

等同於 drawLines(This, Points, [])

-spec drawLines(This, Points, [Option]) -> ok
                   when
                       This :: wxGraphicsContext(),
                       Points :: [{X :: float(), Y :: float()}],
                       Option :: {fillStyle, wx:wx_enum()}.

繪製多邊形。

此函式連結

drawPath(This, Path)

檢視原始碼
-spec drawPath(This, Path) -> ok
                  when This :: wxGraphicsContext(), Path :: wxGraphicsPath:wxGraphicsPath().

等同於 drawPath(This, Path, [])

-spec drawPath(This, Path, [Option]) -> ok
                  when
                      This :: wxGraphicsContext(),
                      Path :: wxGraphicsPath:wxGraphicsPath(),
                      Option :: {fillStyle, wx:wx_enum()}.

先填滿然後描邊來繪製路徑。

此函式連結

drawRectangle(This, X, Y, W, H)

檢視原始碼
-spec drawRectangle(This, X, Y, W, H) -> ok
                       when
                           This :: wxGraphicsContext(),
                           X :: number(),
                           Y :: number(),
                           W :: number(),
                           H :: number().

繪製矩形。

此函式連結

drawRoundedRectangle(This, X, Y, W, H, Radius)

檢視原始碼
-spec drawRoundedRectangle(This, X, Y, W, H, Radius) -> ok
                              when
                                  This :: wxGraphicsContext(),
                                  X :: number(),
                                  Y :: number(),
                                  W :: number(),
                                  H :: number(),
                                  Radius :: number().

繪製圓角矩形。

此函式連結

drawText(This, Str, X, Y)

檢視原始碼
-spec drawText(This, Str, X, Y) -> ok
                  when
                      This :: wxGraphicsContext(),
                      Str :: unicode:chardata(),
                      X :: number(),
                      Y :: number().

在定義的位置繪製文字。

-spec drawText(This, Str, X, Y, Angle) -> ok
                  when
                      This :: wxGraphicsContext(),
                      Str :: unicode:chardata(),
                      X :: number(),
                      Y :: number(),
                      Angle :: number();
              (This, Str, X, Y, BackgroundBrush) -> ok
                  when
                      This :: wxGraphicsContext(),
                      Str :: unicode:chardata(),
                      X :: number(),
                      Y :: number(),
                      BackgroundBrush :: wxGraphicsBrush:wxGraphicsBrush().

在定義的位置繪製文字。

此函式連結

drawText(This, Str, X, Y, Angle, BackgroundBrush)

檢視原始碼
-spec drawText(This, Str, X, Y, Angle, BackgroundBrush) -> ok
                  when
                      This :: wxGraphicsContext(),
                      Str :: unicode:chardata(),
                      X :: number(),
                      Y :: number(),
                      Angle :: number(),
                      BackgroundBrush :: wxGraphicsBrush:wxGraphicsBrush().

在定義的位置繪製文字。

此函式連結

fillPath(This, Path)

檢視原始碼
-spec fillPath(This, Path) -> ok
                  when This :: wxGraphicsContext(), Path :: wxGraphicsPath:wxGraphicsPath().

等同於 fillPath(This, Path, [])

-spec fillPath(This, Path, [Option]) -> ok
                  when
                      This :: wxGraphicsContext(),
                      Path :: wxGraphicsPath:wxGraphicsPath(),
                      Option :: {fillStyle, wx:wx_enum()}.

使用目前筆刷填滿路徑。

此函式連結

getPartialTextExtents(This, Text)

檢視原始碼
-spec getPartialTextExtents(This, Text) -> [number()]
                               when This :: wxGraphicsContext(), Text :: unicode:chardata().

使用從 text 的開頭到 text 的對應字元的寬度來填寫 widths 陣列。

此函式連結

getTextExtent(This, Text)

檢視原始碼
-spec getTextExtent(This, Text) -> Result
                       when
                           Result ::
                               {Width :: number(),
                                Height :: number(),
                                Descent :: number(),
                                ExternalLeading :: number()},
                           This :: wxGraphicsContext(),
                           Text :: unicode:chardata().

使用目前選定的字型取得字串的尺寸。

-spec getTransform(This) -> wxGraphicsMatrix:wxGraphicsMatrix() when This :: wxGraphicsContext().

取得此上下文的當前變換矩陣。

-spec resetClip(This) -> ok when This :: wxGraphicsContext().

將剪裁重設為原始形狀。

-spec rotate(This, Angle) -> ok when This :: wxGraphicsContext(), Angle :: number().

旋轉當前變換矩陣(以弧度為單位)。

此函式連結

scale(This, XScale, YScale)

檢視原始碼
-spec scale(This, XScale, YScale) -> ok
               when This :: wxGraphicsContext(), XScale :: number(), YScale :: number().

縮放當前變換矩陣。

此函式連結

setBrush(This, Brush)

檢視原始碼
-spec setBrush(This, Brush) -> ok
                  when
                      This :: wxGraphicsContext(),
                      Brush :: wxGraphicsBrush:wxGraphicsBrush() | wxBrush:wxBrush().

設定用於填滿路徑的筆刷。

-spec setFont(This, Font) -> ok
                 when This :: wxGraphicsContext(), Font :: wxGraphicsFont:wxGraphicsFont().

設定用於繪製文字的字型。

此函式連結

setFont(This, Font, Colour)

檢視原始碼
-spec setFont(This, Font, Colour) -> ok
                 when This :: wxGraphicsContext(), Font :: wxFont:wxFont(), Colour :: wx:wx_colour().

設定用於繪製文字的字型。

注意:對於 Direct2D,只能使用 TrueType 字型。

-spec setPen(This, Pen) -> ok
                when This :: wxGraphicsContext(), Pen :: wxPen:wxPen() | wxGraphicsPen:wxGraphicsPen().

設定用於描邊的畫筆。

此函式連結

setTransform(This, Matrix)

檢視原始碼
-spec setTransform(This, Matrix) -> ok
                      when This :: wxGraphicsContext(), Matrix :: wxGraphicsMatrix:wxGraphicsMatrix().

設定此上下文的當前變換矩陣。

此函式連結

strokeLine(This, X1, Y1, X2, Y2)

檢視原始碼
-spec strokeLine(This, X1, Y1, X2, Y2) -> ok
                    when
                        This :: wxGraphicsContext(),
                        X1 :: number(),
                        Y1 :: number(),
                        X2 :: number(),
                        Y2 :: number().

描繪單條線條。

此函式連結

strokeLines(This, Points)

檢視原始碼
-spec strokeLines(This, Points) -> ok
                     when This :: wxGraphicsContext(), Points :: [{X :: float(), Y :: float()}].

描繪連接所有點的線條。

與此函式的其他多載不同,此方法繪製單一折線而不是多條不連貫的線條。

此函式連結

strokePath(This, Path)

檢視原始碼
-spec strokePath(This, Path) -> ok
                    when This :: wxGraphicsContext(), Path :: wxGraphicsPath:wxGraphicsPath().

使用目前畫筆沿著路徑描邊。

此函式連結

translate(This, Dx, Dy)

檢視原始碼
-spec translate(This, Dx, Dy) -> ok when This :: wxGraphicsContext(), Dx :: number(), Dy :: number().

平移當前變換矩陣。