NO

Author Topic: SGL - win32 made simple!  (Read 2831 times)

Offline henrin

  • Member
  • *
  • Posts: 21
SGL - win32 made simple!
« on: September 04, 2015, 11:12:34 PM »
I have read many posts looking for easy win32 gui programming.
Not founding a good solution, and considering Win32 is almost
fantastic, I decided to fill the gap.

Here is SGL - Features:
 - easy Win32 programming (better OOP)
 - grid layout with alignmment and padding
 - scalable GUI

The kit contains:
 - help file (sgl.chm)
 - dev kit: x.lib and x.h
 - sample programs (source, project and exe files)
 
The available objects are:
 - buttons
 - table (data grid)
 - image
 - edit
 - graph
 - popups
 
The mandatoty Hello progam is just 12 lines:
 
    #include "sgl.h"
    int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPInst, PSTR cmdLine, int cmdShow)
    {
       SGL_Init(hInst, NULL) ;
       HWND panel = SGL_New(0, SGL_PANEL, 0, "SGL", -1, -1) ;
       HWND btn   = SGL_New(panel, SGL_CTRL_BUTTON, 0, "Hello!", 0, 0) ;
       SGL_Layout(panel) ;
       SGL_VisibleSet(panel, 1) ;
       SGL_Run() ;
       SGL_Exit() ;
       return 0 ;
    }

More samples in the downloadable kit.

Offline jj2007

  • Member
  • *
  • Posts: 454
Re: SGL - win32 made simple!
« Reply #1 on: September 05, 2015, 11:50:06 AM »
Compliments, it works like a charm, in just 40 lines!

Code: [Select]
#include "sgl.h" // all sgl*.h must be in include folder (includes <stdio.h>)
#pragma comment(linker, "sgl32.lib" ) // sgl32.lib must be in lib folder

#pragma warn(disable:2216)    // retval never used
#pragma warn(disable:2018)    // Undeclared function 'sprintf'
#pragma warn(disable:2118)    // para not referenced
#pragma comment(linker, "/Subsystem:Windows" )
#pragma warn(disable:2215)    // conversion ... loss of data

#define BTN_NB 6
#define TEXT_LEN 10

int buttonCB(HWND hwnd, UINT event, WPARAM wParm, LPARAM lParm) {
  if (event == WM_LBUTTONUP) {
RECT rect ; // rectangle for the edit box
GetClientRect(hwnd, &rect) ;
MapWindowPoints(hwnd, NULL, (POINT*) &rect, 2) ;
char* text ; // edited text
SGL_CallbackDataGet(hwnd, (void*) &text) ;
SGL_PopupEdit(hwnd, &rect, ES_CENTER, SGL_WHITE,
text, TEXT_LEN, NULL, NULL) ;
return 1 ;
  }
  return 0 ;
}

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
  static char btnText[BTN_NB][TEXT_LEN] ; // buttons' text
  SGL_Init(hInstance, NULL) ;
  HWND topPanel = SGL_New(0, SGL_PANEL, 0, "BUTTONS", 90, 30) ;
  for (int i = 0 ; i < BTN_NB ; i++) { // create each button
sprintf(btnText[i], "Button #%d", i + 1) ;
HWND btn = SGL_New(topPanel, SGL_CTRL_BUTTON, 0, btnText[i], 0, i) ;
SGL_CallbackFunctionSet(btn, buttonCB) ;
SGL_CallbackDataSet(btn, (void*) &btnText[i]) ;
  }
  SGL_Layout(topPanel) ;
  SGL_VisibleSet(topPanel, 1) ;
  SGL_Run() ;
  SGL_Exit() ;
  return 0 ;
}

migf1

  • Guest
Re: SGL - win32 made simple!
« Reply #2 on: September 06, 2015, 10:01:03 AM »
Although I've personally settled in GTK+ when it comes to GUI programming with C, I want to congratulate you for this effort!

I went through SGL docs, though in a hurry. Was impressed and I believe SGL deserves to go open-source, ideally in its own git repo. If not, it may be a good idea to also provide ming32 and/or mingw-w64 pre-compiled binaries.

Thanks for sharing and once again congrats for the effort so far.

Offline henrin

  • Member
  • *
  • Posts: 21
Re: SGL - win32 made simple!
« Reply #3 on: October 19, 2015, 06:41:20 PM »
Thank you jj2007 and migf1.
The story continues: here is the v1.1 version.

Some improvements in resizing and default values:
  • Panel sizing is now possible.
  • SGL fonts are now strictly linked to the desktop menu font.
  • The separator object is now spanned to its parent border.
New features:
  • New macros for testing the mouse buttons.
  • New tool for Automatic resizing.
  • New object OpenGL

To remain in upload size limit, only the 32-bit sample executables are included.
You still have:
  • the help file
  • the .h and the .lib (32 & 64-bit) files
  • the samples: source, project files, .exe files

Next step : make it open source.

DD

  • Guest
Re: SGL - win32 made simple!
« Reply #4 on: November 05, 2015, 05:38:38 AM »
i've been using it for some tests.
thanks for the hard work!

Offline henrin

  • Member
  • *
  • Posts: 21
Re: SGL - win32 made simple!
« Reply #5 on: January 17, 2016, 05:03:44 PM »
A new release and the source code

The 1.2 release mainly adds a date-time popup. Two sample are provided:
- 2 date buttons for a round trip ticket,
- editing a date in a table (data grid).
One feature has been lost: the backgroung color for user editing is white and cannot be changed.

I have changed publishing:
- the development kit (*.h, *.lib and *.chm) and the samples are now there http://perso.numericable.fr/hserindat/sgl/,
- the source code can now be downloaded here (also includes the samples).

Terms of use:
SGL is freeware for any use: personal, commercial, etc. No registration is required to download it, and you can use it anonymously.
SGL can be freely distributed, but it can not be sold.
SGL is provided 'as-is', without any expressed or implied warranty. In no event will the author be held liable for any damages arising from the use of this software.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1587
Re: SGL - win32 made simple!
« Reply #6 on: January 17, 2016, 09:35:14 PM »
Good job!
Thanks for sharing.  :)

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 754
Re: SGL - win32 made simple!
« Reply #7 on: January 20, 2016, 02:49:31 AM »
Good job!
Thanks for sharing.  :)
+1

Ralf

Offline henrin

  • Member
  • *
  • Posts: 21
New release
« Reply #8 on: October 10, 2016, 05:41:55 PM »
SGL 1.3 is here with new features:

- Temporary font loading.
- New tools for reading and writing in a configuration file.

other improvements and a new sample (custom message box).

The development kit (*.h, *.lib and *.chm) and the samples are here http://perso.numericable.fr/hserindat/sgl/v_1.3/release_sgldevkit.7z,
The source code can now be downloaded here (also includes the samples).

Offline henrin

  • Member
  • *
  • Posts: 21
Re: SGL - win32 made simple!
« Reply #9 on: November 18, 2016, 11:51:33 PM »
A light update.

SGL provided native scrolling under foreground windows [MouseWheelRouting].
As well as Windows10 now. This required some adjustment which accidentally broke the compatibility with Windows XP.
That is repaired with the 1.3.1 version.

The previous release was not exciting; the goodies were not emphazed enough.
Here is a nice one: a message box, in less than 200 lines (exe and ini files attached).
  • Window size and position setting and saving for panels and buttons.
  • Setting and saving of custom colors. 
  • Custom popup. 
  • Automatic size adjustments. 
  • Version info (right click on the .exe file: properties / details).
  • Native scrolling under foreground window as mentionned above.

The development kit (*.h, *.lib and *.chm) and the samples are here http://perso.numericable.fr/hserindat/sgl/v_1.3.1/release_sgldevkit.7z,
The source code can be downloaded here (attached file which also includes the source code of the samples).


Offline jj2007

  • Member
  • *
  • Posts: 454
Re: SGL - win32 made simple!
« Reply #10 on: November 19, 2016, 11:06:09 AM »
Very nice! I had a look at the animated GIF example. How are you doing that?
These seem to be the relevant functions, but what do they use under the hood? Just curious...

SGL_ImagePlay(image, 100);
SGL_ImageFrameIndexSet(image, i);

Offline henrin

  • Member
  • *
  • Posts: 21
Re: SGL - win32 made simple!
« Reply #11 on: November 19, 2016, 08:21:37 PM »
Animated works for GIF, and for multiframe TIFF also! (win7 and above).

The relevant SGL functions are described in the help file : CONTROL OBJECTS / IMAGE (inside http://perso.numericable.fr/hserindat/sgl/v_1.3.1/release_sgldevkit.7z).

Under the hood, there is GDI+ and an animation thread. Unfortunately, at the time of development I did not find a very good gdi+ header. The header I have found in T-Clock (by Frankie) seems much cleaner.

The code for the image object is :
 - sgl_gdiplus_.h  (GDI+ header)
 - sgl_image_.h  (private header)
 - sgl_image.c  (code)
 - sgl_image.h  (public header)
and is attached to this post.

Offline jj2007

  • Member
  • *
  • Posts: 454
Re: SGL - win32 made simple!
« Reply #12 on: November 19, 2016, 09:17:42 PM »
Animated works for GIF, and for multiframe TIFF also! (win7 and above).

I tried to find animated TIFF images for testing but no luck so far I found only two here.

Quote
Under the hood, there is GDI+

In the meantime, I rolled my own, see here. But thanks for inspiring me  :)
« Last Edit: November 19, 2016, 09:27:03 PM by jj2007 »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1587
Re: SGL - win32 made simple!
« Reply #13 on: November 20, 2016, 10:20:29 PM »
Good job henrin  ;)

Offline jj2007

  • Member
  • *
  • Posts: 454
Re: SGL - win32 made simple!
« Reply #14 on: November 20, 2016, 11:16:13 PM »
henrin,
did you have any luck with animated PNGs? Firefox (and others, I suppose) "plays" them just fine, but GdipImageGetFrameCount returns always one frame >:(