bool cursor_t::load(std::string cursorPath) { // Open config file std::ifstream in(cursorPath + "/cursor.cfg"); if (!in.good()) { return false; } g_property_file_parser props(in); auto content = props.getProperties(); // Read required params std::string name = content["name"]; std::string hitpoint_x = content["hitpoint.x"]; std::string hitpoint_y = content["hitpoint.y"]; std::string image = content["image"]; if (name.empty() || hitpoint_x.empty() || hitpoint_y.empty() || image.empty()) { return false; } // Convert hitpoint std::stringstream stx; stx << hitpoint_x; int hitpointX; stx >> hitpointX; std::stringstream sty; sty << hitpoint_y; int hitpointY; sty >> hitpointY; std::string cursorImagePath = (cursorPath + "/" + image); // check if file exists FILE* cursorImageFile = fopen(cursorImagePath.c_str(), "r"); if (cursorImageFile == NULL) { return false; } fclose(cursorImageFile); // load cursor cursor_configuration pack; pack.surface = cairo_image_surface_create_from_png(cursorImagePath.c_str()); if (pack.surface == nullptr) { klog("failed to load cursor image at '%s' for configuration '%s'", cursorImagePath.c_str(), cursorPath.c_str()); return false; } pack.hitpoint = g_point(hitpointX, hitpointY); pack.size = g_dimension(cairo_image_surface_get_width(pack.surface), cairo_image_surface_get_height(pack.surface)); cursorConfigurations[name] = pack; return true; }
bool cursor_t::load(std::string cursorPath) { // Open config file std::ifstream in(cursorPath + "/cursor.cfg"); if (!in.good()) { return false; } g_property_file_parser props(in); auto content = props.getProperties(); // Read required params std::string name = content["name"]; std::string hitpoint_x = content["hitpoint.x"]; std::string hitpoint_y = content["hitpoint.y"]; std::string image = content["image"]; if (name.empty() || hitpoint_x.empty() || hitpoint_y.empty() || image.empty()) { return false; } // Convert hitpoint std::stringstream stx; stx << hitpoint_x; int hitpointX; stx >> hitpointX; std::stringstream sty; sty << hitpoint_y; int hitpointY; sty >> hitpointY; FILE* cursorImageFile = fopen((cursorPath + "/" + image).c_str(), "r"); if (cursorImageFile != NULL) { g_ghost_image_format ghostFormat; g_image cursorImage; g_image_load_status loadStatus = cursorImage.load(cursorImageFile, &ghostFormat); cursor_configuration pack; pack.image = cursorImage; pack.hitpoint = g_point(hitpointX, hitpointY); cursorConfigurations[name] = pack; g_logger::log("created cursor '" + name + "' with hitpoint %i/%i and image %x", hitpointX, hitpointY, cursorImage.getContent()); fclose(cursorImageFile); return loadStatus == g_image_load_status::SUCCESSFUL; } return false; }
g_point getEnd() const { return g_point(x + width, y + height); }
g_point getStart() const { return g_point(x, y); }
g_point operator+(const g_dimension& p) const { return g_point(width + p.width, height + p.height); }
g_point operator-(const g_dimension& p) const { return g_point(width - p.width, height - p.height); }