Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openstructure
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
schwede
openstructure
Commits
94efc6e2
Commit
94efc6e2
authored
13 years ago
by
Ansgar Philippsen
Browse files
Options
Downloads
Patches
Plain Diff
added list for gfx.Gradient ctor in python
parent
900fd648
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/gfx/pymod/export_gradient.cc
+31
-2
31 additions, 2 deletions
modules/gfx/pymod/export_gradient.cc
modules/gfx/tests/test_gfx.py
+2
-1
2 additions, 1 deletion
modules/gfx/tests/test_gfx.py
with
33 additions
and
3 deletions
modules/gfx/pymod/export_gradient.cc
+
31
−
2
View file @
94efc6e2
...
...
@@ -26,7 +26,7 @@ using namespace ost;
using
namespace
ost
::
gfx
;
namespace
{
Gradient
*
make_gradient
(
const
dict
&
d
)
Gradient
*
make_gradient
_d
(
const
dict
&
d
)
{
std
::
auto_ptr
<
Gradient
>
grad
(
new
Gradient
);
list
keys
=
d
.
keys
();
...
...
@@ -57,13 +57,42 @@ namespace {
}
return
grad
.
release
();
}
Gradient
*
make_gradient_l
(
const
list
&
l
)
{
std
::
auto_ptr
<
Gradient
>
grad
(
new
Gradient
);
float
mf
=
len
(
l
)
<
2
?
0.0
:
1.0
/
static_cast
<
float
>
(
len
(
l
)
-
1
);
for
(
int
i
=
0
;
i
<
len
(
l
);
++
i
)
{
float
mark
=
static_cast
<
float
>
(
i
)
*
mf
;
Color
col
;
object
val
=
l
[
i
];
extract
<
Color
>
cex
(
val
);
if
(
cex
.
check
())
{
// use gfx.Color
col
=
cex
();
}
else
{
// try simple sequence
if
(
len
(
val
)
!=
3
)
{
throw
std
::
runtime_error
(
"expected values of gfx.Color or float triplets"
);
}
try
{
col
=
gfx
::
Color
(
extract
<
float
>
(
val
[
0
]),
extract
<
float
>
(
val
[
1
]),
extract
<
float
>
(
val
[
2
]));
}
catch
(...)
{
throw
std
::
runtime_error
(
"expected values of gfx.Color or float triplets"
);
}
}
grad
->
SetColorAt
(
mark
,
col
);
}
return
grad
.
release
();
}
}
void
export_gradient
()
{
class_
<
Gradient
>
(
"Gradient"
,
init
<>
())
.
def
(
init
<
const
String
&>
())
.
def
(
"__init__"
,
make_constructor
(
make_gradient
))
.
def
(
"__init__"
,
make_constructor
(
make_gradient_d
))
.
def
(
"__init__"
,
make_constructor
(
make_gradient_l
))
.
def
(
"SetColorAt"
,
&
Gradient
::
SetColorAt
)
.
def
(
"GetColorAt"
,
&
Gradient
::
GetColorAt
)
.
def
(
"GetStops"
,
&
Gradient
::
GetStops
)
...
...
This diff is collapsed.
Click to expand it.
modules/gfx/tests/test_gfx.py
+
2
−
1
View file @
94efc6e2
...
...
@@ -41,7 +41,8 @@ class TestGfx(unittest.TestCase):
def
test_gradient
(
self
):
gs
=
[
gfx
.
Gradient
(),
gfx
.
Gradient
({
0.0
:
[
1
,
0
,
0
],
1.0
:
gfx
.
Color
(
0
,
1
,
0
)})]
gfx
.
Gradient
({
0.0
:
[
1
,
0
,
0
],
1.0
:
gfx
.
Color
(
0
,
1
,
0
)}),
gfx
.
Gradient
([[
1
,
0
,
0
],
gfx
.
Color
(
0
,
1
,
0
)])]
gs
[
0
].
SetColorAt
(
0.0
,
gfx
.
Color
(
1.0
,
0.0
,
0.0
))
gs
[
0
].
SetColorAt
(
1.0
,
gfx
.
Color
(
0.0
,
1.0
,
0.0
))
for
g
in
gs
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment