|
@@ -1,10 +1,11 @@
|
|
|
-/* solitaire: a Windows 95 style Klondike solitaire for a canvas window.
|
|
|
|
|
|
|
+/* solitaire: a Klondike solitaire for a canvas window.
|
|
|
*
|
|
*
|
|
|
* Seven tableau piles, four foundations, a stock and a waste. Draw one or
|
|
* Seven tableau piles, four foundations, a stock and a waste. Draw one or
|
|
|
* three, drag cards or whole runs, double-click to send a card to a
|
|
* three, drag cards or whole runs, double-click to send a card to a
|
|
|
- * foundation, and click the stock to deal / recycle. The look follows the
|
|
|
|
|
- * old Windows game: green felt, a grey Game/Help menu, white cards, a blue
|
|
|
|
|
- * patterned back and the bouncing cards after a win.
|
|
|
|
|
|
|
+ * foundation, and click the stock to deal / recycle. The table keeps the
|
|
|
|
|
+ * classic look (green felt, white cards, a blue patterned back and the
|
|
|
|
|
+ * bouncing cards after a win), while the menu, status bar and dialogs are
|
|
|
|
|
+ * built from the shared ngui toolkit and its dark theme.
|
|
|
*
|
|
*
|
|
|
* Mouse only (the kernel keyboard path has no F2), so N starts a new game.
|
|
* Mouse only (the kernel keyboard path has no F2), so N starts a new game.
|
|
|
* The window can be resized; the table is re-laid out.
|
|
* The window can be resized; the table is re-laid out.
|
|
@@ -18,8 +19,8 @@
|
|
|
#define RANK_COUNT 13
|
|
#define RANK_COUNT 13
|
|
|
#define DECK_SIZE 52
|
|
#define DECK_SIZE 52
|
|
|
|
|
|
|
|
-#define MENU_H 22
|
|
|
|
|
-#define STATUS_H 20
|
|
|
|
|
|
|
+#define MENU_H 34
|
|
|
|
|
+#define STATUS_H 22
|
|
|
|
|
|
|
|
#define START_W 760
|
|
#define START_W 760
|
|
|
#define START_H 540
|
|
#define START_H 540
|
|
@@ -28,13 +29,6 @@
|
|
|
#define C_SLOT_FILL NGUI_RGB(0, 112, 0)
|
|
#define C_SLOT_FILL NGUI_RGB(0, 112, 0)
|
|
|
#define C_SLOT_LINE NGUI_RGB(0, 84, 0)
|
|
#define C_SLOT_LINE NGUI_RGB(0, 84, 0)
|
|
|
#define C_SLOT_ICON NGUI_RGB(96, 190, 96)
|
|
#define C_SLOT_ICON NGUI_RGB(96, 190, 96)
|
|
|
-#define C_MENU NGUI_RGB(192, 192, 192)
|
|
|
|
|
-#define C_MENU_TOP NGUI_RGB(255, 255, 255)
|
|
|
|
|
-#define C_MENU_DARK NGUI_RGB(64, 64, 64)
|
|
|
|
|
-#define C_MENU_HOT NGUI_RGB(206, 206, 206)
|
|
|
|
|
-#define C_TEXT NGUI_RGB(0, 0, 0)
|
|
|
|
|
-#define C_TEXT_LIGHT NGUI_RGB(255, 255, 255)
|
|
|
|
|
-#define C_NAVY NGUI_RGB(0, 0, 128)
|
|
|
|
|
#define C_CARD NGUI_RGB(255, 255, 255)
|
|
#define C_CARD NGUI_RGB(255, 255, 255)
|
|
|
#define C_CARD_EDGE NGUI_RGB(40, 40, 40)
|
|
#define C_CARD_EDGE NGUI_RGB(40, 40, 40)
|
|
|
#define C_SHADOW NGUI_RGB(0, 82, 0)
|
|
#define C_SHADOW NGUI_RGB(0, 82, 0)
|
|
@@ -44,7 +38,6 @@
|
|
|
#define C_CREAM NGUI_RGB(255, 248, 220)
|
|
#define C_CREAM NGUI_RGB(255, 248, 220)
|
|
|
#define C_SKIN NGUI_RGB(255, 222, 189)
|
|
#define C_SKIN NGUI_RGB(255, 222, 189)
|
|
|
#define C_HAIR NGUI_RGB(72, 48, 24)
|
|
#define C_HAIR NGUI_RGB(72, 48, 24)
|
|
|
-#define C_HILITE NGUI_RGB(255, 255, 0)
|
|
|
|
|
|
|
|
|
|
enum {
|
|
enum {
|
|
|
SRC_NONE = 0,
|
|
SRC_NONE = 0,
|
|
@@ -205,20 +198,17 @@ static const struct menu_entry help_menu[] = {
|
|
|
static const char *const howto_lines[] = {
|
|
static const char *const howto_lines[] = {
|
|
|
"Goal: build each suit from Ace to King.",
|
|
"Goal: build each suit from Ace to King.",
|
|
|
"Drag cards to move them.",
|
|
"Drag cards to move them.",
|
|
|
- "Drop a card on one rank higher and of",
|
|
|
|
|
- "the opposite colour.",
|
|
|
|
|
|
|
+ "Drop a card on one rank higher and of the opposite colour.",
|
|
|
"Empty tableau piles accept a King.",
|
|
"Empty tableau piles accept a King.",
|
|
|
- "Double-click a card to send it to a",
|
|
|
|
|
- "foundation.",
|
|
|
|
|
- "Click the deck to draw; click an empty",
|
|
|
|
|
- "deck to recycle the waste.",
|
|
|
|
|
|
|
+ "Double-click a card to send it to a foundation.",
|
|
|
|
|
+ "Click the deck to draw; click an empty deck to recycle the waste.",
|
|
|
"N: new game Esc: close"
|
|
"N: new game Esc: close"
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
static const char *const about_lines[] = {
|
|
static const char *const about_lines[] = {
|
|
|
"NebOS edition",
|
|
"NebOS edition",
|
|
|
"",
|
|
"",
|
|
|
- "A Windows 95 style Klondike.",
|
|
|
|
|
|
|
+ "A classic Klondike built with ngui.",
|
|
|
"Drag, drop, and bounce."
|
|
"Drag, drop, and bounce."
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -242,21 +232,6 @@ static int point_in(const struct ngui_rect *r, int x, int y)
|
|
|
x < r->x + r->w && y < r->y + r->h;
|
|
x < r->x + r->w && y < r->y + r->h;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static void setup_theme(struct ngui *ui)
|
|
|
|
|
-{
|
|
|
|
|
- ui->theme.panel = C_MENU;
|
|
|
|
|
- ui->theme.panel_alt = C_MENU_HOT;
|
|
|
|
|
- ui->theme.border = C_MENU_DARK;
|
|
|
|
|
- ui->theme.text = C_TEXT;
|
|
|
|
|
- ui->theme.text_dim = NGUI_RGB(88, 88, 88);
|
|
|
|
|
- ui->theme.accent = C_NAVY;
|
|
|
|
|
- ui->theme.selection = C_NAVY;
|
|
|
|
|
- ui->theme.button = C_MENU;
|
|
|
|
|
- ui->theme.button_hot = C_MENU_HOT;
|
|
|
|
|
- ui->theme.button_down = NGUI_RGB(160, 160, 160);
|
|
|
|
|
- ui->theme.error = C_RED;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
static int clampi(int v, int lo, int hi)
|
|
static int clampi(int v, int lo, int hi)
|
|
|
{
|
|
{
|
|
|
if (v < lo)
|
|
if (v < lo)
|
|
@@ -346,14 +321,9 @@ static unsigned int rng_next(void)
|
|
|
|
|
|
|
|
static void frame2(struct ngui *ui, struct ngui_rect r, unsigned short color)
|
|
static void frame2(struct ngui *ui, struct ngui_rect r, unsigned short color)
|
|
|
{
|
|
{
|
|
|
- ngui_frame(ui, r, color);
|
|
|
|
|
- if (r.w > 4 && r.h > 4) {
|
|
|
|
|
- r.x++;
|
|
|
|
|
- r.y++;
|
|
|
|
|
- r.w -= 2;
|
|
|
|
|
- r.h -= 2;
|
|
|
|
|
- ngui_frame(ui, r, color);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (r.w <= 0 || r.h <= 0)
|
|
|
|
|
+ return;
|
|
|
|
|
+ ngui_frame_round(ui, r, 4, 4, 4, 4, 2, color);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void fill_circle(struct ngui *ui, int cx, int cy, int r,
|
|
static void fill_circle(struct ngui *ui, int cx, int cy, int r,
|
|
@@ -1889,7 +1859,7 @@ static void draw_drop_highlight(struct ngui *ui, const struct sol_layout *l)
|
|
|
return;
|
|
return;
|
|
|
r = target_rect(l, &t);
|
|
r = target_rect(l, &t);
|
|
|
if (r.w > 0 && r.h > 0)
|
|
if (r.w > 0 && r.h > 0)
|
|
|
- frame2(ui, r, C_HILITE);
|
|
|
|
|
|
|
+ frame2(ui, r, ui->theme.accent);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void draw_selection_outline(struct ngui *ui, const struct sol_layout *l)
|
|
static void draw_selection_outline(struct ngui *ui, const struct sol_layout *l)
|
|
@@ -1907,7 +1877,7 @@ static void draw_selection_outline(struct ngui *ui, const struct sol_layout *l)
|
|
|
} else {
|
|
} else {
|
|
|
r = sel_rect(l, &select_sel);
|
|
r = sel_rect(l, &select_sel);
|
|
|
}
|
|
}
|
|
|
- frame2(ui, r, C_HILITE);
|
|
|
|
|
|
|
+ frame2(ui, r, ui->theme.accent);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void draw_drag_cards(struct ngui *ui, const struct sol_layout *l)
|
|
static void draw_drag_cards(struct ngui *ui, const struct sol_layout *l)
|
|
@@ -1966,30 +1936,83 @@ static int menu_entries(int which, const struct menu_entry **out)
|
|
|
return (int)(sizeof(help_menu) / sizeof(help_menu[0]));
|
|
return (int)(sizeof(help_menu) / sizeof(help_menu[0]));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int menu_entry_h(const struct menu_entry *e)
|
|
|
|
|
|
|
+static int menu_entry_h(struct ngui *ui, const struct menu_entry *e)
|
|
|
{
|
|
{
|
|
|
- return e->label ? 21 : 7;
|
|
|
|
|
|
|
+ int lh = ngui_text_line_height(ui, ui->font_px, 0);
|
|
|
|
|
+
|
|
|
|
|
+ return e->label ? lh + 10 : 9;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int menu_dropdown_h(int which)
|
|
|
|
|
|
|
+static int menu_dropdown_h(struct ngui *ui, int which)
|
|
|
{
|
|
{
|
|
|
const struct menu_entry *e;
|
|
const struct menu_entry *e;
|
|
|
- int n, i, h = 6;
|
|
|
|
|
|
|
+ int n, i, h = 10;
|
|
|
|
|
|
|
|
n = menu_entries(which, &e);
|
|
n = menu_entries(which, &e);
|
|
|
for (i = 0; i < n; i++)
|
|
for (i = 0; i < n; i++)
|
|
|
- h += menu_entry_h(&e[i]);
|
|
|
|
|
|
|
+ h += menu_entry_h(ui, &e[i]);
|
|
|
return h;
|
|
return h;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int menu_x(int which)
|
|
|
|
|
|
|
+/* Geometry of the Game/Help buttons in the ngui toolbar. */
|
|
|
|
|
+static void menu_button_rect(struct ngui *ui, int which, struct ngui_rect *out)
|
|
|
{
|
|
{
|
|
|
- return which == MENU_GAME ? 4 : 52;
|
|
|
|
|
|
|
+ int gw = (int)ngui_text_width_ui(ui, "Game") + 24;
|
|
|
|
|
+ int hw = (int)ngui_text_width_ui(ui, "Help") + 24;
|
|
|
|
|
+ int y = (MENU_H - 24) / 2;
|
|
|
|
|
+
|
|
|
|
|
+ if (gw < 56)
|
|
|
|
|
+ gw = 56;
|
|
|
|
|
+ if (hw < 56)
|
|
|
|
|
+ hw = 56;
|
|
|
|
|
+ if (which == MENU_GAME)
|
|
|
|
|
+ *out = rect_make(8, y, gw, 24);
|
|
|
|
|
+ else
|
|
|
|
|
+ *out = rect_make(8 + gw + 6, y, hw, 24);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int menu_w(struct ngui *ui, int which)
|
|
|
|
|
+{
|
|
|
|
|
+ const struct menu_entry *e;
|
|
|
|
|
+ int n, i, w = 150;
|
|
|
|
|
+
|
|
|
|
|
+ n = menu_entries(which, &e);
|
|
|
|
|
+ for (i = 0; i < n; i++) {
|
|
|
|
|
+ int lw;
|
|
|
|
|
+
|
|
|
|
|
+ if (!e[i].label)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ lw = (int)ngui_text_width_ui(ui, e[i].label) + 40;
|
|
|
|
|
+ if (e[i].shortcut)
|
|
|
|
|
+ lw += (int)ngui_text_width_ui(ui, e[i].shortcut) + 24;
|
|
|
|
|
+ if (lw > w)
|
|
|
|
|
+ w = lw;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (w > ui->w - 12)
|
|
|
|
|
+ w = ui->w - 12;
|
|
|
|
|
+ if (w < 120)
|
|
|
|
|
+ w = 120;
|
|
|
|
|
+ return w;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int menu_w(int which)
|
|
|
|
|
|
|
+/* The open menu's panel rectangle, clamped into the window. */
|
|
|
|
|
+static int dropdown_rect(struct ngui *ui, struct ngui_rect *out)
|
|
|
{
|
|
{
|
|
|
- return which == MENU_GAME ? 172 : 158;
|
|
|
|
|
|
|
+ struct ngui_rect a;
|
|
|
|
|
+ int w, h, x;
|
|
|
|
|
+
|
|
|
|
|
+ if (menu_open == MENU_NONE)
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ menu_button_rect(ui, menu_open, &a);
|
|
|
|
|
+ w = menu_w(ui, menu_open);
|
|
|
|
|
+ h = menu_dropdown_h(ui, menu_open);
|
|
|
|
|
+ x = a.x;
|
|
|
|
|
+ if (x + w > ui->w - 6)
|
|
|
|
|
+ x = ui->w - 6 - w;
|
|
|
|
|
+ if (x < 6)
|
|
|
|
|
+ x = 6;
|
|
|
|
|
+ *out = rect_make(x, MENU_H + 2, w, h);
|
|
|
|
|
+ return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static int action_checked(int action)
|
|
static int action_checked(int action)
|
|
@@ -2014,44 +2037,37 @@ static int menu_bar_button(struct ngui *ui, unsigned int id,
|
|
|
unsigned short ob = ui->theme.button;
|
|
unsigned short ob = ui->theme.button;
|
|
|
unsigned short oh = ui->theme.button_hot;
|
|
unsigned short oh = ui->theme.button_hot;
|
|
|
unsigned short od = ui->theme.button_down;
|
|
unsigned short od = ui->theme.button_down;
|
|
|
- unsigned short obd = ui->theme.border;
|
|
|
|
|
- unsigned short ot = ui->theme.text;
|
|
|
|
|
int fired;
|
|
int fired;
|
|
|
|
|
|
|
|
if (active) {
|
|
if (active) {
|
|
|
- ui->theme.button = C_NAVY;
|
|
|
|
|
- ui->theme.button_hot = C_NAVY;
|
|
|
|
|
- ui->theme.button_down = C_NAVY;
|
|
|
|
|
- ui->theme.border = C_NAVY;
|
|
|
|
|
- ui->theme.text = C_TEXT_LIGHT;
|
|
|
|
|
|
|
+ ui->theme.button = ui->theme.selection;
|
|
|
|
|
+ ui->theme.button_hot = ui->theme.selection;
|
|
|
|
|
+ ui->theme.button_down = ui->theme.selection;
|
|
|
} else {
|
|
} else {
|
|
|
- ui->theme.button = C_MENU;
|
|
|
|
|
- ui->theme.button_hot = C_MENU_HOT;
|
|
|
|
|
- ui->theme.button_down = NGUI_RGB(160, 160, 160);
|
|
|
|
|
- ui->theme.border = C_MENU;
|
|
|
|
|
- ui->theme.text = C_TEXT;
|
|
|
|
|
|
|
+ ui->theme.button = ui->theme.panel;
|
|
|
|
|
+ ui->theme.button_hot = ui->theme.panel_alt;
|
|
|
|
|
+ ui->theme.button_down = ui->theme.selection;
|
|
|
}
|
|
}
|
|
|
fired = ngui_button(ui, id, r, label);
|
|
fired = ngui_button(ui, id, r, label);
|
|
|
ui->theme.button = ob;
|
|
ui->theme.button = ob;
|
|
|
ui->theme.button_hot = oh;
|
|
ui->theme.button_hot = oh;
|
|
|
ui->theme.button_down = od;
|
|
ui->theme.button_down = od;
|
|
|
- ui->theme.border = obd;
|
|
|
|
|
- ui->theme.text = ot;
|
|
|
|
|
return fired;
|
|
return fired;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void draw_menu_bar(struct ngui *ui, const struct sol_layout *l)
|
|
static void draw_menu_bar(struct ngui *ui, const struct sol_layout *l)
|
|
|
{
|
|
{
|
|
|
- int gw = (int)ngui_text_width_ui(ui, "Game") + 18;
|
|
|
|
|
- int hw = (int)ngui_text_width_ui(ui, "Help") + 18;
|
|
|
|
|
- struct ngui_rect gr = rect_make(6, 2, gw, 18);
|
|
|
|
|
- struct ngui_rect hr = rect_make(6 + gw + 2, 2, hw, 18);
|
|
|
|
|
|
|
+ static const char *const hint = "N new game H help Esc quit";
|
|
|
|
|
+ struct ngui_rect gr, hr;
|
|
|
|
|
+ int hw, hy;
|
|
|
|
|
|
|
|
(void)l;
|
|
(void)l;
|
|
|
- ngui_fill_rect(ui, rect_make(0, 0, ui->w, MENU_H), C_MENU);
|
|
|
|
|
- ngui_fill_rect(ui, rect_make(0, 0, ui->w, 1), C_MENU_TOP);
|
|
|
|
|
- ngui_fill_rect(ui, rect_make(0, MENU_H - 1, ui->w, 1), C_MENU_DARK);
|
|
|
|
|
|
|
+ ngui_fill_rect(ui, rect_make(0, 0, ui->w, MENU_H), ui->theme.panel);
|
|
|
|
|
+ ngui_fill_rect(ui, rect_make(0, MENU_H - 1, ui->w, 1),
|
|
|
|
|
+ ui->theme.border);
|
|
|
|
|
|
|
|
|
|
+ menu_button_rect(ui, MENU_GAME, &gr);
|
|
|
|
|
+ menu_button_rect(ui, MENU_HELP, &hr);
|
|
|
if (menu_bar_button(ui, ID_MENU_GAME, gr, "Game",
|
|
if (menu_bar_button(ui, ID_MENU_GAME, gr, "Game",
|
|
|
menu_open == MENU_GAME)) {
|
|
menu_open == MENU_GAME)) {
|
|
|
menu_open = (menu_open == MENU_GAME) ? MENU_NONE : MENU_GAME;
|
|
menu_open = (menu_open == MENU_GAME) ? MENU_NONE : MENU_GAME;
|
|
@@ -2062,39 +2078,41 @@ static void draw_menu_bar(struct ngui *ui, const struct sol_layout *l)
|
|
|
menu_open = (menu_open == MENU_HELP) ? MENU_NONE : MENU_HELP;
|
|
menu_open = (menu_open == MENU_HELP) ? MENU_NONE : MENU_HELP;
|
|
|
ngui_invalidate(ui);
|
|
ngui_invalidate(ui);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ hw = (int)ngui_text_width_ui(ui, hint);
|
|
|
|
|
+ hy = (MENU_H - ngui_text_line_height(ui, ui->font_px, 0)) / 2;
|
|
|
|
|
+ if (hy < 0)
|
|
|
|
|
+ hy = 0;
|
|
|
|
|
+ if (hw + 24 < ui->w - (hr.x + hr.w))
|
|
|
|
|
+ ngui_text(ui, ui->w - 12 - hw, hy, hint, ui->theme.text_dim);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void draw_dropdown(struct ngui *ui)
|
|
static void draw_dropdown(struct ngui *ui)
|
|
|
{
|
|
{
|
|
|
const struct menu_entry *e;
|
|
const struct menu_entry *e;
|
|
|
- int n, i, x, y, w, h, ey;
|
|
|
|
|
|
|
+ struct ngui_rect r;
|
|
|
|
|
+ int n, i, ey;
|
|
|
|
|
|
|
|
- if (menu_open == MENU_NONE)
|
|
|
|
|
|
|
+ if (!dropdown_rect(ui, &r))
|
|
|
return;
|
|
return;
|
|
|
n = menu_entries(menu_open, &e);
|
|
n = menu_entries(menu_open, &e);
|
|
|
- x = menu_x(menu_open);
|
|
|
|
|
- y = MENU_H;
|
|
|
|
|
- w = menu_w(menu_open);
|
|
|
|
|
- h = menu_dropdown_h(menu_open);
|
|
|
|
|
-
|
|
|
|
|
- ngui_fill_rect(ui, rect_make(x + 2, y + 2, w, h),
|
|
|
|
|
- NGUI_RGB(96, 96, 96));
|
|
|
|
|
- ngui_fill_rect(ui, rect_make(x, y, w, h), C_MENU);
|
|
|
|
|
- ngui_frame(ui, rect_make(x, y, w, h), C_MENU_DARK);
|
|
|
|
|
- ngui_fill_rect(ui, rect_make(x + 1, y + 1, w - 2, 1), C_MENU_TOP);
|
|
|
|
|
-
|
|
|
|
|
- ey = y + 3;
|
|
|
|
|
|
|
+ ngui_fill_round_rect(ui, rect_make(r.x + 2, r.y + 4, r.w, r.h),
|
|
|
|
|
+ 8, 8, 8, 8, ui->theme.bg);
|
|
|
|
|
+ ngui_fill_round_rect(ui, r, 8, 8, 8, 8, ui->theme.panel);
|
|
|
|
|
+ ngui_frame_round(ui, r, 8, 8, 8, 8, 1, ui->theme.border);
|
|
|
|
|
+
|
|
|
|
|
+ ey = r.y + 5;
|
|
|
for (i = 0; i < n; i++) {
|
|
for (i = 0; i < n; i++) {
|
|
|
- int eh = menu_entry_h(&e[i]);
|
|
|
|
|
|
|
+ int eh = menu_entry_h(ui, &e[i]);
|
|
|
|
|
|
|
|
if (!e[i].label) {
|
|
if (!e[i].label) {
|
|
|
- ngui_fill_rect(ui, rect_make(x + 4, ey + 3, w - 8, 1),
|
|
|
|
|
- NGUI_RGB(128, 128, 128));
|
|
|
|
|
|
|
+ ngui_fill_rect(ui, rect_make(r.x + 12, ey + eh / 2,
|
|
|
|
|
+ r.w - 24, 1), ui->theme.border);
|
|
|
ey += eh;
|
|
ey += eh;
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
if (ngui_menu_item(ui, ID_MENU_ITEM + (unsigned int)e[i].action,
|
|
if (ngui_menu_item(ui, ID_MENU_ITEM + (unsigned int)e[i].action,
|
|
|
- rect_make(x + 2, ey, w - 4, eh),
|
|
|
|
|
|
|
+ rect_make(r.x + 5, ey, r.w - 10, eh),
|
|
|
e[i].label, e[i].shortcut,
|
|
e[i].label, e[i].shortcut,
|
|
|
action_checked(e[i].action))) {
|
|
action_checked(e[i].action))) {
|
|
|
pending_action = e[i].action;
|
|
pending_action = e[i].action;
|
|
@@ -2105,62 +2123,154 @@ static void draw_dropdown(struct ngui *ui)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static void fmt_time(char *out, int sec)
|
|
|
|
|
+{
|
|
|
|
|
+ int m, s, n = 0;
|
|
|
|
|
+
|
|
|
|
|
+ if (sec < 0)
|
|
|
|
|
+ sec = 0;
|
|
|
|
|
+ m = sec / 60;
|
|
|
|
|
+ s = sec % 60;
|
|
|
|
|
+ if (m > 0) {
|
|
|
|
|
+ fmt_int(out, m);
|
|
|
|
|
+ while (out[n])
|
|
|
|
|
+ n++;
|
|
|
|
|
+ out[n++] = ':';
|
|
|
|
|
+ out[n++] = (char)('0' + s / 10);
|
|
|
|
|
+ out[n++] = (char)('0' + s % 10);
|
|
|
|
|
+ out[n] = '\0';
|
|
|
|
|
+ } else {
|
|
|
|
|
+ fmt_int(out, s);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static void draw_status(struct ngui *ui, const struct sol_layout *l)
|
|
static void draw_status(struct ngui *ui, const struct sol_layout *l)
|
|
|
{
|
|
{
|
|
|
- char b[32], t[24];
|
|
|
|
|
- int n, y = l->status_y + 2;
|
|
|
|
|
|
|
+ char b[24], t[24];
|
|
|
|
|
+ int lh = ngui_text_line_height(ui, ui->font_px, 0);
|
|
|
|
|
+ int y = l->status_y + (STATUS_H - lh) / 2;
|
|
|
|
|
+ int x = 12, lw, tw, rx;
|
|
|
|
|
+ unsigned short dim = ui->theme.text_dim;
|
|
|
|
|
|
|
|
ngui_fill_rect(ui, rect_make(0, l->status_y, ui->w,
|
|
ngui_fill_rect(ui, rect_make(0, l->status_y, ui->w,
|
|
|
- ui->h - l->status_y), C_MENU);
|
|
|
|
|
- ngui_fill_rect(ui, rect_make(0, l->status_y, ui->w, 1), C_MENU_TOP);
|
|
|
|
|
- ngui_fill_rect(ui, rect_make(0, ui->h - 1, ui->w, 1), C_MENU_DARK);
|
|
|
|
|
-
|
|
|
|
|
- n = 0;
|
|
|
|
|
- b[n++] = 'S';
|
|
|
|
|
- b[n++] = 'c';
|
|
|
|
|
- b[n++] = 'o';
|
|
|
|
|
- b[n++] = 'r';
|
|
|
|
|
- b[n++] = 'e';
|
|
|
|
|
- b[n++] = ':';
|
|
|
|
|
- b[n++] = ' ';
|
|
|
|
|
- fmt_int(b + n, score);
|
|
|
|
|
- ngui_text(ui, 8, y, b, C_TEXT);
|
|
|
|
|
-
|
|
|
|
|
- n = 0;
|
|
|
|
|
- t[n++] = 'T';
|
|
|
|
|
- t[n++] = 'i';
|
|
|
|
|
- t[n++] = 'm';
|
|
|
|
|
- t[n++] = 'e';
|
|
|
|
|
- t[n++] = ':';
|
|
|
|
|
- t[n++] = ' ';
|
|
|
|
|
- fmt_int(t + n, elapsed_seconds(u_ticks_ms()));
|
|
|
|
|
- {
|
|
|
|
|
- int tw = (int)text_len(t) * 8;
|
|
|
|
|
-
|
|
|
|
|
- ngui_text(ui, ui->w - 8 - tw, y, t, C_TEXT);
|
|
|
|
|
|
|
+ ui->h - l->status_y), ui->theme.panel);
|
|
|
|
|
+ ngui_fill_rect(ui, rect_make(0, l->status_y, ui->w, 1),
|
|
|
|
|
+ ui->theme.border);
|
|
|
|
|
+ if (y < l->status_y + 1)
|
|
|
|
|
+ y = l->status_y + 1;
|
|
|
|
|
+
|
|
|
|
|
+ ngui_text(ui, x, y, "Score", dim);
|
|
|
|
|
+ lw = (int)ngui_text_width_ui(ui, "Score") + 6;
|
|
|
|
|
+ fmt_int(b, score);
|
|
|
|
|
+ ngui_text(ui, x + lw, y, b, ui->theme.text);
|
|
|
|
|
+ x += lw + (int)ngui_text_width_ui(ui, b);
|
|
|
|
|
+
|
|
|
|
|
+ fmt_time(t, elapsed_seconds(u_ticks_ms()));
|
|
|
|
|
+ tw = (int)ngui_text_width_ui(ui, "Time") + 6 +
|
|
|
|
|
+ (int)ngui_text_width_ui(ui, t);
|
|
|
|
|
+ rx = ui->w - 12 - tw;
|
|
|
|
|
+ if (rx > x + 16) {
|
|
|
|
|
+ ngui_text(ui, rx, y, "Time", dim);
|
|
|
|
|
+ ngui_text(ui, rx + (int)ngui_text_width_ui(ui, "Time") + 6,
|
|
|
|
|
+ y, t, ui->theme.text);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (won) {
|
|
if (won) {
|
|
|
const char *msg = "You win!";
|
|
const char *msg = "You win!";
|
|
|
- int mw = (int)text_len(msg) * 8;
|
|
|
|
|
|
|
+ int mw = (int)ngui_text_width_ui(ui, msg);
|
|
|
int mx = (ui->w - mw) / 2;
|
|
int mx = (ui->w - mw) / 2;
|
|
|
- int left_w = (int)text_len(b) * 8 + 8;
|
|
|
|
|
- int right_w = (int)text_len(t) * 8 + 8;
|
|
|
|
|
|
|
|
|
|
- if (mx > left_w + 12 && mx + mw < ui->w - right_w - 12)
|
|
|
|
|
- ngui_text(ui, mx, y, msg, C_NAVY);
|
|
|
|
|
|
|
+ if (mx > x + 16 && mx + mw < rx - 12)
|
|
|
|
|
+ ngui_text(ui, mx, y, msg, ui->theme.warning);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static int wrap_count(struct ngui *ui, int w, const char *s)
|
|
|
|
|
+{
|
|
|
|
|
+ int lines = 1, line_w = 0;
|
|
|
|
|
+
|
|
|
|
|
+ while (s && *s) {
|
|
|
|
|
+ const char *word = s;
|
|
|
|
|
+ int ww;
|
|
|
|
|
+
|
|
|
|
|
+ while (*s && *s != ' ')
|
|
|
|
|
+ s++;
|
|
|
|
|
+ ww = (int)ngui_text_width_px(ui, word,
|
|
|
|
|
+ (unsigned int)(s - word),
|
|
|
|
|
+ ui->font_px, 0, 0, 0);
|
|
|
|
|
+ if (line_w > 0 && line_w + 6 + ww > w) {
|
|
|
|
|
+ lines++;
|
|
|
|
|
+ line_w = ww;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ line_w += (line_w ? 6 : 0) + ww;
|
|
|
|
|
+ }
|
|
|
|
|
+ while (*s == ' ')
|
|
|
|
|
+ s++;
|
|
|
|
|
+ }
|
|
|
|
|
+ return lines;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int help_line_count(struct ngui *ui, int w,
|
|
|
|
|
+ const char *const *lines, int n)
|
|
|
|
|
+{
|
|
|
|
|
+ int i, count = 0;
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < n; i++)
|
|
|
|
|
+ count += wrap_count(ui, w, lines[i]);
|
|
|
|
|
+ return count;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* Draw one paragraph word-wrapped into `w`; returns the next line's y. */
|
|
|
|
|
+static int draw_wrapped(struct ngui *ui, int x, int y, int w,
|
|
|
|
|
+ const char *s, unsigned short color, int lh,
|
|
|
|
|
+ int bottom)
|
|
|
|
|
+{
|
|
|
|
|
+ int line_w = 0;
|
|
|
|
|
+
|
|
|
|
|
+ while (s && *s) {
|
|
|
|
|
+ const char *word = s;
|
|
|
|
|
+ int ww, lx;
|
|
|
|
|
+
|
|
|
|
|
+ while (*s && *s != ' ')
|
|
|
|
|
+ s++;
|
|
|
|
|
+ ww = (int)ngui_text_width_px(ui, word,
|
|
|
|
|
+ (unsigned int)(s - word),
|
|
|
|
|
+ ui->font_px, 0, 0, 0);
|
|
|
|
|
+ if (line_w > 0 && line_w + 6 + ww > w) {
|
|
|
|
|
+ y += lh;
|
|
|
|
|
+ line_w = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (y + lh > bottom)
|
|
|
|
|
+ return y;
|
|
|
|
|
+ lx = line_w > 0 ? x + line_w + 6 : x;
|
|
|
|
|
+ ngui_text_n(ui, lx, y, word, (unsigned int)(s - word), color);
|
|
|
|
|
+ line_w = lx + ww - x;
|
|
|
|
|
+ while (*s == ' ')
|
|
|
|
|
+ s++;
|
|
|
|
|
+ }
|
|
|
|
|
+ return y + lh;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static void help_geometry(struct ngui *ui, struct ngui_rect *box,
|
|
static void help_geometry(struct ngui *ui, struct ngui_rect *box,
|
|
|
struct ngui_rect *btn)
|
|
struct ngui_rect *btn)
|
|
|
{
|
|
{
|
|
|
- int w = 470, h = 300;
|
|
|
|
|
|
|
+ const char *const *lines;
|
|
|
|
|
+ int n, w, h, lh;
|
|
|
|
|
|
|
|
|
|
+ if (help_open == HELP_ABOUT) {
|
|
|
|
|
+ lines = about_lines;
|
|
|
|
|
+ n = (int)(sizeof(about_lines) / sizeof(about_lines[0]));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ lines = howto_lines;
|
|
|
|
|
+ n = (int)(sizeof(howto_lines) / sizeof(howto_lines[0]));
|
|
|
|
|
+ }
|
|
|
|
|
+ w = 470;
|
|
|
if (w > ui->w - 24)
|
|
if (w > ui->w - 24)
|
|
|
w = ui->w - 24;
|
|
w = ui->w - 24;
|
|
|
if (w < 280)
|
|
if (w < 280)
|
|
|
w = 280;
|
|
w = 280;
|
|
|
|
|
+ lh = ngui_text_line_height(ui, ui->font_px, 0) + 5;
|
|
|
|
|
+ h = 120 + help_line_count(ui, w - 40, lines, n) * lh;
|
|
|
if (h > ui->h - 40)
|
|
if (h > ui->h - 40)
|
|
|
h = ui->h - 40;
|
|
h = ui->h - 40;
|
|
|
if (h < 220)
|
|
if (h < 220)
|
|
@@ -2169,10 +2279,10 @@ static void help_geometry(struct ngui *ui, struct ngui_rect *box,
|
|
|
box->y = (ui->h - h) / 2;
|
|
box->y = (ui->h - h) / 2;
|
|
|
box->w = w;
|
|
box->w = w;
|
|
|
box->h = h;
|
|
box->h = h;
|
|
|
- btn->x = box->x + (w - 70) / 2;
|
|
|
|
|
- btn->y = box->y + h - 30;
|
|
|
|
|
- btn->w = 70;
|
|
|
|
|
- btn->h = 22;
|
|
|
|
|
|
|
+ btn->x = box->x + (w - 84) / 2;
|
|
|
|
|
+ btn->y = box->y + h - 34;
|
|
|
|
|
+ btn->w = 84;
|
|
|
|
|
+ btn->h = 24;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void draw_help(struct ngui *ui)
|
|
static void draw_help(struct ngui *ui)
|
|
@@ -2180,43 +2290,40 @@ static void draw_help(struct ngui *ui)
|
|
|
struct ngui_rect box, btn;
|
|
struct ngui_rect box, btn;
|
|
|
const char *title = help_open == HELP_ABOUT ?
|
|
const char *title = help_open == HELP_ABOUT ?
|
|
|
"About Solitaire" : "How to play";
|
|
"About Solitaire" : "How to play";
|
|
|
- int y, i;
|
|
|
|
|
|
|
+ const char *const *lines;
|
|
|
|
|
+ int n, i, y, lh;
|
|
|
|
|
|
|
|
help_geometry(ui, &box, &btn);
|
|
help_geometry(ui, &box, &btn);
|
|
|
- ngui_fill_rect(ui, rect_make(box.x + 3, box.y + 3, box.w, box.h),
|
|
|
|
|
- NGUI_RGB(80, 80, 80));
|
|
|
|
|
- ngui_fill_rect(ui, box, C_MENU);
|
|
|
|
|
- ngui_frame(ui, box, C_TEXT);
|
|
|
|
|
- ngui_fill_rect(ui, rect_make(box.x + 1, box.y + 1, box.w - 2, 22),
|
|
|
|
|
- C_NAVY);
|
|
|
|
|
- ngui_text(ui, box.x + 8, box.y + 4, title, C_TEXT_LIGHT);
|
|
|
|
|
- if (menu_bar_button(ui, ID_HELP_X,
|
|
|
|
|
- rect_make(box.x + box.w - 18, box.y + 1, 17, 22),
|
|
|
|
|
- "x", 1)) {
|
|
|
|
|
|
|
+ ngui_fill_round_rect(ui, rect_make(box.x + 3, box.y + 4, box.w, box.h),
|
|
|
|
|
+ 10, 10, 10, 10, ui->theme.bg);
|
|
|
|
|
+ ngui_fill_round_rect(ui, box, 10, 10, 10, 10, ui->theme.panel);
|
|
|
|
|
+ ngui_frame_round(ui, box, 10, 10, 10, 10, 1, ui->theme.border);
|
|
|
|
|
+
|
|
|
|
|
+ ngui_text_px(ui, box.x + 20, box.y + 16, title, text_len(title),
|
|
|
|
|
+ ui->theme.text, 18, 1, 0, 0);
|
|
|
|
|
+ if (ngui_icon_button(ui, ID_HELP_X,
|
|
|
|
|
+ rect_make(box.x + box.w - 36, box.y + 12, 24, 24),
|
|
|
|
|
+ NGUI_ICON_CLOSE)) {
|
|
|
help_open = HELP_NONE;
|
|
help_open = HELP_NONE;
|
|
|
ngui_invalidate(ui);
|
|
ngui_invalidate(ui);
|
|
|
}
|
|
}
|
|
|
|
|
+ ngui_fill_rect(ui, rect_make(box.x + 20, box.y + 46, box.w - 40, 1),
|
|
|
|
|
+ ui->theme.border);
|
|
|
|
|
|
|
|
- y = box.y + 38;
|
|
|
|
|
if (help_open == HELP_ABOUT) {
|
|
if (help_open == HELP_ABOUT) {
|
|
|
- ngui_text_styled(ui, box.x + 18, y, "Solitaire", 9,
|
|
|
|
|
- C_TEXT, 2, 1);
|
|
|
|
|
- y += 36;
|
|
|
|
|
- for (i = 0; i < (int)(sizeof(about_lines) /
|
|
|
|
|
- sizeof(about_lines[0])); i++) {
|
|
|
|
|
- if (y + 16 > box.y + box.h - 40)
|
|
|
|
|
- break;
|
|
|
|
|
- ngui_text(ui, box.x + 18, y, about_lines[i], C_TEXT);
|
|
|
|
|
- y += 18;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ lines = about_lines;
|
|
|
|
|
+ n = (int)(sizeof(about_lines) / sizeof(about_lines[0]));
|
|
|
} else {
|
|
} else {
|
|
|
- for (i = 0; i < (int)(sizeof(howto_lines) /
|
|
|
|
|
- sizeof(howto_lines[0])); i++) {
|
|
|
|
|
- if (y + 16 > box.y + box.h - 40)
|
|
|
|
|
- break;
|
|
|
|
|
- ngui_text(ui, box.x + 18, y, howto_lines[i], C_TEXT);
|
|
|
|
|
- y += 18;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ lines = howto_lines;
|
|
|
|
|
+ n = (int)(sizeof(howto_lines) / sizeof(howto_lines[0]));
|
|
|
|
|
+ }
|
|
|
|
|
+ lh = ngui_text_line_height(ui, ui->font_px, 0) + 5;
|
|
|
|
|
+ y = box.y + 60;
|
|
|
|
|
+ for (i = 0; i < n; i++) {
|
|
|
|
|
+ if (y + lh > btn.y - 12)
|
|
|
|
|
+ break;
|
|
|
|
|
+ y = draw_wrapped(ui, box.x + 20, y, box.w - 40, lines[i],
|
|
|
|
|
+ ui->theme.text, lh, btn.y - 12);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (ngui_button(ui, ID_HELP_CLOSE, btn, "Close")) {
|
|
if (ngui_button(ui, ID_HELP_CLOSE, btn, "Close")) {
|
|
@@ -2370,9 +2477,13 @@ static int ui_press_consumed(struct ngui *ui)
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
if (ui->press_y < MENU_H) {
|
|
if (ui->press_y < MENU_H) {
|
|
|
|
|
+ struct ngui_rect gr, hr;
|
|
|
|
|
+
|
|
|
|
|
+ menu_button_rect(ui, MENU_GAME, &gr);
|
|
|
|
|
+ menu_button_rect(ui, MENU_HELP, &hr);
|
|
|
if (menu_open != MENU_NONE &&
|
|
if (menu_open != MENU_NONE &&
|
|
|
- !(ui->press_x >= 6 && ui->press_x < 50) &&
|
|
|
|
|
- !(ui->press_x >= 52 && ui->press_x < 96)) {
|
|
|
|
|
|
|
+ !point_in(&gr, ui->press_x, ui->press_y) &&
|
|
|
|
|
+ !point_in(&hr, ui->press_x, ui->press_y)) {
|
|
|
menu_open = MENU_NONE;
|
|
menu_open = MENU_NONE;
|
|
|
ngui_invalidate(ui);
|
|
ngui_invalidate(ui);
|
|
|
}
|
|
}
|
|
@@ -2380,12 +2491,12 @@ static int ui_press_consumed(struct ngui *ui)
|
|
|
}
|
|
}
|
|
|
if (menu_open != MENU_NONE) {
|
|
if (menu_open != MENU_NONE) {
|
|
|
struct ngui_rect dr;
|
|
struct ngui_rect dr;
|
|
|
- int x = menu_x(menu_open);
|
|
|
|
|
- int y = MENU_H;
|
|
|
|
|
- int w = menu_w(menu_open);
|
|
|
|
|
- int h = menu_dropdown_h(menu_open);
|
|
|
|
|
|
|
|
|
|
- dr = rect_make(x, y, w, h);
|
|
|
|
|
|
|
+ if (!dropdown_rect(ui, &dr)) {
|
|
|
|
|
+ menu_open = MENU_NONE;
|
|
|
|
|
+ ngui_invalidate(ui);
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
if (!point_in(&dr, ui->press_x, ui->press_y)) {
|
|
if (!point_in(&dr, ui->press_x, ui->press_y)) {
|
|
|
menu_open = MENU_NONE;
|
|
menu_open = MENU_NONE;
|
|
|
ngui_invalidate(ui);
|
|
ngui_invalidate(ui);
|
|
@@ -2638,7 +2749,6 @@ void _start(const char *arg)
|
|
|
ngui_init(&ui, (unsigned short *)info.fb, (int)info.width,
|
|
ngui_init(&ui, (unsigned short *)info.fb, (int)info.width,
|
|
|
(int)info.height);
|
|
(int)info.height);
|
|
|
ngui_font_attach(&ui);
|
|
ngui_font_attach(&ui);
|
|
|
- setup_theme(&ui);
|
|
|
|
|
draw_three = 0;
|
|
draw_three = 0;
|
|
|
deck_style = 0;
|
|
deck_style = 0;
|
|
|
quit = 0;
|
|
quit = 0;
|