21 #include "C4Version.h"
27 #define _WIN32_IE 0x0400
31 #ifndef CSIDL_MYPICTURES
32 #define CSIDL_MYPICTURES 0x0027
39 #define USE_BACKGROUND_THREAD_LOAD 0
56 :
C4FileSelDlg::
ListItem(szFilename), pLbl(nullptr), pCheck(nullptr), pKeyCheck(nullptr), fGrayed(fGrayed)
59 if (szFilename && fTruncateExtension)
64 sLabel.
Take(szFilename);
86 if (pKeyCheck)
delete pKeyCheck;
95 pLbl->SetBounds(caMain.
GetAll());
100 return pCheck ? pCheck->GetChecked() :
false;
106 if (pCheck) pCheck->SetChecked(fChecked);
112 if (pCheck && !IsGrayed())
114 pCheck->ToggleCheck(
true);
128 pLocationComboBox(nullptr), pFileListBox(nullptr), pSelectionInfoBox(nullptr), btnOK(nullptr), pLocations(nullptr), iLocationCount(0), pSelection(nullptr), pSelCallback(pSelCallback)
130 sTitle.
Copy(szTitle);
137 sPath.
Copy(szRootPath);
159 pLocationComboBox->
SetText(pLocations[0].sName.getData());
176 if (pLocationComboBox)
AddElement(pLocationComboBox);
178 if (pSelectionInfoBox)
AddElement(pSelectionInfoBox);
189 delete [] pLocations;
190 if (pSelCallback)
delete pSelCallback;
191 delete pKeyEnterOverride;
198 for (int32_t i=0; i<iLocationCount; ++i)
199 pFiller->
AddEntry(pLocations[i].sName.getData(), i);
211 sPath.
Copy(szNewPath);
212 if (fRefresh &&
IsShown()) UpdateFileList();
224 if (!
fOK || pSelection)
237 if (
fOK && pSelection && pSelCallback)
264 void C4FileSelDlg::UpdateFileList()
269 while ((pEl = pFileListBox->
GetFirst()))
delete pEl;
284 const char *szPath = sPath.
getData();
297 if (pSelectionInfoBox)
301 if (!pSelection) { pSelectionInfoBox->
UpdateHeight();
return; }
313 const char *szFileItemFilename = pFileItem->GetFilename();
314 if (fFilenameOnly) szFileItemFilename =
GetFilename(szFileItemFilename);
315 pFileItem->SetChecked(
SIsModule(szNewSelection, szFileItemFilename));
330 if (szFixedSelection) sResult.
Append(szFixedSelection);
333 if (pFileItem->IsChecked())
335 const char *szAppendFilename = pFileItem->GetFilename();
336 if (fFilenameOnly) szAppendFilename =
GetFilename(szAppendFilename);
341 sResult.
Append(szAppendFilename);
351 int32_t iNewLocCount = iLocationCount+1;
352 Location *pNewLocations =
new Location[iNewLocCount];
353 for (int32_t i=0; i<iLocationCount; ++i) pNewLocations[i] = pLocations[i];
354 pNewLocations[iLocationCount].sName.Copy(szName);
355 pNewLocations[iLocationCount].sPath.Copy(szPath);
356 delete [] pLocations; pLocations = pNewLocations; iLocationCount = iNewLocCount;
358 if (iLocationCount == 1)
SetPath(szPath,
false);
365 if (!szPath || !*szPath)
return;
368 for (int32_t i=0; i<iLocationCount; ++i)
377 return iCurrentLocationIndex;
383 if (!Inside<int32_t>(idx, 0,iLocationCount))
return;
385 iCurrentLocationIndex = idx;
386 if (pLocationComboBox) pLocationComboBox->
SetText(pLocations[idx].sName.getData());
407 if (szFixedSelection) sFixedSelection.
Copy(szFixedSelection);
421 if (!sFixedSelection)
return false;
443 C4PortraitSelDlg::ListItem::ListItem(
const char *szFilename) :
C4FileSelDlg::ListItem(szFilename)
444 , fError(false), fLoaded(false)
459 int32_t iLineHgt = std::max<int32_t>(pUseFont->
BreakMessage(sDisplayLabel.
getData(), ImagePreviewSize-6, &sFilenameLabelText,
false), 1);
464 void C4PortraitSelDlg::ListItem::Load()
474 bool fLoadError =
true;
487 void C4PortraitSelDlg::ListItem::DrawElement(
C4TargetFacet &cgo)
493 if (!fctImage.CopyFromSfcMaxSize(fctLoadedImage.GetFace(), ImagePreviewSize))
495 fctLoadedImage.GetFace().Clear();
496 fctLoadedImage.Clear();
501 if (fError || !sFilename)
504 fctNoneImg.
Draw(cgoPicture.Surface, cgoPicture.X+(cgoPicture.Wdt-fctNoneImg.
Wdt)/2, cgoPicture.Y+(cgoPicture.Hgt-fctNoneImg.
Hgt)/2, 1,0);
508 if (!fctImage.Surface)
515 fctImage.Draw(cgoPicture);
526 void C4PortraitSelDlg::LoaderThread::ClearLoadItems()
534 void C4PortraitSelDlg::LoaderThread::AddLoadItem(ListItem *pItem)
537 assert(!IsStarted());
538 LoadItems.push_back(pItem);
541 void C4PortraitSelDlg::LoaderThread::Execute()
544 if (!LoadItems.size())
551 ListItem *pLoadItem = LoadItems.front();
553 LoadItems.erase(LoadItems.begin());
566 strLocation.
Format(
"%s %s", C4ENGINECAPTION,
LoadResStr(
"IDS_TEXT_USERPATH"));
569 strLocation.
Format(
"%s %s", C4ENGINECAPTION,
LoadResStr(
"IDS_TEXT_PROGRAMDIRECTORY"));
572 wchar_t wpath[MAX_PATH+1];
603 ListItem *pNew =
new ListItem(szFilename);;
605 ImageLoader.AddLoadItem(pNew);
612 ImageLoader.ClearLoadItems();
617 #if USE_BACKGROUND_THREAD_LOAD
625 #if !USE_BACKGROUND_THREAD_LOAD
627 static int32_t i = 0;
628 if (!(i++%10)) ImageLoader.Execute();
C4GraphicsResource GraphicsResource
#define C4GUI_StatusFontClr
#define C4GUI_CheckboxFontClr
#define C4GUI_ButtonAreaHgt
#define C4GUI_CheckboxDisabledFontClr
#define C4GUI_DefDlgIndent
#define C4GUI_DefButton2Wdt
#define C4GUI_DefDlgSmallIndent
#define C4GUI_MessageFontClr
#define C4GUI_DefButton2HSpace
const char * LoadResStr(const char *id)
bool SIsModule(const char *szList, const char *szString, int *ipIndex, bool fCaseSensitive)
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
T Clamp(T bval, T lbound, T rbound)
StdStrBuf FormatString(const char *szFmt,...)
bool DirectoryExists(const char *szFilename)
bool GetParentPath(const char *szFilename, char *szBuffer)
bool ItemIdentical(const char *szFilename1, const char *szFilename2)
char * GetFilename(char *szPath)
bool WildcardListMatch(const char *szWildcardList, const char *szString)
void RemoveExtension(char *szFilename)
void TruncateBackslash(char *szFilename)
char SystemDataPath[CFG_MaxString+1]
char UserDataPath[CFG_MaxString+1]
int32_t LastPortraitFolderIdx
bool IsItemGrayed(const char *szFilename) const override
C4DefinitionSelDlg(C4FileSel_BaseCB *pSelCallback, const char *szFixedSelection)
static bool SelectDefinitions(C4GUI::Screen *pOnScreen, StdStrBuf *pSelection)
bool TextOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
void Draw(C4Facet &cgo, bool fAspect=true, int32_t iPhaseX=0, int32_t iPhaseY=0, bool fTransparent=true)
virtual void OnFileSelected(const char *szFilename)=0
void SetChecked(bool fChecked) override
DefaultListItem(const char *szFilename, bool fTruncateExtension, bool fCheckbox, bool fGrayed, C4GUI::Icons eIcon)
void UpdateOwnPos() override
bool UserToggleCheck() override
bool IsChecked() const override
~DefaultListItem() override
const char * GetFilename()
virtual bool UserToggleCheck()
ListItem(const char *szFilename)
void AddCheckedLocation(const char *szName, const char *szPath)
void OnLocationComboFill(C4GUI::ComboBox_FillCB *pFiller)
virtual int32_t GetFileSelColWidth() const
void SetCurrentLocation(int32_t idx, bool fRefresh)
bool OnLocationComboSelChange(C4GUI::ComboBox *pForCombo, int32_t idNewSelection)
void OnSelChange(class C4GUI::Element *pEl)
virtual const char * GetFileMask() const
virtual C4GUI::Icons GetFileItemIcon() const
virtual void BeginFileListUpdate()
virtual bool IsMultiSelection() const
virtual bool IsItemGrayed(const char *szFilename) const
virtual bool HasPreviewArea() const
void SetPath(const char *szNewPath, bool fRefresh=true)
virtual void AddExtraOptions(const C4Rect &rcOptionsRect)
StdStrBuf GetSelection(const char *szFixedSelection, bool fFilenameOnly) const
void AddLocation(const char *szName, const char *szPath)
virtual void EndFileListUpdate()
void UserClose(bool fOK) override
virtual ListItem * CreateListItem(const char *szFilename)
int32_t GetCurrentLocationIndex() const
virtual bool HasNoneItem() const
void SetSelection(const char *szNewSelection, bool fFilenameOnly)
void OnClosed(bool fOK) override
C4FileSelDlg(const char *szRootPath, const char *szTitle, C4FileSel_BaseCB *pSelCallback, bool fInitElements=true)
void OnSelDblClick(class C4GUI::Element *pEl)
virtual void UpdateSelection()
virtual bool HasExtraOptions() const
void SetEnabled(bool fToVal)
void AddEntry(const char *szText, int32_t id)
static int32_t GetDefaultHeight()
void SetComboCB(ComboBox_FillCB *pNewFillCallback)
void SetText(const char *szToText)
int32_t GetInnerHeight() const
bool GetFromLeft(int32_t iWdt, int32_t iHgt, C4Rect &rcOut)
void ExpandLeft(int32_t iByWdt)
bool GetFromRight(int32_t iWdt, int32_t iHgt, C4Rect &rcOut)
bool GetFromTop(int32_t iHgt, int32_t iWdt, C4Rect &rcOut)
void GetAll(C4Rect &rcOut)
bool GetFromBottom(int32_t iHgt, int32_t iWdt, C4Rect &rcOut)
void AddElement(Element *pChild)
void SetFocus(Control *pCtrl, bool fByMouse)
void UpdateSize() override
Dialog(int32_t iWdt, int32_t iHgt, const char *szTitle, bool fViewportDlg)
virtual void OnClosed(bool fOK)
void SetTitle(const char *szToTitle, bool fShowCloseButton=true)
virtual Screen * GetScreen()
C4Rect GetContainedClientRect()
virtual void UpdateSize()
void SetBounds(const C4Rect &rcNewBound)
Element * GetSelectedItem()
void SetSelectionDblClickFn(BaseCallbackHandler *pToHandler)
void SetSelectionChangeCallbackFn(BaseCallbackHandler *pToHandler)
bool AddElement(Element *pChild, int32_t iIndent=0)
bool ShowModalDlg(Dialog *pDlg, bool fDestruct=true)
bool ShowErrorMessage(const char *szMessage)
void SetDecoration(bool fDrawBG, bool fDrawFrame, ScrollBarFacets *pToGfx, bool fAutoScroll)
void ClearText(bool fDoUpdate)
void AddTextLine(const char *szText, CStdFont *pFont, DWORD dwClr, bool fDoUpdate, bool fMakeReadableOnBlack, CStdFont *pCaptionFont=nullptr)
void UpdateOwnPos() override
C4Rect & GetClientRect() override
bool Open(const char *group_name, bool do_create=false)
C4PlayerSelDlg(C4FileSel_BaseCB *pSelCallback)
C4FileSelDlg::ListItem * CreateListItem(const char *szFilename) override
void EndFileListUpdate() override
void OnClosed(bool fOK) override
static bool SelectPortrait(C4GUI::Screen *pOnScreen, StdStrBuf *pSelection)
void BeginFileListUpdate() override
C4PortraitSelDlg(C4FileSel_BaseCB *pSelCallback)
int GetLineHeight() const
int32_t GetTextWidth(const char *szText, bool fCheckMarkup=true)
std::tuple< std::string, int > BreakMessage(const char *szMsg, int iWdt, bool fCheckMarkup, float fZoom=1.0f)
void Ref(const char *pnData)
const char * getData() const
void AppendChar(char cChar)
void Append(const char *pnData, size_t iChars)
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O