mirror of
https://github.com/fltk/fltk.git
synced 2026-05-28 03:15:21 +08:00
Allow build of sudoku app with macOS + XQuartz
This commit is contained in:
+19
-17
@@ -42,14 +42,17 @@
|
|||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif // !_WIN32
|
#endif // !_WIN32
|
||||||
|
#if defined __APPLE__ && !defined(FLTK_USE_X11)
|
||||||
|
# define USE_MACOS 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_ALSA_ASOUNDLIB_H
|
#ifdef HAVE_ALSA_ASOUNDLIB_H
|
||||||
# define ALSA_PCM_NEW_HW_PARAMS_API
|
# define ALSA_PCM_NEW_HW_PARAMS_API
|
||||||
# include <alsa/asoundlib.h>
|
# include <alsa/asoundlib.h>
|
||||||
#endif // HAVE_ALSA_ASOUNDLIB_H
|
#endif // HAVE_ALSA_ASOUNDLIB_H
|
||||||
#ifdef __APPLE__
|
#ifdef USE_MACOS
|
||||||
# include <CoreAudio/AudioHardware.h>
|
# include <CoreAudio/AudioHardware.h>
|
||||||
#endif // __APPLE__
|
#endif // USE_MACOS
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# include <mmsystem.h>
|
# include <mmsystem.h>
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
@@ -62,11 +65,11 @@
|
|||||||
#define GROUP_SIZE 160
|
#define GROUP_SIZE 160
|
||||||
#define CELL_SIZE 50
|
#define CELL_SIZE 50
|
||||||
#define CELL_OFFSET 5
|
#define CELL_OFFSET 5
|
||||||
#ifdef __APPLE__
|
#ifdef USE_MACOS
|
||||||
# define MENU_OFFSET 0
|
# define MENU_OFFSET 0
|
||||||
#else
|
#else
|
||||||
# define MENU_OFFSET 25
|
# define MENU_OFFSET 25
|
||||||
#endif // __APPLE__
|
#endif // USE_MACOS
|
||||||
|
|
||||||
// Sound class for Sudoku...
|
// Sound class for Sudoku...
|
||||||
//
|
//
|
||||||
@@ -85,11 +88,8 @@
|
|||||||
// the CoreAudio implementation you see here!
|
// the CoreAudio implementation you see here!
|
||||||
class SudokuSound {
|
class SudokuSound {
|
||||||
// Private, OS-specific data...
|
// Private, OS-specific data...
|
||||||
#ifdef __APPLE__
|
#ifdef USE_MACOS
|
||||||
AudioDeviceID device;
|
AudioDeviceID device;
|
||||||
#ifndef MAC_OS_X_VERSION_10_5
|
|
||||||
#define MAC_OS_X_VERSION_10_5 1050
|
|
||||||
#endif
|
|
||||||
# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
||||||
AudioDeviceIOProcID audio_proc_id;
|
AudioDeviceIOProcID audio_proc_id;
|
||||||
# endif
|
# endif
|
||||||
@@ -115,7 +115,7 @@ class SudokuSound {
|
|||||||
# ifdef HAVE_ALSA_ASOUNDLIB_H
|
# ifdef HAVE_ALSA_ASOUNDLIB_H
|
||||||
snd_pcm_t *handle;
|
snd_pcm_t *handle;
|
||||||
# endif // HAVE_ALSA_ASOUNDLIB_H
|
# endif // HAVE_ALSA_ASOUNDLIB_H
|
||||||
#endif // __APPLE__
|
#endif // USE_MACOS
|
||||||
|
|
||||||
// Common data...
|
// Common data...
|
||||||
static int frequencies[9];
|
static int frequencies[9];
|
||||||
@@ -216,7 +216,7 @@ int SudokuSound::sample_size = 0;
|
|||||||
SudokuSound::SudokuSound() {
|
SudokuSound::SudokuSound() {
|
||||||
sample_size = 0;
|
sample_size = 0;
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef USE_MACOS
|
||||||
remaining = 0;
|
remaining = 0;
|
||||||
|
|
||||||
UInt32 size = sizeof(device);
|
UInt32 size = sizeof(device);
|
||||||
@@ -312,7 +312,7 @@ SudokuSound::SudokuSound() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
# endif // HAVE_ALSA_ASOUNDLIB_H
|
# endif // HAVE_ALSA_ASOUNDLIB_H
|
||||||
#endif // __APPLE__
|
#endif // USE_MACOS
|
||||||
|
|
||||||
if (sample_size) {
|
if (sample_size) {
|
||||||
// Make each of the notes using a combination of sine and sawtooth waves
|
// Make each of the notes using a combination of sine and sawtooth waves
|
||||||
@@ -344,7 +344,7 @@ SudokuSound::SudokuSound() {
|
|||||||
|
|
||||||
// Cleanup the SudokuSound class
|
// Cleanup the SudokuSound class
|
||||||
SudokuSound::~SudokuSound() {
|
SudokuSound::~SudokuSound() {
|
||||||
#ifdef __APPLE__
|
#ifdef USE_MACOS
|
||||||
if (sample_size) {
|
if (sample_size) {
|
||||||
# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
||||||
AudioDeviceStop(device, audio_proc_id);
|
AudioDeviceStop(device, audio_proc_id);
|
||||||
@@ -373,7 +373,7 @@ SudokuSound::~SudokuSound() {
|
|||||||
snd_pcm_close(handle);
|
snd_pcm_close(handle);
|
||||||
}
|
}
|
||||||
# endif // HAVE_ALSA_ASOUNDLIB_H
|
# endif // HAVE_ALSA_ASOUNDLIB_H
|
||||||
#endif // __APPLE__
|
#endif // USE_MACOS
|
||||||
|
|
||||||
if (sample_size) {
|
if (sample_size) {
|
||||||
for (int i = 0; i < 9; i ++) {
|
for (int i = 0; i < 9; i ++) {
|
||||||
@@ -383,7 +383,7 @@ SudokuSound::~SudokuSound() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef USE_MACOS
|
||||||
// Callback function for writing audio data...
|
// Callback function for writing audio data...
|
||||||
OSStatus
|
OSStatus
|
||||||
SudokuSound::audio_cb(AudioDeviceID device,
|
SudokuSound::audio_cb(AudioDeviceID device,
|
||||||
@@ -413,7 +413,7 @@ SudokuSound::audio_cb(AudioDeviceID device,
|
|||||||
|
|
||||||
return noErr;
|
return noErr;
|
||||||
}
|
}
|
||||||
#endif // __APPLE__
|
#endif // USE_MACOS
|
||||||
|
|
||||||
#define NOTE_DURATION 50
|
#define NOTE_DURATION 50
|
||||||
|
|
||||||
@@ -421,7 +421,7 @@ SudokuSound::audio_cb(AudioDeviceID device,
|
|||||||
void SudokuSound::play(char note) {
|
void SudokuSound::play(char note) {
|
||||||
Fl::check();
|
Fl::check();
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef USE_MACOS
|
||||||
// Point to the next note...
|
// Point to the next note...
|
||||||
data = sample_data[note - 'A'];
|
data = sample_data[note - 'A'];
|
||||||
remaining = sample_size * 2;
|
remaining = sample_size * 2;
|
||||||
@@ -477,7 +477,7 @@ void SudokuSound::play(char note) {
|
|||||||
XChangeKeyboardControl(fl_display,
|
XChangeKeyboardControl(fl_display,
|
||||||
KBBellPercent | KBBellPitch | KBBellDuration,
|
KBBellPercent | KBBellPitch | KBBellDuration,
|
||||||
&control);
|
&control);
|
||||||
#endif // __APPLE__
|
#endif // USE_MACOS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -643,7 +643,9 @@ Sudoku::Sudoku()
|
|||||||
{ "&Solve Game", FL_COMMAND | 's', solve_cb, 0, FL_MENU_DIVIDER },
|
{ "&Solve Game", FL_COMMAND | 's', solve_cb, 0, FL_MENU_DIVIDER },
|
||||||
{ "&Update Helpers", 0, update_helpers_cb, 0, 0 },
|
{ "&Update Helpers", 0, update_helpers_cb, 0, 0 },
|
||||||
{ "&Mute Sound", FL_COMMAND | 'm', mute_cb, 0, FL_MENU_TOGGLE | FL_MENU_DIVIDER },
|
{ "&Mute Sound", FL_COMMAND | 'm', mute_cb, 0, FL_MENU_TOGGLE | FL_MENU_DIVIDER },
|
||||||
|
#ifndef USE_MACOS
|
||||||
{ "&Quit", FL_COMMAND | 'q', close_cb, 0, 0 },
|
{ "&Quit", FL_COMMAND | 'q', close_cb, 0, 0 },
|
||||||
|
#endif
|
||||||
{ 0 },
|
{ 0 },
|
||||||
{ "&Difficulty", 0, 0, 0, FL_SUBMENU },
|
{ "&Difficulty", 0, 0, 0, FL_SUBMENU },
|
||||||
{ "&Easy", 0, diff_cb, (void *)"0", FL_MENU_RADIO },
|
{ "&Easy", 0, diff_cb, (void *)"0", FL_MENU_RADIO },
|
||||||
|
|||||||
Reference in New Issue
Block a user