Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, VoroneTZ), 831 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 3 of 6 1 2 3 4 5 6
Re: Imgui Lite-c Development [Re: jenGs] #478301
09/28/19 19:58
09/28/19 19:58
Joined: Jul 2010
Posts: 283
Germany
J
jenGs Offline
Member
jenGs  Offline
Member
J

Joined: Jul 2010
Posts: 283
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,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
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,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
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: 122
Maysville, Ga
Evo Offline OP
Member
Evo  Offline OP
Member

Joined: Feb 2013
Posts: 122
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: 283
Germany
J
jenGs Offline
Member
jenGs  Offline
Member
J

Joined: Jul 2010
Posts: 283
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,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
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,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
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: 619
Turkey, Izmir
Emre Offline
User
Emre  Offline
User

Joined: Jul 2007
Posts: 619
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

Re: Imgui Lite-c Development [Re: Evo] #478949
01/23/20 15:03
01/23/20 15:03
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
@txesmi hey! just looked into your git example, can you tell me how and were you created that 'Debug' window, I can't find it myself... It has to be somewhere before
Code
void ShowDemoWindowWidgets()
{
	if (!ImGui->CollapsingHeader("Widgets", NULL, 0))
	return;
But where? grin I'm a bit lost... Want to create same, resizeable window but without close button at the upper right corner.

Plus, can you guys tell me how to make button resize itself with it's parent (f.e. I have collapsing_header and inside of a button, how to make it fill the width of the collapsing_header)?
Thank you all for this awesome contribution and examples, this really makes life easier!

Edit: ok, I found out that debug window will appear automatically, when you create any item without a window for it.. as for the buttons, it seems that it has something to do with imgui_push_item_width(xq), but I didn't figure out yet how.

Edit2: also, would be great to know, how to align text to center (f.e. of a button, or other elements as well), it has to do something with styles I guess..

Last edited by 3run; 01/23/20 17:11.

Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Imgui Lite-c Development [Re: Evo] #478950
01/23/20 17:15
01/23/20 17:15
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi @3Run
That is the original example of the ImGui module. I did not write it myself.

You can find all the window flags into 'imgui_enums.h' file. Not sure what are you trying to thought.

About the button width, you need to get the available width so you can create the button with it.
Code
var _width = imgui_get_content_region_avail_width();
if(imgui_h_button("Button text", _width, 0)) {
   ...
}


I am not at home and I can't try it but I think it should work as spected.

Salud!

Page 3 of 6 1 2 3 4 5 6

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