onilink_

Untitled

Feb 5th, 2019
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1.  
  2. void Skin::render(const PushButton& button) const
  3. {
  4.     const auto& _pos = button.pos();
  5.     const auto& _size = button.size();
  6.     const Style style = button.getStyle();
  7.    
  8.     unsigned frame = static_cast<unsigned>(button.state());
  9.     if(button.disabled()) {
  10.         frame = 3;
  11.     }
  12.     drawButton(style, _pos, _size, frame);
  13.    
  14.     Pos w = _pos;
  15.     w.x += _size.wid / 2.f;
  16.     w.y += _size.hei / 2.f;
  17.    
  18.     if(button.state() == PushButton::State::Down) {
  19.         w += Pos(1, 1);
  20.     }
  21.    
  22.     if(button.disabled()) {
  23.         glColor3f(0.6f, 0.6f, 0.6f);
  24.     }
  25.    
  26.     float dx = 0.f;
  27.     if(button._icon != -1) {
  28.         /// @todo define json parameter for sep
  29.         int sep = button._text.empty()?0:4;
  30.         if(button._icon_policy == IconPolicy::GluedLeft) {
  31.             dx = int( (_icons.getWidth(button._icon) + sep) / 2.f);
  32.             _icons.draw(button._icon, 0,
  33.                         int(w.x - button._text_width/2.f - dx),
  34.                         int(w.y - _icons.getHeight(button._icon)/2.f));
  35.         }
  36.         else if(button._icon_policy == IconPolicy::GluedRight) {
  37.             dx =  - int( (_icons.getWidth(button._icon) + sep) / 2.f);
  38.             _icons.draw(button._icon, 0,
  39.                         int(w.x + button._text_width/2.f + dx + sep),
  40.                         int(w.y - _icons.getHeight(button._icon)/2.f));
  41.         }
  42.         /// @todo geometry update, etc ... (atm it's WIP / not finished)
  43.         else if(button._icon_policy == IconPolicy::Left) {
  44.             /// @todo define json parameter for '+ 8'
  45.             _icons.draw(button._icon, 0,
  46.                         int(_pos.x + 8),
  47.                         int(w.y - _icons.getHeight(button._icon)/2.f));
  48.         }
  49.     }
  50.    
  51.     const auto& attribs = _attribs.at(style.skin);
  52.     const auto& attr = attribs.button.at(style.style);
  53.    
  54.     drawSetColor(attr.text.color);
  55.     _fonts[attr.text.font_index]->draw(w + Pos(dx, 0), button._text,
  56.                                   Font::Middle, Font::Center);
  57.     glColor3f(1, 1, 1);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment