Gamestudio Links
Zorro Links
Newest Posts
New Zorro version 2.20
by AndrewAMD. 11/15/19 03:34
What are you working on?
by jumpman. 11/14/19 16:17
A9
by preacherX. 11/14/19 15:28
Idx calculated every tick
by jcl. 11/14/19 15:25
IG plugin initial release
by Dalla. 11/13/19 19:07
Login 0 IG ..
by Dalla. 11/13/19 19:03
Moving Average crossover
by gra9. 11/13/19 10:43
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
6 registered members (Iglarion, kvm, AndrewAMD, Dooley, 3run, 1 invisible), 675 guests, and 11 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LaszloK, gra9, Dev_ill, Ryu, andrews825
18329 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 3 of 3 1 2 3
Re: Imgui Lite-c Development [Re: jenGs] #478301
09/28/19 19:58
09/28/19 19:58
Joined: Jul 2010
Posts: 281
Germany
J
jenGs Offline
Member
jenGs  Offline
Member
J

Joined: Jul 2010
Posts: 281
Germany
Originally Posted by jenGs
One moment, I make the demo runnable. I tested with the wrong script


Now it should work

Re: Imgui Lite-c Development [Re: jenGs] #478338
10/06/19 07:07
10/06/19 07:07
Joined: Jun 2007
Posts: 1,270
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,270
Hiporope and its pain
Hi, I will be eternally grateful of sharing your work, to both of you. I would never be able to introduce myself into such a great tool. It has openend many doors for my personal evolution. Thank you very much!

Originally Posted by jenGs
@20BN Imgui can display unicode, but the problem is Lite-C. I don't know what _chr(STRING) gives back with an unicode STRING. Can't promise anything, but I will look into it. I think I have to decode the characters, because ImGui uses normal char* not wchars to display unicode (If i am not mistaken)


One of the things I feel like a must is the mutilanguaje support. I have been investigating and it seems that ImGui uses ANSI or UTF8 encoded and NULL ended char strings. The problem here is that acknex does not correctly interpret UTF8 so there must be some sort of recoding work in order to show unicode characters. As a newby in C++, I found windows 'WideCharToMultiByte' function and its inverse been the key for character arrays transformations.

Code
namespace imgui_helpers {
	typedef char utf8;
	typedef wchar_t unicode;

	#define UTF8_MAX 1024
}

using namespace imgui_helpers;

DLLFUNC utf8 *imgui_h_UnicodeToUtf8(unicode *_text) {
	static utf8 _utf8Text[UTF8_MAX];
	WideCharToMultiByte(CP_UTF8, NULL, _text, -1, _utf8Text, UTF8_MAX, NULL, NULL);
	return _utf8Text;
}


In tandem, I wrote a little helper function in LiteC in order to transform ANSI texts to unicode.

Code
typedef char utf8;
typedef short unicode;

#define UNICODE_MAX 1024

unicode *ansi_to_unicode(char *_chrT) {
	static unicode _unicode[UNICODE_MAX];
	unicode *_sT = _unicode;
	int _count = 0;
	for(; *_chrT!=NULL && _count<UNICODE_MAX-2; _chrT+=1, _sT+=1, _count+=1)
		*_sT = *_chrT;
	*_sT = NULL;
	return _unicode;
}


Another needed thing is imgui font installation and usage functions. Their are pretty straight so there is nothing to worry about.

Code
namespace imgui_fonts {
	enum GLYPH_RANGE {
		GLYPH_RANGE_Default,
		GLYPH_RANGE_ChineseFull,
		GLYPH_RANGE_ChineseSimplified,
		GLYPH_RANGE_Cyrillic,
		GLYPH_RANGE_Japanese,
		GLYPH_RANGE_Korean,
		GLYPH_RANGE_Thai,
		GLYPH_RANGE_COUNT
	};
};

using namespace imgui_fonts;

DLLFUNC ImFont *imgui_add_ttf_from_file(char *_chrFont, float _size, var _glyph_range) {
	const ImWchar *_glyphRange = NULL;

	ImGuiIO& io = ImGui::GetIO();

	switch (_INT(_glyph_range)) {
		case GLYPH_RANGE_ChineseFull:       _glyphRange = io.Fonts->GetGlyphRangesChineseFull(); break;
		case GLYPH_RANGE_ChineseSimplified: _glyphRange = io.Fonts->GetGlyphRangesChineseSimplifiedCommon(); break;
		case GLYPH_RANGE_Cyrillic:          _glyphRange = io.Fonts->GetGlyphRangesCyrillic(); break;
		case GLYPH_RANGE_Japanese:          _glyphRange = io.Fonts->GetGlyphRangesJapanese(); break;
		case GLYPH_RANGE_Korean:            _glyphRange = io.Fonts->GetGlyphRangesKorean(); break;
		case GLYPH_RANGE_Thai:              _glyphRange = io.Fonts->GetGlyphRangesThai(); break;
		default:                            _glyphRange = io.Fonts->GetGlyphRangesDefault();
	}
	
	return io.Fonts->AddFontFromFileTTF(_chrFont, _size, NULL, _glyphRange);
}

DLLFUNC void imgui_push_font(ImFont* _font) {
	ImGui::PushFont(_font);
}

DLLFUNC void imgui_pop_font() {
	ImGui::PopFont();
}


So in combination, they can be used to show unicode strings with imgui and liteC.

Code
typedef ImFont void;

#define GLYPH_RANGE_Default               0
#define GLYPH_RANGE_ChineseFull           1
#define GLYPH_RANGE_ChineseSimplified     2
#define GLYPH_RANGE_Cyrillic              3
#define GLYPH_RANGE_Japanese              4
#define GLYPH_RANGE_Korean                5
#define GLYPH_RANGE_Thai                  6
#define GLYPH_RANGE_COUNT                 7

...

STRING *strUnicode = str_createw(ansi_to_unicode("My ansi text"));
STRING *strUTF8 = str_create(imgui_h_UnicodeToUtf8(strUnicode->chars));

ImFont *ImFont01 = imgui_add_ttf_from_file("c:\\Windows\\Fonts\\Arial-unicode-ms.ttf", 18, GLYPH_RANGE_Default);
ImFont *ImFont02 = imgui_add_ttf_from_file("c:\\Windows\\Fonts\\Arial-unicode-ms.ttf", 24, GLYPH_RANGE_Default);

...

imgui_begin(....
   imgui_push_font(ImFont01);
   imgui_text(strUTF8->chars);
   imgui_pop_font();

   imgui_push_font(ImFont02);
   imgui_text(strUTF8->chars);
   imgui_pop_font();
...


Here is the result of buiilding a single string with cyrillic and japanese character codes, converted to UTF8 and shown with two different fonts created with their corresponding glyph ranges.
[Linked Image]

I wrote all this stuff in order to create some helper fuctions so I can build an in-game file explorer with unicode, so it will come in a near future, I hope laugh

Salud!



Re: Imgui Lite-c Development [Re: txesmi] #478390
10/11/19 16:42
10/11/19 16:42
Joined: Jun 2007
Posts: 1,270
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,270
Hiporope and its pain
I have got working a basic file explorer in UTF8. It is not ready to use but maybe someone wants to keep an eye on it.

[Linked Image]

You can find the source code at GitHub, forked from jenGs's repository, all my functions are included in two new files: imgui_dll_fonts.cpp and imgui_dll_helpers.cpp.

The main work has been around a function that prepares the folder data to be shown in an imgui list box: an array of char*. I tried different methods and finally ended up with a function that fills a buffer owned by the caller instead of the dynamic allocation I tried first, so at the end it can happen that the folder content names are longer that the space available and will result in a clipped content list. I do all the stuff with experimental::filesystem. The function can inject a prefix to folders. In the example I used one of the private ucodes (E800-E8FF) to show that folder icon I inserted into the ttf file (with Type Light).

The file explorer behaviour is in liteC with the help of some helper functions included in the dll. It desplegates a combo in root drives and a button per folder in the path. It rebuilds the data when clicking over a subfolder and activates the selection button when clicking over a file.

The fonts implementation is pretty choppy. I have no idea how to easily implement the custom glyph ranges.

Re: Imgui Lite-c Development [Re: EVO] #478394
10/11/19 23:53
10/11/19 23:53
Joined: Feb 2013
Posts: 101
Maysville, Ga
EVO Offline OP
Member
EVO  Offline OP
Member

Joined: Feb 2013
Posts: 101
Maysville, Ga
@Txesmi : Thanks for getting involved and creating some new features.

Sadly I haven't had much time to work on my projects, but once I can, I'll have a new source code template update with some new ideas and new custom plug-n-play examples.
Thanks to everyone for helping out.

Re: Imgui Lite-c Development [Re: EVO] #478395
10/12/19 01:11
10/12/19 01:11
Joined: Jul 2010
Posts: 281
Germany
J
jenGs Offline
Member
jenGs  Offline
Member
J

Joined: Jul 2010
Posts: 281
Germany
thank you txesmi. Due to work obligations I have not much time at the moment to work on more features. And I always hated unicode and ackenx in combination laugh

Re: Imgui Lite-c Development [Re: EVO] #478396
10/12/19 19:06
10/12/19 19:06
Joined: Jun 2007
Posts: 1,270
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,270
Hiporope and its pain
you are welcome laugh

little by little, step by step

Re: Imgui Lite-c Development [Re: EVO] #478397
10/13/19 09:40
10/13/19 09:40
Joined: Jun 2007
Posts: 1,270
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,270
Hiporope and its pain
Hi,
I have just seen the other ImGui::ListBox implementation that uses a label getter function for each list item. I think it is the key to not get lost on char* arrays allocations by using engines native methods. It allows to a 3dgs user the use of TEXT structs to hold arrays of char arrays. It can use any custom data struct at the end.

Code
// C++
DLLFUNC var imgui_h_list_box (const char* label, int* current_item, bool(*items_getter)(void*, int, const char**), void* data, int items_count, int height_in_items) {
	bool res = ImGui::ListBox(label, current_item, items_getter, data, items_count, height_in_items);
	return res ? _VAR(1) : _VAR(0);
}

// liteC
var imgui_h_list_box (char* label, int* current_item, void *items_getter, void* data, int items_count, int height_in_items);
...
TEXT *txtList = {
	string = (
		"eoeoeo 1"
		"eoeoeo 2"
		"eoeoeo 3"
		"eoeoeo 4"
		"eoeoeo 5"
		"eoeoeo 6"
	);
}

BOOL _label_for_text(TEXT *_txt, int _index, char **_label) {
	*_label = (_txt->pstring)[_index]->chars;
	return TRUE;
}

...
static int _currentItem = -1;
imgui_h_list_box ("##TEXT list box", &_currentItem, _label_for_text, txtList, (int)txtList->strings, 10);


-------------

I have got another newby question related to the memory and dynamic libraries. As far as I read last days the executable binary and the dinamic library use two different memory areas. I read that the main law is that the allocator have to be the releaser. In the case of using the engine functions into a dll, the allocated memory shall be into the memory asigned to the engines dll, so it is managed same as it would be allocated in liteC, isn't it?

I did some test and I do not receive any errors, so, my question is: Is it safe to add newly created STRINGs into a dll to a TEXT struct passed from liteC and realease them all in liteC?

Re: Imgui Lite-c Development [Re: txesmi] #478459
10/24/19 07:53
10/24/19 07:53
Joined: Jul 2007
Posts: 539
Turkey, izmir
Emre Offline
User
Emre  Offline
User

Joined: Jul 2007
Posts: 539
Turkey, izmir
Thank you txesmi!

And one for frome me. There is a member of ImGuiIO, named "FontGlobalScale". I use it for scaling everything. You guys can use it too if you need it.

[Linked Image]

//DLL (i'm still using first version of dll.)
Code
DLLFUNC void imgui_set_global_fontscale(float scalefactor)
{
    ImGuiIO& io = ImGui::GetIO();
    io.FontGlobalScale = scalefactor;
	
}

//Lite-c
Code
void imgui_set_global_fontscale(float scalefactor);

float global_font_scale=1.0;
void window_func() //loop
{
	...
        imgui_set_global_fontscale(global_font_scale);
    	...
}


You can use "global_font_scale", wherever you wish. This way, you can scale everything.


Code
void window_func() //loop
{
	...
	imgui_begin_child("ChildVideo", vector(272*global_font_scale,272*global_font_scale,0), 4,ImGuiWindowFlags_NoScrollWithMouse);
	imgui_push_item_width(200*global_font_scale); 
	imgui_input_text("", _chr(klasor_name), MAX_PATH, ImGuiInputTextFlags_ReadOnly);
	...
}


and result is here: https://www.youtube.com/watch?v=AISuErDfPOU&feature=youtu.be

Page 3 of 3 1 2 3

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1