📄 px_ls_ui.c
字号:
/* must been first include begin */
#include "..\ProjectX_Common\ProjectX_Copyright.h"
#include "..\ProjectX_Common\ProjectX_Common.h"
/* must been first include end */
/* std and common include */
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
/* program specify include */
#include "..\ProjectX_Common\ProjectX_Utils.h"
#include "px_ls_ui.h"
#include "px_ls_state.h"
#include "px_ls_module_work.h"
#include "px_ls_config.h"
HANDLE h_console = NULL;
WORD watt_prev = 0;
BOOL auto_cls = TRUE;
BOOL display_internal_version = TRUE;
extern char version[];
extern char author[];
extern char last_edit_time[];
extern PX_LS_STATE * g_state;
extern BOOL bln_run_workthread;
void x_ui_init(){
CONSOLE_SCREEN_BUFFER_INFO csbi;
memset(&csbi,0,sizeof(CONSOLE_SCREEN_BUFFER_INFO));
h_console = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(h_console,&csbi);
watt_prev = csbi.wAttributes;
return;
}
void x_ui_display_info(char * tips){
WORD watt = FOREGROUND_GREEN;
if (watt_prev != watt) {
SetConsoleTextAttribute(h_console,watt);
printf("%s\n",tips);
SetConsoleTextAttribute(h_console,watt_prev);
}else{
printf("%s\n",tips);
}
return;
}
void x_ui_display_error(char * tips){
WORD watt = FOREGROUND_RED;
if (watt_prev != watt) {
SetConsoleTextAttribute(h_console,watt);
printf("%s\n",tips);
SetConsoleTextAttribute(h_console,watt_prev);
}else{
printf("%s\n",tips);
}
return;
}
void x_ui_display_developer(char * tips){
#ifdef DEVELOPER
WORD watt = FOREGROUND_RED|FOREGROUND_INTENSITY;
if (watt_prev != watt) {
SetConsoleTextAttribute(h_console,watt);
printf("%s\n",tips);
SetConsoleTextAttribute(h_console,watt_prev);
}else{
printf("%s\n",tips);
}
return;
#else
return;
#endif
}
void x_debug_info(char * tips){
#ifdef DEBUG
WORD watt = FOREGROUND_GREEN;
if (watt_prev != watt) {
SetConsoleTextAttribute(h_console,watt);
printf("%s\n",tips);
SetConsoleTextAttribute(h_console,watt_prev);
}else{
printf("%s\n",tips);
}
return;
#else
return;
#endif
}
void x_debug_error(char * tips){
#ifdef DEBUG
WORD watt = FOREGROUND_RED;
if (watt_prev != watt) {
SetConsoleTextAttribute(h_console,watt);
printf("%s\n",tips);
SetConsoleTextAttribute(h_console,watt_prev);
}else{
printf("%s\n",tips);
}
return;
#else
return;
#endif
}
void px_ls_display_auto_info(){
char buf[FILENAME_MAX] = "";
sprintf(buf,"I am %s",author);
x_ui_display_info(buf);
x_ui_display_info("Loving com_game + com_game_design + software_develop + music + walking");
x_ui_display_info("I just want to make the ProjectX as open source code project");
x_ui_display_info("If you has any interest with it you may contact me");
x_ui_display_info("Homepage : no available current");
x_ui_display_info("Tel : +8613881887433");
x_ui_display_info("Email : XSuns@hotmail.com");
x_ui_display_info("Addr : Jianshe.Road.Chengdu.Sichuan.China");
x_ui_display_info("University : Cust graduated 2003 as a boy");
x_ui_display_info("Age : 25");
x_ui_display_info("Nike_name : MS");
getchar();
return;
}
void px_ls_display_usage(){
x_ui_display_info("Logic Server side help tips:");
x_ui_display_info("Current support command list as bellow:");
x_ui_display_info("cls Usage:[cls] for clear sreen as dos command cls");
x_ui_display_info("exit Usage:[exit] for exit status server");
x_ui_display_info("run_server() Usage:[run_server()] for running status server");
x_ui_display_info("close_server() Usage:[close_server()] for close status server");
x_ui_display_info("set_auto_cls() Usage:[set_auto_cls() on/off] for auto cls on or off");
x_ui_display_info("set_internal_version() Usage:[set_internal_version() on/off] for display internal version");
x_ui_display_info("report_memory_trance_status() Usage:[report_memory_trance_status()] to see memory usage");
x_ui_display_info("report_memory_trance_info() Usage:[report_memory_trance_info()] to see specify memory info");
x_ui_display_info("author_info() Usage:[author_info()] to see author info");
x_ui_display_info("help /? ? Usage:[help or /? or ?] for help info");
x_ui_display_info("for more info contact me(MS)");
getchar();
return;
}
void px_ls_display_logo(){
char cache[FILENAME_MAX] = "";
if (auto_cls) {
system("cls");
}
x_ui_display_info("=================================================");
if (display_internal_version) {
sprintf(cache,"Logic Server internal version == %s",version);
x_ui_display_info(cache);
}
cache[0] = '\0';
EnterCriticalSection(g_state->cts_state);
switch(g_state->curr_state) {
case STATE_MAIN_NO_INIT:
sprintf(cache,"Current logic server state == %s","no_init");
break;
case STATE_MAIN_REQUEST_INIT:
sprintf(cache,"Current logic server state == %s","request_init");
break;
case STATE_MAIN_INIT_DONE:
sprintf(cache,"Current logic server state == %s","init_done");
break;
case STATE_MAIN_RUN:
sprintf(cache,"Current logic server state == %s","run");
break;
case STATE_MAIN_REQUEST_CLOSE:
sprintf(cache,"Current logic server state == %s","request_close");
break;
case STATE_MAIN_CLOSING:
sprintf(cache,"Current logic server state == %s","closing");
break;
case STATE_MAIN_FREE_RESOURCE:
sprintf(cache,"Current logic server state == %s","free_resource");
break;
case STATE_MAIN_ERROR_FOUND:
sprintf(cache,"Current logic server state == %s","error_found");
break;
default:
break;
}
LeaveCriticalSection(g_state->cts_state);
x_ui_display_info(cache);
x_ui_display_info("=================================================");
return;
}
BOOL px_ls_handle_ui_command(char * cmd){
char cache[FILENAME_MAX] = "";
PopLeftString(cmd,cache);
if (strcmp(cache,"cls") ==0) {
system("cls");
}else if (strcmp(cache,"exit") ==0) {
if (valid_ls_state(STATE_MAIN_NO_INIT)) {
bln_run_workthread = FALSE;
Sleep(1000);
return FALSE;
}
}else if (strcmp(cache,"run_server()") ==0) {
if (valid_ls_state(STATE_MAIN_NO_INIT)) {
set_ls_state(STATE_MAIN_REQUEST_INIT);
}
}else if (strcmp(cache,"close_server()") ==0) {
if (valid_ls_state(STATE_MAIN_RUN)) {
set_ls_state(STATE_MAIN_REQUEST_CLOSE);
}
}else if (strcmp(cache,"set_auto_cls()") ==0) {
PopLeftString(cmd,cache);
if (strcmp(cache,"on") ==0) {
auto_cls = TRUE;
}else{
auto_cls = FALSE;
}
}else if (strcmp(cache,"set_internal_version()") ==0) {
PopLeftString(cmd,cache);
if (strcmp(cache,"on") == 0) {
display_internal_version = TRUE;
}else{
display_internal_version = FALSE;
}
}else if (strcmp(cache,"report_memory_trance_status()") ==0) {
report_memory_trance_status();
}else if (strcmp(cache,"report_memory_trance_info()") ==0) {
report_memory_trance_info();
}else if (strcmp(cache,"author_info()") ==0) {
px_ls_display_auto_info();
}else if ((strcmp(cache,"help") == 0)||(strcmp(cache,"?") == 0)||(strcmp(cache,"/?") ==0)) {
px_ls_display_usage();
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -