Esempio n. 1
0
CL_GUIComponent_Impl *CL_GUIComponent_Impl::create_from_manager(CL_GUIManager *manager)
{
	if (manager)
		return new CL_GUIComponent_Impl(manager->impl, 0, true);
	else
		throw CL_Exception("Cannot create component with a null manager!");
}
CL_Resource CL_ResourceManager::get_resource(
	const CL_String &resource_id,
	bool resolve_alias,
	int reserved)
{
 	std::map<CL_String, CL_Resource>::const_iterator it;
	it = impl->resources.find(resource_id);
	if (it != impl->resources.end())
		return it->second;

	std::vector<CL_ResourceManager>::size_type i;
	for (i = 0; i < impl->additional_resources.size(); i++)
	{
		try
		{
			return impl->additional_resources[i].get_resource(
				resource_id, resolve_alias, reserved);
		}
		catch (const CL_Exception&)
		{
		}
	}

	throw CL_Exception(cl_format("Resource not found: %1", resource_id));
	return CL_Resource(impl->document.get_document_element(), *this);
}
Esempio n. 3
0
CL_GUIComponent_Impl *CL_GUIComponent_Impl::create_from_parent(CL_GUIComponent *parent)
{
	if (parent)
		return new CL_GUIComponent_Impl(parent->get_gui_manager().impl, parent, false);
	else
		throw CL_Exception("Cannot create child component with no parent!");
}
void CL_Collada_Triangles_Impl::create_vertices(CL_Vec2f *destination, int stride, const CL_String &semantic)
{
	CL_Collada_Input_Shared &input = get_input(semantic);

	CL_Collada_Source &source = input.get_source();
	if (source.is_null())
	{
		throw CL_Exception("unsupported situation. fixme");
	}

	std::vector<CL_Vec2f> &pos_array = source.get_vec2f_array();

	if (!stride)
		stride = sizeof(CL_Vec2f);

	char *work_ptr = (char *) destination;

	int primitive_stride = this->stride;
	unsigned int offset = input.get_offset();

	unsigned int max = offset + (triangle_count * 3 * primitive_stride);
	for (unsigned int cnt=offset; cnt < max; cnt+=primitive_stride)
	{
		*( (CL_Vec2f *) work_ptr ) = pos_array[ primitive[cnt] ];
		work_ptr += stride;
	}
}
CL_ListViewColumnHeader CL_ListViewHeader::remove(const CL_StringRef &column_id)
{
	CL_SharedPtr<CL_ListViewColumnHeader_Impl> cur = impl->first_column;
	while (cur)
	{
		if (cur->column_id == column_id)
		{
			CL_ListViewColumnHeader column(cur);
			if (!impl->func_column_removed.is_null())
				impl->func_column_removed.invoke(column);
			if (!cur->prev_sibling.expired())
				cur->prev_sibling.lock()->next_sibling = cur->next_sibling;
			if (cur->next_sibling)
				cur->next_sibling->prev_sibling = cur->prev_sibling;
			if (impl->first_column == cur)
				impl->first_column = cur->next_sibling;
			if (impl->last_column.lock() == cur)
				impl->last_column = cur->prev_sibling;

			return column;
		}
		cur = cur->next_sibling;
	}
	throw CL_Exception(cl_format("No column found with column id: %1", column_id));
}
bool CL_IODeviceProvider_File::seek(int position, CL_IODevice::SeekMode seek_mode)
{
	if (handle == invalid_handle)
		throw CL_Exception("CL_IODeviceProvider_File::seek(): Unable to get file position pointer, no file open");

#ifdef WIN32
	DWORD moveMethod = FILE_BEGIN;
	switch (seek_mode)
	{
	case CL_IODevice::seek_set: moveMethod = FILE_BEGIN; break;
	case CL_IODevice::seek_cur: moveMethod = FILE_CURRENT; break;
	case CL_IODevice::seek_end: moveMethod = FILE_END; break;
	}

	DWORD new_pos = SetFilePointer(handle, position, 0, moveMethod);
	return (new_pos != INVALID_FILE_SIZE);
#else
	int mode = SEEK_SET;
	if (seek_mode == CL_File::seek_set)
		mode = SEEK_SET;
	else if (seek_mode == CL_File::seek_cur)
		mode = SEEK_CUR;
	else if (seek_mode == CL_File::seek_end)
		mode = SEEK_END;
	
	off_t new_pos = lseek(handle, position, mode);
	if (new_pos == (off_t) -1)
		return false;
	else
		return true;
#endif
}
Esempio n. 7
0
CL_VirtualDirectoryListing CL_VirtualFileSystem::get_directory_listing(const CL_String &path_rel)
{
	CL_String path = CL_PathHelp::make_absolute(
		"/",
		path_rel,
		CL_PathHelp::path_type_virtual);

	// First see if its a mount point:
	int index, size;
	size = (int) impl->mounts.size();
	for (index = 0; index < size; index++)
	{
		if (impl->mounts[index].first == path.substr(0, impl->mounts[index].first.length()))
		{
			return impl->mounts[index].second.get_directory_listing( path.substr(impl->mounts[index].first.length(), path.length()));
		}
	}

	// Try open locally, if we got a file provider attached
	if (impl->provider)
	{
		return CL_VirtualDirectoryListing(
			impl->provider,
			CL_PathHelp::make_relative(
				"/",
				path,
				CL_PathHelp::path_type_virtual));		
	}
	else
		throw CL_Exception(cl_format("Unable to list directory: %1", path));

}
CL_ConsoleWindow_Generic::CL_ConsoleWindow_Generic(
	const CL_StringRef &title,
	int width,
	int height)
{
#ifdef WIN32
	AllocConsole();
	SetConsoleTitle(CL_StringHelp::utf8_to_ucs2(title).c_str());
	COORD coord;
	coord.X = width;
	coord.Y = height;
	scrbuf =
		CreateConsoleScreenBuffer(
			GENERIC_READ | GENERIC_WRITE,
			FILE_SHARE_READ | FILE_SHARE_WRITE,
			NULL,
			CONSOLE_TEXTMODE_BUFFER,
			NULL);

	if(scrbuf == INVALID_HANDLE_VALUE)
		throw CL_Exception("Unable to allocate console screen buffer");

	SetStdHandle(STD_OUTPUT_HANDLE, scrbuf);
	SetConsoleActiveScreenBuffer(scrbuf);
	SetConsoleScreenBufferSize(scrbuf, coord);

#endif
}
Esempio n. 9
0
void CL_Lib3dsFile::load(CL_IODevice device)
{
	CL_Lib3dsIo io(device);
	int result = lib3ds_file_read(file, io);
	if (!result)
		throw CL_Exception("Unable to load 3ds file");
}
Esempio n. 10
0
void CL_Lib3dsFile::save(CL_IODevice device)
{
	CL_Lib3dsIo io(device);
	int result = lib3ds_file_write(file, io);
	if (!result)
		throw CL_Exception("Unable to save 3ds file");
}
Esempio n. 11
0
CL_GUIComponent_Impl *CL_GUIComponent_Impl::create_from_owner(CL_GUIComponent *owner)
{
	if (owner)
		return new CL_GUIComponent_Impl(owner->get_gui_manager().impl, owner, true);
	else
		throw CL_Exception("Cannot create child component with a null owner!");
}
Esempio n. 12
0
CL_DomNode CL_DomNode::select_node(const CL_DomString &xpath_expression) const
{
	std::vector<CL_DomNode> nodes = select_nodes(xpath_expression);
	if (nodes.empty())
		throw CL_Exception(cl_format("Xpath did not match any node: %1", xpath_expression));
	return nodes[0];
}
Esempio n. 13
0
CL_Service_Impl::CL_Service_Impl(CL_Service *service, const CL_String &service_name)
: service_name(service_name), service(service)
{
	if (instance != 0)
		throw CL_Exception("More than one instance of CL_Service not allowed");
	instance = this;
}
Esempio n. 14
0
void CL_NetGameClient_Impl::process()
{
	CL_MutexSection mutex_lock(&mutex);
	event_arrived.reset();
	std::vector<CL_NetGameNetworkEvent> new_events;
	new_events.swap(events);
	mutex_lock.unlock();
	for (unsigned int i = 0; i < new_events.size(); i++)
	{
		switch (new_events[i].type)
		{
		case CL_NetGameNetworkEvent::client_connected:
			sig_game_connected.invoke();
			break;
		case CL_NetGameNetworkEvent::event_received:
			sig_game_event_received.invoke(new_events[i].game_event);
			break;
		case CL_NetGameNetworkEvent::client_disconnected:
			sig_game_disconnected.invoke();
			connection.reset();
			break;
		default:
			throw CL_Exception("Unknown server event type");
		}
	}
}
void CL_RegistryKey::set_value_int(const CL_StringRef &name, int value)
{
	DWORD v = value;
	LONG result = RegSetValueEx(impl->key, name.empty() ? 0 : CL_StringHelp::utf8_to_ucs2(name).c_str(), 0, REG_DWORD, (const BYTE *) &v, sizeof(DWORD));
	if (result != ERROR_SUCCESS)
		throw CL_Exception(cl_format("Unable to set registry key value %1", name));
}
Esempio n. 16
0
int App::start(const std::vector<CL_String> &args)
{
	CL_String theme;
	if (CL_FileHelp::file_exists("../../../Resources/GUIThemeAero/theme.css"))
		theme = "../../../Resources/GUIThemeAero";
	else if (CL_FileHelp::file_exists("../../../Resources/GUIThemeBasic/theme.css"))
		theme = "../../../Resources/GUIThemeBasic";
	else
		throw CL_Exception("Not themes found");

	CL_GUIManager gui(theme);

	CL_DisplayWindowDescription win_desc;
	win_desc.set_allow_resize(true);
	win_desc.set_title("GUILayout Test Application");
	win_desc.set_position(CL_Rect(200, 200, 540, 440), false);
	win_desc.set_visible(false);
	CL_Window window(&gui, win_desc);
	window.func_close().set(this, &App::on_close, &window);

	CL_GUILayoutCorners layout;
	window.set_layout(layout);

	window.create_components("Resources/layout.xml");

	CL_PushButton *button = CL_PushButton::get_named_item(&window, "MyButton");
	button->func_clicked().set(this, &App::on_button_clicked, button);

	label = CL_Label::get_named_item(&window, "MyLabel");

	window.set_visible(true);

	gui.exec();
	return 0;
}
CL_RegistryKey CL_RegistryKey::create_key(const CL_StringRef &subkey, unsigned int access_rights, CreateFlags create_flags)
{
	DWORD disposition = 0;
	HKEY new_key = 0;
	LONG result = RegCreateKeyEx(impl->key, CL_StringHelp::utf8_to_ucs2(subkey).c_str(), 0, 0, (create_flags & create_volatile) ? REG_OPTION_VOLATILE : REG_OPTION_NON_VOLATILE, access_rights, 0, &new_key, &disposition);
	if (result != ERROR_SUCCESS)
		throw CL_Exception(cl_format("Unable to create registry key %1", subkey));

	if (disposition != REG_CREATED_NEW_KEY && (create_flags & create_new))
	{
		RegCloseKey(new_key);
		throw CL_Exception(cl_format("Key already exists: %1", subkey));
	}

	return CL_RegistryKey(new_key);
}
void CL_RegistryKey::delete_key(PredefinedKey key, const CL_StringRef &subkey, bool recursive)
{
	HKEY hkey = CL_RegistryKey_Impl::get_predefined_hkey(key);
	if (recursive)
	{
		DWORD result = SHDeleteKey(hkey, CL_StringHelp::utf8_to_ucs2(subkey).c_str());
		if (result != ERROR_SUCCESS)
			throw CL_Exception(cl_format("Unable to delete registry key %1", subkey));
	}
	else
	{
		LONG result = RegDeleteKey(hkey, CL_StringHelp::utf8_to_ucs2(subkey).c_str());
		if (result != ERROR_SUCCESS)
			throw CL_Exception(cl_format("Unable to delete registry key %1", subkey));
	}
}
CL_CSSBoxLength CL_CSSResourceCache::compute_length(const CL_CSSBoxLength &length, float em_size, float ex_size)
{
	float dpi = 96.0f;
	float px_size = 1.0f;
/*
	if (is_printer)
	{
		if (printer.dpi == 300)
		{
			dpi = 300.0f;
			px_size = 3.0f;
		}
		else if (printer.dpi == 600)
		{
			dpi = 600.0f;
			px_size = 5.0f;
		}
		else
		{
			dpi = printer.dpi;
			px_size = (float)(int)(0.20f * dpi / 25.4f + 0.5f); // Find the closest pixel size matching 0.20mm
		}
	}
*/
	CL_CSSBoxLength new_length;
	new_length.type = CL_CSSBoxLength::type_computed_px;
	switch (length.type)
	{
	case CL_CSSBoxLength::type_computed_px:
		new_length.value = length.value;
		break;
	case CL_CSSBoxLength::type_mm:
		new_length.value = length.value * dpi / 25.4f;
		break;
	case CL_CSSBoxLength::type_cm:
		new_length.value = length.value * dpi / 2.54f;
		break;
	case CL_CSSBoxLength::type_in:
		new_length.value = length.value * dpi;
		break;
	case CL_CSSBoxLength::type_pt:
		new_length.value = length.value * dpi / 72.0f;
		break;
	case CL_CSSBoxLength::type_pc:
		new_length.value = length.value * dpi * 12.0f / 72.0f;
		break;
	case CL_CSSBoxLength::type_em:
		new_length.value = length.value * em_size;
		break;
	case CL_CSSBoxLength::type_ex:
		new_length.value = length.value * ex_size;
		break;
	case CL_CSSBoxLength::type_px:
		new_length.value = length.value * px_size;
		break;
	default:
		throw CL_Exception("Unknown css length dimension!");
	}
	return new_length;
}
Esempio n. 20
0
void Model_Impl::Draw(CL_GraphicContext &gc, GraphicStore *gs, const CL_Mat4f &modelview_matrix)
{
	gc.set_modelview(modelview_matrix);

	CL_PrimitivesArray prim_array(gc);

	prim_array.set_attributes(0, vbo_positions, 3, cl_type_float, (void *) 0);
	prim_array.set_attributes(1, vbo_normals, 3, cl_type_float, (void *) 0);

	if (!vbo_texcoords.is_null())
	{
		prim_array.set_attributes(2, vbo_texcoords, 2, cl_type_float, (void *) 0);
		gc.set_texture(0, gs->texture_underwater);
		gc.set_texture(1, gs->texture_background);
		gs->shader_texture.SetMaterial(material_shininess, material_emission, material_ambient, material_specular);
		gs->shader_texture.Use(gc);
	}
	else
	{
		throw CL_Exception("What! no texure coordinates?");
	}

	gc.draw_primitives(cl_triangles, vbo_size, prim_array);

	gc.reset_texture(0);
	gc.reset_texture(0);

}
Esempio n. 21
0
int Model_Impl::count_vertices(const struct aiScene* sc, const struct aiNode* nd)
{
	int vertex_count = 0;
	unsigned int n = 0, t;

	// All meshes assigned to this node
	for (; n < nd->mNumMeshes; ++n)
	{
		const struct aiMesh* mesh = sc->mMeshes[nd->mMeshes[n]];
		int num_vertex = mesh->mNumFaces * 3;
		if (!num_vertex)
			continue;

		vertex_count += num_vertex;
		for (t = 0; t < mesh->mNumFaces; ++t)
		{
			if (mesh->mFaces[t].mNumIndices != 3)
					throw CL_Exception("This example only supports triangles");
		}
	}

	// All children
	for (n = 0; n < nd->mNumChildren; ++n)
	{
		vertex_count += count_vertices(sc, nd->mChildren[n]);
	}

	return vertex_count;
}
Esempio n. 22
0
int CL_PgsqlReaderProvider::get_name_index(const CL_StringRef &name) const
{
	int index = PQfnumber(result, name.c_str());
	if (index < 0)
		throw CL_Exception(cl_format("No such column name %1", name));
	return index;
}
Esempio n. 23
0
void LoginEvents::on_event_login_failed(const CL_NetGameEvent &e)
{
	CL_String fail_reason = e.get_argument(0);

	// TODO: Handle failed login more gracefully
	throw CL_Exception("Login failed: " + fail_reason);
}
Esempio n. 24
0
TileMap::TileMap(CL_GraphicContext& gc, CL_ResourceManager& resmgr, const CL_String& tileset)
: map_width(0), map_height(0), cur_map_x(0), cur_map_y(0) {
    CL_Resource res = resmgr.get_resource(tileset);

    if (res.get_type() != "tilemap")
        throw CL_Exception(cl_format("Resource %1 is not a tilemap", tileset));

    CL_DomElement element = res.get_element();
    levelname = element.get_attribute("name");
    CL_String resource_name = element.get_attribute("resource");
    map_width = element.get_attribute_int("width");
    map_height = element.get_attribute_int("height");

    tiles = CL_Sprite(gc, resource_name, &resmgr);
    float scalex, scaley;
    tiles.get_scale(scalex, scaley);
    tile_width = tiles.get_width() * scalex;
    tile_height = tiles.get_height() * scaley;

    auto layer_nodes = element.select_nodes("layer");
    for (CL_DomNode& idx : layer_nodes) {
        CL_DomElement layer_element = idx.to_element();

        CL_String layer_tiles = layer_element.get_first_child().get_node_value();
        std::vector<CL_String> tile_indices = CL_StringHelp::split_text(layer_tiles, ",");

        MapLayer layer;
        layer.map.reserve(tile_indices.size());
        for (auto& tile : tile_indices)
            layer.map.push_back(CL_StringHelp::text_to_int(tile));

        layers.push_back(layer);
    }
}
Esempio n. 25
0
void CL_Thread::start(CL_Runnable *runnable)
{
	if (runnable == 0)
		throw CL_Exception("Invalid runnable pointer");

	impl->start(runnable);
}
Esempio n. 26
0
CL_RegistryKey CL_RegistryKey::open_key(const CL_StringRef &subkey, unsigned int access_rights)
{
	HKEY new_key = 0;
	LONG result = RegOpenKeyEx(impl->key, CL_StringHelp::utf8_to_ucs2(subkey).c_str(), 0, access_rights, &new_key);
	if (result != ERROR_SUCCESS)
		throw CL_Exception(cl_format("Unable to open registry key %1", subkey));
	return CL_RegistryKey(new_key);
}
Esempio n. 27
0
CL_RegistryKey::CL_RegistryKey(PredefinedKey key, const CL_StringRef &subkey, unsigned int access_rights, unsigned int create_flags)
{
	HKEY hkey = CL_RegistryKey_Impl::get_predefined_hkey(key);
	DWORD disposition = 0;
	HKEY new_key = 0;
	LONG result = RegCreateKeyEx(hkey, CL_StringHelp::utf8_to_ucs2(subkey).c_str(), 0, 0, (create_flags & create_volatile) ? REG_OPTION_VOLATILE : REG_OPTION_NON_VOLATILE, access_rights, 0, &new_key, &disposition);
	if (result != ERROR_SUCCESS)
		throw CL_Exception(cl_format("Unable to create registry key %1", subkey));

	if (disposition != REG_CREATED_NEW_KEY && (create_flags & create_new))
	{
		RegCloseKey(new_key);
		throw CL_Exception(cl_format("Key already exists: %1", subkey));
	}

	impl = CL_SharedPtr<CL_RegistryKey_Impl>(new CL_RegistryKey_Impl(new_key));
}
CL_GL1CreationHelper::CL_GL1CreationHelper(HWND window, HDC hdc)
: window(window), hdc(hdc), query_window(0), query_dc(0), query_context(0)
{
	WINDOWINFO window_info;
	memset(&window_info, 0, sizeof(WINDOWINFO));
	window_info.cbSize = sizeof(WINDOWINFO);
	GetWindowInfo(window, &window_info);

	query_window = CreateWindowEx(
		0,
		WC_STATIC,
		TEXT(""),
		WS_CHILD,
		window_info.rcWindow.left,
		window_info.rcWindow.top,
		window_info.rcWindow.right - window_info.rcWindow.left,
		window_info.rcWindow.bottom - window_info.rcWindow.top,
		window, 0, GetModuleHandle(0), 0);
	if (query_window == 0)
		throw CL_Exception("Unable to create OpenGL creation query window");
	query_dc = GetDC(query_window);
	if (query_dc == 0)
	{
		DestroyWindow(query_window);
		throw CL_Exception("Unable to retrieve OpenGL creation query device context");
	}

	PIXELFORMATDESCRIPTOR pfd;
	memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
	pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
	pfd.nVersion = 1;
	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
	pfd.iPixelType = PFD_TYPE_RGBA;
	pfd.cColorBits = 24;

	int pixelformat = ChoosePixelFormat(query_dc, &pfd);
	SetPixelFormat(query_dc, pixelformat, &pfd);

	query_context = wglCreateContext(query_dc);
	if (query_context == 0)
	{
		DeleteDC(query_dc);
		DestroyWindow(query_window);
		throw CL_Exception("Unable to create OpenGL context for creation query window");
	}
}
CL_InputContext& CL_GUIWindowManagerProvider_System::get_ic(CL_GUITopLevelWindow *handle) const
{
	std::map<CL_GUITopLevelWindow *, CL_GUITopLevelWindowSystem *>::const_iterator it = window_map.find(handle);
	if (it == window_map.end())
		throw CL_Exception("Cannot find window handle");

	return it->second->window.get_ic();
}
Esempio n. 30
0
void WorkerGC::Start(const CL_StringRef &name)
{
	if (worker_thread_processing)
		throw CL_Exception("You forgot to get the result");
	worker_thread_processing = true;
	sprite_name = name;
	event_start.set();
}