Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
GameDevWeek
Sommersemester 2015
Cpp
Deth Buff Arr
Commits
5d643bba
Commit
5d643bba
authored
Sep 27, 2015
by
Jerry
Browse files
no longer negativ spaces for texture widget childs
parent
9fad3629
Changes
4
Hide whitespace changes
Inline
Side-by-side
include/ui/texture_widget.hpp
View file @
5d643bba
...
...
@@ -13,7 +13,12 @@ namespace gdw{
private:
std
::
unique_ptr
<
nanovg_texture
>
texture_
;
protected:
virtual
float
width_px
()
const
override
;
virtual
float
height_px
()
const
override
;
public:
texture_widget
(
float
x
,
float
y
,
float
width
,
float
height
,
std
::
unique_ptr
<
nanovg_texture
>
texture
)
;
virtual
void
render
(
NVGcontext
*
context
,
float
delta_time
)
override
;
...
...
include/ui/ui_widget.hpp
View file @
5d643bba
...
...
@@ -35,22 +35,22 @@ namespace gdw{
virtual
void
render
(
NVGcontext
*
context
,
float
delta_time
)
=
0
;
float
width_px
()
const
{
virtual
float
width_px
()
const
{
if
(
!
parent_
||
parent_
==
this
)
return
size_
.
x
;
return
size_
.
x
*
parent_
->
width_px
();
}
float
height_px
()
const
{
virtual
float
height_px
()
const
{
if
(
!
parent_
||
parent_
==
this
)
return
size_
.
y
;
return
size_
.
y
*
parent_
->
height_px
();
}
float
x_px
()
const
{
virtual
float
x_px
()
const
{
if
(
!
parent_
||
parent_
==
this
)
return
pos_
.
x
;
return
pos_
.
x
*
parent_
->
width_px
();
}
float
y_px
()
const
{
virtual
float
y_px
()
const
{
if
(
!
parent_
||
parent_
==
this
)
return
pos_
.
y
;
return
pos_
.
y
*
parent_
->
height_px
();
}
...
...
src/ui/text_widget.cpp
View file @
5d643bba
...
...
@@ -17,6 +17,7 @@ namespace gdw {
}
void
text_widget
::
render
(
NVGcontext
*
context
,
float
delta_time
)
{
nvgFontSize
(
context
,
font_size_
);
nvgFontFace
(
context
,
font_name_
.
c_str
());
nvgFillColor
(
context
,
nvgRGBAf
(
color_
.
r
,
color_
.
g
,
color_
.
b
,
color_
.
a
));
...
...
@@ -24,6 +25,5 @@ namespace gdw {
//log << "font_name_: " << font_name_ << " text_: " << text_ << std::endl;
nvgText
(
context
,
x_px
(),
y_px
(),
text_
.
c_str
(),
NULL
);
//log << "font_name_: " << font_name_ << " text_: " << text_ << std::endl;
}
}
\ No newline at end of file
src/ui/texture_widget.cpp
View file @
5d643bba
...
...
@@ -16,8 +16,6 @@ namespace gdw {
int
imgw
,
imgh
;
nvgImageSize
(
context
,
texture_
->
nanovg_image_handele
,
&
imgw
,
&
imgh
);
float
aspect
=
(
float
)
imgw
/
(
float
)
imgh
;
float
drawWitdth
=
fabsf
(
width_px
());
float
drawHeight
=
fabsf
(
height_px
());
...
...
@@ -34,6 +32,40 @@ namespace gdw {
nvgRect
(
context
,
0
,
0
,
drawWitdth
,
drawHeight
);
nvgFillPaint
(
context
,
imgPaint
);
nvgFill
(
context
);
}
float
texture_widget
::
width_px
()
const
{
int
imgw
,
imgh
;
nvgImageSize
(
texture_
->
nanovg_context_
,
texture_
->
nanovg_image_handele
,
&
imgw
,
&
imgh
);
float
drawWitdth
=
fabsf
(
ui_widget
::
width_px
());
float
drawHeight
=
fabsf
(
ui_widget
::
height_px
());
if
(
width
()
<
0
&&
height
()
<
0
){
}
else
if
(
width
()
<
0
){
drawWitdth
=
drawHeight
*
(
float
)
imgw
/
(
float
)
imgh
;
}
else
if
(
height
()
<
0
){
drawHeight
=
drawWitdth
*
(
float
)
imgh
/
(
float
)
imgw
;
}
return
drawWitdth
;
}
float
texture_widget
::
height_px
()
const
{
int
imgw
,
imgh
;
nvgImageSize
(
texture_
->
nanovg_context_
,
texture_
->
nanovg_image_handele
,
&
imgw
,
&
imgh
);
float
drawWitdth
=
fabsf
(
ui_widget
::
width_px
());
float
drawHeight
=
fabsf
(
ui_widget
::
height_px
());
if
(
width
()
<
0
&&
height
()
<
0
){
}
else
if
(
width
()
<
0
){
drawWitdth
=
drawHeight
*
(
float
)
imgw
/
(
float
)
imgh
;
}
else
if
(
height
()
<
0
){
drawHeight
=
drawWitdth
*
(
float
)
imgh
/
(
float
)
imgw
;
}
return
drawHeight
;
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment