/** Create an icon from the specified file. */ IconNode *CreateIconFromFile(const char *fileName, char save, char preserveAspect) { ImageNode *image; IconNode *result; if(!fileName) { return NULL; } /* Check if this icon has already been loaded */ result = FindIcon(fileName); if(result) { return result; } image = LoadImage(fileName); if(image) { result = CreateIcon(); result->preserveAspect = preserveAspect; result->images = image; if(save) { result->name = CopyString(fileName); InsertIcon(result); } return result; } else { return NULL; } }
/** Create an icon from XPM image data. */ IconNode *CreateIconFromData(const char *name, char **data) { ImageNode *image; IconNode *result; Assert(name); Assert(data); /* Check if this icon has already been loaded */ result = FindIcon(name); if(result) { return result; } image = LoadImageFromData(data); if(image) { result = CreateIcon(); result->name = CopyString(name); result->images = image; InsertIcon(result); return result; } else { return NULL; } }
/** Create an icon from XPM image data. */ IconNode *GetDefaultIcon(void) { static const char * const name = "default"; const unsigned width = 8; const unsigned height = 8; const unsigned border = 1; ImageNode *image; IconNode *result; unsigned bytes; unsigned x, y; /* Check if this icon has already been loaded */ result = FindIcon(name); if(result) { return result; } /* Allocate image data. */ bytes = (width * height + 7) / 8; image = CreateImage(width, height, 1); memset(image->data, 0, bytes); #ifdef USE_XRENDER image->render = 0; #endif /* Allocate the icon node. */ result = CreateIcon(image); result->name = CopyString(name); result->images = image; InsertIcon(result); /* Draw the icon. */ for(y = border; y < height - border; y++) { const unsigned pixel_left = y * width + border; const unsigned pixel_right = y * width + width - 1 - border; const unsigned offset_left = pixel_left / 8; const unsigned mask_left = 1 << (pixel_left % 8); const unsigned offset_right = pixel_right / 8; const unsigned mask_right = 1 << (pixel_right % 8); image->data[offset_left] |= mask_left; image->data[offset_right] |= mask_right; } for(x = border; x < width - border; x++) { const unsigned pixel_top = x + border * width; const unsigned pixel_bottom = x + width * (height - 1 - border); const unsigned offset_top = pixel_top / 8; const unsigned mask_top = 1 << (pixel_top % 8); const unsigned offset_bottom = pixel_bottom / 8; const unsigned mask_bottom = 1 << (pixel_bottom % 8); image->data[offset_top] |= mask_top; image->data[offset_bottom] |= mask_bottom; } return result; }
/// <summary> /// Add's the icon with the specified ID to the view /// </summary> void TileGroup::AddIcon(PCITEMID_CHILD pidl) { // Don't add existing icons if (FindIcon(pidl) != nullptr) return; // Check if the icon should be supressed WCHAR buffer[MAX_PATH]; GetDisplayNameOf(pidl, SHGDN_FORPARSING, buffer, _countof(buffer)); if (mHiddenItems.find(buffer) != mHiddenItems.end()) return; LoadItemRequest request; request.folder = mWorkingFolder; request.targetIconWidth = mTileSettings.mIconSize; request.id = ILClone(pidl); nCore::LoadFolderItem(request, this); }
/** Load an icon from a file. */ IconNode *LoadNamedIcon(const char *name, char save, char preserveAspect) { IconNode *icon; IconPathNode *ip; Assert(name); /* If no icon is specified, return an empty icon. */ if(name[0] == 0) { return &emptyIcon; } /* See if this icon has already been loaded. */ icon = FindIcon(name); if(icon) { return icon; } /* Check for an absolute file name. */ if(name[0] == '/') { ImageNode *image = LoadImage(name, 0, 0, 1); if(image) { icon = CreateIcon(image); icon->preserveAspect = preserveAspect; icon->name = CopyString(name); if(save) { InsertIcon(icon); } DestroyImage(image); return icon; } else { return &emptyIcon; } } /* Try icon paths. */ for(ip = iconPaths; ip; ip = ip->next) { icon = LoadNamedIconHelper(name, ip->path, save, preserveAspect); if(icon) { return icon; } } /* The default icon. */ return NULL; }
IconNode *LoadSuffixedIcon(const char *path, const char *name, const char *suffix) { IconNode *result; ImageNode *image; char *iconName; unsigned int len; Assert(path); Assert(name); Assert(suffix); len = strlen(name) + strlen(path) + strlen(suffix); iconName = Allocate(len + 1); strcpy(iconName, path); strcat(iconName, name); strcat(iconName, suffix); result = FindIcon(iconName); if(result) { Release(iconName); return result; } image = LoadImage(iconName); if(image) { result = CreateIcon(); result->name = iconName; result->images = image; InsertIcon(result); return result; } else { Release(iconName); return NULL; } }
/// <summary> /// /// </summary> void TileGroup::RenameIcon(PCITEMID_CHILD oldID, PCITEMID_CHILD newID) { auto icon = FindIcon(oldID); if (icon != nullptr) { icon->Rename(newID); } }
/// <summary> /// /// </summary> void TileGroup::UpdateIcon(PCITEMID_CHILD pidl) { auto icon = FindIcon(pidl); if (icon != nullptr) { icon->UpdateIcon(); } }
void BitmapView::MouseDown( BPoint cPosition ) { MakeFocus( true ); Icon* pcIcon = FindIcon( cPosition ); if ( pcIcon != NULL ) { if ( pcIcon->m_bSelected ) { if ( m_nHitTime + 500000 >= system_time() ) { if ( pcIcon->GetName() == "Root (List)" ) { BWindow* pcWindow = new DirWindow( BRect( 200, 150, 600, 400 ), "/" ); pcWindow->Activate(); } else if ( pcIcon->GetName() == "Root (Icon)" ) { BWindow* pcWindow = new DirIconWindow( BRect( 20, 20, 359, 220 ), "/", g_pcBackDrop ); pcWindow->Activate(); } else if ( pcIcon->GetName() == "Terminal" ) { pid_t nPid = fork(); if ( nPid == 0 ) { set_thread_priority( -1, 0 ); execlp( "cterm", "cterm", NULL ); exit( 1 ); } } else if ( pcIcon->GetName() == "Prefs" ) { pid_t nPid = fork(); if ( nPid == 0 ) { set_thread_priority( -1, 0 ); execlp( "guiprefs", "guiprefs", NULL ); exit( 1 ); } } else if ( pcIcon->GetName() == "Pulse" ) { pid_t nPid = fork(); if ( nPid == 0 ) { set_thread_priority( -1, 0 ); execlp( "pulse", "pulse", NULL ); exit( 1 ); } } else if ( pcIcon->GetName() == "Calculator" ) { pid_t nPid = fork(); if ( nPid == 0 ) { set_thread_priority( -1, 0 ); execlp( "calc", "calc", NULL ); exit( 1 ); } } else if ( pcIcon->GetName() == "Editor" ) { pid_t nPid = fork(); if ( nPid == 0 ) { set_thread_priority( -1, 0 ); execlp( "aedit", "aedit", NULL ); exit( 1 ); } } else if ( pcIcon->GetName() == "Guido" ) { pid_t nPid = fork(); if ( nPid == 0 ) { set_thread_priority( -1, 0 ); execlp( "guido", "guido", NULL ); exit( 1 ); } } } else { m_bCanDrag = true; } m_nHitTime = system_time(); return; } } for ( uint i = 0 ; i < m_cIcons.size() ; ++i ) { m_cIcons[i]->Select( this, false ); } if ( pcIcon != NULL ) { m_bCanDrag = true; pcIcon->Select( this, true ); } else { m_bSelRectActive = true; m_cSelRect = BRect( cPosition.x, cPosition.y, cPosition.x, cPosition.y ); SetDrawingMode( B_OP_INVERT ); DrawFrame( m_cSelRect, FRAME_TRANSPARENT | FRAME_THIN ); } Flush(); m_cLastPos = cPosition; m_nHitTime = system_time(); }