Commit 5d643bba authored by Jerry's avatar Jerry
Browse files

no longer negativ spaces for texture widget childs

parent 9fad3629
......@@ -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;
......
......@@ -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();
}
......
......@@ -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
......@@ -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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment