Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
card10
firmware
Commits
7a73dd6a
Commit
7a73dd6a
authored
Apr 12, 2022
by
Rahix
Browse files
pycardium: Add ctx module
Add new ctx module using the CTX client library and the epic_disp_ctx() API call.
parent
0bd4d49e
Pipeline
#5458
passed with stages
in 1 minute and 45 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pycardium/meson.build
View file @
7a73dd6a
...
...
@@ -3,6 +3,7 @@ name = 'pycardium'
modsrc = files(
'modules/bhi160-sys.c',
'modules/buttons.c',
'modules/ctx.c',
'modules/sys_config.c',
'modules/fat_file.c',
'modules/fat_reader_import.c',
...
...
@@ -100,7 +101,7 @@ elf = executable(
mp_headers,
version_hdr,
include_directories: micropython_includes,
dependencies: [max32665_startup_core1, periphdriver, rd117, api_caller, lodepng],
dependencies: [max32665_startup_core1, periphdriver, rd117, api_caller, lodepng
, libctxclient
],
link_with: upy,
link_whole: [max32665_startup_core1_lib, api_caller_lib],
link_args: [
...
...
pycardium/modules/ctx.c
0 → 100644
View file @
7a73dd6a
/* ctx needs an allocator - make it use the one from MicroPython */
#include
"ctx.h"
#include
"ctx-alloc.h"
#include
"py/obj.h"
#include
"py/runtime.h"
/* CTX allocator wrappers {{{ */
void
*
ctx_alloc_malloc
(
size_t
size
)
{
return
m_malloc
(
size
);
}
void
*
ctx_alloc_calloc
(
size_t
nmemb
,
size_t
size
)
{
size_t
byte_size
=
nmemb
*
size
;
char
*
ret
=
(
char
*
)
m_malloc
(
byte_size
);
for
(
size_t
i
=
0
;
i
<
byte_size
;
i
++
)
ret
[
i
]
=
0
;
return
ret
;
}
void
*
ctx_alloc_realloc
(
void
*
ptr
,
size_t
size
)
{
return
m_realloc
(
ptr
,
size
);
}
void
ctx_alloc_free
(
void
*
ptr
)
{
return
m_free
(
ptr
);
}
/* CTX allocator wrappers }}} */
typedef
struct
_mp_ctx_obj_t
{
mp_obj_base_t
base
;
Ctx
*
ctx
;
}
mp_ctx_obj_t
;
/* CTX API functions {{{ */
#define MP_CTX_COMMON_FUN_0(name) \
static mp_obj_t mp_ctx_##name(mp_obj_t self_in) \
{ \
mp_ctx_obj_t *self = MP_OBJ_TO_PTR(self_in); \
ctx_##name(self->ctx); \
return MP_OBJ_FROM_PTR(self); \
} \
MP_DEFINE_CONST_FUN_OBJ_1(mp_ctx_##name##_obj, mp_ctx_##name);
#define MP_CTX_COMMON_FUN_1F(name) \
static mp_obj_t mp_ctx_##name(mp_obj_t self_in, mp_obj_t arg1) \
{ \
mp_ctx_obj_t *self = MP_OBJ_TO_PTR(self_in); \
ctx_##name(self->ctx, mp_obj_get_float(arg1)); \
return MP_OBJ_FROM_PTR(self); \
} \
MP_DEFINE_CONST_FUN_OBJ_2(mp_ctx_##name##_obj, mp_ctx_##name);
#define MP_CTX_COMMON_FUN_1I(name) \
static mp_obj_t mp_ctx_##name(mp_obj_t self_in, mp_obj_t arg1) \
{ \
mp_ctx_obj_t *self = MP_OBJ_TO_PTR(self_in); \
ctx_##name(self->ctx, mp_obj_get_int(arg1)); \
return MP_OBJ_FROM_PTR(self); \
} \
MP_DEFINE_CONST_FUN_OBJ_2(mp_ctx_##name##_obj, mp_ctx_##name);
#define MP_CTX_COMMON_FUN_2F(name) \
static mp_obj_t mp_ctx_##name( \
mp_obj_t self_in, mp_obj_t arg1, mp_obj_t arg2) \
{ \
mp_ctx_obj_t *self = MP_OBJ_TO_PTR(self_in); \
ctx_##name( \
self->ctx, \
mp_obj_get_float(arg1), \
mp_obj_get_float(arg2)); \
return MP_OBJ_FROM_PTR(self); \
} \
MP_DEFINE_CONST_FUN_OBJ_3(mp_ctx_##name##_obj, mp_ctx_##name);
#define MP_CTX_COMMON_FUN_4F(name) \
static mp_obj_t mp_ctx_##name(size_t n_args, const mp_obj_t *args) \
{ \
assert(n_args == 5); \
mp_ctx_obj_t *self = MP_OBJ_TO_PTR(args[0]); \
ctx_##name( \
self->ctx, \
mp_obj_get_float(args[1]), \
mp_obj_get_float(args[2]), \
mp_obj_get_float(args[3]), \
mp_obj_get_float(args[4])); \
return MP_OBJ_FROM_PTR(self); \
} \
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( \
mp_ctx_##name##_obj, 5, 5, mp_ctx_##name);
#define MP_CTX_COMMON_FUN_5F(name) \
static mp_obj_t mp_ctx_##name(size_t n_args, const mp_obj_t *args) \
{ \
assert(n_args == 6); \
mp_ctx_obj_t *self = MP_OBJ_TO_PTR(args[0]); \
ctx_##name( \
self->ctx, \
mp_obj_get_float(args[1]), \
mp_obj_get_float(args[2]), \
mp_obj_get_float(args[3]), \
mp_obj_get_float(args[4]), \
mp_obj_get_float(args[5])); \
return MP_OBJ_FROM_PTR(self); \
} \
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( \
mp_ctx_##name##_obj, 6, 6, mp_ctx_##name);
#define MP_CTX_COMMON_FUN_6F(name) \
static mp_obj_t mp_ctx_##name(size_t n_args, const mp_obj_t *args) \
{ \
assert(n_args == 7); \
mp_ctx_obj_t *self = MP_OBJ_TO_PTR(args[0]); \
ctx_##name( \
self->ctx, \
mp_obj_get_float(args[1]), \
mp_obj_get_float(args[2]), \
mp_obj_get_float(args[3]), \
mp_obj_get_float(args[4]), \
mp_obj_get_float(args[5]), \
mp_obj_get_float(args[6])); \
return MP_OBJ_FROM_PTR(self); \
} \
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( \
mp_ctx_##name##_obj, 7, 7, mp_ctx_##name);
MP_CTX_COMMON_FUN_0
(
begin_path
);
MP_CTX_COMMON_FUN_0
(
save
);
MP_CTX_COMMON_FUN_0
(
restore
);
MP_CTX_COMMON_FUN_0
(
start_group
);
MP_CTX_COMMON_FUN_0
(
end_group
);
MP_CTX_COMMON_FUN_0
(
clip
);
MP_CTX_COMMON_FUN_0
(
identity
);
MP_CTX_COMMON_FUN_1F
(
rotate
);
MP_CTX_COMMON_FUN_1F
(
miter_limit
);
MP_CTX_COMMON_FUN_1F
(
line_width
);
MP_CTX_COMMON_FUN_1F
(
line_dash_offset
);
MP_CTX_COMMON_FUN_1F
(
font_size
);
MP_CTX_COMMON_FUN_2F
(
scale
);
MP_CTX_COMMON_FUN_2F
(
translate
);
MP_CTX_COMMON_FUN_2F
(
line_to
);
MP_CTX_COMMON_FUN_2F
(
move_to
);
MP_CTX_COMMON_FUN_6F
(
curve_to
);
MP_CTX_COMMON_FUN_4F
(
quad_to
);
MP_CTX_COMMON_FUN_5F
(
arc_to
);
MP_CTX_COMMON_FUN_5F
(
rel_arc_to
);
MP_CTX_COMMON_FUN_4F
(
rectangle
);
MP_CTX_COMMON_FUN_5F
(
round_rectangle
);
MP_CTX_COMMON_FUN_2F
(
rel_line_to
);
MP_CTX_COMMON_FUN_2F
(
rel_move_to
);
MP_CTX_COMMON_FUN_6F
(
rel_curve_to
);
MP_CTX_COMMON_FUN_4F
(
rel_quad_to
);
MP_CTX_COMMON_FUN_0
(
close_path
);
MP_CTX_COMMON_FUN_4F
(
linear_gradient
);
MP_CTX_COMMON_FUN_6F
(
radial_gradient
);
MP_CTX_COMMON_FUN_0
(
preserve
);
MP_CTX_COMMON_FUN_0
(
fill
);
MP_CTX_COMMON_FUN_0
(
stroke
);
MP_CTX_COMMON_FUN_1I
(
blend_mode
);
MP_CTX_COMMON_FUN_1I
(
text_align
);
MP_CTX_COMMON_FUN_1I
(
text_baseline
);
MP_CTX_COMMON_FUN_1I
(
fill_rule
);
MP_CTX_COMMON_FUN_1I
(
line_cap
);
MP_CTX_COMMON_FUN_1I
(
line_join
);
MP_CTX_COMMON_FUN_1I
(
compositing_mode
);
static
mp_obj_t
mp_ctx_line_dash
(
mp_obj_t
self_in
,
mp_obj_t
dashes_in
)
{
mp_ctx_obj_t
*
self
=
MP_OBJ_TO_PTR
(
self_in
);
size_t
count
=
mp_obj_get_int
(
mp_obj_len
(
dashes_in
));
float
*
dashes
=
m_malloc
(
sizeof
(
float
)
*
count
);
for
(
size_t
i
=
0
;
i
<
count
;
i
++
)
{
dashes
[
i
]
=
mp_obj_get_float
(
mp_obj_subscr
(
dashes_in
,
mp_obj_new_int
(
i
),
MP_OBJ_SENTINEL
)
);
}
ctx_line_dash
(
self
->
ctx
,
dashes
,
count
);
m_free
(
dashes
);
return
MP_OBJ_FROM_PTR
(
self
);
}
MP_DEFINE_CONST_FUN_OBJ_2
(
mp_ctx_line_dash_obj
,
mp_ctx_line_dash
);
static
mp_obj_t
mp_ctx_arc
(
size_t
n_args
,
const
mp_obj_t
*
args
)
{
assert
(
n_args
==
7
);
mp_ctx_obj_t
*
self
=
MP_OBJ_TO_PTR
(
args
[
0
]);
ctx_arc
(
self
->
ctx
,
mp_obj_get_float
(
args
[
1
]),
mp_obj_get_float
(
args
[
2
]),
mp_obj_get_float
(
args
[
3
]),
mp_obj_get_float
(
args
[
4
]),
mp_obj_get_float
(
args
[
5
]),
mp_obj_get_int
(
args
[
6
]));
return
MP_OBJ_FROM_PTR
(
self
);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
mp_ctx_arc_obj
,
7
,
7
,
mp_ctx_arc
);
static
mp_obj_t
mp_ctx_font
(
mp_obj_t
self_in
,
mp_obj_t
font_in
)
{
mp_ctx_obj_t
*
self
=
MP_OBJ_TO_PTR
(
self_in
);
const
char
*
font
=
mp_obj_str_get_str
(
font_in
);
ctx_font
(
self
->
ctx
,
font
);
return
MP_OBJ_FROM_PTR
(
self
);
}
MP_DEFINE_CONST_FUN_OBJ_2
(
mp_ctx_font_obj
,
mp_ctx_font
);
#define MP_CTX_TEXT_FUN(name) \
static mp_obj_t mp_ctx_##name(size_t n_args, const mp_obj_t *args) \
{ \
assert(n_args == 4); \
mp_ctx_obj_t *self = MP_OBJ_TO_PTR(args[0]); \
ctx_##name( \
self->ctx, \
mp_obj_str_get_str(args[1]), \
mp_obj_get_float(args[2]), \
mp_obj_get_float(args[3])); \
return MP_OBJ_FROM_PTR(self); \
} \
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( \
mp_ctx_##name##_obj, 4, 4, mp_ctx_##name);
MP_CTX_TEXT_FUN
(
fill_text
);
MP_CTX_TEXT_FUN
(
stroke_text
);
static
mp_obj_t
mp_ctx_text_width
(
mp_obj_t
self_in
,
mp_obj_t
string_in
)
{
mp_ctx_obj_t
*
self
=
MP_OBJ_TO_PTR
(
self_in
);
const
char
*
string
=
mp_obj_str_get_str
(
string_in
);
return
mp_obj_new_float
(
ctx_text_width
(
self
->
ctx
,
string
));
}
MP_DEFINE_CONST_FUN_OBJ_2
(
mp_ctx_text_width_obj
,
mp_ctx_text_width
);
static
mp_obj_t
mp_ctx_color_common
(
size_t
n_args
,
const
mp_obj_t
*
args
,
bool
stroke
)
{
mp_ctx_obj_t
*
self
=
MP_OBJ_TO_PTR
(
args
[
0
]);
mp_obj_t
color_in
=
args
[
1
];
float
alpha_f
=
1
.
0
;
if
(
n_args
==
3
)
{
alpha_f
=
mp_obj_get_float
(
args
[
2
]);
}
if
(
alpha_f
<
0
.
0
||
alpha_f
>
1
.
0
)
{
mp_raise_ValueError
(
"alpha must be between 0.0 or 1.0"
);
}
mp_obj_t
red_in
,
green_in
,
blue_in
;
if
(
mp_obj_get_int
(
mp_obj_len
(
color_in
))
<
3
)
{
mp_raise_ValueError
(
"color must have 3 elements"
);
}
red_in
=
mp_obj_subscr
(
color_in
,
mp_obj_new_int
(
0
),
MP_OBJ_SENTINEL
);
green_in
=
mp_obj_subscr
(
color_in
,
mp_obj_new_int
(
1
),
MP_OBJ_SENTINEL
);
blue_in
=
mp_obj_subscr
(
color_in
,
mp_obj_new_int
(
2
),
MP_OBJ_SENTINEL
);
/*
* The color can be either floats between 0 and 1 or integers between 0
* and 255. Make this decision based on the first element we find.
*/
if
(
mp_obj_is_type
(
red_in
,
&
mp_type_float
))
{
float
red
,
green
,
blue
;
red
=
mp_obj_get_float
(
red_in
);
green
=
mp_obj_get_float
(
green_in
);
blue
=
mp_obj_get_float
(
blue_in
);
if
(
stroke
)
{
ctx_rgba_stroke
(
self
->
ctx
,
red
,
green
,
blue
,
alpha_f
);
}
else
{
ctx_rgba
(
self
->
ctx
,
red
,
green
,
blue
,
alpha_f
);
}
}
else
{
uint8_t
red
,
green
,
blue
,
alpha
;
red
=
mp_obj_get_int
(
red_in
);
green
=
mp_obj_get_int
(
green_in
);
blue
=
mp_obj_get_int
(
blue_in
);
alpha
=
(
int
)(
alpha_f
*
255
.
0
);
if
(
stroke
)
{
ctx_rgba8_stroke
(
self
->
ctx
,
red
,
green
,
blue
,
alpha
);
}
else
{
ctx_rgba8
(
self
->
ctx
,
red
,
green
,
blue
,
alpha
);
}
}
return
MP_OBJ_FROM_PTR
(
self
);
}
static
mp_obj_t
mp_ctx_color
(
size_t
n_args
,
const
mp_obj_t
*
args
)
{
return
mp_ctx_color_common
(
n_args
,
args
,
false
);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
mp_ctx_color_obj
,
2
,
3
,
mp_ctx_color
);
static
mp_obj_t
mp_ctx_stroke_color
(
size_t
n_args
,
const
mp_obj_t
*
args
)
{
return
mp_ctx_color_common
(
n_args
,
args
,
true
);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
mp_ctx_stroke_color_obj
,
2
,
3
,
mp_ctx_stroke_color
);
static
mp_obj_t
mp_ctx_add_stop
(
size_t
n_args
,
const
mp_obj_t
*
args
)
{
mp_ctx_obj_t
*
self
=
MP_OBJ_TO_PTR
(
args
[
0
]);
mp_obj_t
color_in
=
args
[
2
];
float
pos
=
mp_obj_get_float
(
args
[
1
]);
float
alpha_f
=
1
.
0
;
if
(
n_args
==
4
)
{
alpha_f
=
mp_obj_get_float
(
args
[
3
]);
}
if
(
alpha_f
<
0
.
0
||
alpha_f
>
1
.
0
)
{
mp_raise_ValueError
(
"alpha must be between 0.0 or 1.0"
);
}
mp_obj_t
red_in
,
green_in
,
blue_in
;
if
(
mp_obj_get_int
(
mp_obj_len
(
color_in
))
<
3
)
{
mp_raise_ValueError
(
"color must have 3 elements"
);
}
red_in
=
mp_obj_subscr
(
color_in
,
mp_obj_new_int
(
0
),
MP_OBJ_SENTINEL
);
green_in
=
mp_obj_subscr
(
color_in
,
mp_obj_new_int
(
1
),
MP_OBJ_SENTINEL
);
blue_in
=
mp_obj_subscr
(
color_in
,
mp_obj_new_int
(
2
),
MP_OBJ_SENTINEL
);
/*
* The color can be either floats between 0 and 1 or integers between 0
* and 255. Make this decision based on the first element we find.
*/
if
(
mp_obj_is_type
(
red_in
,
&
mp_type_float
))
{
float
red
,
green
,
blue
;
red
=
mp_obj_get_float
(
red_in
);
green
=
mp_obj_get_float
(
green_in
);
blue
=
mp_obj_get_float
(
blue_in
);
ctx_gradient_add_stop
(
self
->
ctx
,
pos
,
red
,
green
,
blue
,
alpha_f
);
}
else
{
uint8_t
red
,
green
,
blue
,
alpha
;
red
=
mp_obj_get_int
(
red_in
);
green
=
mp_obj_get_int
(
green_in
);
blue
=
mp_obj_get_int
(
blue_in
);
alpha
=
(
int
)(
alpha_f
*
255
.
0
);
ctx_gradient_add_stop_u8
(
self
->
ctx
,
pos
,
red
,
green
,
blue
,
alpha
);
}
return
MP_OBJ_FROM_PTR
(
self
);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
mp_ctx_add_stop_obj
,
3
,
4
,
mp_ctx_add_stop
);
static
mp_obj_t
mp_ctx_update
(
mp_obj_t
self_in
,
mp_obj_t
display_in
)
{
mp_ctx_obj_t
*
self
=
MP_OBJ_TO_PTR
(
self_in
);
/* TODO: Don't ignore the passed in display */
if
(
display_in
==
mp_const_none
)
{
mp_raise_ValueError
(
"must pass in the display object"
);
}
int
res
=
epic_disp_ctx
(
self
->
ctx
);
/*
* The drawlist still contains the draw commands which were just
* executed. Flush them now.
*/
ctx_drawlist_clear
(
self
->
ctx
);
/* report errors from epic_disp_ctx() */
if
(
res
<
0
)
{
mp_raise_OSError
(
-
res
);
}
return
MP_OBJ_FROM_PTR
(
self
);
}
MP_DEFINE_CONST_FUN_OBJ_2
(
mp_ctx_update_obj
,
mp_ctx_update
);
/* CTX API functions }}} */
static
mp_obj_t
mp_ctx_make_new
(
const
mp_obj_type_t
*
type
,
size_t
n_args
,
size_t
n_kw
,
const
mp_obj_t
*
args
)
{
mp_ctx_obj_t
*
o
=
m_new_obj
(
mp_ctx_obj_t
);
o
->
base
.
type
=
type
;
o
->
ctx
=
ctx_new
();
return
MP_OBJ_FROM_PTR
(
o
);
}
/* CTX class/type */
#define MP_CTX_INT_CONSTANT(ident) \
{ \
MP_ROM_QSTR(MP_QSTR_##ident), MP_ROM_INT((int)CTX_##ident) \
}
#define MP_CTX_METHOD(name) \
{ \
MP_ROM_QSTR(MP_QSTR_##name), MP_ROM_PTR(&mp_ctx_##name##_obj) \
}
static
const
mp_rom_map_elem_t
mp_ctx_locals_dict_table
[]
=
{
MP_CTX_INT_CONSTANT
(
FILL_RULE_WINDING
),
MP_CTX_INT_CONSTANT
(
FILL_RULE_EVEN_ODD
),
MP_CTX_INT_CONSTANT
(
JOIN_BEVEL
),
MP_CTX_INT_CONSTANT
(
JOIN_ROUND
),
MP_CTX_INT_CONSTANT
(
JOIN_MITER
),
MP_CTX_INT_CONSTANT
(
CAP_NONE
),
MP_CTX_INT_CONSTANT
(
CAP_ROUND
),
MP_CTX_INT_CONSTANT
(
CAP_SQUARE
),
MP_CTX_INT_CONSTANT
(
COMPOSITE_SOURCE_OVER
),
MP_CTX_INT_CONSTANT
(
COMPOSITE_COPY
),
MP_CTX_INT_CONSTANT
(
COMPOSITE_SOURCE_IN
),
MP_CTX_INT_CONSTANT
(
COMPOSITE_SOURCE_OUT
),
MP_CTX_INT_CONSTANT
(
COMPOSITE_SOURCE_ATOP
),
MP_CTX_INT_CONSTANT
(
COMPOSITE_CLEAR
),
MP_CTX_INT_CONSTANT
(
COMPOSITE_DESTINATION_OVER
),
MP_CTX_INT_CONSTANT
(
COMPOSITE_DESTINATION
),
MP_CTX_INT_CONSTANT
(
COMPOSITE_DESTINATION_IN
),
MP_CTX_INT_CONSTANT
(
COMPOSITE_DESTINATION_OUT
),
MP_CTX_INT_CONSTANT
(
COMPOSITE_DESTINATION_ATOP
),
MP_CTX_INT_CONSTANT
(
COMPOSITE_XOR
),
MP_CTX_INT_CONSTANT
(
BLEND_NORMAL
),
MP_CTX_INT_CONSTANT
(
BLEND_MULTIPLY
),
MP_CTX_INT_CONSTANT
(
BLEND_SCREEN
),
MP_CTX_INT_CONSTANT
(
BLEND_OVERLAY
),
MP_CTX_INT_CONSTANT
(
BLEND_DARKEN
),
MP_CTX_INT_CONSTANT
(
BLEND_LIGHTEN
),
MP_CTX_INT_CONSTANT
(
BLEND_COLOR_DODGE
),
MP_CTX_INT_CONSTANT
(
BLEND_COLOR_BURN
),
MP_CTX_INT_CONSTANT
(
BLEND_HARD_LIGHT
),
MP_CTX_INT_CONSTANT
(
BLEND_SOFT_LIGHT
),
MP_CTX_INT_CONSTANT
(
BLEND_DIFFERENCE
),
MP_CTX_INT_CONSTANT
(
BLEND_EXCLUSION
),
MP_CTX_INT_CONSTANT
(
BLEND_HUE
),
MP_CTX_INT_CONSTANT
(
BLEND_SATURATION
),
MP_CTX_INT_CONSTANT
(
BLEND_COLOR
),
MP_CTX_INT_CONSTANT
(
BLEND_LUMINOSITY
),
MP_CTX_INT_CONSTANT
(
BLEND_DIVIDE
),
MP_CTX_INT_CONSTANT
(
BLEND_ADDITION
),
MP_CTX_INT_CONSTANT
(
BLEND_SUBTRACT
),
MP_CTX_INT_CONSTANT
(
TEXT_BASELINE_ALPHABETIC
),
MP_CTX_INT_CONSTANT
(
TEXT_BASELINE_TOP
),
MP_CTX_INT_CONSTANT
(
TEXT_BASELINE_HANGING
),
MP_CTX_INT_CONSTANT
(
TEXT_BASELINE_MIDDLE
),
MP_CTX_INT_CONSTANT
(
TEXT_BASELINE_IDEOGRAPHIC
),
MP_CTX_INT_CONSTANT
(
TEXT_BASELINE_BOTTOM
),
MP_CTX_INT_CONSTANT
(
TEXT_ALIGN_START
),
MP_CTX_INT_CONSTANT
(
TEXT_ALIGN_END
),
MP_CTX_INT_CONSTANT
(
TEXT_ALIGN_CENTER
),
MP_CTX_INT_CONSTANT
(
TEXT_ALIGN_LEFT
),
MP_CTX_INT_CONSTANT
(
TEXT_ALIGN_RIGHT
),
MP_CTX_METHOD
(
begin_path
),
MP_CTX_METHOD
(
save
),
MP_CTX_METHOD
(
restore
),
MP_CTX_METHOD
(
start_group
),
MP_CTX_METHOD
(
end_group
),
MP_CTX_METHOD
(
clip
),
MP_CTX_METHOD
(
identity
),
MP_CTX_METHOD
(
rotate
),
MP_CTX_METHOD
(
miter_limit
),
MP_CTX_METHOD
(
line_width
),
MP_CTX_METHOD
(
line_dash_offset
),
MP_CTX_METHOD
(
font
),
MP_CTX_METHOD
(
font_size
),
MP_CTX_METHOD
(
scale
),
MP_CTX_METHOD
(
translate
),
MP_CTX_METHOD
(
line_to
),
MP_CTX_METHOD
(
move_to
),
MP_CTX_METHOD
(
curve_to
),
MP_CTX_METHOD
(
quad_to
),
MP_CTX_METHOD
(
arc
),
MP_CTX_METHOD
(
arc_to
),
MP_CTX_METHOD
(
rel_arc_to
),
MP_CTX_METHOD
(
rectangle
),
MP_CTX_METHOD
(
round_rectangle
),
MP_CTX_METHOD
(
rel_line_to
),
MP_CTX_METHOD
(
rel_move_to
),
MP_CTX_METHOD
(
rel_curve_to
),
MP_CTX_METHOD
(
rel_quad_to
),
MP_CTX_METHOD
(
close_path
),
MP_CTX_METHOD
(
preserve
),
MP_CTX_METHOD
(
fill
),
MP_CTX_METHOD
(
stroke
),
MP_CTX_METHOD
(
blend_mode
),
MP_CTX_METHOD
(
text_align
),
MP_CTX_METHOD
(
text_baseline
),
MP_CTX_METHOD
(
fill_rule
),
MP_CTX_METHOD
(
line_cap
),
MP_CTX_METHOD
(
line_join
),
MP_CTX_METHOD
(
compositing_mode
),
MP_CTX_METHOD
(
fill_text
),
MP_CTX_METHOD
(
stroke_text
),
MP_CTX_METHOD
(
text_width
),
MP_CTX_METHOD
(
linear_gradient
),
MP_CTX_METHOD
(
radial_gradient
),
MP_CTX_METHOD
(
line_dash
),
MP_CTX_METHOD
(
add_stop
),
MP_CTX_METHOD
(
color
),
MP_CTX_METHOD
(
stroke_color
),
MP_CTX_METHOD
(
update
),
};
static
MP_DEFINE_CONST_DICT
(
mp_ctx_locals_dict
,
mp_ctx_locals_dict_table
);
const
mp_obj_type_t
mp_ctx_type
=
{
.
base
=
{
&
mp_type_type
},
.
name
=
MP_QSTR_Ctx
,
.
make_new
=
mp_ctx_make_new
,
.
locals_dict
=
(
mp_obj_t
)
&
mp_ctx_locals_dict
,
};
/* The globals table for this module */
static
const
mp_rom_map_elem_t
mp_ctx_module_globals_table
[]
=
{
{
MP_ROM_QSTR
(
MP_QSTR___name__
),
MP_ROM_QSTR
(
MP_QSTR_ctx_graphics
)
},
{
MP_ROM_QSTR
(
MP_QSTR_Ctx
),
MP_ROM_PTR
(
&
mp_ctx_type
)
},
};
static
MP_DEFINE_CONST_DICT
(
mp_ctx_module_globals
,
mp_ctx_module_globals_table
);
const
mp_obj_module_t
mp_ctx_module
=
{
.
base
=
{
&
mp_type_module
},
.
globals
=
(
mp_obj_dict_t
*
)
&
mp_ctx_module_globals
,
};
/* This is a special macro that will make MicroPython aware of this module */
/* clang-format off */
MP_REGISTER_MODULE
(
MP_QSTR_ctx_graphics
,
mp_ctx_module
,
MODULE_CTX_ENABLED
);
pycardium/modules/qstrdefs.h
View file @
7a73dd6a
...
...
@@ -225,3 +225,117 @@ Q(maxim_rd117)
/* PNG */
Q
(
sys_png
)
Q
(
decode
)
/* ctx */
Q
(
Ctx
)
Q
(
ctx_graphics
)
Q
(
LINE_WIDTH_HAIRLINE
)
Q
(
begin_path
)
Q
(
save
)
Q
(
restore
)
Q
(
start_group
)
Q
(
end_group
)
Q
(
clip
)
Q
(
identity
)
Q
(
rotate
)
Q
(
image_smoothing
)
Q
(
get_image_smoothing
)
Q
(
miter_limit
)
Q
(
get_miter_limit
)
Q
(
line_width
)
Q
(
line_dash_offset
)
Q
(
get_line_dash_offset
)
Q
(
apply_transform
)
Q
(
set_transform
)
Q
(
line_dash
)
Q
(
font_size
)
Q
(
font
)
Q
(
font_family
)
Q
(
scale
)
Q
(
translate
)
Q
(
line_to
)
Q
(
move_to
)
Q
(
curve_to
)
Q
(
quad_to
)
Q
(
arc
)
Q
(
arc_to
)
Q
(
rel_arc_to
)
Q
(
rectangle
)
Q
(
round_rectangle
)
Q
(
rel_line_to
)
Q
(
rel_move_to
)
Q
(
rel_curve_to
)
Q
(
rel_quad_to
)
Q
(
close_path
)
Q
(
get_font_size
)
Q
(
get_font
)
Q
(
get_line_width
)
Q
(
preserve
)
Q
(
fill
)
Q
(
stroke
)
Q
(
blend_mode
)
Q
(
text_align
)
Q
(
text_baseline
)
Q
(
fill_rule
)
Q
(
line_cap
)
Q
(
line_join
)
Q
(
compositing_mode
)
Q
(
color
)
Q
(
stroke_color
)
Q
(
linear_gradient
)
Q
(
radial_gradient
)
Q
(
text_width
)
Q
(
fill_text
)
Q
(
stroke_text
)
Q
(
add_stop
)