Commit b671f5f3 authored by sirjorj's avatar sirjorj

add color page

parent fbf2c78a
......@@ -43,6 +43,7 @@ PAGES=pages/index.o \
pages/validator2.o \
pages/dialcomp.o \
pages/squad2.o \
pages/colors2.o \
pages/test2.o
all: xwing.cgi
......
Subproject commit 383126e20e9d28446d087d316c9606effc51321e
Subproject commit 2ebd9118d2ffa47fc469c46a0f9dc1cefa4c3743
......@@ -29,6 +29,8 @@
#include "pages/validator2.h"
#include "pages/dialcomp.h"
#include "pages/squad2.h"
#include "pages/colors2.h"
// add new stuff here
#include "pages/test2.h"
......@@ -65,6 +67,8 @@ enum page {
PAGE_VALIDATOR2,
PAGE_DIALCOMP,
PAGE_SQUAD2,
PAGE_COLORS2,
// add new stuff here
PAGE_TEST2,
PAGE__MAX
};
......@@ -116,6 +120,8 @@ static const char *const pages[PAGE__MAX] = {
"validator2",
"dialcomp",
"squad2",
"colors2",
// add new stuff here
"test2",
};
......@@ -153,6 +159,8 @@ static const disp disps[PAGE__MAX] = {
validator2,
dialcomp,
squad2,
colors2,
// add new stuff here
test2,
};
......
#include "colors2.h"
using namespace libxwing2;
void colors2(struct kreq *req) {
struct khtmlreq r;
// page
resp_open(req, KHTTP_200);
khtml_open(&r, req, KHTML_PRETTY);
khtml_elem(&r, KELEM_DOCTYPE);
khtml_attr(&r, KELEM_HTML, KATTR_LANG, "en", KATTR__MAX);
// head
PrintHead(r, std::string(req->pname) + req->fullpath);
// body
khtml_elem(&r, KELEM_BODY);
PrintBreadcrumbs(r, {{req->pname, StripLeadingSlash(req->pname)}}, req->pagename);
// colors
khtml_attr(&r, KELEM_TABLE, KATTR__MAX);
for(const Color &c : Color::GetAllColors()) {
khtml_attr(&r, KELEM_TR, KATTR__MAX);
// name
khtml_attr(&r, KELEM_TD, KATTR__MAX);
khtml_puts(&r, c.GetName().c_str());
khtml_closeelem(&r, 1);
// color
khtml_attr(&r, KELEM_TD, KATTR_STYLE, "font-family:monospace;", KATTR__MAX);
khtml_puts(&r, c.GetHex().c_str());
khtml_closeelem(&r, 1);
// example
std::string style = "background-color:#" + c.GetHex() + ";width:100px;";
khtml_attr(&r, KELEM_TD, KATTR_STYLE, style.c_str(), KATTR__MAX);
khtml_closeelem(&r, 1);
// done
khtml_closeelem(&r, 1); // row
}
khtml_closeelem(&r, 1); // table
khtml_elem(&r, KELEM_P);
khtml_puts(&r, "These come from a number of sources, including the official squadbuilder site, images from official site, and scans I made. If you have more accurate colors or additional ones that I forgot, please let me know! :)");
khtml_closeelem(&r, 1);
khtml_closeelem(&r, 1); // body
khtml_close(&r);
}
#pragma once
#include "xwingcgi2.h"
void colors2(struct kreq *req);
......@@ -103,6 +103,14 @@ void index(struct kreq *req) {
khtml_attr(&r, KELEM_A, KATTR_HREF, (std::string(req->pname) + "/dialcomp").c_str(), KATTR__MAX); khtml_puts(&r, "dialcomp");
khtml_closeelem(&r, 3); // a td tr
}
{ // colors
khtml_elem(&r, KELEM_TR);
khtml_elem(&r, KELEM_TD);
khtml_closeelem(&r, 1); // td
khtml_elem(&r, KELEM_TD);
khtml_attr(&r, KELEM_A, KATTR_HREF, (std::string(req->pname) + "/colors2").c_str(), KATTR__MAX); khtml_puts(&r, "colors");
khtml_closeelem(&r, 3); // a td tr
}
khtml_closeelem(&r, 1); // table
......
......@@ -11,44 +11,8 @@ void test2(struct kreq *req) {
if(strcmp(req->fields[i].key, "subject") == 0) { subject = req->fields[i].val; }
}
if(subject == "color") {
struct khtmlreq r;
// page
resp_open(req, KHTTP_200);
khtml_open(&r, req, KHTML_PRETTY);
khtml_elem(&r, KELEM_DOCTYPE);
khtml_attr(&r, KELEM_HTML, KATTR_LANG, "en", KATTR__MAX);
// head
PrintHead(r, std::string(req->pname) + req->fullpath);
// body
khtml_elem(&r, KELEM_BODY);
PrintBreadcrumbs(r, {{req->pname, StripLeadingSlash(req->pname)}}, req->pagename);
// colors
khtml_elem(&r, KELEM_P);
khtml_puts(&r, "This is just a temporary test page showing off a work in progress. If you have any better colors or additional ones that I forgot, please let me know! :)");
khtml_closeelem(&r, 1);
khtml_attr(&r, KELEM_TABLE, KATTR__MAX);
for(const Color &c : Color::GetAllColors()) {
khtml_attr(&r, KELEM_TR, KATTR__MAX);
// name
khtml_attr(&r, KELEM_TD, KATTR__MAX);
khtml_puts(&r, c.GetName().c_str());
khtml_closeelem(&r, 1);
// color
khtml_attr(&r, KELEM_TD, KATTR_STYLE, "font-family:monospace;", KATTR__MAX);
khtml_puts(&r, c.GetHex().c_str());
khtml_closeelem(&r, 1);
// example
std::string style = "background-color:#" + c.GetHex() + ";width:100px;";
khtml_attr(&r, KELEM_TD, KATTR_STYLE, style.c_str(), KATTR__MAX);
khtml_closeelem(&r, 1);
// done
khtml_closeelem(&r, 1); // row
}
if(subject != subject) {
khtml_closeelem(&r, 2); // table, body
khtml_close(&r);
}
else {
struct khtmlreq r;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment