-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
52 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Twin - A Tiny Window System | ||
* Copyright (c) 2004 Keith Packard <[email protected]> | ||
* Copyright (c) 2024-2025 National Cheng Kung University, Taiwan | ||
* All rights reserved. | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Twin - A Tiny Window System | ||
* Copyright (c) 2004 Keith Packard <[email protected]> | ||
* Copyright (c) 2024 National Cheng Kung University, Taiwan | ||
* All rights reserved. | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Twin - A Tiny Window System | ||
* Copyright (c) 2004 Keith Packard <[email protected]> | ||
* Copyright (c) 2024 National Cheng Kung University, Taiwan | ||
* All rights reserved. | ||
*/ | ||
|
||
|
@@ -16,6 +17,7 @@ void twin_dispatch(twin_context_t *ctx) | |
for (;;) { | ||
_twin_run_timeout(); | ||
_twin_run_work(); | ||
|
||
if (g_twin_backend.poll && !g_twin_backend.poll(ctx)) { | ||
twin_time_t delay = _twin_timeout_delay(); | ||
if (delay > 0) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Twin - A Tiny Window System | ||
* Copyright (c) 2004 Keith Packard <[email protected]> | ||
* Copyright (c) 2024 National Cheng Kung University, Taiwan | ||
* All rights reserved. | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Twin - A Tiny Window System | ||
* Copyright (c) 2004 Keith Packard <[email protected]> | ||
* Copyright (c) 2024 National Cheng Kung University, Taiwan | ||
* All rights reserved. | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Twin - A Tiny Window System | ||
* Copyright (c) 2004 Keith Packard <[email protected]> | ||
* Copyright (c) 2024 National Cheng Kung University, Taiwan | ||
* All rights reserved. | ||
*/ | ||
|
||
|
@@ -11,9 +12,9 @@ void twin_matrix_multiply(twin_matrix_t *result, | |
const twin_matrix_t *b) | ||
{ | ||
twin_matrix_t r; | ||
twin_fixed_t t; | ||
|
||
for (int row = 0; row < 3; row++) | ||
for (int row = 0; row < 3; row++) { | ||
twin_fixed_t t; | ||
for (int col = 0; col < 2; col++) { | ||
if (row == 2) | ||
t = b->m[2][col]; | ||
|
@@ -23,6 +24,7 @@ void twin_matrix_multiply(twin_matrix_t *result, | |
t += twin_fixed_mul(a->m[row][n], b->m[n][col]); | ||
r.m[row][col] = t; | ||
} | ||
} | ||
|
||
*result = r; | ||
} | ||
|
@@ -72,14 +74,13 @@ void twin_matrix_scale(twin_matrix_t *m, twin_fixed_t sx, twin_fixed_t sy) | |
twin_fixed_t _twin_matrix_determinant(twin_matrix_t *matrix) | ||
{ | ||
twin_fixed_t a, b, c, d; | ||
twin_fixed_t det; | ||
|
||
a = matrix->m[0][0]; | ||
b = matrix->m[0][1]; | ||
c = matrix->m[1][0]; | ||
d = matrix->m[1][1]; | ||
|
||
det = twin_fixed_mul(a, d) - twin_fixed_mul(b, c); | ||
twin_fixed_t det = twin_fixed_mul(a, d) - twin_fixed_mul(b, c); | ||
|
||
return det; | ||
} | ||
|
@@ -99,31 +100,32 @@ twin_point_t _twin_matrix_expand(twin_matrix_t *matrix) | |
|
||
void twin_matrix_rotate(twin_matrix_t *m, twin_angle_t a) | ||
{ | ||
twin_matrix_t t; | ||
twin_fixed_t c, s; | ||
twin_sincos(a, &s, &c); | ||
|
||
t.m[0][0] = c; | ||
t.m[0][1] = s; | ||
t.m[1][0] = -s; | ||
t.m[1][1] = c; | ||
t.m[2][0] = 0; | ||
t.m[2][1] = 0; | ||
twin_matrix_t t = { | ||
.m[0][0] = c, | ||
.m[0][1] = s, | ||
.m[1][0] = -s, | ||
.m[1][1] = c, | ||
.m[2][0] = 0, | ||
.m[2][1] = 0, | ||
}; | ||
twin_matrix_multiply(m, &t, m); | ||
} | ||
|
||
twin_sfixed_t _twin_matrix_x(twin_matrix_t *m, twin_fixed_t x, twin_fixed_t y) | ||
{ | ||
twin_sfixed_t s; | ||
s = twin_fixed_to_sfixed(twin_fixed_mul(m->m[0][0], x) + | ||
twin_sfixed_t s = | ||
twin_fixed_to_sfixed(twin_fixed_mul(m->m[0][0], x) + | ||
twin_fixed_mul(m->m[1][0], y) + m->m[2][0]); | ||
return s; | ||
} | ||
|
||
twin_sfixed_t _twin_matrix_y(twin_matrix_t *m, twin_fixed_t x, twin_fixed_t y) | ||
{ | ||
twin_sfixed_t s; | ||
s = twin_fixed_to_sfixed(twin_fixed_mul(m->m[0][1], x) + | ||
twin_sfixed_t s = | ||
twin_fixed_to_sfixed(twin_fixed_mul(m->m[0][1], x) + | ||
twin_fixed_mul(m->m[1][1], y) + m->m[2][1]); | ||
return s; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Twin - A Tiny Window System | ||
* Copyright (c) 2004 Keith Packard <[email protected]> | ||
* Copyright (c) 2024 National Cheng Kung University, Taiwan | ||
* All rights reserved. | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Twin - A Tiny Window System | ||
* Copyright (c) 2004 Keith Packard <[email protected]> | ||
* Copyright (c) 2024-2025 National Cheng Kung University, Taiwan | ||
* All rights reserved. | ||
*/ | ||
|
||
|
@@ -13,6 +14,7 @@ | |
(((alignment) & ((alignment) - 1)) == 0 \ | ||
? (((sz) + (alignment) - 1) & ~((alignment) - 1)) \ | ||
: ((((sz) + (alignment) - 1) / (alignment)) * (alignment))) | ||
|
||
twin_pixmap_t *twin_pixmap_create(twin_format_t format, | ||
twin_coord_t width, | ||
twin_coord_t height) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Twin - A Tiny Window System | ||
* Copyright (c) 2004 Keith Packard <[email protected]> | ||
* Copyright (c) 2024 National Cheng Kung University, Taiwan | ||
* All rights reserved. | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Twin - A Tiny Window System | ||
* Copyright (c) 2004 Keith Packard <[email protected]> | ||
* Copyright (c) 2024 National Cheng Kung University, Taiwan | ||
* All rights reserved. | ||
*/ | ||
|
||
|
@@ -17,6 +18,7 @@ void _twin_queue_insert(twin_queue_t **head, | |
for (prev = head; (q = *prev); prev = &q->next) | ||
if ((*proc)(new, q) == TWIN_AFTER) | ||
break; | ||
|
||
new->next = *prev; | ||
new->order = 0; | ||
new->deleted = false; | ||
|
@@ -59,9 +61,8 @@ twin_queue_t *_twin_queue_set_order(twin_queue_t **head) | |
{ | ||
twin_queue_t *first = *head; | ||
|
||
for (twin_queue_t *q = first; q; q = q->next) { | ||
for (twin_queue_t *q = first; q; q = q->next) | ||
q->order = q->next; | ||
} | ||
return first; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Twin - A Tiny Window System | ||
* Copyright (c) 2004 Keith Packard <[email protected]> | ||
* Copyright (c) 2024-2025 National Cheng Kung University, Taiwan | ||
* All rights reserved. | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Twin - A Tiny Window System | ||
* Copyright (c) 2004 Carl Worth <[email protected]> | ||
* Copyright (c) 2024 National Cheng Kung University, Taiwan | ||
* All rights reserved. | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Twin - A Tiny Window System | ||
* Copyright (c) 2004 Keith Packard <[email protected]> | ||
* Copyright (c) 2024 National Cheng Kung University, Taiwan | ||
* All rights reserved. | ||
*/ | ||
|
||
|
@@ -34,6 +35,7 @@ twin_fixed_t twin_tan(twin_angle_t a) | |
} | ||
if (s == 0) | ||
return 0; | ||
|
||
return ((s << 15) / c) << 1; | ||
} | ||
|
||
|
@@ -124,7 +126,9 @@ static twin_angle_t twin_atan2_first_quadrant(twin_fixed_t y, twin_fixed_t x) | |
return TWIN_ANGLE_90; | ||
if (y == 0) | ||
return TWIN_ANGLE_0; | ||
|
||
twin_angle_t angle = 0; | ||
|
||
/* CORDIC iteration */ | ||
/* | ||
* To enhance accuracy, the angle is mapped from the range 0-360 degrees to | ||
|
@@ -143,6 +147,7 @@ static twin_angle_t twin_atan2_first_quadrant(twin_fixed_t y, twin_fixed_t x) | |
angle -= atan_table[i]; | ||
} | ||
} | ||
|
||
return (twin_angle_t) (double) angle / (32768.0) * TWIN_ANGLE_360; | ||
} | ||
|
||
|
@@ -154,6 +159,7 @@ twin_angle_t twin_atan2(twin_fixed_t y, twin_fixed_t x) | |
return (y > 0) ? TWIN_ANGLE_90 : TWIN_ANGLE_270; | ||
if (y == 0) | ||
return (x > 0) ? TWIN_ANGLE_0 : TWIN_ANGLE_180; | ||
|
||
twin_fixed_t x_sign_mask = x >> 31; | ||
twin_fixed_t abs_x = (x ^ x_sign_mask) - x_sign_mask; | ||
twin_fixed_t y_sign_mask = y >> 31; | ||
|
@@ -164,6 +170,7 @@ twin_angle_t twin_atan2(twin_fixed_t y, twin_fixed_t x) | |
((~x_sign_mask & y_sign_mask) * 2); | ||
twin_fixed_t sign = 1 - 2 * (x_sign_mask ^ y_sign_mask); | ||
twin_angle_t angle = twin_atan2_first_quadrant(abs_y, abs_x); | ||
|
||
/* First quadrant : angle | ||
* Second quadrant : 180 - angle | ||
* Third quadrant : 180 + angle | ||
|
@@ -178,6 +185,7 @@ twin_angle_t twin_acos(twin_fixed_t x) | |
return TWIN_ANGLE_180; | ||
if (x >= TWIN_FIXED_ONE) | ||
return TWIN_ANGLE_0; | ||
|
||
twin_fixed_t y = twin_fixed_sqrt(TWIN_FIXED_ONE - twin_fixed_mul(x, x)); | ||
if (x < 0) | ||
return TWIN_ANGLE_180 - twin_atan2_first_quadrant(y, -x); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Twin - A Tiny Window System | ||
* Copyright (c) 2004 Keith Packard <[email protected]> | ||
* Copyright (c) 2024-2025 National Cheng Kung University, Taiwan | ||
* All rights reserved. | ||
*/ | ||
|
||
|
@@ -117,6 +118,7 @@ void _twin_widget_init(twin_widget_t *widget, | |
window = parent->widget.window; | ||
} else | ||
widget->next = NULL; | ||
|
||
widget->window = window; | ||
widget->parent = parent; | ||
widget->copy_geom = NULL; | ||
|
@@ -137,6 +139,7 @@ void _twin_widget_queue_paint(twin_widget_t *widget) | |
while (widget->parent) { | ||
if (widget->paint) | ||
return; | ||
|
||
widget->paint = true; | ||
widget = &widget->parent->widget; | ||
} | ||
|
@@ -148,6 +151,7 @@ void _twin_widget_queue_layout(twin_widget_t *widget) | |
while (widget->parent) { | ||
if (widget->layout) | ||
return; | ||
|
||
widget->layout = true; | ||
widget->paint = true; | ||
widget = &widget->parent->widget; | ||
|
@@ -179,6 +183,7 @@ void _twin_widget_bevel(twin_widget_t *widget, twin_fixed_t b, bool down) | |
top_color = 0x80808080; | ||
bot_color = 0x80000000; | ||
} | ||
|
||
twin_path_move(path, 0, 0); | ||
twin_path_draw(path, w, 0); | ||
twin_path_draw(path, w - b, b); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Twin - A Tiny Window System | ||
* Copyright (c) 2004 Keith Packard <[email protected]> | ||
* Copyright (c) 2024-2025 National Cheng Kung University, Taiwan | ||
* All rights reserved. | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters