GithubHelp home page GithubHelp logo

kiss_sdl's Introduction

NAME

kiss_sdl - Simple generic GUI widget toolkit for SDL2

SCREENSHOTS

DESCRIPTION

KISS is an acronym and software development approach that means "Keep It Small and Simple". Sometimes all the user interaction is GUI, so GUI is very general. Certainly there are an immense number of ways how a developer may want to do it. Having everything ready made is thus not a good idea, except for some special cases. The solution is to make GUI toolkit general, but small and simple, so that for basic purposes it can be used as is, or it can be changed when one wants to do it differently. Most other toolkits enable to write your own widgets, but it is not simple to do that, and they are not intended for that.

This toolkit was made as simple as possible, to solve the problem of an immense complexity of many existing toolkits, which makes it impossible for many people to even use them. At that it was made general, many simpler toolkits don't enable you to do many things that you want, due to their restricted internal design. This toolkit implements an original innovative approach for a widget toolkit that i call principal GUI, going further from immediate GUI, this new approach enabled to make the widget toolkit simpler. The toolkit is written in C, but it can also be used in C++.

The GUI toolkit was made as modifiable as possible, so that it will not stand on the way of doing what the user may want to do. The code of this GUI toolkit is split into four files. The file kiss_widgets.c contains only the functions of the widgets, and none of the SDL functions or external library functions are directly called in that file. The three other files serve as abstraction layers, and rewriting the functions in some of these files, enables to redefine how the operations that use the external library functions, are implemented. These three files are kiss_draw.c , for general drawing functions, kiss_general.c , for general functions such as an implementation of the variable size array, and kiss_posix.c , for some of the most necessary POSIX functions.

What is necessary for using the toolkit in a code is simple and straightforward. Every widget has three functions written for it, a function to create a new widget, a function to process the events, and a function to draw. The base functions implemented for the widgets, do all the automagical things, and the user can write one's own function, using a base function inside it, to do any additional things that the user may want to do. See the examples and the header file kiss_sdl.h .

The few global variables there are, are not declared as constant, to make the code more easily modifiable, but they should be used as constants, by changing them only during the initialization. In case of an error, the functions of this toolkit return -1 or NULL, depending on the return type, and the event processing functions return 0.

Widgets can be made visible and invisible, an invisible widget is also inactive and doesn't perform any functions. In the examples, all widgets are created first, and then only these that should be active and present on the screen, are made visible. It is also possible to create and free widgets dynamically. Making a user interface in that way may sound strange at first, but all the user written functions for widgets have to be there anyway, a lot has to be there for all widgets. For bigger interfaces it is possible to create widgets dynamically. But making it only by switching the visibility, enables a simpler implementation of a user interface.

The functions for creating widgets also have an argument wdw which, if provided, makes the widget to become visible when the window widget pointed by that argument becomes visible, and not visible when that window becomes not visible. That window is thus like a dialog window on which all the widgets in the dialog are drawn, the examples show how to do that. Some of these functions also have an additional argument named decorate, this determines whether the widget should be decorated by the default function. The default function draws a blue rectangle around the edge of the widget.

In addition to visibility, the widgets also may or may not have focus. Focus determines whether the widget processes mouse events. The focus of the widget is determined by the focus of the window wdw. If this window is provided and has no focus, the focus of a widget is determined by the focus member of the structure of that widget.

The event processing functions are called after each other in the event processing loop. The scrollbar, progressbar and combo box event functions are also called after the event processing loop with the event argument NULL. The base functions return nonzero when an event happened in the widget that the user may want to additionally process. The event functions have an additional argument, a pointer to an integer that is assigned a nonzero value when the widgets have to be redrawn.

The drawing functions are called after each other in every iteration, after the event processing loop, when there is a need to redraw the widgets. The user may write ones own drawing functions and call the base functions inside them, to do an additional drawing. The order of the drawing functions in the loop is important, the next functions draw over the drawing done by the previous functions. Especially when combo boxes are used, as their popup text boxes draw over the widgets below the combo box.

Ten widgets are implemented as base widgets, these are a window, multiline label, button, select button, vertical scrollbar, horizontal scrollbar, progress bar, entry box, text box, and combo box. The two examples show how to use these widgets together. The first example implements a working file selection dialog with scrollable text boxes, the second example shows a use of a combo box. Likely most of the user interfaces can be made by using only these widgets, but the toolkit doesn't prevent adding any additional functionality.

Is it possible to make composite widgets from several other widgets? The widgets have coordinates relative to the main window, but it is possible and not so difficult, to add the coordinates of a local window to a certain group of widgets. It is possible to create and free such group of widgets in one function, or process its events or draw it in one function. Combo box is an example of a composite widget.

For the entry widget, the editing provided is that of the early versions of Unix, backspace deletes the last character and ctrl-u deletes the entire text. Clicking inside the entry widget causes it to become active, and its text can then be edited. Pressing Enter when the widget is active, causes the entry widget to become inactive, and causes its event function to return true. Which enables to run a code to use the changed value. An additional functionality can be added, such as clipboard, but what it may be depends on the particular needs.

Is it possible to do the event processing in a separate function? Yes it is, by using separate event loops for different widgets, or by passing objects using a variable size array, but because of simplicity this has not been done in the examples of this toolkit. This also makes a re-entrant or thread-safe code possible, and also different widgets can then be drawn in different threads. In such widget toolkit there is essentially nothing central, except in that case a table may be necessary, that shows for every thread whether it has received an expose event and whether it has processed it.

Can the images be compiled into the code, instead of being in separate files? Yes they can, images can be compiled into the C code, also Gimp enables to save them directly in that way. Then with a special function they can be retrieved from the data in the code. But again because of simplicity, this has not been done in the examples of this toolkit.

Can i use other colors, images, etc? Yes. Different widgets can have different fonts and images, that can be loaded after the init function and assigned to the widget structure before creating the widget. To use certain other types of fonts or images, you may have to rewrite the init function. You can also draw anything you like on the widgets in the drawing function, this will be automatically redrawn every time after the window is exposed.

Can i do this or that other thing? You can do whatever you want, different from some other widget toolkits, this toolkit has not been made to restrict your freedom, or dictating to you how you should do things or what you can do. Just learn the basic things about how it works, the toolkit is simple and thus not difficult to learn, but it would be difficult to do what you want otherwise.

kiss_sdl is fully capable of UTF-8 (8-bit Unicode). The rendered text, the keyboard input and also the C source code, all is in UTF-8.

The kiss_sdl manual, including the full reference, Hello World example and example 2 tutorial, is at the following link.

https://raw.githubusercontent.com/actsl/kiss_sdl/master/kiss_manual.pdf

INSTALL

To maintain simplicity, no library has been made, but either a static or a dynamic library can be made, and the path to the resources (images and fonts) can be defined by adding a macro definition like -DRESDIR=\"kiss/\" to the compiler's command line. The simplest way to use it, is to copy all files to your project's directory and compile them with your code.

The common way in Windows is to copy all the dll-s from the proper bin directories (or library directories when using Visual Studio) of SDL, SDL_image and SDL_ttf, to your project's directory (copy the duplicate files from SDL_image, not from SDL_ttf), this is how SDL programs are usually distributed. Or to add all these bin directories to Path (in user variables). Or copy them to the Windows system directory, but then they may have to be replaced when using different versions of SDL2.

The kiss_makefile compiles the examples that show all the widgets in the toolkit. The kiss_makefile was made for Linux, to use it in Windows, edit it, comment the lines LDFLAGS, CFLAGS, BIN1 and BIN2, and uncomment the corresponding lines for 32 bit Windows, 64 bit Windows or macOS. The Xcode command line tools also have to be installed standalone in macOS. Then change the paths to the directories under which you installed the SDL2 development libraries. By default, it is assumed that the libraries are installed under C:\. No change may be necessary, or the change may be simple, like only changing the version of the library from 2.0.8 to 2.0.9.

In Windows, this toolkit was tested with MinGW-w64, installed with the installer downloaded from https://sourceforge.net/projects/mingw-w64 for i686 (32 bit) to C:\mingw-w64 , with C:\mingw-w64\mingw32\bin added to the Path. Other versions of MinGW should also work, but they are not tested. A 32 bit compiler also works with 64 bit Windows, but a 64 bit compiler cannot be used with 32 bit Windows.

It was also tested in the Visual Studio Community 2015 and SDL2 version 2.0.7. The project files for the Visual Studio are provided, but a similar changes to the library paths should be made if necessary, as described above, in the project -> properties -> configuration properties -> vc++ directories. The paths of the 64 bit SDL2 libraries for x64 are entered, but it was not tested with x64.

For compiling in Visual Studio, run kiss_example1.vcxproj or kiss_example2.vcxproj, make sure that on the toolbar x86 is selected (instead of x64), it was tested with x86, then build. Use one of the following commands to compile either in Linux or macOS, or in Windows using MinGW.

make -f kiss_makefile

mingw32-make -f kiss_makefile

The kiss_sdl project page is https://github.com/actsl/kiss_sdl .

CREDITS

Thanks to all users of kiss_sdl, start from simple, then hack the hell out of it. These are the people who found bugs, recommended changes, or helped otherwise to develop kiss_sdl, many thanks.

Michael Bethke (https://github.com/AVividLight), solarHunter (https://github.com/solarHunter).

VERSION

1.2.12

LICENSE

zlib license

kiss_sdl's People

Contributors

actsl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kiss_sdl's Issues

Android builds but crashes

Hi,
Good and simple little GUI kit!
I'm guessing it's not compatible with mobile?
Anyone got it working?

I got kiss_sdl built and example 1 working on linux and also built on NDK but when running it I get:

adb logcat com.example.hellojni:V hellojni:V SDL:V SDL2:V org.libsdl.app.SDLActivity:V com.example.hellojni/.HelloJni:V *:S

V/SDL ( 4092): Device: phone
V/SDL ( 4092): Model: phone
V/SDL ( 4092): onCreate(): null
V/SDL ( 4092): onResume()
V/SDL ( 4092): surfaceCreated()
V/SDL ( 4092): surfaceChanged()
V/SDL ( 4092): pixel format RGB_565
V/SDL ( 4092): Window size: 545x295
I/SDL ( 4092): SDL_Android_Init()
I/SDL ( 4092): SDL_Android_Init() finished!
V/SDL ( 4092): onWindowFocusChanged(): true
V/SDL ( 4092): onWindowFocusChanged(): false
V/SDL ( 4092): onPause()
V/SDL ( 4092): nativePause()
V/SDL ( 4092): surfaceDestroyed()
V/SDL ( 4092): surfaceCreated()
V/SDL ( 4092): onDestroy()

I'm a noob with Android.. so maybe I'm missing how to debug properly.
All the images are in the asset folder and accessible.
Any tips?
Cheers

easy way to implement scrolling?

Hello,
I am in a need of a "widget" (editing the window widget would suffice), that would be able to let it's content be bigger than what fits on the screen, and upon swipe (it's meant for android) would scroll to reveal the content.
The problem is, the content will be multiple widgets, which can be clicked, and I need smooth scrolling while still being able to properly execute events on the widget I click, and of course only on that one.
For drawing, I'm using https://github.com/memononen/nanovg/ , so I suppose I'll have to figure that out separately.
Is there a recommended way to do this?
Thanks in advance :)

Segmentation Fault running Example1 from KISS_SDL 0.10.2

Hello!

I'm trying to build the first example, but it's throwing a segmentation fault (Segmentation fault: 11) when I run it. Everything does compile (albeit with lots of depreciation warnings) and link fine; I haven't really looked into the code to see if I can figure out why it's not working yet, I wanted to post here in case I'm already doing something wrong. I don't have a lot of experience with linking C to C++ code, so that could be the root of my problem. Also, the Makefile was not able to find my installation of SDL2, so I made a small CMakeLists for the project. I think it's unlikely that this would cause an issue, but it certainly could, as I'm pretty new to using CMake.

Bellow is the OS-generated [Mac OSX 10.11.5 Beta (15F31a)] crash log, and my entire test-project. Please let me know if there's any more information I can provide to help fix this.

Problem Report.txt
Test_KISS.zip

Thank you!
Michael

Exception Thrown in Example2 ComboBox in Windows 64 bit / Visual Studio 2015 Ver 1.2.4 + current master

Tried to run example 2 in Visual Studio 2015 Community.

Found if you select anything but the first entry (eg select Baltimore) of the combo box the app crashes with exception thrown by combobox_event function. Appears the bsearch is returning a pointer to unreadable (maybe unallocated memory), haven't managed to diagnose this further.

PS Also noticed that Linker complains of no entry point, easily fixed by setting Linker > System > Subsystem to WINDOWS, not sure if that is intended?

Undefined symbols for x86 - KISS 0.10.6 (sorry!)

Hello!

Sorry for creating another issue here, I hope I'm not becoming bothersome! After upgrading my test project to the latest version of KISS_SDL, 0.10.6, I'm seeing undefined linker errors. Specifically, the following.

Undefined symbols for architecture x86_64:
  "kiss_clean(kiss_array*)", referenced from:
      _main in main.cpp.o
  "kiss_array_new(kiss_array*)", referenced from:
      _main in main.cpp.o
  "kiss_label_new(kiss_label*, kiss_window*, char*, int, int)", referenced from:
      _main in main.cpp.o
  "kiss_button_new(kiss_button*, kiss_window*, char*, int, int)", referenced from:
      _main in main.cpp.o
  "kiss_label_draw(kiss_label*, SDL_Renderer*)", referenced from:
      _main in main.cpp.o
  "kiss_window_new(kiss_window*, kiss_window*, int, int, int, int, int)", referenced from:
      _main in main.cpp.o
  "kiss_button_draw(kiss_button*, SDL_Renderer*)", referenced from:
      _main in main.cpp.o
  "kiss_window_draw(kiss_window*, SDL_Renderer*)", referenced from:
      _main in main.cpp.o
  "kiss_button_event(kiss_button*, SDL_Event*, int*)", referenced from:
      button_event(kiss_button*, SDL_Event*, int*, int*) in main.cpp.o
  "kiss_window_event(kiss_window*, SDL_Event*, int*)", referenced from:
      _main in main.cpp.o
  "kiss_init(char*, kiss_array*, int, int)", referenced from:
      _main in main.cpp.o
ld: symbol(s) not found for architecture x86_64

In my main.cpp, changing

#include "kiss_sdl.h

to

extern "C" {
#include "kiss_sdl.h"
}

fixes the issues, and the project then builds, links, and runs as expected. Adding the following back to the header fixed this for me.

#ifdef __cplusplus
extern "C" {
#endif

...

#ifdef __cplusplus
};
#endif

Here's a pull request to add the above definition back to kiss_sdl.h, but please ignore it if there are better ways!

Sorry for creating so many issues! Please let me know if you'd appreciate some radio silence, or if I need to learn a bit more about how to use my compiler, or something. Thank you for the support!

Have kiss_sdl use an existing SDL_Renderer?

It seems kiss_init creates an entirely new SDL_Window along with it's SDL_Renderer and all that.
But how would I use this for e.g a game UI where they it should be on the same window?

SDL2 and KISS_SDL linking on macOS

I don't know by now what to do with it, so i created this issue myself. It was posted in Satck Overflow https://stackoverflow.com/questions/69351191/sdl2-and-kiss-sdl-trouble-linking-on-macos

The SDL include files are not used to be under SDL2 for MSVC and Mac, thus so far the code has worked for these using MSVC or Mac. But now for the first time someone had a problem who uses Mac and has SDL include files under SDL2. I'm willing to fix it if it is an issue, but i don't know by now what to do, if there were some compiler macros for that case, then i could use them. Otherwise i don't know by now when and for what compiler are the SDL libraries installed under SDL2 in Mac, and when they are not.

In Mac, the include files and libraries for linking are determined by framework. The framework for SDL2 should thus provide the include files and libraries, and there is no need for specifying SDL2 directory. In what case is it different and how to find it out is by now not certain. I don't have Mac, so i cannot find out whether it was just a result of wrongly installing the framework, some who have Mac may help. So i will leave this issue open until this becomes clear, and it can be decided whether there is a need to make any change or not.

By now the solution for these who may encounter that problem, is to edit kiss_makefile and add -U__APPLE__ to CFLAGS , this should prevent defining the macro __APPLE__ , if that solves it. The last option is to manually edit kiss_sdl.h file, but it may not go so far. Sorry for inconvenience in that case. I have thought to add a Python build script to the project, that may solve such unexpected issues, but because it adds an additional dependency on Python, i have so far avoided that.

Typo found

Just starting into the code so I understand it. I like it! I need to create a number of custom widgets for process control displays and this looks like a good basis to start with.

Anyway, on Line 515 of kiss_widgets.c there appears to be a typo in the function name:

int kiss_p[r]ogressbar_draw(...

/phil

Duplicate definitions in kiss_sdl.h

Hello!

Sorry to raise another issue here, but I'm having trouble using KISS_SDL with C++. Specifically, when linking the example code from page 4 of the manual, several duplicate symbol linker errors pop up. I asked about this on StackOverflow, and the answer I got seemed to suggest that the header does actually contain duplicate variable definitions. As a preliminary test, I commented out a few of the duplicate variables from kiss_sdl.h, and several of the linker errors were solved. I'm going to do some digging to see if I can do something about this without modifying the library, but I wanted to bring your attention to it, in case the header or manual needs to be modified.

For reference, the StackOverflow question is here, please see it for specifics.

Thank you!
Michael

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.