void Button::set_text(const std::string &t)
{
- text=t;
+ text = t;
}
void Button::set_icon(const GL::Texture2D *i)
{
- icon=i;
+ icon = i;
}
void Button::button_press(int, int, unsigned btn)
{
if(btn==1)
{
- pressed=true;
- state|=ACTIVE;
+ pressed = true;
+ state |= ACTIVE;
}
}
{
if(pressed && btn==1)
{
- state&=~ACTIVE;
- pressed=false;
+ state &= ~ACTIVE;
+ pressed = false;
if(geom.is_inside_relative(x, y))
signal_clicked.emit();
if(pressed)
{
if(!geom.is_inside_relative(x, y))
- state&=~ACTIVE;
+ state &= ~ACTIVE;
else
- state|=ACTIVE;
+ state |= ACTIVE;
}
}
if(part.get_name()=="icon" && icon)
{
Geometry rgeom;
- rgeom.w=icon->get_width();
- rgeom.h=icon->get_height();
+ rgeom.w = icon->get_width();
+ rgeom.h = icon->get_height();
part.get_alignment().apply(rgeom, geom, part.get_margin());
icon->bind();
void Button::Loader::text(const std::string &t)
{
- static_cast<Button &>(wdg).text=t;
+ static_cast<Button &>(wdg).text = t;
}
} // namespace GLtk
void Connector::connect(const Logic &logic)
{
- const list<Logic::WidgetBinding> &logic_binds=logic.get_bindings();
+ const list<Logic::WidgetBinding> &logic_binds = logic.get_bindings();
for(list<Logic::WidgetBinding>::const_iterator i=logic_binds.begin(); i!=logic_binds.end(); ++i)
{
- map<string, ConnAction *>::const_iterator j=actions.find(i->type);
+ map<string, ConnAction *>::const_iterator j = actions.find(i->type);
if(j!=actions.end())
j->second->connect(*this, *i->wdg, i->data);
else
void Connector::add(const string &type, ConnAction *act)
{
- map<string, ConnAction *>::iterator i=actions.find(type);
+ map<string, ConnAction *>::iterator i = actions.find(type);
if(i!=actions.end())
{
delete i->second;
- i->second=act;
+ i->second = act;
}
else
- actions[type]=act;
+ actions[type] = act;
}
} // namespace GLtk
Widget *Container::get_descendant_at(int x, int y)
{
- Widget *wdg=get_child_at(x, y);
- if(Container *cont=dynamic_cast<Container *>(wdg))
+ Widget *wdg = get_child_at(x, y);
+ if(Container *cont = dynamic_cast<Container *>(wdg))
{
- const Geometry &cgeom=wdg->get_geometry();
- Widget *wdg2=cont->get_descendant_at(x-cgeom.x, y-cgeom.y);
+ const Geometry &cgeom = wdg->get_geometry();
+ Widget *wdg2 = cont->get_descendant_at(x-cgeom.x, y-cgeom.y);
if(wdg2)
return wdg2;
}
{
if(click_focus)
{
- const Geometry &cgeom=click_focus->get_geometry();
+ const Geometry &cgeom = click_focus->get_geometry();
click_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
}
else
{
- if(Widget *wdg=get_child_at(x, y))
+ if(Widget *wdg = get_child_at(x, y))
{
- click_focus=wdg;
- click_button=btn;
+ click_focus = wdg;
+ click_button = btn;
- const Geometry &cgeom=wdg->get_geometry();
+ const Geometry &cgeom = wdg->get_geometry();
wdg->button_press(x-cgeom.x, y-cgeom.y, btn);
}
}
{
if(click_focus)
{
- Widget *wdg=click_focus;
+ Widget *wdg = click_focus;
if(btn==click_button)
- click_focus=0;
+ click_focus = 0;
- const Geometry &cgeom=wdg->get_geometry();
+ const Geometry &cgeom = wdg->get_geometry();
wdg->button_release(x-cgeom.x, y-cgeom.y, btn);
}
else
{
- if(Widget *wdg=get_child_at(x, y))
+ if(Widget *wdg = get_child_at(x, y))
{
- const Geometry &cgeom=wdg->get_geometry();
+ const Geometry &cgeom = wdg->get_geometry();
wdg->button_release(x-cgeom.x, y-cgeom.y, btn);
}
}
{
if(click_focus)
{
- const Geometry &cgeom=click_focus->get_geometry();
+ const Geometry &cgeom = click_focus->get_geometry();
click_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
}
else
{
- Widget *wdg=get_child_at(x, y);
+ Widget *wdg = get_child_at(x, y);
if(wdg)
{
- const Geometry &cgeom=wdg->get_geometry();
+ const Geometry &cgeom = wdg->get_geometry();
wdg->pointer_motion(x-cgeom.x, y-cgeom.y);
}
}
void Container::pointer_leave()
{
Widget::pointer_leave();
- click_focus=0;
+ click_focus = 0;
}
Container::Child *Container::create_child(Widget *wdg)
Container::Child::~Child()
{
if(widget==container.click_focus)
- container.click_focus=0;
+ container.click_focus = 0;
}
void Container::Child::visibility_changed(bool v)
{
if(!v && widget==container.click_focus)
- container.click_focus=0;
+ container.click_focus = 0;
}
} // namespace GLtk
{
on_response(code);
signal_response.emit(code);
- stale=true;
+ stale = true;
}
} // namespace GLtk
Container::button_press(x, y, btn);
if(!click_focus)
{
- dropped=false;
- state&=~ACTIVE;
+ dropped = false;
+ state &= ~ACTIVE;
signal_ungrab_pointer.emit();
}
}
else if(btn==1)
{
- dropped=true;
- state|=ACTIVE;
+ dropped = true;
+ state |= ACTIVE;
signal_grab_pointer.emit();
}
}
void Dropdown::resize_list()
{
// XXX This is a hack.
- unsigned n_items=list.get_n_items();
- const Style &stl=list.get_style();
- const GL::Font &font=*stl.get_font();
- unsigned h=min(max(n_items, 1U), 10U)*static_cast<unsigned>((font.get_ascent()-font.get_descent())*font.get_default_size());
+ unsigned n_items = list.get_n_items();
+ const Style &stl = list.get_style();
+ const GL::Font &font = *stl.get_font();
+ unsigned h = min(max(n_items, 1U), 10U)*static_cast<unsigned>((font.get_ascent()-font.get_descent())*font.get_default_size());
for(std::list<Part>::const_iterator i=stl.get_parts().begin(); i!=stl.get_parts().end(); ++i)
if(i->get_name()=="items")
{
- const Sides &margin=i->get_margin();
- h+=margin.top+margin.bottom;
+ const Sides &margin = i->get_margin();
+ h += margin.top+margin.bottom;
}
list.set_geometry(Geometry(0, -h, geom.w, h));
}
{
if(dropped)
{
- dropped=false;
- state&=~ACTIVE;
+ dropped = false;
+ state &= ~ACTIVE;
signal_ungrab_pointer.emit();
}
void Entry::set_text(const string &t)
{
- text=t;
- edit_pos=text.size();
+ text = t;
+ edit_pos = text.size();
}
void Entry::set_multiline(bool m)
{
unsigned row, col;
text.offset_to_coords(edit_pos, row, col);
- edit_pos=text.coords_to_offset(row+1, col);
+ edit_pos = text.coords_to_offset(row+1, col);
}
else if(key==Input::KEY_UP && multiline)
{
unsigned row, col;
text.offset_to_coords(edit_pos, row, col);
if(row>0)
- edit_pos=text.coords_to_offset(row-1, col);
+ edit_pos = text.coords_to_offset(row-1, col);
else
- edit_pos=0;
+ edit_pos = 0;
}
else if(key==Input::KEY_BACKSPACE)
{
unsigned row, col;
text.offset_to_coords(edit_pos, row, col);
- Geometry rgeom=text.coords_to_geometry(row, col);
+ Geometry rgeom = text.coords_to_geometry(row, col);
part.get_alignment().apply(rgeom, geom, part.get_margin());
GL::push_matrix();
{
if(parent.w>geom.w)
{
- geom.w+=static_cast<unsigned>((parent.w-geom.w)*w);
- geom.x+=static_cast<int>((parent.w-geom.w)*x);
+ geom.w += static_cast<unsigned>((parent.w-geom.w)*w);
+ geom.x += static_cast<int>((parent.w-geom.w)*x);
}
if(parent.h>geom.h)
{
- geom.h+=static_cast<unsigned>((parent.h-geom.h)*h);
- geom.y+=static_cast<int>((parent.h-geom.h)*y);
+ geom.h += static_cast<unsigned>((parent.h-geom.h)*h);
+ geom.y += static_cast<int>((parent.h-geom.h)*y);
}
}
void Alignment::apply(Geometry &geom, const Geometry &parent, const Sides &margin) const
{
- unsigned pw=parent.w-margin.left-margin.right;
- unsigned ph=parent.h-margin.bottom-margin.top;
+ unsigned pw = parent.w-margin.left-margin.right;
+ unsigned ph = parent.h-margin.bottom-margin.top;
- geom.x+=margin.left;
- geom.y+=margin.bottom;
+ geom.x += margin.left;
+ geom.y += margin.bottom;
if(pw>geom.w)
{
- geom.w+=static_cast<unsigned>((pw-geom.w)*w);
- geom.x+=static_cast<int>((pw-geom.w)*x);
+ geom.w += static_cast<unsigned>((pw-geom.w)*w);
+ geom.x += static_cast<int>((pw-geom.w)*x);
}
if(ph>geom.h)
{
- geom.h+=static_cast<unsigned>((ph-geom.h)*h);
- geom.y+=static_cast<int>((ph-geom.h)*y);
+ geom.h += static_cast<unsigned>((ph-geom.h)*h);
+ geom.y += static_cast<int>((ph-geom.h)*y);
}
}
create_texcoords(slice.x, slice.x+slice.w, border.left, border.right, texture->get_width(), u);
create_texcoords(slice.y, slice.y+slice.h, border.bottom, border.top, texture->get_height(), v);
- unsigned xmin=border.left ? 0 : 1;
- unsigned xmax=x.size()-(border.right ? 2 : 3);
- unsigned ymin=border.bottom ? 0 : 1;
- unsigned ymax=y.size()-(border.top ? 2 : 3);
+ unsigned xmin = border.left ? 0 : 1;
+ unsigned xmax = x.size()-(border.right ? 2 : 3);
+ unsigned ymin = border.bottom ? 0 : 1;
+ unsigned ymax = y.size()-(border.top ? 2 : 3);
texture->bind();
GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
imm.begin(GL::QUADS);
for(unsigned i=ymin; i<=ymax; ++i)
{
- unsigned i2=(i==0 ? 0 : i==y.size()-2 ? 2 : 1);
+ unsigned i2 = (i==0 ? 0 : i==y.size()-2 ? 2 : 1);
for(unsigned j=xmin; j<=xmax; ++j)
{
- unsigned j2=(j==0 ? 0 : j==x.size()-2 ? 2 : 1);
+ unsigned j2 = (j==0 ? 0 : j==x.size()-2 ? 2 : 1);
imm.texcoord(u[j2], v[i2]);
imm.vertex(x[j], y[i]);
imm.texcoord(u[j2+1], v[i2]);
coords.push_back(low+brd1);
if(repeat)
{
- float space=high-low-brd1-brd2;
- unsigned div=max(static_cast<unsigned>(space/block), 1U);
- float delta=space/div;
+ float space = high-low-brd1-brd2;
+ unsigned div = max(static_cast<unsigned>(space/block), 1U);
+ float delta = space/div;
for(unsigned i=1; i<div; ++i)
coords.push_back(low+brd1+delta*i);
}
void Graphic::Loader::texture(const string &n)
{
- graph.texture=res.get<GL::Texture2D>(n);
- graph.slice=Geometry(0, 0, graph.texture->get_width(), graph.texture->get_height());
+ graph.texture = res.get<GL::Texture2D>(n);
+ graph.slice = Geometry(0, 0, graph.texture->get_width(), graph.texture->get_height());
}
void Graphic::Loader::slice(unsigned x, unsigned y, unsigned w, unsigned h)
{
- graph.slice=Geometry(x, y, w, h);
+ graph.slice = Geometry(x, y, w, h);
}
void Graphic::Loader::border()
{
if(btn==1 && geom.is_inside_relative(x, y) && max>min)
{
- int sx=static_cast<int>((geom.w-slider_size)*(value-min)/(max-min));
+ int sx = static_cast<int>((geom.w-slider_size)*(value-min)/(max-min));
if(x<sx)
set_value(value-step*10);
else if(x>=static_cast<int>(sx+slider_size))
{
if(part.get_name()=="slider")
{
- Alignment align=part.get_alignment();
+ Alignment align = part.get_alignment();
if(max>min)
- align.x=(value-min)/(max-min);
+ align.x = (value-min)/(max-min);
- Geometry pgeom=part.get_geometry();
+ Geometry pgeom = part.get_geometry();
align.apply(pgeom, geom, part.get_margin());
GL::push_matrix();
void HSlider::on_geometry_change()
{
- drag_area_size=geom.w-slider_size;
+ drag_area_size = geom.w-slider_size;
}
void HSlider::on_style_change()
{
for(PartSeq::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
if(i->get_name()=="slider")
- slider_size=i->get_geometry().w;
+ slider_size = i->get_geometry().w;
on_geometry_change();
}
Indicator::Indicator(const Resources &r):
Widget(r)
{
- focusable=false;
+ focusable = false;
update_style();
}
void Indicator::set_active(bool a)
{
if(a)
- state|=ACTIVE;
+ state |= ACTIVE;
else
- state&=~ACTIVE;
+ state &= ~ACTIVE;
}
} // namespace GLtk
Widget(r),
text()
{
- focusable=false;
+ focusable = false;
update_style();
set_text(t);
}
void Label::autosize()
{
- const list<Part> &parts=style->get_parts();
- const Part *text_part=0;
+ const list<Part> &parts = style->get_parts();
+ const Part *text_part = 0;
for(list<Part>::const_iterator i=parts.begin(); (!text_part && i!=parts.end()); ++i)
if(i->get_name()=="text")
- text_part=&*i;
+ text_part = &*i;
- geom.h=text.get_height();
- geom.w=text.get_width();
+ geom.h = text.get_height();
+ geom.w = text.get_width();
if(text_part)
{
- const Sides &margin=text_part->get_margin();
- geom.w+=margin.left+margin.right;
- geom.h+=margin.top+margin.bottom;
+ const Sides &margin = text_part->get_margin();
+ geom.w += margin.left+margin.right;
+ geom.h += margin.top+margin.bottom;
}
}
void Label::set_text(const string &t)
{
- text=t;
+ text = t;
}
void Label::render_special(const Part &part) const
void Label::Loader::text(const string &t)
{
- static_cast<Label &>(wdg).text=t;
+ static_cast<Label &>(wdg).text = t;
}
} // namespace GLtk
if(sel_index>static_cast<int>(i))
--sel_index;
else if(sel_index==static_cast<int>(i))
- sel_index=-1;
+ sel_index = -1;
recalculate_parameters();
}
void List::clear()
{
items.clear();
- sel_index=-1;
+ sel_index = -1;
recalculate_parameters();
}
void List::set_selected_index(int i)
{
if(i<0)
- sel_index=-1;
+ sel_index = -1;
else if(i<static_cast<int>(items.size()))
{
- sel_index=i;
+ sel_index = i;
signal_item_selected.emit(sel_index, items[sel_index]);
}
else
if(!click_focus && btn==1)
{
if(items_part)
- y+=items_part->get_margin().top;
+ y += items_part->get_margin().top;
- unsigned i=(geom.h-1-y)/row_height;
+ unsigned i = (geom.h-1-y)/row_height;
if(i<n_visible && first+i<items.size())
{
- sel_index=first+i;
+ sel_index = first+i;
signal_item_selected.emit(sel_index, items[sel_index]);
}
{
if(part.get_name()=="items")
{
- const GL::Font &font=*style->get_font();
- const float font_size=font.get_default_size();
- const GL::Color &color=style->get_font_color();
- const Sides &margin=part.get_margin();
+ const GL::Font &font = *style->get_font();
+ const float font_size = font.get_default_size();
+ const GL::Color &color = style->get_font_color();
+ const Sides &margin = part.get_margin();
- Geometry pgeom=geom;
- pgeom.h=row_height;
- pgeom.w-=margin.left+margin.right;
+ Geometry pgeom = geom;
+ pgeom.h = row_height;
+ pgeom.w -= margin.left+margin.right;
for(unsigned i=0; (i<n_visible && first+i<items.size()); ++i)
{
Geometry rgeom;
- rgeom.w=static_cast<unsigned>(font.get_string_width(items[first+i])*font_size);
- rgeom.h=row_height;
- rgeom.x=margin.left;
- rgeom.y=geom.h-margin.top-(i+1)*row_height-static_cast<int>(font.get_descent()*font_size);
+ rgeom.w = static_cast<unsigned>(font.get_string_width(items[first+i])*font_size);
+ rgeom.h = row_height;
+ rgeom.x = margin.left;
+ rgeom.y = geom.h-margin.top-(i+1)*row_height-static_cast<int>(font.get_descent()*font_size);
part.get_alignment().apply(rgeom, pgeom);
GL::push_matrix();
{
if(sel_index>=static_cast<int>(first) && sel_index<static_cast<int>(first+n_visible))
{
- const Sides &margin=part.get_margin();
+ const Sides &margin = part.get_margin();
- Geometry pgeom=geom;
- pgeom.h=row_height;
- pgeom.w-=margin.left+margin.right;
+ Geometry pgeom = geom;
+ pgeom.h = row_height;
+ pgeom.w -= margin.left+margin.right;
- Geometry rgeom=part.get_geometry();
- rgeom.y+=geom.h-margin.top-row_height*(sel_index-first+1);
- rgeom.x+=margin.left;
+ Geometry rgeom = part.get_geometry();
+ rgeom.y += geom.h-margin.top-row_height*(sel_index-first+1);
+ rgeom.x += margin.left;
part.get_alignment().apply(rgeom, pgeom);
GL::push_matrix();
{
reposition_slider();
- items_part=0;
+ items_part = 0;
for(list<Part>::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
if(i->get_name()=="items")
- items_part=&*i;
+ items_part = &*i;
- const GL::Font &font=*style->get_font();
- row_height=static_cast<unsigned>((font.get_ascent()-font.get_descent())*font.get_default_size());
+ const GL::Font &font = *style->get_font();
+ row_height = static_cast<unsigned>((font.get_ascent()-font.get_descent())*font.get_default_size());
recalculate_parameters();
}
for(list<Part>::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
if(i->get_name()=="slider")
{
- Geometry sgeom=i->get_geometry();
+ Geometry sgeom = i->get_geometry();
i->get_alignment().apply(sgeom, geom, i->get_margin());
slider.set_geometry(sgeom);
}
void List::recalculate_parameters()
{
- unsigned h=geom.h;
+ unsigned h = geom.h;
if(items_part)
{
- const Sides &margin=items_part->get_margin();
- h-=margin.top+margin.bottom;
+ const Sides &margin = items_part->get_margin();
+ h -= margin.top+margin.bottom;
}
- n_visible=h/row_height;
+ n_visible = h/row_height;
if(first+n_visible>items.size())
{
if(items.size()>n_visible)
- first=items.size()-n_visible;
+ first = items.size()-n_visible;
else
- first=0;
+ first = 0;
}
if(items.size()>n_visible)
void List::slider_value_changed(double value)
{
if(items.size()>n_visible)
- first=items.size()-n_visible-static_cast<unsigned>(value);
+ first = items.size()-n_visible-static_cast<unsigned>(value);
}
void Logic::Loader::bind(const string &wdg, const string &data)
{
- map<string, Widget *>::const_iterator i=widgets.find(wdg);
+ map<string, Widget *>::const_iterator i = widgets.find(wdg);
if(i==widgets.end())
throw KeyError("Unknown widget", wdg);
- string::size_type colon=data.find(':');
+ string::size_type colon = data.find(':');
WidgetBinding act;
- act.wdg=i->second;
- act.type=data.substr(0, colon);
+ act.wdg = i->second;
+ act.type = data.substr(0, colon);
if(colon!=string::npos)
- act.data=data.substr(colon+1);
+ act.data = data.substr(colon+1);
logic.bindings.push_back(act);
}
Widget *Panel::get_final_input_focus() const
{
- if(Panel *panel=dynamic_cast<Panel *>(input_focus))
+ if(Panel *panel = dynamic_cast<Panel *>(input_focus))
{
- Widget *focus=panel->get_final_input_focus();
+ Widget *focus = panel->get_final_input_focus();
if(focus)
return focus;
}
{
if(pointer_grabbed)
{
- const Geometry &cgeom=pointer_focus->get_geometry();
+ const Geometry &cgeom = pointer_focus->get_geometry();
pointer_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
}
else
{
- if(Widget *wdg=get_child_at(x, y))
+ if(Widget *wdg = get_child_at(x, y))
{
set_pointer_focus(wdg);
if(wdg->is_focusable())
{
if(pointer_grabbed)
{
- const Geometry &cgeom=pointer_focus->get_geometry();
+ const Geometry &cgeom = pointer_focus->get_geometry();
pointer_focus->button_release(x-cgeom.x, y-cgeom.y, btn);
}
else
{
if(pointer_grabbed)
{
- const Geometry &cgeom=pointer_focus->get_geometry();
+ const Geometry &cgeom = pointer_focus->get_geometry();
pointer_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
}
else
if(pointer_focus)
pointer_focus->pointer_leave();
- pointer_focus=wdg;
+ pointer_focus = wdg;
if(pointer_focus)
pointer_focus->pointer_enter();
if(input_focus)
input_focus->focus_out();
- input_focus=wdg;
+ input_focus = wdg;
if(input_focus)
{
template<typename T>
void Panel::Loader::child(const string &n)
{
- RefPtr<T> chl=new T(pnl.res);
+ RefPtr<T> chl = new T(pnl.res);
load_sub(*chl);
pnl.add(*chl.get());
- wdg_map[n]=chl.release();
+ wdg_map[n] = chl.release();
}
void Panel::Loader::panel(const string &n)
{
- RefPtr<Panel> p=new Panel(pnl.res);
+ RefPtr<Panel> p = new Panel(pnl.res);
load_sub(*p, wdg_map);
pnl.add(*p.get());
- wdg_map[n]=p.release();
+ wdg_map[n] = p.release();
}
{
if(!v)
{
- Panel &panel=static_cast<Panel &>(container);
+ Panel &panel = static_cast<Panel &>(container);
if(widget==panel.pointer_focus)
panel.set_pointer_focus(0);
if(widget==panel.input_focus)
void Panel::Child::request_focus()
{
- Panel &panel=static_cast<Panel &>(container);
+ Panel &panel = static_cast<Panel &>(container);
panel.set_input_focus(widget);
if(panel.parent && panel.visible)
panel.set_focus();
void Panel::Child::grab_pointer()
{
- Panel &panel=static_cast<Panel &>(container);
+ Panel &panel = static_cast<Panel &>(container);
if(!panel.pointer_grabbed)
{
panel.set_pointer_focus(widget);
- panel.pointer_grabbed=true;
+ panel.pointer_grabbed = true;
panel.signal_grab_pointer.emit();
}
}
void Panel::Child::ungrab_pointer()
{
- Panel &panel=static_cast<Panel &>(container);
+ Panel &panel = static_cast<Panel &>(container);
if(panel.pointer_grabbed && panel.pointer_focus==widget)
{
// XXX Should set to the widget under pointer
panel.set_pointer_focus(0);
- panel.pointer_grabbed=false;
+ panel.pointer_grabbed = false;
panel.signal_ungrab_pointer.emit();
}
}
name(n)
{
for(unsigned i=0; i<N_STATES_; ++i)
- graphic[i]=0;
+ graphic[i] = 0;
}
const Graphic *Part::get_graphic(State state) const
if(!graphic[state])
return;
- Geometry rgeom=geom;
+ Geometry rgeom = geom;
align.apply(rgeom, parent, margin);
GL::translate(rgeom.x, rgeom.y, 0);
graphic[state]->render(rgeom.w, rgeom.h);
for(unsigned i=0; i<N_STATES_; ++i)
if(part.graphic[i])
{
- const Sides &shadow=part.graphic[i]->get_shadow();
- part.geom.w=max(part.geom.w, part.graphic[i]->get_width()-shadow.left-shadow.right);
- part.geom.h=max(part.geom.h, part.graphic[i]->get_height()-shadow.bottom-shadow.top);
+ const Sides &shadow = part.graphic[i]->get_shadow();
+ part.geom.w = max(part.geom.w, part.graphic[i]->get_width()-shadow.left-shadow.right);
+ part.geom.h = max(part.geom.h, part.graphic[i]->get_height()-shadow.bottom-shadow.top);
}
}
void Part::Loader::graphic(State s, const string &n)
{
- Graphic *grph=res.get<Graphic>(n);
+ Graphic *grph = res.get<Graphic>(n);
for(int i=0; i<N_STATES_; ++i)
if((i&s)==s)
- part.graphic[i]=grph;
+ part.graphic[i] = grph;
}
void Part::Loader::align(float x, float y)
{
- part.align.x=x;
- part.align.y=y;
+ part.align.x = x;
+ part.align.y = y;
}
void Part::Loader::fill(float w, float h)
{
- part.align.w=w;
- part.align.h=h;
+ part.align.w = w;
+ part.align.h = h;
}
void Part::Loader::margin()
void Part::Loader::size(unsigned w, unsigned h)
{
- part.geom.w=w;
- part.geom.h=h;
+ part.geom.w = w;
+ part.geom.h = h;
}
} // namespace GLtk
void Resources::set_path(const FS::Path &p)
{
- path=p;
+ path = p;
}
const GL::Font &Resources::get_default_font() const
GL::Font *Resources::create_font(const string &name)
{
- RefPtr<GL::Font> fnt=new GL::Font;
+ RefPtr<GL::Font> fnt = new GL::Font;
DataFile::load(*fnt, (path/name).str(), *this);
if(!default_font)
- default_font=fnt.get();
+ default_font = fnt.get();
return fnt.release();
}
GL::Texture2D *Resources::create_texture(const string &name)
{
- RefPtr<GL::Texture2D> tex=new GL::Texture2D;
+ RefPtr<GL::Texture2D> tex = new GL::Texture2D;
tex->load_image((path/name).str());
tex->set_min_filter(GL::LINEAR);
return tex.release();
void Resources::Loader::default_font(const string &name)
{
- res.default_font=res.get<GL::Font>(name);
+ res.default_font = res.get<GL::Font>(name);
}
void Resources::Loader::font(const string &name)
{
- RefPtr<GL::Font> fnt=new GL::Font;
+ RefPtr<GL::Font> fnt = new GL::Font;
load_sub(*fnt, res);
res.add(name, fnt.get());
if(!res.default_font)
- res.default_font=fnt.get();
+ res.default_font = fnt.get();
fnt.release();
}
void Resources::Loader::style(const string &name)
{
- RefPtr<Style> stl=new Style(res);
+ RefPtr<Style> stl = new Style(res);
load_sub(*stl, res);
res.add(name, stl.get());
stl.release();
if(tooltip_timeout && Time::now()>tooltip_timeout)
{
std::string tip;
- if(Widget *wdg=get_descendant_at(pointer_x, pointer_y))
+ if(Widget *wdg = get_descendant_at(pointer_x, pointer_y))
{
- tip=wdg->get_tooltip();
- tooltip_target=wdg;
+ tip = wdg->get_tooltip();
+ tooltip_target = wdg;
}
else
{
- tip=signal_tooltip.emit(pointer_x, pointer_y);
- tooltip_target=this;
+ tip = signal_tooltip.emit(pointer_x, pointer_y);
+ tooltip_target = this;
}
if(!tip.empty())
{
if(!lbl_tooltip)
{
- lbl_tooltip=new Label(res);
+ lbl_tooltip = new Label(res);
add(*lbl_tooltip);
lbl_tooltip->set_style("tooltip");
}
lbl_tooltip->set_text(tip);
lbl_tooltip->autosize();
- const Geometry &tip_geom=lbl_tooltip->get_geometry();
- unsigned x=pointer_x+10;
- unsigned y=pointer_y-10-lbl_tooltip->get_geometry().h;
+ const Geometry &tip_geom = lbl_tooltip->get_geometry();
+ unsigned x = pointer_x+10;
+ unsigned y = pointer_y-10-lbl_tooltip->get_geometry().h;
if(x+tip_geom.w>geom.w)
{
if(pointer_x>static_cast<int>(tip_geom.w+2))
- x=pointer_x-2-tip_geom.w;
+ x = pointer_x-2-tip_geom.w;
else
- x=geom.w-tip_geom.w;
+ x = geom.w-tip_geom.w;
}
lbl_tooltip->set_position(x, y);
raise(*lbl_tooltip);
lbl_tooltip->set_visible(true);
}
- tooltip_timeout=Time::TimeStamp();
+ tooltip_timeout = Time::TimeStamp();
}
}
{
if(visible)
{
- Widget *old_focus=pointer_focus;
+ Widget *old_focus = pointer_focus;
translate_coords(x, y);
button_press(x, y, btn);
{
if(visible)
{
- Widget *old_focus=pointer_focus;
+ Widget *old_focus = pointer_focus;
translate_coords(x, y);
button_release(x, y, btn);
if(!tooltip_target)
{
- pointer_x=x;
- pointer_y=y;
- tooltip_timeout=Time::now()+700*Time::msec;
+ pointer_x = x;
+ pointer_y = y;
+ tooltip_timeout = Time::now()+700*Time::msec;
}
else if(get_descendant_at(x, y)!=tooltip_target)
{
if(lbl_tooltip)
lbl_tooltip->set_visible(false);
- tooltip_target=0;
+ tooltip_target = 0;
}
if(!pointer_focus)
{
if(visible)
{
- Widget *old_focus=input_focus;
+ Widget *old_focus = input_focus;
key_press(Input::key_from_sys(key), mod, ch);
{
if(visible)
{
- Widget *old_focus=input_focus;
+ Widget *old_focus = input_focus;
key_release(Input::key_from_sys(key), mod);
void Root::translate_coords(int &x, int &y)
{
- x=x*geom.w/window.get_width();
- y=geom.h-1-y*geom.h/window.get_height();
+ x = x*geom.w/window.get_width();
+ y = geom.h-1-y*geom.h/window.get_height();
}
} // namespace GLtk
void Slider::set_value(double v)
{
- double old_value=value;
+ double old_value = value;
if(v<min)
- value=min;
+ value = min;
else if(v>max)
- value=max;
+ value = max;
else
{
- unsigned steps=static_cast<unsigned>((v-min)/step+0.5);
- value=min+steps*step;
+ unsigned steps = static_cast<unsigned>((v-min)/step+0.5);
+ value = min+steps*step;
}
if(value!=old_value)
void Slider::set_range(double a, double b)
{
- min=a;
- max=b;
+ min = a;
+ max = b;
set_value(value);
}
void Slider::set_step(double s)
{
- step=s;
+ step = s;
set_value(value);
}
void Slider::start_drag(int p)
{
- dragging=true;
- drag_start_pos=p;
- drag_start_value=value;
- state|=ACTIVE;
+ dragging = true;
+ drag_start_pos = p;
+ drag_start_value = value;
+ state |= ACTIVE;
}
void Slider::drag(int p)
void Slider::end_drag()
{
- dragging=false;
- state&=~ACTIVE;
+ dragging = false;
+ state &= ~ACTIVE;
}
string str;
is>>str;
- unsigned start=0;
- state=NORMAL;
+ unsigned start = 0;
+ state = NORMAL;
while(1)
{
- string::size_type underscore=str.find('_', start);
+ string::size_type underscore = str.find('_', start);
if(!str.compare(start, underscore-start, "NORMAL"))
- state|=NORMAL;
+ state |= NORMAL;
else if(!str.compare(start, underscore-start, "HOVER"))
- state|=HOVER;
+ state |= HOVER;
else if(!str.compare(start, underscore-start, "ACTIVE"))
- state|=ACTIVE;
+ state |= ACTIVE;
else if(!str.compare(start, underscore-start, "FOCUS"))
- state|=FOCUS;
+ state |= FOCUS;
else if(!str.compare(start, underscore-start, "DISABLED"))
- state|=DISABLED;
+ state |= DISABLED;
else
{
is.setstate(ios_base::failbit);
if(underscore==std::string::npos)
break;
- start=underscore+1;
+ start = underscore+1;
}
return is;
enum State
{
- NORMAL=0, //< Default state
- HOVER=1, //< Pointer over the widget
- ACTIVE=2, //< Widget is active (e.g. pressed button)
- FOCUS=4, //< Widget has input focus
- DISABLED=8, //< Widget is unresponsive
- N_STATES_=16 //< Sentry value
+ NORMAL = 0, //< Default state
+ HOVER = 1, //< Pointer over the widget
+ ACTIVE = 2, //< Widget is active (e.g. pressed button)
+ FOCUS = 4, //< Widget has input focus
+ DISABLED = 8, //< Widget is unresponsive
+ N_STATES_ = 16 //< Sentry value
};
inline State operator|(State a, State b)
{ return static_cast<State>(static_cast<int>(a)|static_cast<int>(b)); }
inline State operator|=(State &a, State b)
-{ a=a|b; return a; }
+{ a = a|b; return a; }
inline State operator&(State a, State b)
{ return static_cast<State>(static_cast<int>(a)&static_cast<int>(b)); }
inline State operator&=(State &a, State b)
-{ a=a&b; return a; }
+{ a = a&b; return a; }
inline State operator~(State a)
{ return static_cast<State>(~static_cast<int>(a)); }
void Style::Loader::font_color(float r, float g, float b)
{
- style.font_color=GL::Color(r, g, b);
+ style.font_color = GL::Color(r, g, b);
}
void Style::Loader::part()
data(1),
col_w(1)
{
- focusable=false;
+ focusable = false;
update_style();
}
void Table::set_rows(unsigned r)
{
- rows=r;
+ rows = r;
data.resize(rows*columns);
}
for(unsigned j=0; j<min(c, columns); ++j)
new_data[i*c+j].swap(data[i*columns+j]);
data.swap(new_data);
- columns=c;
+ columns = c;
col_w.resize(columns);
}
{
if(c>=columns)
throw InvalidParameterValue("Column index out of bounds");
- col_w[c]=w;
+ col_w[c] = w;
}
void Table::set_cell_text(unsigned r, unsigned c, const string &t)
if(r>=rows || c>=columns)
throw InvalidParameterValue("Cell coordinates out of bounds");
- data[r*columns+c]=t;
+ data[r*columns+c] = t;
}
void Table::render_special(const Part &part) const
{
if(part.get_name()=="cells")
{
- const GL::Font *const font=style->get_font();
- const float font_size=font->get_default_size();
+ const GL::Font *const font = style->get_font();
+ const float font_size = font->get_default_size();
- unsigned free_width=geom.w;
+ unsigned free_width = geom.w;
for(unsigned i=0; i<columns; ++i)
- free_width-=col_w[i];
+ free_width -= col_w[i];
Geometry cgeom;
- cgeom.h=geom.h/rows;
- cgeom.y=geom.h-cgeom.h;
+ cgeom.h = geom.h/rows;
+ cgeom.y = geom.h-cgeom.h;
for(unsigned i=0; i<rows; ++i)
{
- cgeom.x=0;
+ cgeom.x = 0;
for(unsigned j=0; j<columns; ++j)
{
if(col_w[j])
- cgeom.w=col_w[j];
+ cgeom.w = col_w[j];
else
- cgeom.w=free_width/columns;
+ cgeom.w = free_width/columns;
- const string &text=data[i*columns+j];
+ const string &text = data[i*columns+j];
Geometry rgeom;
- rgeom.x=cgeom.x;
- rgeom.y=cgeom.y;
- rgeom.w=static_cast<unsigned>(font->get_string_width(text)*font_size);
- rgeom.h=static_cast<unsigned>((font->get_ascent()-font->get_descent())*font_size);
+ rgeom.x = cgeom.x;
+ rgeom.y = cgeom.y;
+ rgeom.w = static_cast<unsigned>(font->get_string_width(text)*font_size);
+ rgeom.h = static_cast<unsigned>((font->get_ascent()-font->get_descent())*font_size);
part.get_alignment().apply(rgeom, cgeom, part.get_margin());
font->draw_string(text);
GL::pop_matrix();
- cgeom.x+=cgeom.w;
+ cgeom.x += cgeom.w;
}
- cgeom.y-=cgeom.h;
+ cgeom.y -= cgeom.h;
}
}
}
{
style = s;
- float font_size=style->get_font()->get_default_size();
+ float font_size = style->get_font()->get_default_size();
for(vector<Line>::iterator i=lines.begin(); i!=lines.end(); ++i)
- i->width=static_cast<unsigned>(style->get_font()->get_string_width(text.substr(i->start, i->length))*font_size);
+ i->width = static_cast<unsigned>(style->get_font()->get_string_width(text.substr(i->start, i->length))*font_size);
}
unsigned Text::get_width() const
{
- unsigned width=0;
+ unsigned width = 0;
for(vector<Line>::const_iterator i=lines.begin(); i!=lines.end(); ++i)
- width=max(width, i->width);
+ width = max(width, i->width);
return width;
}
unsigned Text::get_height() const
{
- const GL::Font *font=style->get_font();
- float font_size=font->get_default_size();
- unsigned line_height=static_cast<unsigned>((font->get_ascent()-font->get_descent())*font_size);
- unsigned line_spacing=line_height*6/5;
+ const GL::Font *font = style->get_font();
+ float font_size = font->get_default_size();
+ unsigned line_height = static_cast<unsigned>((font->get_ascent()-font->get_descent())*font_size);
+ unsigned line_spacing = line_height*6/5;
return line_height+(lines.size()-1)*line_spacing;
}
void Text::set(const string &t)
{
- text=t;
+ text = t;
find_lines();
}
find_lines();
else
{
- i->length-=len;
+ i->length -= len;
for(++i; i!=lines.end(); ++i)
- i->start-=len;
+ i->start -= len;
}
}
vector<Line>::iterator i;
for(i=lines.begin(); (i!=lines.end() && i->start+i->length<pos); ++i) ;
- i->length+=s.size();
+ i->length += s.size();
for(++i; i!=lines.end(); ++i)
- i->start+=s.size();
+ i->start += s.size();
}
}
{
if(lines.empty())
{
- row=0;
- col=0;
+ row = 0;
+ col = 0;
return;
}
for(unsigned i=0; i<lines.size(); ++i)
if(offs>=lines[i].start && offs<=lines[i].start+lines[i].length)
{
- row=i;
- col=offs-lines[i].start;
+ row = i;
+ col = offs-lines[i].start;
return;
}
}
Geometry Text::coords_to_geometry(unsigned row, unsigned col) const
{
if(row>=lines.size())
- row=lines.size()-1;
- const Line &line=lines[row];
+ row = lines.size()-1;
+ const Line &line = lines[row];
if(col>line.length)
- col=line.length;
+ col = line.length;
- const GL::Font *font=style->get_font();
- float font_size=font->get_default_size();
- unsigned line_height=static_cast<unsigned>((font->get_ascent()-font->get_descent())*font_size);
- unsigned line_spacing=static_cast<unsigned>(font_size*6/5);
- unsigned height=line_height+(lines.size()-1)*line_spacing;
- int y_offset=static_cast<int>(-font->get_descent()*font_size);
+ const GL::Font *font = style->get_font();
+ float font_size = font->get_default_size();
+ unsigned line_height = static_cast<unsigned>((font->get_ascent()-font->get_descent())*font_size);
+ unsigned line_spacing = static_cast<unsigned>(font_size*6/5);
+ unsigned height = line_height+(lines.size()-1)*line_spacing;
+ int y_offset = static_cast<int>(-font->get_descent()*font_size);
Geometry geom;
- geom.w=line.width;
- geom.h=height;
- geom.x=static_cast<unsigned>(font->get_string_width(text.substr(line.start, col))*font_size);
- geom.y=(lines.size()-1-row)*line_spacing+y_offset;
+ geom.w = line.width;
+ geom.h = height;
+ geom.x = static_cast<unsigned>(font->get_string_width(text.substr(line.start, col))*font_size);
+ geom.y = (lines.size()-1-row)*line_spacing+y_offset;
return geom;
}
if(lines.empty())
return;
- const GL::Font *font=style->get_font();
- float font_size=font->get_default_size();
- unsigned line_height=static_cast<unsigned>((font->get_ascent()-font->get_descent())*font_size);
- unsigned line_spacing=static_cast<unsigned>(font_size*6/5);
- unsigned height=line_height+(lines.size()-1)*line_spacing;
- int y_offset=static_cast<int>(-font->get_descent()*font_size);
+ const GL::Font *font = style->get_font();
+ float font_size = font->get_default_size();
+ unsigned line_height = static_cast<unsigned>((font->get_ascent()-font->get_descent())*font_size);
+ unsigned line_spacing = static_cast<unsigned>(font_size*6/5);
+ unsigned height = line_height+(lines.size()-1)*line_spacing;
+ int y_offset = static_cast<int>(-font->get_descent()*font_size);
- const GL::Color &color=style->get_font_color();
+ const GL::Color &color = style->get_font_color();
GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
imm.color(color.r, color.g, color.b);
for(unsigned i=0; i<lines.size(); ++i)
{
- const Line &line=lines[i];
+ const Line &line = lines[i];
Geometry rgeom;
- rgeom.w=line.width;
- rgeom.h=height;
- rgeom.y=(lines.size()-1-i)*line_spacing+y_offset;
+ rgeom.w = line.width;
+ rgeom.h = height;
+ rgeom.y = (lines.size()-1-i)*line_spacing+y_offset;
part.get_alignment().apply(rgeom, geom, part.get_margin());
GL::push_matrix();
void Text::find_lines()
{
lines.clear();
- float font_size=style->get_font()->get_default_size();
- string::size_type start=0;
+ float font_size = style->get_font()->get_default_size();
+ string::size_type start = 0;
while(1)
{
- string::size_type newline=text.find('\n', start);
+ string::size_type newline = text.find('\n', start);
Line line;
- line.start=start;
- line.length=(newline==string::npos ? text.size() : newline)-start;
- line.width=static_cast<unsigned>(style->get_font()->get_string_width(text.substr(line.start, line.length))*font_size);
+ line.start = start;
+ line.length = (newline==string::npos ? text.size() : newline)-start;
+ line.width = static_cast<unsigned>(style->get_font()->get_string_width(text.substr(line.start, line.length))*font_size);
lines.push_back(line);
if(newline==string::npos)
break;
- start=newline+1;
+ start = newline+1;
}
}
void Toggle::set_text(const string &t)
{
- text=t;
+ text = t;
}
void Toggle::set_exclusive(bool e)
{
- exclusive=e;
+ exclusive = e;
if(exclusive && value)
exclude_siblings();
}
void Toggle::set_value(bool v)
{
- value=v;
+ value = v;
if(value)
{
- state|=ACTIVE;
+ state |= ACTIVE;
if(exclusive && parent)
exclude_siblings();
}
else
- state&=~ACTIVE;
+ state &= ~ACTIVE;
}
void Toggle::button_press(int, int, unsigned btn)
{
if(btn==1)
- pressed=true;
+ pressed = true;
}
void Toggle::button_release(int x, int y, unsigned btn)
signal_toggled.emit(value);
}
- pressed=false;
+ pressed = false;
}
}
void Toggle::exclude_siblings()
{
- const list<Widget *> &siblings=parent->get_children();
+ const list<Widget *> &siblings = parent->get_children();
for(list<Widget *>::const_iterator i=siblings.begin(); i!=siblings.end(); ++i)
- if(Toggle *tgl=dynamic_cast<Toggle *>(*i))
+ if(Toggle *tgl = dynamic_cast<Toggle *>(*i))
if(tgl!=this && tgl->get_exclusive() && tgl->get_value())
tgl->set_value(false);
}
void Toggle::Loader::finish()
{
- Toggle &tgl=static_cast<Toggle &>(wdg);
+ Toggle &tgl = static_cast<Toggle &>(wdg);
if(tgl.value)
- tgl.state|=ACTIVE;
+ tgl.state |= ACTIVE;
else
- tgl.state&=~ACTIVE;
+ tgl.state &= ~ACTIVE;
}
void Toggle::Loader::text(const string &t)
{
- static_cast<Toggle &>(wdg).text=t;
+ static_cast<Toggle &>(wdg).text = t;
}
} // namespace GLtk
template<typename W>
W &get_widget(const std::string &n) const
{
- std::map<std::string, Widget *>::const_iterator i=widgets.find(n);
+ std::map<std::string, Widget *>::const_iterator i = widgets.find(n);
if(i==widgets.end())
throw KeyError("Unknown widget", n);
- W *w=dynamic_cast<W *>(i->second);
+ W *w = dynamic_cast<W *>(i->second);
if(!w)
throw Exception("Widget type mismatch");
template<typename W>
void get_widget(const std::string &n, W *&w) const
{
- w=&get_widget<W>(n);
+ w = &get_widget<W>(n);
}
};
{
if(btn==1 && geom.is_inside_relative(x, y) && max>min)
{
- int sy=static_cast<int>((geom.h-slider_size)*(value-min)/(max-min));
+ int sy = static_cast<int>((geom.h-slider_size)*(value-min)/(max-min));
if(y<sy)
set_value(value-step*10);
else if(y>=static_cast<int>(sy+slider_size))
{
if(part.get_name()=="slider")
{
- Alignment align=part.get_alignment();
+ Alignment align = part.get_alignment();
if(max>min)
- align.y=(value-min)/(max-min);
+ align.y = (value-min)/(max-min);
- Geometry pgeom=part.get_geometry();
+ Geometry pgeom = part.get_geometry();
align.apply(pgeom, geom, part.get_margin());
GL::push_matrix();
void VSlider::on_geometry_change()
{
- drag_area_size=geom.h-slider_size;
+ drag_area_size = geom.h-slider_size;
}
void VSlider::on_style_change()
{
for(PartSeq::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
if(i->get_name()=="slider")
- slider_size=i->get_geometry().h;
+ slider_size = i->get_geometry().h;
on_geometry_change();
}
void Widget::set_position(int x, int y)
{
- geom.x=x;
- geom.y=y;
+ geom.x = x;
+ geom.y = y;
on_geometry_change();
}
void Widget::set_size(unsigned w, unsigned h)
{
- geom.w=w;
- geom.h=h;
+ geom.w = w;
+ geom.h = h;
on_geometry_change();
}
void Widget::set_geometry(const Geometry &g)
{
- geom=g;
+ geom = g;
on_geometry_change();
}
void Widget::set_style(const string &s)
{
- style_name=s;
+ style_name = s;
update_style();
}
if(v==visible)
return;
- visible=v;
+ visible = v;
signal_visibility_changed.emit(visible);
}
void Widget::set_focusable(bool f)
{
- focusable=f;
+ focusable = f;
}
void Widget::set_focus()
void Widget::pointer_enter()
{
- state|=HOVER;
+ state |= HOVER;
}
void Widget::pointer_leave()
{
- state&=~HOVER;
+ state &= ~HOVER;
}
void Widget::focus_in()
{
- state|=FOCUS;
+ state |= FOCUS;
}
void Widget::focus_out()
{
- state&=~FOCUS;
+ state &= ~FOCUS;
}
void Widget::update_style()
{
- string sname=get_class();
+ string sname = get_class();
if(!style_name.empty())
{
- sname+='-';
- sname+=style_name;
+ sname += '-';
+ sname += style_name;
}
- style=res.get<Style>(sname);
+ style = res.get<Style>(sname);
on_style_change();
}
{
if(parent && p)
throw InvalidState("Widget is already in a Container");
- parent=p;
+ parent = p;
on_reparent();
}