Skip to content

Commit

Permalink
First pass keyboard navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
jhhoward committed Mar 13, 2024
1 parent 97611f7 commit e9a1a7e
Show file tree
Hide file tree
Showing 20 changed files with 361 additions and 62 deletions.
12 changes: 11 additions & 1 deletion src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,28 @@ void App::Run(int argc, char* argv[])
ui.Init();
pageRenderer.Init();

char* targetURL = nullptr;
if (argc > 1)
{
for (int n = 1; n < argc; n++)
{
if (*argv[n] != '-')
{
OpenURL(argv[n]);
targetURL = argv[n];
break;
}
}
}

if (targetURL)
{
OpenURL(targetURL);
}
else
{
ui.FocusNode(ui.addressBarNode);
}

while (running)
{
Platform::Update();
Expand Down
2 changes: 1 addition & 1 deletion src/Draw/Surf2bpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void DrawSurface_2BPP::InvertRect(DrawContext& context, int x, int y, int width,
VRAMptr += (x >> 2);
int count = width;
uint8_t data = *VRAMptr;
uint8_t mask = (0xc0 >> (x & 3));
uint8_t mask = bitmaskTable[x & 3];

while (count--)
{
Expand Down
63 changes: 40 additions & 23 deletions src/Draw/Surf8bpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,61 +452,78 @@ void DrawSurface_8BPP::InvertRect(DrawContext& context, int x, int y, int width,
}
}

static uint8_t edge[16] =
{
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
};

static uint8_t widgetEdge[16] =
{
0x0,0xf,0xf,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xf,0xf,0x0
};

static uint8_t inner[16] =
{
0x0,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0x0
};

static uint8_t widgetInner[16] =
{
0x0,0xf,0x0,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0x0,0xf,0x0
};

static uint8_t grab[16] =
{
0x0,0xf,0x0,0xf,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xf,0x0,0xf,0x0
};

void DrawSurface_8BPP::VerticalScrollBar(DrawContext& context, int x, int y, int height, int position, int size)
{
#if 0
x += context.drawOffsetX;
y += context.drawOffsetY;
int startY = y;

x >>= 3;
const int grabSize = 7;
const int minWidgetSize = grabSize + 4;
const int widgetPaddingSize = size - minWidgetSize;
int topPaddingSize = widgetPaddingSize >> 1;
int bottomPaddingSize = widgetPaddingSize - topPaddingSize;
const uint16_t edge = 0;
const uint16_t inner = 0xfe7f;
int bottomSpacing = height - position - size;

while (position--)
{
*(uint16_t*)(&lines[y++][x]) = inner;
memcpy(&lines[y++][x], inner, 16);
}

const uint16_t widgetEdge = 0x0660;
*(uint16_t*)(&lines[y++][x]) = inner;
*(uint16_t*)(&lines[y++][x]) = widgetEdge;

const uint16_t widgetInner = 0xfa5f;
const uint16_t grab = 0x0a50;
memcpy(&lines[y++][x], inner, 16);
memcpy(&lines[y++][x], widgetEdge, 16);

while (topPaddingSize--)
{
*(uint16_t*)(&lines[y++][x]) = widgetInner;
memcpy(&lines[y++][x], widgetInner, 16);
}

*(uint16_t*)(&lines[y++][x]) = widgetInner;
*(uint16_t*)(&lines[y++][x]) = grab;
*(uint16_t*)(&lines[y++][x]) = widgetInner;
*(uint16_t*)(&lines[y++][x]) = grab;
*(uint16_t*)(&lines[y++][x]) = widgetInner;
*(uint16_t*)(&lines[y++][x]) = grab;
*(uint16_t*)(&lines[y++][x]) = widgetInner;
memcpy(&lines[y++][x], widgetInner, 16);
memcpy(&lines[y++][x], grab, 16);
memcpy(&lines[y++][x], widgetInner, 16);
memcpy(&lines[y++][x], grab, 16);
memcpy(&lines[y++][x], widgetInner, 16);
memcpy(&lines[y++][x], grab, 16);
memcpy(&lines[y++][x], widgetInner, 16);

while (bottomPaddingSize--)
{
*(uint16_t*)(&lines[y++][x]) = widgetInner;
memcpy(&lines[y++][x], widgetInner, 16);
}

*(uint16_t*)(&lines[y++][x]) = widgetEdge;
*(uint16_t*)(&lines[y++][x]) = inner;
memcpy(&lines[y++][x], widgetEdge, 16);
memcpy(&lines[y++][x], inner, 16);

while (bottomSpacing--)
{
*(uint16_t*)(&lines[y++][x]) = inner;
memcpy(&lines[y++][x], inner, 16);
}
#endif
}

void DrawSurface_8BPP::Clear()
Expand Down
4 changes: 4 additions & 0 deletions src/Image/Gif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,10 @@ void GifDecoder::EmitLine(int y)
if (outputImage->bpp == 8)
{
bool useColourDithering = true;
//if (Platform::video->paletteLUT == compositeCgaPaletteLUT)
//{
// useColourDithering = false;
//}

if (useColourDithering)
{
Expand Down
73 changes: 50 additions & 23 deletions src/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ void AppInterface::Reset()

void AppInterface::Update()
{
if (app.page.GetPageHeight() != oldPageHeight)
{
oldPageHeight = app.page.GetPageHeight();
UpdatePageScrollBar();
}

int buttons, mouseX, mouseY;
Platform::input->GetMouseStatus(buttons, mouseX, mouseY);

Expand Down Expand Up @@ -179,7 +173,13 @@ void AppInterface::Update()
ScrollAbsolute(0);
break;
case KEYCODE_END:
//ScrollAbsolute(0);
{
int end = app.pageRenderer.GetVisiblePageHeight() - windowRect.height;
if (end > 0)
{
ScrollAbsolute(end);
}
}
break;
case KEYCODE_BACKSPACE:
app.PreviousPage();
Expand All @@ -194,14 +194,14 @@ void AppInterface::Update()
break;
case KEYCODE_CTRL_L:
case KEYCODE_F6:
//ActivateWidget(&addressBar);
FocusNode(addressBarNode);
break;

case KEYCODE_TAB:
//CycleWidgets(1);
CycleNodes(1);
break;
case KEYCODE_SHIFT_TAB:
//CycleWidgets(-1);
CycleNodes(-1);
break;

case 'm':
Expand Down Expand Up @@ -309,7 +309,7 @@ void AppInterface::UpdateAddressBar(const URL& url)
void AppInterface::UpdatePageScrollBar()
{
ScrollBarNode::Data* data = static_cast<ScrollBarNode::Data*>(scrollBarNode->data);
int maxScrollHeight = app.page.GetRootNode()->size.y - app.ui.windowRect.height;
int maxScrollHeight = app.pageRenderer.GetVisiblePageHeight() - app.ui.windowRect.height;
if (maxScrollHeight < 0)
maxScrollHeight = 0;
data->scrollPosition = scrollPositionY;
Expand Down Expand Up @@ -474,7 +474,7 @@ void AppInterface::ScrollRelative(int delta)
if (scrollPositionY < 0)
scrollPositionY = 0;

int maxScrollY = app.page.GetRootNode()->size.y - app.ui.windowRect.height;
int maxScrollY = app.pageRenderer.GetVisiblePageHeight() - app.ui.windowRect.height;
if (maxScrollY > 0 && scrollPositionY > maxScrollY)
{
scrollPositionY = maxScrollY;
Expand All @@ -484,21 +484,48 @@ void AppInterface::ScrollRelative(int delta)

UpdatePageScrollBar();

//Platform::input->HideMouse();

app.pageRenderer.OnPageScroll(delta);

//DrawContext context;
//app.pageRenderer.GenerateDrawContext(context, NULL);
//context.drawOffsetY = 0;
//context.surface->FillRect(context, 0, 0, Platform::video->screenWidth, Platform::video->screenHeight, Platform::video->colourScheme.pageColour);
//app.pageRenderer.GenerateDrawContext(context, NULL);
////app.pageRenderer.DrawAll(context, app.page.GetRootNode());

Platform::input->ShowMouse();
}

void AppInterface::ScrollAbsolute(int position)
{
int delta = position - scrollPositionY;
if (delta)
{
ScrollRelative(delta);
}
}

void AppInterface::CycleNodes(int direction)
{
Node* node = focusedNode;

if (!node)
{
node = app.page.GetRootNode();
}

if (node)
{
if (!IsInterfaceNode(node))
{
while (node)
{
if (direction > 0)
{
node = node->GetNextInTree();
}
else
{
node = node->GetPreviousInTree();
}

if (node && node->Handler().CanPick(node))
{
FocusNode(node);
return;
}
}
}
}
}
4 changes: 3 additions & 1 deletion src/Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class AppInterface
void ScrollAbsolute(int position);


Node* addressBarNode;
URL addressBarURL;

Rect windowRect;
Expand All @@ -66,6 +67,8 @@ class AppInterface
void HandleRelease(int mouseX, int mouseY);
void HandleDrag(int mouseX, int mouseY);

void CycleNodes(int direction);

static void OnBackButtonPressed(Node* node);
static void OnForwardButtonPressed(Node* node);
static void OnAddressBarSubmit(Node* node);
Expand All @@ -83,7 +86,6 @@ class AppInterface
Node* titleNode;
Node* backButtonNode;
Node* forwardButtonNode;
Node* addressBarNode;
Node* statusBarNode;
Node* scrollBarNode;

Expand Down
2 changes: 1 addition & 1 deletion src/Layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void Layout::Reset()

LayoutParams& params = GetParams();
params.marginLeft = 0;
params.marginRight = page.GetPageWidth();
params.marginRight = page.GetApp().ui.windowRect.width;
}

void Layout::BreakNewLine()
Expand Down
52 changes: 52 additions & 0 deletions src/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,45 @@ void Node::Redraw()
Platform::input->ShowMouse();
}

Node* Node::GetPreviousInTree()
{
if (parent)
{
if (parent->firstChild == this)
{
return parent;
}

for (Node* child = parent->firstChild; child; child = child->next)
{
if (child->next == this)
{
Node* node = child;

while (node->firstChild)
{
node = node->firstChild;

while (node->next)
{
node = node->next;
}
}

return node;
}
}

// Shouldn't ever get here
return nullptr;
}
else
{
// Top of the tree
return nullptr;
}
}

Node* Node::GetNextInTree()
{
Node* node = this;
Expand All @@ -261,3 +300,16 @@ Node* Node::GetNextInTree()

return nullptr;
}

bool Node::IsChildOf(Node* potentialParent)
{
for(Node* node = parent; node; node = node->parent)
{
if (node == potentialParent)
{
return true;
}
}

return false;
}
2 changes: 2 additions & 0 deletions src/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ class Node
}
return nullptr;
}
bool IsChildOf(Node* node);

void Redraw();

Node* GetPreviousInTree();
Node* GetNextInTree();

ElementStyle style;
Expand Down
Loading

0 comments on commit e9a1a7e

Please sign in to comment.