界面库

This commit is contained in:
2025-08-13 01:17:00 +08:00
parent 103d439f50
commit 7740139b6d
8 changed files with 82 additions and 18 deletions

View File

@@ -6,7 +6,7 @@
#include <sg_main.h>
int main(int argc, char *argv[]) {
sg_init_sdl("test");
sg_main_init("test");
return 0;
}

View File

@@ -22,6 +22,8 @@ LOCAL_C_INCLUDES := \
LOCAL_SRC_FILES := \
sg_widget.c \
sg_main.c \
sg_media.c \
sg_button.c \
# SDL
LOCAL_SHARED_LIBRARIES := SDL2 SDL2_ttf SDL2_net

View File

@@ -0,0 +1,44 @@
#include "sg_media.h"
#include "sg_main.h"
extern sg_main_data *main_data;
sg_media* sg_media_init(sg_rect *rect){
if(main_data == NULL){
printf("没有初始化系统\n");
return NULL;
}
sg_media *media = SDL_malloc(sizeof(sg_media));
SDL_memset(media, 0, sizeof(sg_media));
media->base.show = true;
media->base.rect = SDL_malloc(sizeof(sg_rect));
SDL_memcpy(media->base.rect,rect,sizeof(sg_rect));
media->info = SDL_malloc(sizeof(sg_media_info));
SDL_memset(media->info , 0, sizeof(sg_media_info));
media->video_texture = SDL_CreateTexture(main_data->renderer, SDL_PIXELFORMAT_IYUV,
SDL_TEXTUREACCESS_STREAMING, rect->w, rect->h);
//组件公共函数
}
void sg_media_set_play_file(sg_media *media,char *file_path){
}
void sg_media_get_info(sg_media *media,sg_media_info * info){
}
void sg_media_play(sg_media *media){
}
void sg_media_pause(sg_media *media){
}
void sg_media_stop(sg_media *media){
}

View File

@@ -0,0 +1,22 @@
#ifndef SG_BUTTON_H_
#define SG_BUTTON_H_
#include "sg_widget.h"
#include <stdint.h>
typedef enum sg_button_status {
SG_BUTTON_STATUS_NO_SOURCE = 0x00000000,
SG_BUTTON_STATUS_INITIALIZED = 0x00000001,
SG_BUTTON_STATUS_PLAYING = 0x00000002,
SG_BUTTON_STATUS_PAUSE = 0x00000003,
SG_BUTTON_STATUS_STOP = 0x00000004
} sg_button_status;
typedef struct sg_button {
sg_widget base;
int status;
void (*click)(struct sg_button *src);
} sg_button;
#endif /* SG_BUTTON_H_ */

View File

@@ -2,13 +2,6 @@
#include "sg_main.h"
#include "sg_widget.h"
typedef struct sg_main_data {
sg_rect *rect;
SDL_Window *window;
SDL_Renderer *renderer;
sg_widget *widgets;
} sg_main_data;
sg_main_data *main_data = NULL;
void sg_main_init(char *title) {

View File

@@ -6,16 +6,22 @@
// Swallow GUI
#include "sg_widget.h"
typedef struct sg_main_data {
sg_rect *rect;
SDL_Window *window;
SDL_Renderer *renderer;
sg_widget *widgets;
} sg_main_data;
/**
* 初始化
* @param title
*/
void sg_main_init(char *title);
void sg_main_event_loop();
/**
* 事件循环
*/
void sg_event_loop();
void sg_main_event_loop();
#endif /* SG_MAIN_H_ */

View File

@@ -1,7 +1,5 @@
#ifndef SG_MEDIA_H_
#define SG_MEDIA_H_
#include "sg_media.h"
#include "sg_main.h"
extern sg_main_data *main_data;
@@ -13,8 +11,8 @@ sg_media* sg_media_init(sg_rect *rect){
sg_media *media = SDL_malloc(sizeof(sg_media));
SDL_memset(media, 0, sizeof(sg_media));
media->base.show = true;
media->base->rect = SDL_malloc(sizeof(sg_rect));
SDL_memcpy(media->base->rect,rect,sizeof(sg_rect));
media->base.rect = SDL_malloc(sizeof(sg_rect));
SDL_memcpy(media->base.rect,rect,sizeof(sg_rect));
media->info = SDL_malloc(sizeof(sg_media_info));
SDL_memset(media->info , 0, sizeof(sg_media_info));
@@ -43,6 +41,4 @@ void sg_media_pause(sg_media *media){
void sg_media_stop(sg_media *media){
}
#endif /* SG_MEDIA_H_ */
}

View File

@@ -2,6 +2,7 @@
#define SG_MEDIA_H_
#include "sg_widget.h"
#include <stdint.h>
typedef enum sg_media_status {
SG_MEDIA_STATUS_NO_SOURCE = 0x00000000,