wxErlang

wxPalette.erl

  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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
%          |¯\  /\  |   |_¯ ¯|¯ ¯|¯ |_¯ 
%\     W X |¯¯ /¯¯\ |__ |__  |   |  |__ . E R L 
%%                                                                     
%%                                                                     
%%   Copyright Ericsson AB 2008-2013. All Rights Reserved.
%%                                                                     
%%                                                                     
%% Whitespace Beautified by ScriptCulture © 2018
%% Sit Back · Feet Up · Learn wxErlang
%% For use as a reference only
%% www.scriptculture.com
%% Not check-summed 
%% wx 1.8 —————————————————————————————————————— 
%%
%% Licensed under the Apache License, 
%% Version 2.0 (the "License"); you may 
%% not use this file except in compliance 
%% with the License. You may obtain a copy 
%% of the License at:
%%
%%     http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by 
%% applicable law or agreed to in writing, software
%% distributed under the License is distributed 
%% on an "AS IS" BASIS, WITHOUT WARRANTIES 
%% OR CONDITIONS OF ANY KIND, either 
%% express or implied. See the 
%% License for the specific 
%% language governing 
%% permissions and
%% limitations 
%% under the 
%% License.
%%%%%%%
%%%%
%%%%%
%% @doc See external documentation: <a href="http://www.wxwidgets.org/manuals/2.8.12/wx_wxpalette.html">wxPalette</a>.
%% @type wxPalette().  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%   
%%   OVERVIEW
%%   ––––––––
%%   A palette is a table that maps pixel values to RGB colours. 
%%   It allows the colours of a low-depth bitmap, for example, 
%%   to be mapped to the available colours in a display. 
%%   The notion of palettes is becoming more and more obsolete 
%%   nowadays and only the MSW port is still using a native palette. 
%%   All other ports use generic code which is basically just an array of colours.
%%   
%%   It is likely that in the future the only use for 
%%   palettes within wxWidgets will be for representing colour 
%%   indeces from images (such as GIF or PNG). 
%%   The image handlers for these formats have been modified to 
%%   create a palette if there is such information in the original 
%%   image file (usually 256 or less colour images). 
%%   See wxImage for more information.
%%   
%%   
%%   See Also:
%%   —————————
%%   wxDC::SetPalette, wxBitmap
%%   
%%   
-module(wxPalette).
-include("wxe.hrl").
-export([create/4,destroy/1,getColoursCount/1,getPixel/4,getRGB/2,isOk/1,new/0,
  new/3]).

%% inherited exports
-export([parent_class/1]).

-export_type([wxPalette/0]).
%% @hidden
parent_class(_Class) -> erlang:error({badtype, ?MODULE}).


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




           %·%% NEW / 0 %%·%

%%   
%%    Default constructor.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec new() -> wxPalette().

new() ->
  wxe_util:construct(?wxPalette_new_0,
               <<>>).





           %·%% NEW / 3 %%·%

%%   
%%   Creates a palette from arrays of size n, 
%%   one for each red, blue or green component.
%%   
%%       palette        A pointer or reference to the palette to copy.
%%   
%%       n              The number of indices in the palette.
%%       
%%       red            An array of red values.
%%       
%%       green          An array of green values.
%%       
%%       blue           An array of blue values.
%%
%% Return Value:
%% See Also: wxPalette::Create
%%*%%*%%
          -spec new(Red, Green, Blue) -> wxPalette()
           when
           Red   :: binary(), 
           Green :: binary(), 
           Blue  :: binary().

new(Red,Green,Blue)
           when 
           is_binary(Red),
           is_binary(Green),
           is_binary(Blue) ->
          wxe_util:send_bin(Red),
          wxe_util:send_bin(Green),
          wxe_util:send_bin(Blue),
          wxe_util:construct(?wxPalette_new_4,
                                             <<>>).







           %·%% CREATE %%·%

%%   
%%   Creates a palette from arrays of size n, 
%%   one for each red, blue or green component.
%%   
%% Return Value: true if the creation was successful, false otherwise.
%% See Also:
%%*%%*%%
          -spec create(This, Red, Green, Blue) -> boolean()
           when
           This  :: wxPalette(), 
           Red   ::   binary(),   %      An array of red values.
           Green ::   binary(),   %      An array of green values.
           Blue  ::   binary().   %      An array of blue values.

create(#wx_ref{type=ThisT,ref=ThisRef}, Red, Green, Blue)
           when 
           is_binary(Red),
           is_binary(Green),
           is_binary(Blue) ->
                            ?CLASS(ThisT,wxPalette),
                    wxe_util:send_bin(Red),
                    wxe_util:send_bin(Green),
                    wxe_util:send_bin(Blue),
                    wxe_util:call(?wxPalette_Create,
                                                   <<ThisRef:32/?UI>>).







           %·%% GET COLOURS COUNT %%·%

%%   
%%    Returns number of entries in palette.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec getColoursCount(This) -> integer()
           when
           This :: wxPalette().

getColoursCount(#wx_ref{type=ThisT,ref=ThisRef}) ->
                                                  ?CLASS(ThisT,wxPalette),
                                    wxe_util:call(?wxPalette_GetColoursCount,
                                    <<ThisRef:32/?UI>>).





           %·%% GET PIXEL %%·%

%%   
%%    Returns a pixel value (index into the palette) for the given RGB values.
%%   
%% Return Value: The nearest palette index or wxNOT_FOUND for unexpected errors.
%% See Also: wxPalette::GetRGB
%%*%%*%%
          -spec getPixel(This, Red, Green, Blue) -> integer()
           when
           This  :: wxPalette(), 
           Red   ::   integer(),  % Red Value
           Green ::   integer(),  % Green Value
           Blue  ::   integer().  % Blue Value

getPixel(#wx_ref{type=ThisT,ref=ThisRef}, Red, Green, Blue)
           when 
           is_integer(Red),
           is_integer(Green),
           is_integer(Blue) ->
                             ?CLASS(ThisT,wxPalette),
               wxe_util:call(?wxPalette_GetPixel,
               <<ThisRef:32/?UI,Red:32/?UI,Green:32/?UI,Blue:32/?UI>>).





           %·%% GET RGB %%·%

%%   
%%    Returns RGB values for a given palette index.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec getRGB(This, Pixel) -> Result 
           when
           Result  :: {Res   :: boolean(),  % true if the operation was successful.
                       Red   :: integer(), 
                       Green :: integer(), 
                       Blue  :: integer()},
           This    :: wxPalette(), 
           Pixel   :: integer().

getRGB(#wx_ref{type=ThisT,ref=ThisRef},Pixel)
           when 
           is_integer(Pixel) ->
                              ?CLASS(ThisT,wxPalette),
                wxe_util:call(?wxPalette_GetRGB,
                <<ThisRef:32/?UI,Pixel:32/?UI>>).





           %·%% IS OK %%·%

%%   
%%    Returns true if palette data is present.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec isOk(This) -> boolean()
           when
           This :: wxPalette().

isOk(#wx_ref{type=ThisT,ref=ThisRef}) ->
                                       ?CLASS(ThisT,wxPalette),
                         wxe_util:call(?wxPalette_IsOk,
                         <<ThisRef:32/?UI>>).





           %·%% DESTROY %%·%

%%   
%%   
%% @doc Destroys this object, do not use object again
          -spec destroy(This :: wxPalette()) -> ok.

destroy(Obj=#wx_ref{type=Type}) ->
                                 ?CLASS(Type,wxPalette),
                wxe_util:destroy(?DESTROY_OBJECT,Obj),
                ok.