Difference between revisions of "CPlusPlus for Gideros Studio Help"

From GiderosMobile
Line 185: Line 185:
 
'''refs''':
 
'''refs''':
 
* https://cplusplus.com/reference/cwchar/wcschr/
 
* https://cplusplus.com/reference/cwchar/wcschr/
 +
* https://cplusplus.com/reference/string/string/find/
 
<source lang="c++">
 
<source lang="c++">
 +
std::wstring gs=ws(args[0].s.c_str()); // "Title|C:/tmp/|Text (*.txt);; Image (*.png)"
 +
size_t index = gs.find(L"|");
 +
size_t index2 = gs.find(L"|", index+1);
 +
printf("args0: %ls\n", gs.c_str()); // output: Title|C:/tmp/|Text (*.txt);; Image (*.png)
 +
printf("indices: %d, %d\n", index,index2); // output 5, 13
 +
std::wstring title = gs.substr(0, index);
 +
std::wstring path = gs.substr(index+1, index2-index-1);
 +
std::wstring exts = gs.substr(index2+1);
 +
printf("t p e:\n %ls\n %ls\n %ls\n", title.c_str(),path.c_str(),exts.c_str()); // Title C:/tmp/ Text (*.txt);; Image (*.png)
 
</source>
 
</source>
  

Revision as of 15:36, 26 October 2022

Here you will find various resources to help learn C++ for people who wish to help with Gideros Studio development.


KNOWNFOLDERID

platform-win32.cpp

refs:

C:\dev\gideros_hgy29\libgid\src\win32\platform-win32.cpp


Convert wstring <-> string

platform-win32.cpp

refs:

C:\dev\gideros_hgy29\libgid\src\win32\platform-win32.cpp

#include <locale> // new 20221014 XXX
#include <codecvt> // new 20221014 XXX

...

std::wstring s2ws(const std::string& str)
{
    using convert_typeX = std::codecvt_utf8<wchar_t>;
    std::wstring_convert<convert_typeX, wchar_t> converterX;

    return converterX.from_bytes(str);
}

std::string ws2s(const std::wstring& wstr)
{
    using convert_typeX = std::codecvt_utf8<wchar_t>;
    std::wstring_convert<convert_typeX, wchar_t> converterX;

    return converterX.to_bytes(wstr);
}


win32 minimum, maximum screen size

platform-win32.cpp

refs:

C:\dev\gideros_hgy29\libgid\src\win32\platform-win32.cpp


win32 LFS problem with separator

Recent changes to path handling (most likely [0]) caused AssetCatalogTest.create_catalog_after_loading_file to fail on WIN32.

The test relied on the resulting path to be joined with "/" as a path separator. The resulting path used both forward and back-slashes. While these do work for some API's on WIN32, mixing both in a file path isn't expected behavior in most cases, so update the tests to use native slash direction for file-paths.

 * \note If you want a trailing slash, add `SEP_STR` as the last path argument,
 * duplicate slashes will be cleaned up.
 */
size_t BLI_path_join(char *__restrict dst, size_t dst_len, const char *path, ...)
#  define SEP '\\'
#  define ALTSEP '/'
#  define SEP_STR "\\"
#  define ALTSEP_STR "/"
#else
#  define SEP '/'
#define SEP_CHR     '#'
#define SEP_STR     "#"

#define EPS 0.001

#define UN_SC_KM    1000.0f
#define UN_SC_HM    100.0f
      str_tmp, TEMP_STR_SIZE, "*%.9g" SEP_STR, unit->scalar / scale_pref);

  if (len_num > len_max) {
    len_num = len_max;
  }

  if (found_ofs + len_num + len_move > len_max) {


openFileDialog

platform-win32.cpp

refs:

        }else if (strcmp(what, "openFileDialog") == 0)
        {
            DWORD dwFlags; // XXX

            if (args.size()>0)
            {
//                printf("args: %s, %s\n",args[0],args[1]); // TEST

                HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
                if (SUCCEEDED(hr))
                {
                    IFileOpenDialog *pFile;
                    COMDLG_FILTERSPEC fileTypes[] =
                    {
                        { L"Text Documents", L"*.txt" },
                        { L"All Files", L"*.*" },
                    }; // NEED TO PASS FROM ARGS!

                    // Create the FileOpenDialog object.
                    hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, 
                            IID_IFileOpenDialog, reinterpret_cast<void**>(&pFile));

                    if (SUCCEEDED(hr))
                    {
                        // get/set options
                        pFile->GetOptions(&dwFlags);
                        pFile->SetOptions(dwFlags | FOS_FORCEFILESYSTEM);
                        pFile->SetFileTypes(ARRAYSIZE(fileTypes), fileTypes);
                        pFile->SetFileTypeIndex(1); // index starts at 1 XXX
//                        pFile->SetDefaultExtension(L"obj;fbx"); // XXX
//                        pFile->SetFolder(shellItem);

                        // Show the Open dialog box.
                        hr = pFile->Show(NULL);

                        // Get the file name from the dialog box.
                        if (SUCCEEDED(hr))
                        {
                            IShellItem *pItem;
                            hr = pFile->GetResult(&pItem);
                            if (SUCCEEDED(hr))
                            {
                                PWSTR pszFilePath;
                                hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);

                                // Display the file name to the user.
                                if (SUCCEEDED(hr))
                                {
//                                  MessageBoxW(NULL, pszFilePath, L"File Path", MB_OK);
                                    r.type=gapplication_Variant::STRING;
                                    r.s=us(pszFilePath);
                                    rets.push_back(r);

                                    CoTaskMemFree(pszFilePath);
                                }
                                pItem->Release();
                            }
                        }
                        pFile->Release();
                    }
                    CoUninitialize();
                }
            }
            /*------------------------------------------------------------------*/
        }else if (strcmp(what, "saveFileDialog") == 0)


Locate first occurrence of character in wide string

platform-win32.cpp

refs:

std::wstring gs=ws(args[0].s.c_str()); // "Title|C:/tmp/|Text (*.txt);; Image (*.png)"
size_t index = gs.find(L"|");
size_t index2 = gs.find(L"|", index+1);
printf("args0: %ls\n", gs.c_str()); // output: Title|C:/tmp/|Text (*.txt);; Image (*.png)
printf("indices: %d, %d\n", index,index2); // output 5, 13
std::wstring title = gs.substr(0, index);
std::wstring path = gs.substr(index+1, index2-index-1);
std::wstring exts = gs.substr(index2+1);
printf("t p e:\n %ls\n %ls\n %ls\n", title.c_str(),path.c_str(),exts.c_str()); // Title C:/tmp/ Text (*.txt);; Image (*.png)