Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Main Page Layout code #727

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 39 additions & 36 deletions src/config/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,18 +392,6 @@ static int parse_int_list(const char *ptr, void *vals, int max_count, int type)
return max_count - count;
}

static void create_element(struct elem *elem, int type, s16 *data)
{
//int x, int y, int src, int e0, int e1, int e2)
ELEM_SET_X(*elem, data[0]);
ELEM_SET_Y(*elem, data[1]);
ELEM_SET_TYPE(*elem, type);
elem->src = data[5];
elem->extra[0] = data[2];
elem->extra[1] = data[3];
elem->extra[2] = data[4];
}

static int layout_ini_handler(void* user, const char* section, const char* name, const char* value)
{
struct Model *m = (struct Model *)user;
Expand All @@ -420,7 +408,7 @@ static int layout_ini_handler(void* user, const char* section, const char* name,
int max = PAGE_GetNumPages();
for(i = 0; i < max; i++) {
if(mapstrcasecmp(PAGE_GetName(i), value) == 0) {
m->pagecfg2.quickpage[idx] = i;
m->quickpage[idx] = i;
return 1;
}
}
Expand All @@ -435,7 +423,7 @@ static int layout_ini_handler(void* user, const char* section, const char* name,
};
if (! MATCH_SECTION(SECTION_GUI)) {
if(MATCH_SECTION("gui-320x240")
&& (! ELEM_USED(Model.pagecfg2.elem[0]) || seen_res != HIRES))
&& (Model.elem[0].type == 0 || seen_res != HIRES))
{
seen_res = LOWRES;
offset_x = (LCD_WIDTH - 320) / 2;
Expand All @@ -444,7 +432,7 @@ static int layout_ini_handler(void* user, const char* section, const char* name,
return 1;
} else {
if (seen_res == LOWRES) {
memset(&Model.pagecfg2.elem, 0, sizeof(Model.pagecfg2.elem));
memset(&Model.elem, 0, sizeof(Model.elem));
}
seen_res = HIRES;
}
Expand All @@ -453,20 +441,22 @@ static int layout_ini_handler(void* user, const char* section, const char* name,
return 1;
#endif
for (idx = 0; idx < NUM_ELEMS; idx++) {
if (! ELEM_USED(Model.pagecfg2.elem[idx]))
if (Model.elem[idx].type == ELEM_NONE)
break;
}

if (idx == NUM_ELEMS) {
printf("No free element available (max = %d)\n", NUM_ELEMS);
return 1;
}

int type;
for (type = 0; type < ELEM_LAST; type++)
for (type = ELEM_NONE + 1; type < ELEM_LAST; type++) {
if(mapstrcasecmp(name, GetElemName(type)) == 0)
break;
}
if (type == ELEM_LAST)
return 1;

int count = 5;
s16 data[6] = {0};
const char *ptr = parse_partial_int_list(value, data, &count, S16);
Expand All @@ -476,12 +466,20 @@ static int layout_ini_handler(void* user, const char* section, const char* name,
printf("Could not parse coordinates from %s=%s\n", name,value);
return 1;
}

struct elem *cur_elem;
cur_elem = &Model.elem[idx];

memset(cur_elem, 0, sizeof(struct elem));
cur_elem->x = data[0];
cur_elem->y = data[1];
cur_elem->type = type;

switch(type) {
//case ELEM_MODEL: //x, y
case ELEM_VTRIM: //x, y, src
case ELEM_HTRIM: //x, y, src
data[5] = data[2];
data[2] = 0;
cur_elem->src = data[2];
break;
case ELEM_SMALLBOX: //x, y, src
case ELEM_BIGBOX: //x. y. src
Expand Down Expand Up @@ -522,7 +520,7 @@ static int layout_ini_handler(void* user, const char* section, const char* name,
}
if (src == -1)
src = 0;
data[5] = src;
cur_elem->src = src;
break;
}
case ELEM_BAR: //x, y, src
Expand All @@ -532,24 +530,28 @@ static int layout_ini_handler(void* user, const char* section, const char* name,
u8 src = get_source(section, ptr);
if (src < NUM_INPUTS)
src = 0;
data[5] = src - NUM_INPUTS;
cur_elem->src = src - NUM_INPUTS;
break;
}
case ELEM_TOGGLE: //x, y, tgl0, tgl1, tgl2, src
{
if(count)
return 1;
cur_elem->extra.ico[0] = data[2];
cur_elem->extra.ico[1] = data[3];
cur_elem->extra.ico[2] = data[4];

for (int j = 0; j <= NUM_SOURCES; j++) {
char cmp[10];
if(mapstrcasecmp(INPUT_SourceNameAbbrevSwitchReal(cmp, j), ptr+1) == 0) {
data[5] = j;
cur_elem->src = j;
break;
}
}
break;
}
}
create_element(&m->pagecfg2.elem[idx], type, data);

return 1;
}

Expand Down Expand Up @@ -1382,12 +1384,13 @@ u8 CONFIG_WriteModel(u8 model_num) {
}
fprintf(fh, "[%s]\n", SECTION_GUI);
for(idx = 0; idx < NUM_ELEMS; idx++) {
if (! ELEM_USED(Model.pagecfg2.elem[idx]))
struct elem *cur_elem = &Model.elem[idx];
if (cur_elem->type == ELEM_NONE)
break;
int src = Model.pagecfg2.elem[idx].src;
int x = ELEM_X(Model.pagecfg2.elem[idx]);
int y = ELEM_Y(Model.pagecfg2.elem[idx]);
int type = ELEM_TYPE(Model.pagecfg2.elem[idx]);
int src = cur_elem->src;
int x = cur_elem->x;
int y = cur_elem->y;
int type = cur_elem->type;
const char *elename = GetElemName(type);
switch(type) {
case ELEM_SMALLBOX:
Expand All @@ -1400,9 +1403,9 @@ u8 CONFIG_WriteModel(u8 model_num) {
break;
case ELEM_TOGGLE:
fprintf(fh, "%s=%d,%d,%d,%d,%d,%s\n", elename, x, y,
Model.pagecfg2.elem[idx].extra[0],
Model.pagecfg2.elem[idx].extra[1],
INPUT_NumSwitchPos(src) == 2 ? 0 : Model.pagecfg2.elem[idx].extra[2],
cur_elem->extra.ico[0],
cur_elem->extra.ico[1],
INPUT_NumSwitchPos(src) == 2 ? 0 : cur_elem->extra.ico[2],
INPUT_SourceNameAbbrevSwitchReal(file, src));
break;
case ELEM_HTRIM:
Expand All @@ -1415,8 +1418,8 @@ u8 CONFIG_WriteModel(u8 model_num) {
}
}
for(idx = 0; idx < NUM_QUICKPAGES; idx++) {
if (WRITE_FULL_MODEL || m->pagecfg2.quickpage[idx]) {
u8 val = m->pagecfg2.quickpage[idx];
if (WRITE_FULL_MODEL || m->quickpage[idx]) {
u8 val = m->quickpage[idx];
fprintf(fh, "%s%d=%s\n", GUI_QUICKPAGE, idx+1, PAGE_GetName(val));
}
}
Expand Down Expand Up @@ -1498,7 +1501,7 @@ u8 CONFIG_ReadModel(u8 model_num) {
if (CONFIG_IniParse(file, ini_handler, &Model)) {
printf("Failed to parse Model file: %s\n", file);
}
if (! ELEM_USED(Model.pagecfg2.elem[0]))
if (Model.elem[0].type == ELEM_NONE)
CONFIG_ReadLayout("layout/default.ini");
if(! PROTOCOL_HasPowerAmp(Model.protocol))
Model.tx_power = TXPOWER_150mW;
Expand Down Expand Up @@ -1625,7 +1628,7 @@ u8 CONFIG_ReadTemplate(const char *filename) {
}

u8 CONFIG_ReadLayout(const char *filename) {
memset(&Model.pagecfg2, 0, sizeof(Model.pagecfg2));
memset(&Model.elem, 0, sizeof(Model.elem));
if (CONFIG_IniParse(filename, layout_ini_handler, &Model)) {
printf("Failed to parse Layout file: %s\n", filename);
return 0;
Expand Down
3 changes: 2 additions & 1 deletion src/config/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ struct Model {
struct Mixer mixers[NUM_MIXERS];
struct Limit limits[NUM_OUT_CHANNELS];
struct Timer timer[NUM_TIMERS];
struct PageCfg2 pagecfg2;
struct elem elem[NUM_ELEMS];
u8 quickpage[NUM_QUICKPAGES];
#if HAS_DATALOG
struct datalog datalog;
#endif
Expand Down
54 changes: 8 additions & 46 deletions src/config/pagecfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,53 +19,19 @@ enum BarSize {
BARS_LAST,
};

struct elem_xy {
struct elem {
u16 x;
u16 y;
};
struct elem_trim {
struct elem_xy pos;
u8 src;
u8 is_vert;
};
struct elem_toggle {
struct elem_xy pos;
u8 src;
u8 ico[3];
};
struct elem_box {
struct elem_xy pos;
u8 src;
u8 type;
};
struct elem_modelico {
struct elem_xy pos;
};
struct elem_bar {
struct elem_xy pos;
u8 src;
union {
// for vert
// u8 is_vert;
// for toggle
u8 ico[3];
}extra;
};

struct elem {
u8 blob[3];
u8 src;
u8 extra[3];
u8 padding_1[1];
};

#define ELEM_X(elem) (*((u32 *)(&(elem))) & 0x1FF)
#define ELEM_Y(elem) ((*((u32 *)(&(elem))) >> 9) & 0x1FF)
#define ELEM_USED(elem) (*((u32 *)(&(elem))) & 0x3FFFF)
#define ELEM_TYPE(elem) ((*((u32 *)(&(elem))) >> 18) & 0x0F)
#define ELEM_SET_X(elem, x) *((u32 *)(&(elem))) = ((*((u32 *)(&(elem))) & ~0x1FF) | (x))
#define ELEM_SET_Y(elem, y) *((u32 *)(&(elem))) = ((*((u32 *)(&(elem))) & ~(0x1FF << 9)) | ((y) << 9))
#define ELEM_SET_TYPE(elem, type) *((u32 *)(&(elem))) = ((*((u32 *)(&(elem))) & ~(0x0F << 18)) | ((type) << 18))

#define ELEM_ICO(elem, j) ((elem).extra[j])
//#define ELEM_TRIM_IS_VERT(elem) (*((u32 *)((elem).blob)) & (1 << 22))
//#define ELEM_BOX_IS_BIG(elem) (*((u32 *)((elem).blob)) & (1 << 22))
//#define ELEM_TRIM_SET_VERT(elem, val) ((*((u32 *)((elem).blob)) & ~(1 << 22)) | (val) << 22)
//#define ELEM_BOX_SET_BIG(elem, val) ((*((u32 *)((elem).blob)) & ~(1 << 22)) | (val) << 22)
//NUM_TRIM_ELEMS + NUM_BOX_ELEMS + NUM_BAR_ELEMS + NUM_TOGGLE_ELEMS
#ifndef NUM_ELEMS
#define NUM_ELEMS (6 + 8 + 8 + 4 + 1)
Expand All @@ -75,13 +41,9 @@ struct elem {
//#define NUM_BAR_ELEMS 8
//#define NUM_TOGGLE_ELEMS 4

struct PageCfg2 {
struct elem elem[NUM_ELEMS];
u8 quickpage[NUM_QUICKPAGES];
u8 padding_1[3];
};

enum {
ELEM_NONE,
ELEM_SMALLBOX,
ELEM_BIGBOX,
ELEM_TOGGLE,
Expand Down
15 changes: 7 additions & 8 deletions src/pages/128x64x1/main_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ enum {
};
#endif //OVERRIDE_PLACEMENT
static struct layout_page * const lp = &pagemem.u.layout_page;
static struct PageCfg2 * const pc = &Model.pagecfg2;
static struct mainconfig_obj * const gui = &gui_objs.u.mainconfig;
static u16 current_selected = 0;

Expand Down Expand Up @@ -77,7 +76,7 @@ static const char *cfglabel_cb(guiObject_t *obj, const void *data)
{
(void)obj;
int i = (long)data;
int type = ELEM_TYPE(pc->elem[i]);
int type = Model.elem[i].type;
int idx = elem_abs_to_rel(i);
const char *str;
switch(type) {
Expand Down Expand Up @@ -122,13 +121,13 @@ void newelem_press_cb(guiObject_t *obj, const void *data)
static const char *dlgts1_cb(guiObject_t *obj, int dir, void *data)
{
int idx = (long)data;
if (pc->elem[idx].src == 0 && dir < 0)
pc->elem[idx].src = -1;
if ((s8)pc->elem[idx].src == -1 && dir > 0) {
pc->elem[idx].src = 0;
if (Model.elem[idx].src == 0 && dir < 0)
Model.elem[idx].src = -1;
if ((s8)Model.elem[idx].src == -1 && dir > 0) {
Model.elem[idx].src = 0;
dir = 0;
}
if ((s8)pc->elem[idx].src < 0) {
if ((s8)Model.elem[idx].src < 0) {
GUI_TextSelectEnablePress((guiTextSelect_t *)obj, 1);
//PAGE_MainLayoutExit();
return _tr("Delete");
Expand Down Expand Up @@ -205,7 +204,7 @@ void show_config()
{
long count = 0;
for (count = 0; count < NUM_ELEMS; count++) {
if (! ELEM_USED(pc->elem[count]))
if (Model.elem[count].type == ELEM_NONE)
break;
}
#if HAS_LAYOUT_EDITOR
Expand Down
1 change: 0 additions & 1 deletion src/pages/128x64x1/main_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#if HAS_LAYOUT_EDITOR

static struct layout_page * const lp = &pagemem.u.layout_page;
static struct PageCfg2 * const pc = &Model.pagecfg2;
static struct mainlayout_obj * const gui = &gui_objs.u.mainlayout;

#define NUMERIC_LABELS
Expand Down
6 changes: 3 additions & 3 deletions src/pages/128x64x1/pages.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,21 @@ void PAGE_ChangeQuick(int dir)
{
int quick = 0;
for (int i = 0; i < NUM_QUICKPAGES; i++) {
if(Model.pagecfg2.quickpage[i] && Model.pagecfg2.quickpage[i] == cur_page) {
if (Model.quickpage[i] && Model.quickpage[i] == cur_page) {
quick = i + 1;
break;
}
}
int increment = dir > 0 ? 1 : NUM_QUICKPAGES;
while(1) {
quick = (quick + increment) % 5;
if (quick == 0 || (Model.pagecfg2.quickpage[quick-1] && PAGE_IsValidQuickPage(Model.pagecfg2.quickpage[quick-1])))
if (quick == 0 || (Model.quickpage[quick-1] && PAGE_IsValidQuickPage(Model.quickpage[quick-1])))
break;
}
if (quick == 0) {
PAGE_ChangeByID(PAGEID_MAIN, 0);
} else {
PAGE_ChangeByID(Model.pagecfg2.quickpage[quick-1], 0);
PAGE_ChangeByID(Model.quickpage[quick-1], 0);
}
}
int PAGE_QuickPage(u32 buttons, u8 flags, void *data)
Expand Down
10 changes: 5 additions & 5 deletions src/pages/128x64x1/toggle_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static void show_iconsel_page(int SelectedIcon) {
GUI_RemoveAllObjects();
memset(gui, 0, sizeof(*gui));
current_toggleicon = SelectedIcon;
int toggleinput = MIXER_SRC(Model.pagecfg2.elem[tp->tglidx].src);
int toggleinput = MIXER_SRC(Model.elem[tp->tglidx].src);

//Header
PAGE_ShowHeader(INPUT_SourceNameAbbrevSwitch(tempstring, toggleinput));
Expand All @@ -100,9 +100,9 @@ static void show_iconsel_page(int SelectedIcon) {
GUI_CreateLabelBox(&gui->togglelabel[i], LABEL_X, row, LABEL_W, LABEL_H, SelectedIcon == i ? &inverted : &DEFAULT_FONT, NULL, NULL, tglidx[i]);
#ifdef HAS_CHAR_ICONS
GUI_CreateLabelBox(&gui->toggleicon[i], ICON_X, row, ICON_W, LABEL_H, &DEFAULT_FONT, TGLICO_font_cb,
NULL, (void *)(long)Model.pagecfg2.elem[tp->tglidx].extra[i]);
NULL, (void *)(uintptr_t)Model.elem[tp->tglidx].extra.ico[i]);
#else
struct ImageMap img = TGLICO_GetImage(Model.pagecfg2.elem[tp->tglidx].extra[i]);
struct ImageMap img = TGLICO_GetImage(Model.elem[tp->tglidx].extra.ico[i]);
GUI_CreateImageOffset(&gui->toggleicon[i], ICON_X, row, ICON_W, LABEL_H, img.x_off, img.y_off, img.file,
NULL, //SelectedIcon == 0 ? tglico_reset_cb : tglico_setpos_cb,
(void *)(long)i);
Expand All @@ -121,13 +121,13 @@ static void show_iconsel_page(int SelectedIcon) {
void PAGE_ToggleEditInit(int page)
{
tp->tglidx = page;
memcpy(tp->tglicons, Model.pagecfg2.elem[tp->tglidx].extra, sizeof(tp->tglicons));
memcpy(tp->tglicons, Model.elem[tp->tglidx].extra.ico, sizeof(tp->tglicons));
PAGE_SetActionCB(_action_cb);
show_iconsel_page(0);
}

static void navigate_toggleicons(s8 direction) {
int toggleinput = MIXER_SRC(Model.pagecfg2.elem[tp->tglidx].src);
int toggleinput = MIXER_SRC(Model.elem[tp->tglidx].src);
int num_positions = INPUT_NumSwitchPos(toggleinput);
if(num_positions < 2)
num_positions = 2;
Expand Down
Loading