void CL_GlyphCache::insert_glyph(CL_GraphicContext &gc, CL_Font_System_Position &position, CL_PixelBuffer &pixel_buffer) { unsigned int glyph = position.glyph; // Search for duplicated glyph's, if found silently ignore them std::vector< CL_Font_TextureGlyph * >::size_type size = glyph_list.size(); for (int cnt=0; cnt<size; cnt++) { if (glyph_list[cnt]->glyph == glyph) return; } CL_Font_TextureGlyph *font_glyph = new CL_Font_TextureGlyph(); glyph_list.push_back(font_glyph); font_glyph->glyph = glyph; font_glyph->offset = CL_Point(position.x_offset, position.y_offset); font_glyph->increment = CL_Point(position.x_increment, position.y_increment); if ( (position.width > 0 ) && (position.height > 0) ) { CL_Rect source_rect(position.x_pos, position.y_pos, position.width + position.x_pos, position.height + position.y_pos); CL_PixelBuffer buffer_with_border = CL_PixelBufferHelp::add_border(pixel_buffer, glyph_border_size, source_rect); font_glyph->empty_buffer = false; font_glyph->subtexture = texture_group.add(gc, CL_Size(buffer_with_border.get_width(), buffer_with_border.get_height() )); font_glyph->geometry = CL_Rect(font_glyph->subtexture.get_geometry().left + glyph_border_size, font_glyph->subtexture.get_geometry().top + glyph_border_size, source_rect.get_size() ); font_glyph->subtexture.get_texture().set_subimage(font_glyph->subtexture.get_geometry().left, font_glyph->subtexture.get_geometry().top, buffer_with_border, buffer_with_border.get_size()); } else { font_glyph->empty_buffer = true; } }
void Map::draw(float elapsed) { CL_Vec2<float> fieldSize; CL_Pointf p; CL_Rect viewport = window.get_viewport(); fieldSize.x = (float)viewport.get_width() / size.width; fieldSize.y = (float)viewport.get_height() / size.height; for (int row = 0; row < size.height; row++) for (int col = 0; col < size.width; col++) { p = CL_Pointf(col * fieldSize.x, row * fieldSize.y) + fieldSize / 2; if (row < size.height - 1) { CL_Colorf color(getEdge(CL_Point(col, row), CL_Point(col, row + 1)).pheromone / 10, 0, 0); CL_Draw::line(window.get_gc(), p, p + CL_Vec2<float>(0, fieldSize.y), color); } if (col < size.width - 1) { CL_Colorf color(getEdge(CL_Point(col, row), CL_Point(col + 1, row)).pheromone / 10, 0, 0); CL_Draw::line(window.get_gc(), p, p + CL_Vec2<float>(fieldSize.x, 0), color); } } p = CL_Pointf(start.x * fieldSize.x, start.y * fieldSize.y); CL_Draw::fill(window.get_gc(), p, p + fieldSize, CL_Colorf::red); p = CL_Pointf(target.x * fieldSize.x, target.y * fieldSize.y); CL_Draw::fill(window.get_gc(), p, p + fieldSize, CL_Colorf::green); }
Window::Window(const CL_Rect& rect, const std::string& title, CL_Component* parent) : CL_Component(rect, parent), impl(new WindowImpl()) { impl->titlebar = new Titlebar(CL_Rect(CL_Point(3+16,3), CL_Size(get_width()-6-18-18-18, 12+3)), title, this); //Fonts::verdana11.draw(8+15, 3, title); impl->close = new Icon(CL_Rect(CL_Point(3, 3), CL_Size(18,18)), make_sprite(datadir + "/images/window/close.png"), "", this); impl->minimize = new Icon(CL_Rect(CL_Point(get_width()-3-18-18, 3), CL_Size(18,18)), make_sprite(datadir + "/images/window/minimize.png"), "", this); impl->maximize = new Icon(CL_Rect(CL_Point(get_width()-3-18, 3), CL_Size(18,18)), make_sprite(datadir + "/images/window/maximize.png"), "", this); impl->client_area = new CL_Component(CL_Rect(CL_Point(4, 3+12+7), CL_Size(rect.get_width()-10, rect.get_height()-28)), this); impl->parent = this; impl->is_maximized = false; impl->slots.push_back(sig_resize().connect(impl.get(), &WindowImpl::on_resize)); impl->slots.push_back(sig_paint().connect(impl.get(), &WindowImpl::draw)); impl->slots.push_back(impl->maximize->sig_clicked().connect(impl.get(), &WindowImpl::do_maximize)); impl->slots.push_back(impl->close->sig_clicked().connect(impl.get(), &WindowImpl::do_close)); }
int main() { Flexlay flexlay; flexlay.init(); Editor editor; GUIManager* gui = editor.get_gui_manager(); new CL_Button(CL_Rect(CL_Point(50, 50), CL_Size(100, 25)), "Hello World", gui->get_component()); EditorMap m; Tileset tileset(32); TilemapLayer tilemap(tileset, 20, 10); m.add_layer(tilemap.to_layer()); TilemapLayer::set_current(tilemap); EditorMapComponent editor_map(CL_Rect(0, 0, 799, 599), gui->get_component()); Workspace workspace(799, 599); editor_map.set_workspace(workspace); workspace.set_map(m); new CL_Button(CL_Rect(CL_Point(50, 150), CL_Size(100, 25)), "Quit", gui->get_component()); gui->run(); flexlay.deinit(); }
void TitlebarImpl::draw() { CL_Display::push_translate(parent->get_screen_x(), parent->get_screen_y()); // FIXME: Hack should be done via has_mouse_over(), but that doesn't include child components if (parent->get_parent()->get_position().is_inside(CL_Point(CL_Mouse::get_x(), CL_Mouse::get_y()))) //parent->get_parent()->has_mouse_over()) { CL_Display::fill_rect(CL_Rect(CL_Point(0, 0), CL_Size(parent->get_width()-1, parent->get_height())), CL_Color(250, 250, 250)); } else { CL_Display::fill_rect(CL_Rect(CL_Point(0, 0), CL_Size(parent->get_width()-1, parent->get_height())), CL_Color(240, 240, 240)); } Fonts::verdana11.draw(4, 0, title); CL_Display::pop_modelview(); }
CL_FileDialog_Generic::CL_FileDialog_Generic( CL_FileDialog *self, const std::string &title, const std::string &file, const std::string &filter) : filedialog(self) { behavior = CL_FileDialog::quit_always; button = CL_FileDialog::button_none; // TODO: Calculate proper size int width = 400; int height = 315; int x = (CL_Display::get_width() - width) / 2; int y = (CL_Display::get_height() - height) / 2; filedialog->set_position(CL_Rect(x, y, x + width, y + height)); filedialog->set_title(title); CL_Component *client_area = filedialog->get_client_area(); width = client_area->get_width(); label_dir = new CL_Label(CL_Point(10, 12), "Directory:", client_area); input_dir = new CL_InputBox(CL_Rect(65, 10, width - 120, 30), client_area); input_dir->enable(false); button_parent = new CL_Button(CL_Rect(width - 115, 9, width - 65, 28), "Parent", client_area); button_createdir = new CL_Button(CL_Rect(width - 60, 9, width - 10, 28), "New", client_area); treeview_files = new CL_TreeView(CL_Rect(10, 32, width - 10, 197), client_area); treeview_files->add_column("Filename", 200); treeview_files->add_column("Size", 80); treeview_files->add_column("Type", 100); treeview_files->show_root_decoration(false); label_file = new CL_Label(CL_Point(10, 207), "Filename:", client_area); input_file = new CL_InputBox(CL_Rect(65, 205, width - 10, 225), client_area); label_filter = new CL_Label(CL_Point(10, 232), "Filter:", client_area); input_filter = new CL_InputBox(CL_Rect(65, 230, width - 10, 250), client_area); button_ok = new CL_Button(CL_Rect(10, 260, 100, 280), "OK", client_area); button_cancel = new CL_Button(CL_Rect(width - 110, 260, width - 10, 280), "Cancel", client_area); slots.connect(self->sig_set_options(), this, &CL_FileDialog_Generic::on_set_options); slots.connect(treeview_files->sig_selection_changed(), this, &CL_FileDialog_Generic::on_file_activated); slots.connect(button_ok->sig_clicked(), this, &CL_FileDialog_Generic::on_button_quit, true); slots.connect(button_cancel->sig_clicked(), this, &CL_FileDialog_Generic::on_button_quit, false); slots.connect(button_parent->sig_clicked(), this, &CL_FileDialog_Generic::on_button_parent); slots.connect(button_createdir->sig_clicked(), this, &CL_FileDialog_Generic::on_button_createdir); slots.connect(input_file->sig_return_pressed(), this, &CL_FileDialog_Generic::on_edit_file); slots.connect(input_filter->sig_return_pressed(), this, &CL_FileDialog_Generic::on_edit_filter); slots.connect(input_dir->sig_return_pressed(), this, &CL_FileDialog_Generic::on_edit_dir); set_file(file, false); set_filter(filter, false); show_hidden = false; read_dir(); }
void TileMapPaintToolImpl::draw() { TilemapLayer tilemap = TilemapLayer::current(); if (tilemap.is_null()) return; switch(mode) { case TileMapPaintToolImpl::SELECTING: if (CL_Keyboard::get_keycode(CL_KEY_LSHIFT)) selection.draw(CL_Color(255, 128, 128, 100)); else selection.draw(); break; default: int tile_size = tilemap.get_tileset().get_tile_size(); // Draw the brush: for(int y = 0; y < brush.get_height(); ++y) for(int x = 0; x < brush.get_width(); ++x) { Tile* tile = tilemap.get_tileset().create(brush.at(x, y)); if (tile) { CL_Sprite sprite = tile->get_sprite(); sprite.set_alpha(0.5f); sprite.draw((current_tile.x + x) * tile_size, (current_tile.y + y) * tile_size); CL_Display::fill_rect(CL_Rect(CL_Point((current_tile.x + x) * tile_size, (current_tile.y + y) * tile_size), CL_Size(tile_size, tile_size)), CL_Color(255, 255, 255, 100)); } else if (brush.is_opaque()) { CL_Display::fill_rect(CL_Rect(CL_Point((current_tile.x + x) * tile_size, (current_tile.y + y) * tile_size), CL_Size(tile_size, tile_size)), CL_Color(255, 255, 255, 100)); } else { CL_Display::fill_rect(CL_Rect(CL_Point((current_tile.x + x) * tile_size, (current_tile.y + y) * tile_size), CL_Size(tile_size, tile_size)), CL_Color(255, 255, 255, 50)); } } break; } }
void WindowImpl::on_resize(int, int) { titlebar->set_position(CL_Rect(CL_Point(3+16,3), CL_Size(parent->get_width()-6-18-18-18, 12+3))); close->set_position(3, 3); minimize->set_position(parent->get_width()-3-18-18, 3); maximize->set_position(parent->get_width()-3-18, 3); CL_Rect rect = parent->get_position(); client_area->set_position(CL_Rect(CL_Point(4, 3+12+7), CL_Size(rect.get_width()-10, rect.get_height()-28))); }
void CL_Quad::rotate(const CL_Point &hotspot, float angle) { //Find the rotated positions of each corner CL_Point p1 = CL_Point(x1, y1).rotate(hotspot, angle); CL_Point p2 = CL_Point(x2, y2).rotate(hotspot, angle); CL_Point p3 = CL_Point(x3, y3).rotate(hotspot, angle); CL_Point p4 = CL_Point(x4, y4).rotate(hotspot, angle); x1 = p1.x; y1 = p1.y; x2 = p2.x; y2 = p2.y; x3 = p3.x; y3 = p3.y; x4 = p4.x; y4 = p4.y; }
//Nachbarpunkte in Form von CL_Point-Objekten berechnen map<string, CL_Point> HexMap::getNeighborPoints(CL_Point position) { int x = position.x; int y = position.y; int nextX = (x + 1) % mapWidth; map<string, CL_Point> neighborPoints = map<string, CL_Point>(); //Positionen berechnen neighborPoints.insert(createNeighborPointPair(CL_Point(x + 1, y))); neighborPoints.insert(createNeighborPointPair(CL_Point(x, y + 1))); neighborPoints.insert(createNeighborPointPair(CL_Point(x - 1, y))); neighborPoints.insert(createNeighborPointPair(CL_Point(x, y - 1))); if(x % 2 == 0) { neighborPoints.insert(createNeighborPointPair(CL_Point(x + 1, y - 1))); neighborPoints.insert(createNeighborPointPair(CL_Point(x - 1, y - 1))); } else { neighborPoints.insert(createNeighborPointPair(CL_Point(x + 1, y + 1))); neighborPoints.insert(createNeighborPointPair(CL_Point(x - 1, y + 1))); } return neighborPoints; }
void CL_ListView_Impl::update_scrollbar() { cancel_edit(); if (!layout) { return; } CL_Rect rect( rect_content.get_width()-scrollbar->get_preferred_width(), rect_content.top, rect_content.get_width(), rect_content.get_height()); scrollbar->set_geometry(rect); int total_height = layout->get_total_size().height; bool visible = total_height > rect_columns_content.get_height(); scrollbar->calculate_ranges(rect_columns_content.get_height(), total_height); scrollbar->set_line_step(layout->get_row_height()); scrollbar->set_visible(visible); if (visible == false) layout->set_scroll_offset(CL_Point(0, 0)); }
CL_Rect DrawingContext::get_clip_rect() { return CL_Rect(CL_Point(static_cast<int>(translate_stack.back().x), static_cast<int>(translate_stack.back().y)), CL_Size(800, 600)); }
void WindowImpl::draw() { CL_Display::push_translate (parent->get_screen_x(), parent->get_screen_y()); CL_Color highlight(255, 255, 255); CL_Color midtone(150, 150, 150); CL_Rect rect = parent->get_position() ; Box::draw_window(CL_Rect(CL_Point(0, 0), CL_Size(rect.get_width()-1, rect.get_height()-1))); Box::draw_panel_down(client_area->get_position()); /* CL_Display::fill_rect(CL_Rect(CL_Point(0, 0), rect.get_size()), CL_Color(220, 220, 220)); CL_Display::draw_rect(CL_Rect(CL_Point(0, 0), rect.get_size()), CL_Color(0, 0, 0)); CL_Display::draw_line(1, rect.get_height()-2, rect.get_width()-2, rect.get_height()-2, midtone); CL_Display::draw_line(rect.get_width()-2, 1, rect.get_width()-2, rect.get_height()-2, midtone); CL_Display::draw_line(1, 1, rect.get_width()-2, 1, highlight); CL_Display::draw_line(1, 1, 1, rect.get_height()-2, highlight); */ CL_Display::pop_modelview(); }
CL_Rectf ObjMapSpriteObjectImpl::get_bound_rect() const { CL_Point align = CL_Point(0, 0); CL_Origin origin_e; sprite.get_alignment(origin_e, align.x, align.y); CL_Point origin = calc_origin(origin_e, CL_Size(sprite.get_width(), sprite.get_height())); align.x = -align.x; // FIXME: This looks a bit hacky float scale_x, scale_y; sprite.get_scale(scale_x, scale_y); if (scale_x < 0) align.x += sprite.get_width(); if (scale_y < 0) align.y += sprite.get_height(); // if (scale_x > 1.0f && scale_y > 1.0f) // return CL_Rectf(pos - origin - align, // CL_Sizef(sprite.get_width() * scale_x, sprite.get_height() * scale_y)); // else return CL_Rectf(pos - origin - align, CL_Sizef(sprite.get_width(), sprite.get_height())); }
void CL_StatusBar_Impl::position_parts() { CL_Rect rect(CL_Point(0,0), statusbar->get_geometry().get_size()); CL_Rect content = part_component.get_content_box(rect); int xpos = content.right; if (show_size_grip) { int preferred_width = part_size_grip.get_preferred_width(); CL_Rect rect_sizegrip(content.right - preferred_width, content.top, content.right, content.bottom); xpos = rect_sizegrip.left; } for (unsigned int index = statusbar_parts.size(); index > 0; index--) { CL_StatusBar_Part &statusbar_part = statusbar_parts[index-1]; int left = xpos - statusbar_part.width; int right = xpos; CL_Rect new_position(left, content.top, right, content.bottom); if (statusbar_part.component && statusbar_part.position != new_position) statusbar_part.component->set_geometry(part_status_part.get_content_box(new_position)); statusbar_part.position = new_position; xpos = left; } }
TileMapPaintTool::TileMapPaintTool() : impl(new TileMapPaintToolImpl()) { impl->last_draw = CL_Point(-1, -1); current_ = *this; impl->brush = TileBrush(1, 1); impl->brush.at(0, 0) = 0; impl->brush.set_opaque(); impl->current_tile = CL_Point(0,0); impl->command = 0; impl->mode = TileMapPaintToolImpl::NONE; }
WorkspaceMoveTool::WorkspaceMoveTool() : impl(new WorkspaceMoveToolImpl()) { impl->scrolling = false; impl->click_pos = CL_Point(0, 0); impl->old_trans_offset = CL_Pointf(0,0); }
CL_Rect CL_ListViewLayoutIcons::get_icon_rect(const CL_Rect &cell_content_rect, CL_ListViewItem item, int offset_x) { int icon_x = cell_content_rect.get_center().x - size_icon.width/2; int icon_y = cell_content_rect.get_center().y - size_icon.height/2; CL_Rect rect_icon(CL_Point(icon_x, icon_y), size_icon); return rect_icon; }
void Slider::draw() { CL_Display::push_modelview(); CL_Display::add_translate(get_screen_x(), get_screen_y()); CL_Display::fill_rect(CL_Rect(CL_Point(0, get_height()/2 - 2), CL_Size(get_width(), 5)), CL_Color(255, 255, 255, 255)); CL_Display::fill_rect(CL_Rect(CL_Point(int(-2 + (value/(end-start)) * get_width()), 0), CL_Size(5, get_height())), CL_Color(0, 0, 0, 255)); CL_Display::pop_modelview(); }
void Shadow::onFieldCenter() { //Im Pursuit-Modus Pacman jagen und ansonsten zur rechten, oberen Ecke gehen if(pursuitMode) goToTargetField(world->getPacMan()->getCurrentField()); else goToTargetField(CL_Point(26, 1)); }
void CL_ListView_Impl::on_scroll() { cancel_edit(); layout->set_scroll_offset(CL_Point(0,scrollbar->get_position())); layout->invalidate(); listview->request_repaint(); }
CL_Point CL_Sprite::get_frame_offset(int frameno) const { const CL_Sprite_Impl::SpriteFrame *frame = impl->get_frame(frameno); if(frame) return frame->offset; else return CL_Point(0, 0); }
CL_Point CL_ListViewIcon::get_offset(CL_ListViewDisplayMode mode) { std::map<CL_ListViewDisplayMode, CL_Point>::iterator it; it = impl->offsets.find(mode); if (it != impl->offsets.end()) return impl->offsets[mode]; return CL_Point(0,0); }
std::vector<CL_Point> Map::getNeighbors(const CL_Point& position) const { std::vector<CL_Point> neighbors; if (position.x > 0) neighbors.push_back(CL_Point(position.x - 1, position.y)); if (position.x < size.width - 1) neighbors.push_back(CL_Point(position.x + 1, position.y)); if (position.y > 0) neighbors.push_back(CL_Point(position.x, position.y - 1)); if (position.y < size.height - 1) neighbors.push_back(CL_Point(position.x, position.y + 1)); return neighbors; }
void CL_SpanLayout_Impl::layout_float_block(CurrentLine ¤t_line, int max_width) { FloatBox floatbox; floatbox.type = objects[current_line.object_index].type; floatbox.image = objects[current_line.object_index].image; floatbox.component = objects[current_line.object_index].component; floatbox.id = objects[current_line.object_index].id; if (objects[current_line.object_index].type == object_image) floatbox.rect = CL_Rect(CL_Point(0, current_line.y_position), floatbox.image.get_size()); else if (objects[current_line.object_index].type == object_component) floatbox.rect = CL_Rect(CL_Point(0, current_line.y_position), floatbox.component->get_size()); if (objects[current_line.object_index].float_type == float_left) floats_left.push_back(float_box_left(floatbox, max_width)); else floats_right.push_back(float_box_right(floatbox, max_width)); reflow_line(current_line, max_width); }
CL_Point CL_GUIWindowManagerProvider_System::window_to_screen(CL_GUITopLevelWindow *handle, const CL_Point &window_point, bool client_area) const { std::map<CL_GUITopLevelWindow *, CL_GUITopLevelWindowSystem *>::const_iterator it = window_map.find(handle); if (it != window_map.end()) { if (client_area) { return it->second->window.client_to_screen(window_point); } else { CL_Rect geometry = it->second->window.get_geometry(); return CL_Point(geometry.left + window_point.x, geometry.top + window_point.y); } } else { return CL_Point(); } }
TileEditor::TileEditor(int x, int y, int w, int h, CL_Component* parent) : CL_Component(CL_Rect(CL_Rect(CL_Point(x, y), CL_Size(w, h))), // FIXME: make this editable via script parent) { tile = 0; slots.connect(sig_paint(), this, &TileEditor::draw); slots.connect(sig_mouse_move(), this, &TileEditor::mouse_move); slots.connect(sig_mouse_down(), this, &TileEditor::mouse_down); slots.connect(sig_mouse_up (), this, &TileEditor::mouse_up); }
ObjMapObject ObjectLayer::find_object(const CL_Pointf& click_pos) { for(Objects::reverse_iterator i = impl->objects.rbegin(); i != impl->objects.rend(); ++i) { CL_Rectf rect = (*i).get_bound_rect(); if (rect.is_inside(CL_Point(click_pos))) return *i; } return ObjMapObject(); }
CL_Point CL_GUILayoutProvider_Corners::get_point(CL_ComponentAnchorPoint ap, int dist_x, int dist_y) { if (ap == cl_anchor_top_left) { return CL_Point(dist_x, dist_y); } else if (ap == cl_anchor_top_right) { return CL_Point(rect.get_width()-dist_x, dist_y); } else if (ap == cl_anchor_bottom_left) { return CL_Point(dist_x, rect.get_height()-dist_y); } else if (ap == cl_anchor_bottom_right) { return CL_Point(rect.get_width()-dist_x, rect.get_height()-dist_y); } // ap == cl_anchor_relative return CL_Point(rect.get_width()*dist_x, rect.get_height()*dist_y); }
CL_TextureGroup_Impl::RootNode *CL_TextureGroup_Impl::add_new_root(CL_GraphicContext &context, const CL_Size &texture_size) { CL_Rect rect(CL_Point(0, 0), texture_size); Node node(rect); active_root = new RootNode(); active_root->texture = CL_Texture(context, texture_size); active_root->node = node; root_nodes.push_back(active_root); return active_root; }