Commit graph

67 commits

Author SHA1 Message Date
Andreas Kling
d6abfbdc5a LibCore: Remove ObjectPtr in favor of RefPtr
Now that CObject is fully ref-counted, just use RefPtr everywhere! :^)
2019-09-22 00:31:54 +02:00
Andreas Kling
bc319d9e88 LibCore: Make CObject reference-counted
Okay, I've spent a whole day on this now, and it finally kinda works!
With this patch, CObject and all of its derived classes are reference
counted instead of tree-owned.

The previous, Qt-like model was nice and familiar, but ultimately also
outdated and difficult to reason about.

CObject-derived types should now be stored in RefPtr/NonnullRefPtr and
each class can be constructed using the forwarding construct() helper:

    auto widget = GWidget::construct(parent_widget);

Note that construct() simply forwards all arguments to an existing
constructor. It is inserted into each class by the C_OBJECT macro,
see CObject.h to understand how that works.

CObject::delete_later() disappears in this patch, as there is no longer
a single logical owner of a CObject.
2019-09-22 00:25:25 +02:00
Andreas Kling
defafd72bc LibGUI: Convert custom widgets and subclasses to ObjectPtr 2019-09-21 20:04:00 +02:00
Andreas Kling
45cfd57f6e GButton: Convert most code to using ObjectPtr for GButton 2019-09-21 19:28:28 +02:00
Andreas Kling
7584480f62 LibGUI: Convert GWindow to ObjectPtr 2019-09-21 18:34:06 +02:00
Andreas Kling
f4b51a63ec LibCore: Remove CTimer::create() overloads in favor of construct() 2019-09-21 18:13:17 +02:00
Andreas Kling
ff6ce422dd LibGUI: Convert GWidget to ObjectPtr 2019-09-21 17:05:35 +02:00
Andreas Kling
c7437f9caa LibGUI: Convert GLabel to ObjectPtr 2019-09-21 15:25:08 +02:00
Andreas Kling
50a6560413 LibCore: Convert CTimer to ObjectPtr 2019-09-20 15:20:10 +02:00
Andreas Kling
e83390387c LibGUI: Simplify GCommonActions a bit
Use the same callback signature as GAction so we can just forward it
to GAction instead of chaining callbacks.
2019-09-14 22:10:44 +02:00
rhin123
3261ffb2fd Snake: Added GCommonActions 2019-09-05 09:40:54 +02:00
rhin123
aab28ea9c0 Minesweeper: Added GCommonActions 2019-09-05 09:40:54 +02:00
Andreas Kling
a3788f1297 Minesweeper: Reorganize menus a bit
Move some of the "Game" menu into the app menu, and add a separate menu
for the difficulty setting.
2019-08-27 13:51:04 +02:00
Andreas Kling
227bfd79d3 Snake: Merge "Game" menu into the app menu 2019-08-27 13:25:08 +02:00
Andreas Kling
4917445e2e Minesweeper: Make the SquareButtons non-checkable
We manage the checked state of these buttons manually in the code, and
we don't want the user to interfere with it, which would be possible if
we put them in checkable state.
2019-08-12 18:51:23 +02:00
Drew Stratford
80cb833594 Minesweeper: refactor on_square_clicked and flood_mark
Both on_square_clicked and flood_mark were very similar so I've
introduced the on_square_clicked_impl function which is now
called by on_square_clicked and flood_fill.
2019-07-29 19:34:31 +02:00
Drew Stratford
6b757a152a Minesweeper: updated flood_fill to use Queue 2019-07-29 19:34:31 +02:00
Drew Stratford
77cb83b629 Minesweeper: make Field::flood_fill iterative
This change uses an iterative traversal to avoid stack overflows
in, the previously recursive, flood_fill.
2019-07-29 19:34:31 +02:00
Andreas Kling
841b2e5d13 WindowServer+LibGUI: Pass window icons as shared buffers rather than paths.
Now that we support more than 2 clients per shared buffer, we can use them
for window icons. I didn't do that previously since it would have made the
Taskbar process unable to access the icons.

This opens up some nice possibilities for programmatically generated icons.
2019-07-28 10:18:49 +02:00
Andreas Kling
72a3f69df7 LibGUI: Get rid of GWindow::should_exit_event_loop_on_close().
This behavior and API was extremely counter-intuitive since our default
behavior was for applications to never exit after you close all of their
windows.

Now that we exit the event loop by default when the very last GWindow is
deleted, we don't have to worry about this.
2019-07-23 18:20:00 +02:00
Andreas Kling
aa2224a2f0 GWidget: Add set_preferred_size(width, height) overload.
It was annoying to always write set_preferred_size({ width, height }). :^)
2019-07-20 22:39:24 +02:00
Andreas Kling
1c0669f010 LibDraw: Introduce (formerly known as SharedGraphics.)
Instead of LibGUI and WindowServer building their own copies of the drawing
and graphics code, let's it in a separate LibDraw library.

This avoids building the code twice, and will encourage better separation
of concerns. :^)
2019-07-18 10:18:16 +02:00
Andreas Kling
8327b12291 Minesweeper: Remove use of copy_ref(). 2019-07-11 15:53:01 +02:00
Andreas Kling
b79112e6d6 AK: Add String::number() for creating a String from a number.
Instead of manually doing String::format("%d"/"%u") everywhere, let's have
a String API for this. It's just a wrapper around format() for now, but it
could be made more efficient in the future.
2019-07-03 14:56:27 +02:00
Jookia
eb4c42bfa8 Minesweeper: Move configuration reading to Field
This makes more sense as it's where configuration writing happens.
2019-07-01 09:51:03 +02:00
Jookia
9dbf453015 Minesweeper: Allow single-click chording
This is how other Minesweeper games I've played usually behave.
Single-click chording can be disabled from the menu or config file.
2019-07-01 09:51:03 +02:00
VAN BOSSUYT Nicolas
802d4dcb6b Meta: Removed all gitignore in the source tree only keeping the root one 2019-06-30 10:41:26 +02:00
Andreas Kling
315716d193 GUI: Use Win2K-like "warm gray" color instead of the older colder gray.
Someone suggested this a long time ago and I never got around to it.
So here we go, here's the warm gray! I have to admit I like it better. :^)
2019-06-30 09:23:16 +02:00
Andreas Kling
d403e56494 Snake: Use NonnullRefPtrVector. 2019-06-27 13:46:31 +02:00
Andreas Kling
90b1354688 AK: Rename RetainPtr => RefPtr and Retained => NonnullRefPtr. 2019-06-21 18:37:47 +02:00
Andreas Kling
39d1a9ae66 Meta: Tweak .clang-format to not wrap braces after enums. 2019-06-07 17:13:23 +02:00
Andreas Kling
fba2c971e7 Games: Run clang-format on everything. 2019-06-07 11:48:15 +02:00
Robin Burchell
0dc9af5f7e Add clang-format file
Also run it across the whole tree to get everything using the One True Style.
We don't yet run this in an automated fashion as it's a little slow, but
there is a snippet to do so in makeall.sh.
2019-05-28 17:31:20 +02:00
Robin Burchell
40a5eb4e6e Minesweeper: Make things a little more friendly at the start
Rather than having the first click hit a bomb, if the first click would
hit a bomb, instead, reset the game board.

This is a (sort of) feature of Windows minesweeper, and IMO makes
playing a bit more fun :-)
2019-05-19 21:33:50 +02:00
Andreas Kling
852d648912 Fix "make clean" not deleting app binaries. 2019-05-13 14:56:18 +02:00
Andreas Kling
ab42180e83 Fix some more victims of the new default layout spacing. 2019-05-11 03:06:18 +02:00
Andreas Kling
ac67a2ed5e Minesweeper: Flag unflagged mines on win. 2019-05-06 13:27:58 +02:00
Andreas Kling
13b8c7eab8 Minesweeper: Fix lag when changing the field size.
Use a number of techniques to avoid freezing the UI for too long.

- Keep reusing the same widgets for the squares once they've been created.
- Temporarily disable widget updates.
- Avoid some redundant work on each run of reset().
2019-05-02 04:21:21 +02:00
Andreas Kling
75734aa003 Minesweeper: Add considering feature, where middle clicking marks with '?'
This is useful in the harder modes, for trying out different possibilities.
2019-04-28 13:55:41 +02:00
Andreas Kling
146aedc32c Minesweeper: Implement some feature requests.
Someone was playing this game and suggested a number of improvements so here
we go trying to address them:

- Add "chording" support, where you can click a numbered square using both
  mouse buttons simultaneously to sweep all non-flagged adjacent squares.

- Mis-flagged squares are now revealed as such on game over, with a special
  "bad flag" icon.

- The game timer now shows tenths of seconds. It also doesn't start until
  you click the first square.

- Add the three difficulty modes from the classic Windows version.
2019-04-26 19:54:31 +02:00
Andreas Kling
08bc5d44e7 Games: Use Makefile.common here too. 2019-04-26 15:14:28 +02:00
Andreas Kling
b3f7f5436a Snake+Minesweeper: Exit process when game window is closed. 2019-04-21 04:11:29 +02:00
Andreas Kling
a56e1afb64 Snake: Show the highest score achieved so far (in this session.) 2019-04-20 21:24:38 +02:00
Andreas Kling
0dcb7a234e LibGUI+Minesweeper: Add GWindow::set_resizable(). 2019-04-20 21:24:02 +02:00
Andreas Kling
a0633c298b Snake: Add a window icon. :^) 2019-04-20 20:14:02 +02:00
Andreas Kling
ca9a430965 Snake: Disable double-buffering for the game window.
There's no need to use automatic double-buffering here since we manage the
backing store manually.
2019-04-20 19:51:10 +02:00
Andreas Kling
c9b86be1cc Snake: Add some more fruit types. 2019-04-20 18:50:41 +02:00
Andreas Kling
4619019481 Snake: Tweak game speed so it's not too easy. 2019-04-20 17:46:59 +02:00
Andreas Kling
79573ce7e6 Snake: Try to only repaint the parts that actually changed between ticks. 2019-04-20 15:04:34 +02:00
Andreas Kling
301a269ca0 Get rid of SERENITY macro since the compiler already defines __serenity__
This makes it a bit easier to use AK templates out-of-tree.
2019-04-20 12:58:49 +02:00