// === GLOBALS ==
int giInterface_Width = 0;
+ int giInterface_HeaderBarSize = 20;
+ int giInterface_TabBarSize = 20;
tElement *gpInterface_Sidebar;
+tElement *gpInterface_ProgramList;
tElement *gpInterface_MainArea;
tElement *gpInterface_HeaderBar;
tElement *gpInterface_TabBar;
*/
void Interface_Init(void)
{
- tElement *area;
tElement *btn, *text;
-
+ tElement *ele;
+
// Calculate sizes
giInterface_Width = giScreenWidth/16;
WM_SetFlags(NULL, 0);
// -- Create Sidebar --
- gpInterface_Sidebar = WM_CreateElement(NULL, ELETYPE_TOOLBAR, ELEFLAG_VERTICAL);
+ gpInterface_Sidebar = WM_CreateElement(NULL, ELETYPE_TOOLBAR, ELEFLAG_VERTICAL, "Sidebar");
WM_SetSize( gpInterface_Sidebar, giInterface_Width );
- // --- Top segment ---
- area = WM_CreateElement(gpInterface_Sidebar, ELETYPE_BOX, ELEFLAG_VERTICAL);
- // ---- Menu Button ----
- btn = WM_CreateElement(area, ELETYPE_BUTTON, ELEFLAG_NOSTRETCH);
- WM_SetSize(btn, giInterface_Width);
- //text = WM_CreateElement(btn, ELETYPE_IMAGE, ELEFLAG_SCALE);
- //WM_SetText(text, "asset://LogoSmall.sif");
- text = WM_CreateElement(btn, ELETYPE_TEXT, 0);
+ // > System Menu Button
+ btn = WM_CreateElement(gpInterface_Sidebar, ELETYPE_BUTTON, ELEFLAG_NOSTRETCH, "SystemMenu");
+ WM_SetSize(btn, giInterface_Width-4);
+ // TODO: Once image loading is implemented, switch to a logo
+ #if 0
+ text = WM_CreateElement(btn, ELETYPE_IMAGE, ELEFLAG_SCALE);
+ WM_SetText(text, "asset://LogoSmall.sif");
+ #else
+ text = WM_CreateElement(btn, ELETYPE_TEXT, 0, NULL);
WM_SetText(text, "Acess");
+ #endif
+ // > Plain <hr/> style spacer
+ ele = WM_CreateElement(gpInterface_Sidebar, ELETYPE_SPACER, ELEFLAG_NOSTRETCH, "SideBar Spacer Top");
+ WM_SetSize(ele, 4);
+ // > Application List
+ gpInterface_ProgramList = WM_CreateElement(gpInterface_Sidebar, ELETYPE_BOX, ELEFLAG_VERTICAL, "ProgramList");
+ // > Plain <hr/> style spacer
+ ele = WM_CreateElement(gpInterface_Sidebar, ELETYPE_SPACER, ELEFLAG_NOSTRETCH, "SideBar Spacer Bottom");
+ WM_SetSize(ele, 4);
+ // > Version/Time
+ text = WM_CreateElement(gpInterface_Sidebar, ELETYPE_TEXT, ELEFLAG_NOSTRETCH, "Version String");
+ WM_SetSize(text, 20);
+ WM_SetText(text, "2.0");
- // ---- Plain <hr/> style spacer ----
- WM_CreateElement(area, ELETYPE_SPACER, 0);
-
- // Open Windows Go Here
-
- // --- Bottom Segment ---
- area = WM_CreateElement(gpInterface_Sidebar, ELETYPE_BOX, ELEFLAG_VERTICAL|ELEFLAG_ALIGN_END);
-
- // ---- Plain <hr/> style spacer ----
- WM_CreateElement(area, ELETYPE_SPACER, 0);
-
- // ---- Version String ----
- text = WM_CreateElement(area, ELETYPE_TEXT, ELEFLAG_WRAP);
- WM_SetText(text, "AxWin 1.0");
-
+ // --
// -- Create Main Area and regions within --
- gpInterface_MainArea = WM_CreateElement(NULL, ELETYPE_BOX, ELEFLAG_VERTICAL);
- gpInterface_HeaderBar = WM_CreateElement(gpInterface_MainArea, ELETYPE_BOX, 0);
- gpInterface_TabBar = WM_CreateElement(gpInterface_MainArea, ELETYPE_TABBAR, 0);
- gpInterface_TabContent = WM_CreateElement(gpInterface_MainArea, ELETYPE_BOX, 0);
+ // --
+ // > Righthand Area
+ gpInterface_MainArea = WM_CreateElement(NULL, ELETYPE_BOX, ELEFLAG_VERTICAL, "MainArea");
+ // > Header Bar (Title)
+ gpInterface_HeaderBar = WM_CreateElement(gpInterface_MainArea, ELETYPE_BOX, 0, "HeaderBar");
+ WM_SetSize(gpInterface_HeaderBar, giInterface_HeaderBarSize);
+ text = WM_CreateElement(gpInterface_HeaderBar, ELETYPE_TEXT, 0, NULL);
+ WM_SetText(text, "Acess2 GUI - By thePowersGang (John Hodge)");
+ // > Tab Bar (Current windows)
+ gpInterface_TabBar = WM_CreateElement(gpInterface_MainArea, ELETYPE_TABBAR, 0, "TabBar");
+ WM_SetSize(gpInterface_TabBar, giInterface_TabBarSize);
+ // > Application Space
+ gpInterface_TabContent = WM_CreateElement(gpInterface_MainArea, ELETYPE_BOX, 0, "TabContent");
}
void Interface_Update(void)
// === IMPORTS ===
extern void Decorator_RenderWidget(tElement *Element);
+extern void Video_GetTextDims(tFont *Font, const char *Text, int *W, int *H);
// === PROTOTYPES ===
-tElement *WM_CreateElement(tElement *Parent, int Type, int Flags);
+tElement *WM_CreateElement(tElement *Parent, int Type, int Flags, const char *DebugName);
void WM_UpdateMinDims(tElement *Element);
void WM_SetFlags(tElement *Element, int Flags);
void WM_SetSize(tElement *Element, int Size);
void WM_Update(void);
// === GLOBALS ===
-tElement gWM_RootElement;
+tElement gWM_RootElement = {
+ DebugName: "ROOT"
+};
struct {
void (*Init)(tElement *This);
void (*UpdateFlags)(tElement *This);
// === CODE ===
// --- Widget Creation and Control ---
-tElement *WM_CreateElement(tElement *Parent, int Type, int Flags)
+tElement *WM_CreateElement(tElement *Parent, int Type, int Flags, const char *DebugName)
{
tElement *ret;
+ const char *dbgName = DebugName ? DebugName : "";
- ret = calloc(sizeof(tElement), 1);
+ ret = calloc(sizeof(tElement)+strlen(dbgName)+1, 1);
if(!ret) return NULL;
// Prepare
ret->Type = Type;
+ strcpy(ret->DebugName, dbgName);
if(Parent == NULL) Parent = &gWM_RootElement;
ret->Parent = Parent;
ret->Flags = Flags;
// Append to parent's list
- ret->NextSibling = Parent->LastChild;
+ if(Parent->LastChild)
+ Parent->LastChild->NextSibling = ret;
Parent->LastChild = ret;
if(!Parent->FirstChild) Parent->FirstChild = ret;
Element->MinCross = ((tImage*)Element->Data)->Height;
}
break;
+
+ case ELETYPE_TEXT:
+ {
+ int w=0, h=0;
+ Video_GetTextDims(NULL, Element->Text, &w, &h);
+ if(Element->Parent && Element->Parent->Flags & ELEFLAG_VERTICAL) {
+ Element->MinCross = w;
+ Element->MinWith = h;
+ }
+ else {
+ Element->MinWith = w;
+ Element->MinCross = h;
+ }
+ }
+ break;
}
return ;
int fixedSize = 0;
int fullCross, dynWith;
- _SysDebug("%p -> Flags = 0x%x", Element, Element->Flags);
- _SysDebug("%p ->CachedH = %i, ->PaddingT = %i, ->PaddingB = %i",
- Element, Element->CachedH, Element->PaddingT, Element->PaddingB
+ _SysDebug("WM_UpdateDimensions %p'%s'", Element, Element->DebugName);
+ _SysDebug(" -> Flags = 0x%x", Element->Flags);
+ _SysDebug(" ->CachedH = %i, ->PaddingT = %i, ->PaddingB = %i",
+ Element->CachedH, Element->PaddingT, Element->PaddingB
);
- _SysDebug("%p ->CachedW = %i, ->PaddingL = %i, ->PaddingR = %i",
- Element, Element->CachedW, Element->PaddingL, Element->PaddingR
+ _SysDebug(" ->CachedW = %i, ->PaddingL = %i, ->PaddingR = %i",
+ Element->CachedW, Element->PaddingL, Element->PaddingR
);
// Pass 1
if( child->Flags & ELEFLAG_ABSOLUTEPOS )
continue ;
- _SysDebug("%p,%p ->FixedWith = %i", Element, child, child->FixedWith);
+ _SysDebug(" > %p'%s' ->FixedWith = %i", child, child->DebugName, child->FixedWith);
if( child->FixedWith )
{
nFixed ++;
nChildren ++;
}
- _SysDebug("%p - nChildren = %i, nFixed = %i", Element, nChildren, nFixed);
+ _SysDebug(" - nChildren = %i, nFixed = %i", Element, nChildren, nFixed);
if( nChildren > nFixed ) {
if( Element->Flags & ELEFLAG_VERTICAL )
dynWith = Element->CachedH - Element->PaddingT
dynWith -= fixedSize;
if( dynWith < 0 ) return ;
dynWith /= nChildren - nFixed;
- _SysDebug("%p - dynWith = %i", Element, dynWith);
+ _SysDebug(" - dynWith = %i", dynWith);
}
if( Element->Flags & ELEFLAG_VERTICAL )
else
fullCross = Element->CachedH - Element->PaddingT - Element->PaddingB;
- _SysDebug("%p - fullCross = %i", Element, fullCross);
+ _SysDebug(" - fullCross = %i", Element, fullCross);
// Pass 2 - Set sizes and recurse
for( child = Element->FirstChild; child; child = child->NextSibling )
{
int cross, with;
- _SysDebug("%p,%p ->MinCross = %i", Element, child, child->MinCross);
+ _SysDebug(" > %p'%s' ->MinCross = %i", child, child->DebugName, child->MinCross);
// --- Cross Size ---
cross = child->MinCross;
else
cross = fullCross;
- _SysDebug("%p,%p - cross = %i", Element, child, cross);
+ _SysDebug(" > %p'%s' - cross = %i", child, child->DebugName, cross);
if( Element->Flags & ELEFLAG_VERTICAL )
child->CachedW = cross;
else
with = child->MinWith;
else
with = dynWith;
- _SysDebug("%p,%p - with = %i", Element, child, with);
+ _SysDebug(" > %p'%s' - with = %i", child, child->DebugName, with);
if( Element->Flags & ELEFLAG_VERTICAL )
child->CachedH = with;
else
WM_UpdateDimensions(child, 0);
}
+
+ _SysDebug("%p'%s' Done", Element, Element->DebugName);
}
/**
{
tElement *child;
int x, y;
+ static int depth = 0;
+ char indent[depth+1];
if( Element->Flags & ELEFLAG_NORENDER ) return ;
- _SysDebug("Element=%p{PaddingL:%i, PaddingT:%i}",
- Element, Element->PaddingL, Element->PaddingT);
+ memset(indent, ' ', depth);
+ indent[depth] = '\0';
+ depth ++;
+
+ _SysDebug("%sWM_UpdatePosition %p'%s'{PaddingL:%i, PaddingT:%i}",
+ indent, Element, Element->DebugName, Element->PaddingL, Element->PaddingT);
// Initialise
x = Element->CachedX + Element->PaddingL;
y = Element->CachedY + Element->PaddingT;
+ _SysDebug("%s- Alignment = %s", indent,
+ (Element->Flags & ELEFLAG_VERTICAL) ? "vertical" : "horizontal");
+
// Update each child
for(child = Element->FirstChild; child; child = child->NextSibling)
{
+ _SysDebug("%s- x = %i, y = %i", indent, x, y);
child->CachedX = x;
child->CachedY = y;
// Set Alignment
if( Element->Flags & ELEFLAG_ALIGN_CENTER ) {
- if(Element->Flags & ELEFLAG_VERTICAL )
+ _SysDebug("%sChild being aligned to center", indent);
+ if(Element->Flags & ELEFLAG_VERTICAL)
child->CachedX += Element->CachedW/2 - child->CachedW/2;
else
child->CachedY += Element->CachedH/2 - child->CachedH/2;
}
- else if( Element->Flags & ELEFLAG_ALIGN_END ) {
+ else if( Element->Flags & ELEFLAG_ALIGN_END) {
+ _SysDebug("%sChild being aligned to end", indent);
if(Element->Flags & ELEFLAG_VERTICAL )
- child->CachedX += Element->CachedW - child->CachedW;
+ child->CachedX += Element->CachedW
+ - Element->PaddingL - Element->PaddingR
+ - child->CachedW;
else
- child->CachedY += Element->CachedH - child->CachedH;
+ child->CachedY += Element->CachedH
+ - Element->PaddingT
+ - Element->PaddingB
+ - child->CachedH;
}
+ _SysDebug("%s> %p'%s' at (%i,%i)", indent, child, child->DebugName,
+ child->CachedX, child->CachedY);
+
// Update child's children positions
WM_UpdatePosition(child);
}
}
- _SysDebug("Element %p (%i,%i)",
- Element, Element->CachedX, Element->CachedY
+ _SysDebug("%sElement %p'%s' (%i,%i)",
+ indent, Element, Element->DebugName, Element->CachedX, Element->CachedY
);
+ depth --;
}
/**