!30 Remove audio, optimize header guard

!30 Remove audio, optimize header guard
This commit is contained in:
idea4good 2020-10-15 12:25:58 +08:00
parent d4fe9e584f
commit 7512f9ecfe
26 changed files with 42 additions and 769 deletions

342
GuiLite.h
View File

@ -1,5 +1,4 @@
#ifndef GUILITE_CORE_INCLUDE_API_H
#define GUILITE_CORE_INCLUDE_API_H
#pragma once
#define REAL_TIME_TASK_CYCLE_MS 50
#define MAX(a,b) (((a)>(b))?(a):(b))
@ -103,9 +102,6 @@ public:
int m_right;
int m_bottom;
};
#endif
#ifndef GUILITE_CORE_INCLUDE_CMD_TARGET_H
#define GUILITE_CORE_INCLUDE_CMD_TARGET_H
#define MSG_TYPE_INVALID 0xFFFF
#define MSG_TYPE_WND 0x0001
#define MSG_TYPE_USR 0x0002
@ -223,9 +219,6 @@ private:
static unsigned short ms_user_map_size;
GL_DECLARE_MESSAGE_MAP()
};
#endif
#ifndef GUILITE_CORE_INCLUDE_RESOURCE_H
#define GUILITE_CORE_INCLUDE_RESOURCE_H
//BITMAP
typedef struct struct_bitmap_info
{
@ -247,9 +240,6 @@ typedef struct struct_font_info
unsigned int count;
LATTICE* lattice_array;
} FONT_INFO;
#endif
#ifndef GUILITE_CORE_INCLUDE_THEME_H
#define GUILITE_CORE_INCLUDE_THEME_H
typedef struct struct_font_info FONT_INFO;
typedef struct struct_color_rect COLOR_RECT;
typedef struct struct_bitmap_info BITMAP_INFO;
@ -356,9 +346,6 @@ private:
static const BITMAP_INFO* s_bmp_map[BITMAP_MAX];
static unsigned int s_color_map[COLOR_MAX];
};
#endif
#ifndef GUILITE_CORE_INCLUDE_DISPLAY_H
#define GUILITE_CORE_INCLUDE_DISPLAY_H
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
@ -945,9 +932,6 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1
m_phy_write_index++;
return 0;
}
#endif
#ifndef GUILITE_CORE_INCLUDE_WORD_H
#define GUILITE_CORE_INCLUDE_WORD_H
#include <string.h>
#include <stdio.h>
#define BUFFER_LEN 16
@ -1222,9 +1206,6 @@ private:
return utf8_bytes;
}
};
#endif
#ifndef GUILITE_CORE_INCLUDE_BITMAP_H
#define GUILITE_CORE_INCLUDE_BITMAP_H
#define DEFAULT_MASK_COLOR 0xFF080408
class c_surface;
class c_bitmap
@ -1309,9 +1290,6 @@ public:
}
}
};
#endif
#ifndef GUILITE_CORE_INCLUDE_WND_H
#define GUILITE_CORE_INCLUDE_WND_H
typedef struct struct_font_info FONT_INFO;
typedef struct struct_color_rect COLOR_RECT;
class c_wnd;
@ -1774,25 +1752,6 @@ private:
c_wnd(const c_wnd &win);
c_wnd& operator=(const c_wnd &win);
};
#endif
#ifndef GUILITE_CORE_INCLUDE_AUDIO_H
#define GUILITE_CORE_INCLUDE_AUDIO_H
enum AUDIO_TYPE
{
AUDIO_HEART_BEAT,
AUDIO_ALARM,
AUDIO_MAX
};
class c_audio
{
public:
static int play(AUDIO_TYPE type);
private:
static void init();
};
#endif
#ifndef GUILITE_WIDGETS_INCLUDE_BUTTON_H
#define GUILITE_WIDGETS_INCLUDE_BUTTON_H
#define GL_BN_CLICKED 0x1111
#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)},
typedef struct struct_bitmap_info BITMAP_INFO;
@ -1878,9 +1837,6 @@ protected:
return c_wnd::on_navigate(key);
}
};
#endif
#ifndef GUILITE_WIDGETS_INCLUDE_DIALOG_H
#define GUILITE_WIDGETS_INCLUDE_DIALOG_H
class c_surface;
class c_dialog;
typedef struct
@ -1989,9 +1945,6 @@ private:
}
static DIALOG_ARRAY ms_the_dialogs[SURFACE_CNT_MAX];
};
#endif
#ifndef GUILITE_WIDGETS_INCLUDE_KEYBOARD_H
#define GUILITE_WIDGETS_INCLUDE_KEYBOARD_H
#include <string.h>
//Changing key width/height will change the width/height of keyboard
#define KEY_WIDTH 65
@ -2206,9 +2159,6 @@ protected:
c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr);
}
};
#endif /* KEYBOARD_H_ */
#ifndef GUILITE_WIDGETS_INCLUDE_EDIT_H
#define GUILITE_WIDGETS_INCLUDE_EDIT_H
#include <string.h>
#define MAX_EDIT_STRLEN 32
#define IDD_KEY_BOARD 0x1
@ -2394,9 +2344,6 @@ private:
char m_str_input[MAX_EDIT_STRLEN];
char m_str[MAX_EDIT_STRLEN];
};
#endif
#ifndef GUILITE_WIDGETS_INCLUDE_LABEL_H
#define GUILITE_WIDGETS_INCLUDE_LABEL_H
class c_label : public c_wnd
{
public:
@ -2419,9 +2366,6 @@ protected:
m_font_type = c_theme::get_font(FONT_DEFAULT);
}
};
#endif
#ifndef GUILITE_WIDGETS_INCLUDE_LIST_BOX_H
#define GUILITE_WIDGETS_INCLUDE_LIST_BOX_H
#include <string.h>
#define MAX_ITEM_NUM 4
#define GL_LIST_CONFIRM 0x1
@ -2639,9 +2583,6 @@ private:
c_rect m_list_wnd_rect; //rect relative to parent wnd.
c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer)
};
#endif
#ifndef GUILITE_WIDGETS_INCLUDE_SLIDE_GROUP_H
#define GUILITE_WIDGETS_INCLUDE_SLIDE_GROUP_H
#include <stdlib.h>
#define MAX_PAGES 5
class c_gesture;
@ -2977,9 +2918,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action)
}
}
}
#endif
#ifndef GUILITE_WIDGETS_INCLUDE_SPINBOX_H
#define GUILITE_WIDGETS_INCLUDE_SPINBOX_H
#define ID_BT_ARROW_UP 0x1111
#define ID_BT_ARROW_DOWN 0x2222
#define GL_SPIN_CHANGE 0x3333
@ -3066,9 +3004,6 @@ inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action)
}
c_button::on_touch(x, y, action);
}
#endif
#ifndef GUILITE_WIDGETS_INCLUDE_TABLE_H
#define GUILITE_WIDGETS_INCLUDE_TABLE_H
#define MAX_COL_NUM 30
#define MAX_ROW_NUM 30
class c_table: public c_wnd
@ -3167,9 +3102,6 @@ protected:
unsigned int m_row_height[MAX_ROW_NUM];
unsigned int m_col_width[MAX_COL_NUM];
};
#endif
#ifndef GUILITE_WIDGETS_INCLUDE_WAVE_BUFFER_H
#define GUILITE_WIDGETS_INCLUDE_WAVE_BUFFER_H
#include <string.h>
#include <stdio.h>
#define WAVE_BUFFER_LEN 1024
@ -3277,9 +3209,6 @@ private:
short m_read_cache_sum;
unsigned int m_refresh_sequence;
};
#endif
#ifndef GUILITE_WIDGETS_INCLUDE_WAVE_CTRL_H
#define GUILITE_WIDGETS_INCLUDE_WAVE_CTRL_H
#include <stdlib.h>
#include <string.h>
#define CORRECT(x, high_limit, low_limit) {\
@ -3522,7 +3451,6 @@ private:
unsigned char m_frame_len_map[64];
unsigned char m_frame_len_map_index;
};
#endif
#ifdef GUILITE_ON
GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX];
unsigned short c_cmd_target::ms_user_map_size;
@ -4373,274 +4301,6 @@ int c_fifo::write(void* buf, int len)
#endif
#endif
#ifdef GUILITE_ON
#if (defined __linux__) || (defined __APPLE__)
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <pthread.h>
#include <stdio.h>
typedef void(*ANDROID_PLAY_WAV)(const char* fileName);
ANDROID_PLAY_WAV gAndroidPlayWav;
typedef struct
{
AUDIO_TYPE type;
}AUDIO_REQUEST;
static c_fifo s_request_fifo;
static void* render_thread(void* param)
{
while (true)
{
AUDIO_REQUEST request;
s_request_fifo.read(&request, sizeof(request));
if (AUDIO_MAX <= request.type)
{
continue;
}
if(gAndroidPlayWav)
{
gAndroidPlayWav("heart_beat.wav");
}
}
}
void c_audio::init()
{
static bool s_flag = false;
if (s_flag)
{
return;
}
unsigned long pid;
create_thread(&pid, 0, render_thread, 0);
s_flag = true;
}
int c_audio::play(AUDIO_TYPE type)
{
if (AUDIO_MAX <= type)
{
return -1;
}
init();
AUDIO_REQUEST request;
request.type = type;
s_request_fifo.write(&request, sizeof(request));
return 0;
}
#endif
#endif
#ifdef GUILITE_ON
#if (defined _WIN32) || (defined WIN32) || (defined _WIN64) || (defined WIN64)
#include <windows.h>
#include <Audioclient.h>
#include <mmdeviceapi.h>
#ifndef AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM
#define AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM 0x80000000
#endif
#define AUDIO_CHANNELS_MONO 1
#define AUDIO_SAMPLE_RATE 44000
#define AUDIO_BITS 16
#define AUDIO_BLOCK_ALIGN (AUDIO_CHANNELS_MONO * (AUDIO_BITS >> 3))
#define AUDIO_BYTE_RATE (AUDIO_SAMPLE_RATE * AUDIO_BLOCK_ALIGN)
#define AUDIO_OUTPUT_BUF_LEN (10000000 * 5) //5 seconds long.
#define CHECK_ERROR(ret) if(ret != 0){ASSERT(false);}
typedef struct
{
AUDIO_TYPE type;
}AUDIO_REQUEST;
typedef struct
{
BYTE* p_data;
int size;
}WAV_RESOURCE;
static WAV_RESOURCE s_wav_resource[AUDIO_MAX];
static c_fifo s_request_fifo;
static IAudioClient* s_audio_client;
static IAudioRenderClient* s_audio_render_client;
static HANDLE s_audio_event;
//Should be call by UWP, and UWP create audio client.
void set_audio_client(IAudioClient* audio_client)
{
s_audio_client = audio_client;
}
static WAVEFORMATEX s_wav_format = {
WAVE_FORMAT_PCM,
AUDIO_CHANNELS_MONO,
AUDIO_SAMPLE_RATE,
AUDIO_BYTE_RATE,
AUDIO_BLOCK_ALIGN,
AUDIO_BITS,
0
};
static int register_wav_resouce(AUDIO_TYPE type, const wchar_t* wav_path)
{
if (s_wav_resource[type].p_data)
{
return 0;
}
void* hFile = CreateFile(wav_path, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (INVALID_HANDLE_VALUE == hFile)
{
log_out("Open wave file failed\n");
return -1;
}
LARGE_INTEGER ret;
GetFileSizeEx(hFile, &ret);
int size = ret.LowPart;
if (INVALID_SET_FILE_POINTER == SetFilePointer(hFile, 0x2C, 0, FILE_BEGIN))
{
ASSERT(false);
return -2;
}
size -= 0x2C;
BYTE* p_data = (BYTE*)malloc(size);
DWORD read_num;
ReadFile(hFile, p_data, size, &read_num, 0);
s_wav_resource[type].p_data = p_data;
s_wav_resource[type].size = size;
return 0;
}
static int load_wav_chunk(BYTE* p_des, int des_size, BYTE* p_src, int src_size)
{
if (des_size <= 0 || src_size <= 0)
{
return -1;
}
int write_size = (src_size > des_size) ? des_size : src_size;
memcpy(p_des, p_src, write_size);
memset(p_des + write_size, 0, (des_size - write_size));
return write_size;
}
static int play_wav(BYTE* p_data, int size)
{
if (0 == p_data || 0 >= size)
{
return -1;
}
UINT32 bufferFrameCount;
UINT32 numFramesAvailable;
UINT32 numFramesPadding;
BYTE* p_buffer = 0;
int ret = s_audio_client->GetBufferSize(&bufferFrameCount);
CHECK_ERROR(ret);
int offset = 0;
while (WaitForSingleObject(s_audio_event, INFINITE) == WAIT_OBJECT_0)
{
ret = s_audio_client->GetCurrentPadding(&numFramesPadding);
CHECK_ERROR(ret);
numFramesAvailable = bufferFrameCount - numFramesPadding;
if (numFramesAvailable < 1600)
{
Sleep(10);
continue;
}
ret = s_audio_render_client->GetBuffer(numFramesAvailable, &p_buffer);
CHECK_ERROR(ret);
ret = load_wav_chunk(p_buffer, numFramesAvailable * s_wav_format.nBlockAlign, p_data + offset, (size - offset));
if (ret > 0)
{
s_audio_render_client->ReleaseBuffer((ret / s_wav_format.nBlockAlign), 0);
offset += ret;
}
else
{
s_audio_render_client->ReleaseBuffer(0, AUDCLNT_BUFFERFLAGS_SILENT);
break;
}
}
return 0;
}
static void* render_thread(void* param)
{
s_audio_client->Start();
while (true)
{
AUDIO_REQUEST request;
s_request_fifo.read(&request, sizeof(request));
if (AUDIO_MAX <= request.type)
{
ASSERT(false);
continue;
}
play_wav(s_wav_resource[request.type].p_data, s_wav_resource[request.type].size);
}
s_audio_client->Stop();
}
static int init_audio_client()
{
if (s_audio_client)
{
return 0;
}
//For desktop only, could not pass Windows Store certification.
/*
int ret = CoInitializeEx(0, COINIT_MULTITHREADED);
CHECK_ERROR(ret);
IMMDeviceEnumerator *pEnumerator = nullptr;
ret = CoCreateInstance(__uuidof(MMDeviceEnumerator), 0,
CLSCTX_ALL, __uuidof(IMMDeviceEnumerator),
(void**)&pEnumerator);
CHECK_ERROR(ret);
IMMDevice* audio_output_device;
pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &audio_output_device);
if (0 == audio_output_device)
{
ASSERT(false);
}
ret = audio_output_device->Activate(__uuidof(IAudioClient), CLSCTX_ALL, 0, (void**)&s_audio_client);
CHECK_ERROR(ret);
return 0;
*/
return -1;
}
void c_audio::init()
{
static bool s_flag = false;
if (s_flag)
{
return;
}
register_wav_resouce(AUDIO_HEART_BEAT, L"heart_beat.wav");
if (0 > init_audio_client())
{
return;
}
int ret = s_audio_client->Initialize(AUDCLNT_SHAREMODE_SHARED,
AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM | AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
AUDIO_OUTPUT_BUF_LEN * 2, 0, &s_wav_format, 0);
CHECK_ERROR(ret);
//s_audio_event = CreateEventEx(0, 0, 0, EVENT_ALL_ACCESS);
s_audio_event = CreateEvent(0, 0, 0, 0);
ret = s_audio_client->SetEventHandle(s_audio_event);
CHECK_ERROR(ret);
ret = s_audio_client->GetService(__uuidof(IAudioRenderClient), (void**)&s_audio_render_client);
CHECK_ERROR(ret);
unsigned long pid;
create_thread(&pid, 0, render_thread, 0);
s_flag = true;
}
int c_audio::play(AUDIO_TYPE type)
{
if (AUDIO_MAX <= type)
{
return -1;
}
init();
if (!s_audio_client || !s_audio_render_client)
{
return -2;
}
AUDIO_REQUEST request;
request.type = type;
s_request_fifo.write(&request, sizeof(request));
return 0;
}
#endif
#endif
#ifdef GUILITE_ON
DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX];
#endif
#ifdef GUILITE_ON

View File

@ -16,8 +16,8 @@
- [中文](README_zh.md)
## Lightweight
- ✂Small: Just under 5,000 lines of C++ and header-only: GuiLite.h
- ⚡Fast: Render a GUI within one invocation, independent of any OS or 3rd party library
- ✂Small: 4,000+ lines of C++ code, zero dependency, header-only(GuiLite.h)
- ⚡Fast: High Rendering performance, even work on MCU
- 💉Embeddable: Runs inside Qt/MFC/Winform/Cocoa/Web - Keep legacy Qt/MFC code reusable
- ⚙Hardware Minimum Requirements:
@ -31,7 +31,7 @@
- Supported 3rd party libraries: Qt, MFC, Winforms, CoCoa...
## Useful features
- 🔣Multi-language, supports UTF-8
- 🔣Multi-language, supports UTF-8;📀Playback Video
- 🔨[Toolkit](https://github.com/idea4good/GuiLiteToolkit) for building font/image resources
- 📐[Layout GUI WYSIWYG](https://github.com/idea4good/GuiLitePreviewer)
- ☁Cloud + IoT Solution
@ -60,7 +60,8 @@ Even a C beginner could master GuiLite quickly. The source code only uses basic
- 🌐[GitHub link](https://github.com/idea4good/GuiLite)
## Demo wall
Click the image you like, and run it on your hardware
- Zero dependency, 100% build pass & runnable
- Click the demo you like, and run it on your hardware
<table>
<tr>
<td align="center"><a href="https://gitee.com/idea4good/GuiLiteSamples/tree/master/Hello3D"><img src="documents/Hello3D.gif" width="200px;"/><br /><sub><b>3D on STM32</b></sub></a>

View File

@ -14,8 +14,8 @@
</p>
## 轻-快-灵
- ✂️轻量: 5千行C++代码单一头文件库GuiLite.h
- ⚡超快: 一次调用就可以完成图形渲染,与操作系统及第三方库无关
- ✂️轻量: 4千行C++代码0依赖单一头文件库GuiLite.h
- ⚡超快: 高效渲染,单片机上也能流畅运行
- 💉灵活: 可注入在Qt/MFC/Winform/Cocoa/Web程序中运行 - 重用现有Qt/MFC代码
- ⚙️️最低硬件要求:
@ -29,7 +29,7 @@
- 支持的第3方库Qt, MFC, Winforms, CoCoa...
## 实用的功能
- 🔣支持多语言,采用 UTF-8 编码
- 🔣支持多语言,采用 UTF-8 编码;📀支持视频播放
- 🔨[资源制作工具](https://github.com/idea4good/GuiLiteToolkit)为你定制自己的字体/图片资源
- 📐[所见即所得的GUI布局工具](https://github.com/idea4good/GuiLitePreviewer)
- ☁️完美的“云” + “物联网”解决方案
@ -58,7 +58,8 @@
- 🌐[GitHub链接](https://github.com/idea4good/GuiLite)
## Demo展示墙
点击你喜欢的实例,并运行在你的硬件上面
- 0依赖100%编译通过,可直接运行
- 点击你喜欢的实例,并运行在你的硬件上面
<table>
<tr>
<td align="center"><a href="https://gitee.com/idea4good/GuiLiteSamples/tree/master/Hello3D"><img src="documents/Hello3D.gif" width="200px;"/><br /><sub><b>3D on STM32</b></sub></a>

View File

@ -1,69 +0,0 @@
#ifdef GUILITE_ON
#if (defined __linux__) || (defined __APPLE__)
#include "../../core_include/api.h"
#include "../../core_include/audio.h"
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <pthread.h>
#include <stdio.h>
typedef void(*ANDROID_PLAY_WAV)(const char* fileName);
ANDROID_PLAY_WAV gAndroidPlayWav;
typedef struct
{
AUDIO_TYPE type;
}AUDIO_REQUEST;
static c_fifo s_request_fifo;
static void* render_thread(void* param)
{
while (true)
{
AUDIO_REQUEST request;
s_request_fifo.read(&request, sizeof(request));
if (AUDIO_MAX <= request.type)
{
continue;
}
if(gAndroidPlayWav)
{
gAndroidPlayWav("heart_beat.wav");
}
}
}
void c_audio::init()
{
static bool s_flag = false;
if (s_flag)
{
return;
}
unsigned long pid;
create_thread(&pid, 0, render_thread, 0);
s_flag = true;
}
int c_audio::play(AUDIO_TYPE type)
{
if (AUDIO_MAX <= type)
{
return -1;
}
init();
AUDIO_REQUEST request;
request.type = type;
s_request_fifo.write(&request, sizeof(request));
return 0;
}
#endif
#endif

View File

@ -1,252 +0,0 @@
#ifdef GUILITE_ON
#if (defined _WIN32) || (defined WIN32) || (defined _WIN64) || (defined WIN64)
#include <windows.h>
#include <Audioclient.h>
#include <mmdeviceapi.h>
#include "../../core_include/api.h"
#include "../../core_include/audio.h"
#ifndef AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM
#define AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM 0x80000000
#endif
#define AUDIO_CHANNELS_MONO 1
#define AUDIO_SAMPLE_RATE 44000
#define AUDIO_BITS 16
#define AUDIO_BLOCK_ALIGN (AUDIO_CHANNELS_MONO * (AUDIO_BITS >> 3))
#define AUDIO_BYTE_RATE (AUDIO_SAMPLE_RATE * AUDIO_BLOCK_ALIGN)
#define AUDIO_OUTPUT_BUF_LEN (10000000 * 5) //5 seconds long.
#define CHECK_ERROR(ret) if(ret != 0){ASSERT(false);}
typedef struct
{
AUDIO_TYPE type;
}AUDIO_REQUEST;
typedef struct
{
BYTE* p_data;
int size;
}WAV_RESOURCE;
static WAV_RESOURCE s_wav_resource[AUDIO_MAX];
static c_fifo s_request_fifo;
static IAudioClient* s_audio_client;
static IAudioRenderClient* s_audio_render_client;
static HANDLE s_audio_event;
//Should be call by UWP, and UWP create audio client.
void set_audio_client(IAudioClient* audio_client)
{
s_audio_client = audio_client;
}
static WAVEFORMATEX s_wav_format = {
WAVE_FORMAT_PCM,
AUDIO_CHANNELS_MONO,
AUDIO_SAMPLE_RATE,
AUDIO_BYTE_RATE,
AUDIO_BLOCK_ALIGN,
AUDIO_BITS,
0
};
static int register_wav_resouce(AUDIO_TYPE type, const wchar_t* wav_path)
{
if (s_wav_resource[type].p_data)
{
return 0;
}
void* hFile = CreateFile(wav_path, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (INVALID_HANDLE_VALUE == hFile)
{
log_out("Open wave file failed\n");
return -1;
}
LARGE_INTEGER ret;
GetFileSizeEx(hFile, &ret);
int size = ret.LowPart;
if (INVALID_SET_FILE_POINTER == SetFilePointer(hFile, 0x2C, 0, FILE_BEGIN))
{
ASSERT(false);
return -2;
}
size -= 0x2C;
BYTE* p_data = (BYTE*)malloc(size);
DWORD read_num;
ReadFile(hFile, p_data, size, &read_num, 0);
s_wav_resource[type].p_data = p_data;
s_wav_resource[type].size = size;
return 0;
}
static int load_wav_chunk(BYTE* p_des, int des_size, BYTE* p_src, int src_size)
{
if (des_size <= 0 || src_size <= 0)
{
return -1;
}
int write_size = (src_size > des_size) ? des_size : src_size;
memcpy(p_des, p_src, write_size);
memset(p_des + write_size, 0, (des_size - write_size));
return write_size;
}
static int play_wav(BYTE* p_data, int size)
{
if (0 == p_data || 0 >= size)
{
return -1;
}
UINT32 bufferFrameCount;
UINT32 numFramesAvailable;
UINT32 numFramesPadding;
BYTE* p_buffer = 0;
int ret = s_audio_client->GetBufferSize(&bufferFrameCount);
CHECK_ERROR(ret);
int offset = 0;
while (WaitForSingleObject(s_audio_event, INFINITE) == WAIT_OBJECT_0)
{
ret = s_audio_client->GetCurrentPadding(&numFramesPadding);
CHECK_ERROR(ret);
numFramesAvailable = bufferFrameCount - numFramesPadding;
if (numFramesAvailable < 1600)
{
Sleep(10);
continue;
}
ret = s_audio_render_client->GetBuffer(numFramesAvailable, &p_buffer);
CHECK_ERROR(ret);
ret = load_wav_chunk(p_buffer, numFramesAvailable * s_wav_format.nBlockAlign, p_data + offset, (size - offset));
if (ret > 0)
{
s_audio_render_client->ReleaseBuffer((ret / s_wav_format.nBlockAlign), 0);
offset += ret;
}
else
{
s_audio_render_client->ReleaseBuffer(0, AUDCLNT_BUFFERFLAGS_SILENT);
break;
}
}
return 0;
}
static void* render_thread(void* param)
{
s_audio_client->Start();
while (true)
{
AUDIO_REQUEST request;
s_request_fifo.read(&request, sizeof(request));
if (AUDIO_MAX <= request.type)
{
ASSERT(false);
continue;
}
play_wav(s_wav_resource[request.type].p_data, s_wav_resource[request.type].size);
}
s_audio_client->Stop();
}
static int init_audio_client()
{
if (s_audio_client)
{
return 0;
}
//For desktop only, could not pass Windows Store certification.
/*
int ret = CoInitializeEx(0, COINIT_MULTITHREADED);
CHECK_ERROR(ret);
IMMDeviceEnumerator *pEnumerator = nullptr;
ret = CoCreateInstance(__uuidof(MMDeviceEnumerator), 0,
CLSCTX_ALL, __uuidof(IMMDeviceEnumerator),
(void**)&pEnumerator);
CHECK_ERROR(ret);
IMMDevice* audio_output_device;
pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &audio_output_device);
if (0 == audio_output_device)
{
ASSERT(false);
}
ret = audio_output_device->Activate(__uuidof(IAudioClient), CLSCTX_ALL, 0, (void**)&s_audio_client);
CHECK_ERROR(ret);
return 0;
*/
return -1;
}
void c_audio::init()
{
static bool s_flag = false;
if (s_flag)
{
return;
}
register_wav_resouce(AUDIO_HEART_BEAT, L"heart_beat.wav");
if (0 > init_audio_client())
{
return;
}
int ret = s_audio_client->Initialize(AUDCLNT_SHAREMODE_SHARED,
AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM | AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
AUDIO_OUTPUT_BUF_LEN * 2, 0, &s_wav_format, 0);
CHECK_ERROR(ret);
//s_audio_event = CreateEventEx(0, 0, 0, EVENT_ALL_ACCESS);
s_audio_event = CreateEvent(0, 0, 0, 0);
ret = s_audio_client->SetEventHandle(s_audio_event);
CHECK_ERROR(ret);
ret = s_audio_client->GetService(__uuidof(IAudioRenderClient), (void**)&s_audio_render_client);
CHECK_ERROR(ret);
unsigned long pid;
create_thread(&pid, 0, render_thread, 0);
s_flag = true;
}
int c_audio::play(AUDIO_TYPE type)
{
if (AUDIO_MAX <= type)
{
return -1;
}
init();
if (!s_audio_client || !s_audio_render_client)
{
return -2;
}
AUDIO_REQUEST request;
request.type = type;
s_request_fifo.write(&request, sizeof(request));
return 0;
}
#endif
#endif

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_CORE_INCLUDE_API_H
#define GUILITE_CORE_INCLUDE_API_H
#pragma once
#define REAL_TIME_TASK_CYCLE_MS 50
#define MAX(a,b) (((a)>(b))?(a):(b))
@ -103,4 +102,3 @@ public:
int m_right;
int m_bottom;
};
#endif

View File

@ -1,19 +0,0 @@
#ifndef GUILITE_CORE_INCLUDE_AUDIO_H
#define GUILITE_CORE_INCLUDE_AUDIO_H
enum AUDIO_TYPE
{
AUDIO_HEART_BEAT,
AUDIO_ALARM,
AUDIO_MAX
};
class c_audio
{
public:
static int play(AUDIO_TYPE type);
private:
static void init();
};
#endif

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_CORE_INCLUDE_BITMAP_H
#define GUILITE_CORE_INCLUDE_BITMAP_H
#pragma once
#include "../core_include/api.h"
#include "../core_include/resource.h"
@ -92,5 +91,3 @@ public:
}
};
#endif

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_CORE_INCLUDE_CMD_TARGET_H
#define GUILITE_CORE_INCLUDE_CMD_TARGET_H
#pragma once
#include "../core_include/api.h"
@ -133,5 +132,3 @@ private:
static unsigned short ms_user_map_size;
GL_DECLARE_MESSAGE_MAP()
};
#endif

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_CORE_INCLUDE_DISPLAY_H
#define GUILITE_CORE_INCLUDE_DISPLAY_H
#pragma once
#include "../core_include/api.h"
#include "../core_include/cmd_target.h"
@ -653,5 +652,3 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1
m_phy_write_index++;
return 0;
}
#endif

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_CORE_INCLUDE_RESOURCE_H
#define GUILITE_CORE_INCLUDE_RESOURCE_H
#pragma once
//BITMAP
typedef struct struct_bitmap_info
@ -24,5 +23,3 @@ typedef struct struct_font_info
unsigned int count;
LATTICE* lattice_array;
} FONT_INFO;
#endif

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_CORE_INCLUDE_THEME_H
#define GUILITE_CORE_INCLUDE_THEME_H
#pragma once
#include "../core_include/api.h"
#include "../core_include/resource.h"
@ -118,5 +117,3 @@ private:
static const BITMAP_INFO* s_bmp_map[BITMAP_MAX];
static unsigned int s_color_map[COLOR_MAX];
};
#endif

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_CORE_INCLUDE_WND_H
#define GUILITE_CORE_INCLUDE_WND_H
#pragma once
#include "../core_include/api.h"
#include "../core_include/cmd_target.h"
@ -524,4 +523,3 @@ private:
c_wnd(const c_wnd &win);
c_wnd& operator=(const c_wnd &win);
};
#endif

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_CORE_INCLUDE_WORD_H
#define GUILITE_CORE_INCLUDE_WORD_H
#pragma once
#include "../core_include/api.h"
#include "../core_include/resource.h"
@ -298,5 +297,3 @@ private:
return utf8_bytes;
}
};
#endif

View File

@ -2,7 +2,7 @@ echo "Build header-only library: GuiLite.h"
# build GuiLiteRaw.h
cd core_include
cat api.h cmd_target.h resource.h theme.h display.h word.h bitmap.h wnd.h audio.h > core.h
cat api.h cmd_target.h resource.h theme.h display.h word.h bitmap.h wnd.h > core.h
mv core.h ../
cd ../widgets_include
@ -11,7 +11,6 @@ mv widgets.h ../
cd ..
cat core.h widgets.h > GuiLiteRaw.h
rm core.h widgets.h
# build GuiLiteRaw.cpp
cd core
@ -28,17 +27,20 @@ mv widgets.cpp ../
cd ..
cat core.cpp adapter.cpp widgets.cpp > GuiLiteRaw.cpp
rm core.cpp adapter.cpp widgets.cpp
# remove include core_include widgets_include from GuiLiteRaw.h
sed '/^#include.*core_include\|widgets_include.*/d' GuiLiteRaw.h > GuiLiteNoInclude.h
sed -i '/^#include.*core_include\|widgets_include.*/d' GuiLiteRaw.h
# remove all #pragma once
sed -i '/^#pragma once/d' GuiLiteRaw.h
# add #pragma once for 1st line
sed -i '1 s/^/#pragma once\n/' GuiLiteRaw.h
# remove include core_include widgets_include from GuiLiteRaw.cpp
sed '/^#include.*core_include\|widgets_include.*/d' GuiLiteRaw.cpp > GuiLiteNoInclude.cpp
sed -i '/^#include.*core_include\|widgets_include.*/d' GuiLiteRaw.cpp
# Delete empty lines or blank lines
sed '/^$/d' GuiLiteNoInclude.h > GuiLite.h
sed '/^$/d' GuiLiteNoInclude.cpp > GuiLite.cpp
sed '/^$/d' GuiLiteRaw.h > GuiLite.h
sed '/^$/d' GuiLiteRaw.cpp > GuiLite.cpp
# Append GuiLite.cpp to GuiLite.h
cat GuiLite.cpp >> GuiLite.h
@ -47,10 +49,10 @@ cat GuiLite.cpp >> GuiLite.h
echo '#include "GuiLite.h"' > test.cpp
gcc -c -D GUILITE_ON test.cpp
# clean
rm GuiLiteRaw.h GuiLiteNoInclude.h GuiLiteRaw.cpp GuiLiteNoInclude.cpp GuiLite.cpp test.cpp
mv GuiLite.h ../
echo "Done!"
echo "You could find GuiLite.h in root folder"
./.sync.sh GuiLite-header
# clean
rm *.h *.cpp *.o

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_WIDGETS_INCLUDE_BUTTON_H
#define GUILITE_WIDGETS_INCLUDE_BUTTON_H
#pragma once
#include "../core_include/api.h"
#include "../core_include/cmd_target.h"
@ -98,5 +97,3 @@ protected:
return c_wnd::on_navigate(key);
}
};
#endif

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_WIDGETS_INCLUDE_DIALOG_H
#define GUILITE_WIDGETS_INCLUDE_DIALOG_H
#pragma once
#include "../core_include/api.h"
#include "../core_include/cmd_target.h"
@ -127,5 +126,3 @@ private:
}
static DIALOG_ARRAY ms_the_dialogs[SURFACE_CNT_MAX];
};
#endif

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_WIDGETS_INCLUDE_EDIT_H
#define GUILITE_WIDGETS_INCLUDE_EDIT_H
#pragma once
#include "../core_include/api.h"
#include "../core_include/cmd_target.h"
@ -199,5 +198,3 @@ private:
char m_str_input[MAX_EDIT_STRLEN];
char m_str[MAX_EDIT_STRLEN];
};
#endif

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_WIDGETS_INCLUDE_KEYBOARD_H
#define GUILITE_WIDGETS_INCLUDE_KEYBOARD_H
#pragma once
#include "../core_include/api.h"
#include "../core_include/resource.h"
@ -238,5 +237,3 @@ protected:
c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr);
}
};
#endif /* KEYBOARD_H_ */

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_WIDGETS_INCLUDE_LABEL_H
#define GUILITE_WIDGETS_INCLUDE_LABEL_H
#pragma once
#include "../core_include/api.h"
#include "../core_include/cmd_target.h"
@ -32,5 +31,3 @@ protected:
m_font_type = c_theme::get_font(FONT_DEFAULT);
}
};
#endif

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_WIDGETS_INCLUDE_LIST_BOX_H
#define GUILITE_WIDGETS_INCLUDE_LIST_BOX_H
#pragma once
#include "../core_include/api.h"
#include "../core_include/cmd_target.h"
@ -234,5 +233,3 @@ private:
c_rect m_list_wnd_rect; //rect relative to parent wnd.
c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer)
};
#endif

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_WIDGETS_INCLUDE_SLIDE_GROUP_H
#define GUILITE_WIDGETS_INCLUDE_SLIDE_GROUP_H
#pragma once
#include "../core_include/api.h"
#include "../core_include/display.h"
@ -361,4 +360,3 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action)
}
}
}
#endif

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_WIDGETS_INCLUDE_SPINBOX_H
#define GUILITE_WIDGETS_INCLUDE_SPINBOX_H
#pragma once
#include "../core_include/api.h"
#include "../core_include/cmd_target.h"
@ -103,4 +102,3 @@ inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action)
}
c_button::on_touch(x, y, action);
}
#endif

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_WIDGETS_INCLUDE_TABLE_H
#define GUILITE_WIDGETS_INCLUDE_TABLE_H
#pragma once
#include "../core_include/api.h"
#include "../core_include/resource.h"
@ -113,4 +112,3 @@ protected:
unsigned int m_row_height[MAX_ROW_NUM];
unsigned int m_col_width[MAX_COL_NUM];
};
#endif

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_WIDGETS_INCLUDE_WAVE_BUFFER_H
#define GUILITE_WIDGETS_INCLUDE_WAVE_BUFFER_H
#pragma once
#include "../core_include/api.h"
#include <string.h>
@ -119,5 +118,3 @@ private:
short m_read_cache_sum;
unsigned int m_refresh_sequence;
};
#endif

View File

@ -1,5 +1,4 @@
#ifndef GUILITE_WIDGETS_INCLUDE_WAVE_CTRL_H
#define GUILITE_WIDGETS_INCLUDE_WAVE_CTRL_H
#pragma once
#include "../core_include/api.h"
#include "../core_include/cmd_target.h"
@ -278,4 +277,3 @@ private:
unsigned char m_frame_len_map[64];
unsigned char m_frame_len_map_index;
};
#endif