Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 13 Nov 2018, 01:08
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Unbloated coding resources
Post new topic   Reply to topic View previous topic :: View next topic
Page 4 of 4 [53 Posts]   Goto page: Previous 1, 2, 3, 4
Author Message
vovchik


Joined: 23 Oct 2006
Posts: 1469
Location: Ukraine

PostPosted: Mon 23 Jul 2018, 11:35    Post subject:  

Dear technosaurus,

You are always doing useful and interesting things. Thanks. I learn from your code...

With kind regards,
vovchik
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4841
Location: Blue Springs, MO

PostPosted: Sat 11 Aug 2018, 01:45    Post subject:  

Many of the projects I have linked are single header C libraries, while others are one header file and one .c file. These work a bit different than the traditional C project.

Normally a compiler command line would look something like

$CC main.c -lmylib

For the 2-file projects (1 *.h and *.c file), the header is used just as in any other context, but it its possible to use the *.c file (or even its compiled object file) where one would normally link in a library. (Let me know if this description isn't clear enough)

Ex. $CC main.c mylib.c

The single header libraries are slightly different. You still use it as a regular header file, but it contains a conditionally compiled section that is the equivalent of the *.c file. This must be compiled once and only once by defining the appropriate macro in an appropriate place. You can either define the macro before its #include in the source or use the command line.

Ex. $CC -DMYLIB_IMPLEMENTATION main.c

Here is a basic template for single header c libraries
Code:
//filename.h
//author, copyright
//license
//description, etc...

#ifndef FILENAME_H
#define FILENAME_H

//Define feature test macros
#define _GNU_SOURCE 1

//local includes
#include "my_other_header.h"

//global includes
#include <stdio.h>

//Define config macros
#define Y(...) __VA_ARGS__
#define N(...)
//Followed by config by config options
#define USE_FOO Y
#define USE_BAR N

//Pragmas?

//Constant macros
#define PI 3.14f

//function-like macros
#define X(...) __VA_ARGS__

//enums
enum {A,B,C};

//forward struct declarations
struct G;

//forward typedef declarations;
typedef struct G G;

//typedefs
typedef unsigned char u8;

//struct definitions
struct G {int a,b,c;};

//external variables
extern int extern_global_int;

//function prototypes

//externally visible static inline functions

#endif //FILENAME_H

///above here would go in header (*.h) file, below in C (*.c) file.

#ifdef FILENAME_IMPLEMENTATION
#ifndef FILENAME_IMPLEMENTED
#define  FILENAME_IMPLEMENTED

//Anything above that you don't want to be externally visible can  be here instead

//exported globals: To access, should have corresponding extern in *.h
int global_int; // Are you really sure you need this?

//static (local) variables
static int static_int;

//local function implementations
static inline int get0(void){return 0;}

//exported function implementations
int main_like(int argc, char **argv){
   int x=get0();
   return x;
}
#endif FILENAME_IMPLEMENTED
#endif //FILENAME_IMPLEMENTATION

_________________
Check out my github repositories. I may eventually get around to updating my blogspot.
Back to top
View user's profile Send private message Visit poster's website 
lmemsm

Joined: 27 Jun 2012
Posts: 17

PostPosted: Sat 25 Aug 2018, 11:50    Post subject: picogl  

technosaurus wrote:
FWIW I never tracked down the (proprietary?) MorphOS sources either; however, there are a couple of forks with some improvements tinysdgl and picogl IIRC


Some members of the Syllable forum did a comparison of the various forks of tinygl and recommended picogl. I started with the source for it and added some features from other forks. I've been working on adding new features to the code to improve OpenGL compatibility as time allows. I can get Emilia pinball working with it. If anyone's interested, I'd love to compare notes on updating picogl and improving it.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4841
Location: Blue Springs, MO

PostPosted: Sun 26 Aug 2018, 02:43    Post subject: Re: picogl  

lmemsm wrote:
If anyone's interested, I'd love to compare notes on updating picogl and improving it.
Do you have a github project page?
_________________
Check out my github repositories. I may eventually get around to updating my blogspot.
Back to top
View user's profile Send private message Visit poster's website 
lmemsm

Joined: 27 Jun 2012
Posts: 17

PostPosted: Mon 27 Aug 2018, 08:33    Post subject: Re: picogl  

technosaurus wrote:
Do you have a github project page?


I do, but I really don't use it much. You'll find links to what I'm working on here for now:
http://www.distasis.com/cpp/lmports.htm

Haven't uploaded my picogl modifications yet, because I'm in the middle of making some further changes.

I'm trying to see if I can do anything to improve texture-mapping, but haven't had much luck so far. I did add some basic support for color blending. I'm also using it with GL_FEATURE_RENDER_BITS = 32 so that alpha blending works. I have SDL 2.x back-end support (as well as the SDL 1.x support which was already available) so I can use it with any systems that work with either version of SDL. Was just investigating an issue with RGB settings. If I run the gears demo program with picogl the colors look similar to white/yellow/cyan. The OpenGL glxgears demo has colors red/green/blue. I tried running the picogl gears example program with an OpenGL backend instead of picogl and the colors are still white/yellow/cyan. Am wondering if it's some kind of endian issue with color conversion. With all the different projects and lightweight operating systems that experimented with tinygl or picogl, I'm finding it hard to believe no one would have noticed an issue like that before. Has anyone else ever noticed this? Going to see if I can make the colors better match what I see with OpenGL and then will try to upload what I have to date.
Back to top
View user's profile Send private message 
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 8705
Location: Perth, Western Australia

PostPosted: Wed 29 Aug 2018, 07:35    Post subject:  

The developer of LittlevGL has put a "help wanted" flag on one of the issues, "need evdev mouse and keyboard":

https://github.com/littlevgl/lvgl/issues

I recently started to use LittlevGL, after technosaurus advised a list of contenders for GUI apps running on Linux framebuffer.

I narrowed it down to LittlevGL (LVGL), and found it to be very nice, capable of creating very small static apps, that I compiled with uClibc and musl.

Extremely efficient handling of fonts and images, with no external library deps, only libc/uclibc/musl. Or, SDL if you want to create desktop apps.

I did run into a limitation running on Linux, as LVGL is designed for embedded systems, with tiny RTOSs or no RTOS, and typically a keypad or touch-screen.

On Linux, without X (and SDL), the framebuffer can be used for display, and the mouse via evdev.

However, keyboard input via evdev is not functioning, hence the issue that I started on the author's github site. I started to suggest possible code for initializing evdev for both mouse, touchpad, and keyboard, but that's as far as I got.

If anyone feels inspired to take this up, please do!!!

Here is my last blog post, preliminary evaluation of LVGL:

http://bkhome.org/news/201808/littlevgl-evaluation-part-3.html

I have created a password-entry app with custom on-screen keyboard, quite easy to write, haven't posted to blog about it yet. So far it only works with the mouse, and requires hard-coded /dev/input/event0 -- hence my start to autodetect the evdev devices.

_________________
http://bkhome.org/news/
Back to top
View user's profile Send private message Visit poster's website 
lmemsm

Joined: 27 Jun 2012
Posts: 17

PostPosted: Thu 30 Aug 2018, 08:09    Post subject:  

BarryK wrote:
I narrowed it down to LittlevGL (LVGL), and found it to be very nice, capable of creating very small static apps, that I compiled with uClibc and musl.

Extremely efficient handling of fonts and images, with no external library deps, only libc/uclibc/musl. Or, SDL if you want to create desktop apps.


Was reading your blog comments on LittlevGL a few days ago. Am always looking for a good lightweight cross-platform GUI. Was wondering how LVGL compares to using SDL with PDcurses for a GUI. Version 1.2.15 of SDL has framebuffer support. (Version 2.x only works in framebuffer with DirectFB. Keep wondering if an OpenGL backend might be an alternative on some systems though.) PDCurses has a SDL backend that lets you still use the graphics capabilities of SDL along with the text (TUI) capabilities of curses. There are ports of BSD libmenu and libform that work with PDCurses as well. Fonts can be bitmap or TrueType (using SDL2_ttf with SDL 1.x or 2.x). I'm guessing LVGL is probably much more compact than using multiple libraries. Was just wondering about how the capabilities (what kind of user interfaces you can create/support) compared. Am also curious about what you thought of the LVGL API. Is it easy to learn and work with? Thanks.

Was also wondering if any of the keyboard code from Android (which also uses the Linux kernel) might be useful for LVGL. The android_native_app_glue.c gives one example of how keyboard input could be handled and the system code behind it is available as Open Source from Google.
Back to top
View user's profile Send private message 
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 8705
Location: Perth, Western Australia

PostPosted: Thu 30 Aug 2018, 21:08    Post subject:  

lmemsm wrote:
BarryK wrote:
I narrowed it down to LittlevGL (LVGL), and found it to be very nice, capable of creating very small static apps, that I compiled with uClibc and musl.

Extremely efficient handling of fonts and images, with no external library deps, only libc/uclibc/musl. Or, SDL if you want to create desktop apps.


Was reading your blog comments on LittlevGL a few days ago. Am always looking for a good lightweight cross-platform GUI. Was wondering how LVGL compares to using SDL with PDcurses for a GUI. Version 1.2.15 of SDL has framebuffer support. (Version 2.x only works in framebuffer with DirectFB. Keep wondering if an OpenGL backend might be an alternative on some systems though.) PDCurses has a SDL backend that lets you still use the graphics capabilities of SDL along with the text (TUI) capabilities of curses. There are ports of BSD libmenu and libform that work with PDCurses as well. Fonts can be bitmap or TrueType (using SDL2_ttf with SDL 1.x or 2.x). I'm guessing LVGL is probably much more compact than using multiple libraries. Was just wondering about how the capabilities (what kind of user interfaces you can create/support) compared. Am also curious about what you thought of the LVGL API. Is it easy to learn and work with? Thanks.

Was also wondering if any of the keyboard code from Android (which also uses the Linux kernel) might be useful for LVGL. The android_native_app_glue.c gives one example of how keyboard input could be handled and the system code behind it is available as Open Source from Google.


I don't know anything about PDCurses, but with SDL it would have to be much bigger final size.

With LGVL, I created just over 200KB static executable, that's with all the modules included, for every type of widget. Using a generic makefile that is pulling in everything:

Code:
pntr_20x32_img.o show_36x32_img.o show_not_36x32_img.o lv_group.o lv_indev.o lv_obj.o lv_refr.o lv_style.o lv_vdb.o lv_hal_disp.o lv_hal_indev.o lv_hal_tick.o lv_bar.o lv_cb.o lv_ddlist.o lv_kb.o lv_line.o lv_mbox.o lv_roller.o lv_tabview.o lv_btn.o lv_chart.o lv_gauge.o lv_label.o lv_list.o lv_slider.o lv_ta.o lv_btnm.o lv_cont.o lv_img.o lv_led.o lv_lmeter.o lv_page.o lv_sw.o lv_win.o lv_font_dejavu_10.o lv_font_dejavu_20.o lv_font_dejavu_30.o lv_font_dejavu_40.o lv_font_dejavu_10_cyrillic.o lv_font_dejavu_20_cyrillic.o lv_font_dejavu_30_cyrillic.o lv_font_dejavu_40_cyrillic.o lv_font_dejavu_10_latin_sup.o lv_font_dejavu_20_latin_sup.o lv_font_dejavu_30_latin_sup.o lv_font_dejavu_40_latin_sup.o lv_font_symbol_10.o lv_font_symbol_20.o lv_font_symbol_30.o lv_font_symbol_40.o lv_font.o lv_circ.o lv_area.o lv_task.o lv_fs.o lv_anim.o lv_mem.o lv_ll.o lv_color.o lv_txt.o lv_ufs.o lv_trigo.o lv_math.o lv_theme_alien.o lv_theme.o lv_theme_default.o lv_theme_night.o lv_theme_templ.o lv_theme_zen.o lv_theme_material.o lv_draw_vbasic.o lv_draw.o lv_draw_rbasic.o fbdev.o monitor.o R61581.o SSD1963.o ST7565.o FT5406EE8.o keyboard.o mouse.o evdev.o XPT2046.o main.o


The LVGL docs say that complete executables may be only about 40 - 50KB.

Regarding the ease of programming, I was very pleasantly surprised. There is an online tool for converting images in C-arrays, that can be included in the program, which I have done in this program:

Code:
#include "lvgl/lvgl.h"
#include "lv_drivers/display/fbdev.h"
#include "lv_drivers/indev/evdev.h"
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

/*images*/
extern const lv_img_t pntr_img;
extern const lv_img_t show_img;
extern const lv_img_t show_not_img;
lv_obj_t *show_obj;
lv_obj_t *label3;

//Add a display for the LittlevGL using the frame buffer driver
void register_display(void)
{
   lv_disp_drv_t disp_drv;
   lv_disp_drv_init(&disp_drv);
   disp_drv.disp_flush = fbdev_flush;      //It flushes the internal graphical buffer to the frame buffer
   lv_disp_drv_register(&disp_drv);
}

static lv_res_t btn3_click_action(lv_obj_t * btn)
{
    uint8_t id = lv_obj_get_free_num(btn);
    printf("Button %d is released\n", id);
//   lv_img_set_src(show_obj, &show_not_img);
   lv_label_set_text(label3, "Hide");
    /* The button is released.
     * Make something here */
    return LV_RES_OK; /*Return OK if the button is not deleted*/
}

static lv_res_t ok_action_func(lv_obj_t * btn)
{
   exit(0);
}

int main(void)
{
    /*LittlevGL init*/
    lv_init();

    /*Linux frame buffer device init*/
    fbdev_init();

    // get a display
   register_display();
   
   // enable event input
   evdev_init();
   
   // get an input device like mouse
   lv_indev_drv_t indev_drv;
   lv_indev_drv_init(&indev_drv);
   indev_drv.type = LV_INDEV_TYPE_POINTER;
   indev_drv.read = evdev_read;
    lv_indev_t * mouse_indev = lv_indev_drv_register(&indev_drv);
   /*need an image for the mouse*/
    lv_obj_t * cursor_obj =  lv_img_create(lv_scr_act(), NULL); /*Create an image for the cursor */
    //lv_img_set_src(cursor_obj, SYMBOL_GPS);                 /*For simlicity add a built in symbol not an image*/
    lv_img_set_src(cursor_obj, &pntr_img);
    lv_indev_set_cursor(mouse_indev, cursor_obj); /* connect the object to the driver*/
   
   /*Create a title label*/
   lv_obj_t *label1 = lv_label_create(lv_scr_act(), NULL);
   lv_label_set_text(label1, "Title text here");
   lv_obj_align(label1, NULL, LV_ALIGN_IN_TOP_MID, 0, 5);
   
   /*create map for custom kbd*/
   /*ref: https://littlevgl.com/object-types/button-matrix-lv_btnm*/
   const char *map1[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "\n",
                        "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "\n",
                        "a", "s", "d", "f", "g", "h", "j", "k", "l", "\n",
                        "z", "x", "c", "v", "b", "n", "m", "Del", SYMBOL_OK, ""};
   
   /*create a keyboard*/
   lv_obj_t *kb = lv_kb_create(lv_scr_act(), NULL);
   lv_kb_set_cursor_manage(kb, true);
   /*create a custom kbd*/
   lv_kb_set_map(kb, map1);
   /*action when click ok button*/
   lv_kb_set_ok_action(kb, ok_action_func);

   /*Create a one lined text area with password mode*/
   lv_obj_t * ta2 = lv_ta_create(lv_scr_act(), NULL);
   lv_obj_set_size(ta2, 100, 20);
   lv_obj_align(ta2, label1, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
/*Apply the background style*/
   lv_ta_set_one_line(ta2, true);
   lv_ta_set_cursor_type(ta2, LV_CURSOR_LINE);
   lv_ta_set_pwd_mode(ta2, true);
   lv_ta_set_text(ta2, "");
   /*Assign the text area to the keyboard*/
   lv_kb_set_ta(kb, ta2);
   
   /*create a group for keyboard input*/
   lv_group_t *group2 = lv_group_create();
   lv_group_add_obj(group2, ta2);
   /*evdev to handle kb input*/
   lv_indev_drv_t kb_drv;
   lv_indev_drv_init(&kb_drv);
   kb_drv.type = LV_INDEV_TYPE_KEYPAD;
   kb_drv.read = evdev_read;
   /*assign kb to group*/
   lv_indev_t *kb_indev = lv_indev_drv_register(&kb_drv);
   lv_indev_set_group(kb_indev, group2);
   /*set focus on ta2*/
   lv_group_focus_obj(ta2);
   lv_group_focus_freeze(group2, true);
   
   /*button to show or hide password*/
   lv_obj_t *btn3 = lv_btn_create(lv_scr_act(), NULL);
   lv_cont_set_fit(btn3, true, true); /*Enable resizing horizontally and vertically*/
   lv_obj_align(btn3, ta2, LV_ALIGN_OUT_RIGHT_MID, 10, 0);
   lv_obj_set_free_num(btn3, 3);   /*Set a unique number for the button*/
   lv_btn_set_action(btn3, LV_BTN_ACTION_CLICK, btn3_click_action);
   label3 = lv_label_create(btn3, NULL);
   lv_label_set_text(label3, "Show");
//   show_obj =  lv_img_create(btn3, NULL); /*Create an image for the button */
//   lv_img_set_src(show_obj, &show_img);

   /*Handle LitlevGL tasks (tickless mode)*/
    while(1)
   {
        lv_tick_inc(5);
        lv_task_handler();
        usleep(5000);
    }

    return 0;
}


...a work-in-progress, as I was trying to get keyboard to work. Mouse works. There is a default keyboard, but I created a custom one. Also created a custom image for the mouse pointer.

With just a bit of practice, I found the api very simple and logical.

Re buttons, images on buttons not yet supported. That is scheduled for version 5.2.

_________________
http://bkhome.org/news/
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 4 of 4 [53 Posts]   Goto page: Previous 1, 2, 3, 4
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1071s ][ Queries: 12 (0.0156s) ][ GZIP on ]