diff --git a/CMakeLists.txt b/CMakeLists.txt index dd8d9c8623..463aa92999 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ add_subdirectory(TestApps) add_subdirectory(Samples/HelloWorld) add_subdirectory(Samples/Raytracer) add_subdirectory(Samples/Launcher) +add_subdirectory(Samples/Dialog) else() configure_file(cmake/retro68.toolchain.cmake.in cmake/retro68.toolchain.cmake @ONLY) diff --git a/Rez/Rez.cc b/Rez/Rez.cc index b11a9ac783..53b06dc288 100644 --- a/Rez/Rez.cc +++ b/Rez/Rez.cc @@ -83,7 +83,7 @@ int main(int argc, const char *argv[]) world.getResources().addResources(rsrcFile.resources); } if(options.count("copy")) - for(std::string copyFile : options["define"].as>()) + for(std::string copyFile : options["copy"].as>()) { ResourceFile copyRsrc(copyFile); diff --git a/Rez/RezLexer.cc b/Rez/RezLexer.cc index a21f281b31..42c8fc7d5a 100644 --- a/Rez/RezLexer.cc +++ b/Rez/RezLexer.cc @@ -27,6 +27,8 @@ static std::string preFilter(std::string str) boost::regex dollar_escape("\\\\\\$([a-zA-Z0-9][a-zA-Z0-9])"); str = boost::regex_replace(str, dollar_escape, "\\\\0x$1"); + if(str.size() == 0 || str[str.size()-1] != '\n') + str += "\n"; return str; } diff --git a/Rez/RezLexerNextToken.cc b/Rez/RezLexerNextToken.cc index b00d3e2b4f..e9322b556c 100644 --- a/Rez/RezLexerNextToken.cc +++ b/Rez/RezLexerNextToken.cc @@ -286,5 +286,5 @@ case T_ ## name: /*std::cout << #name << std::endl;*/ return RezParser::make_ ## } } } - return RezSymbol(); + return RezParser::symbol_type(RezParser::token_type(0), yy::location()); } diff --git a/Samples/Dialog/CMakeLists.txt b/Samples/Dialog/CMakeLists.txt new file mode 100644 index 0000000000..beb1e50e62 --- /dev/null +++ b/Samples/Dialog/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright 2015 Wolfgang Thaller. +# +# This file is part of Retro68. +# +# Retro68 is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Retro68 is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Retro68. If not, see . + +# To use this example as a standalone project using CMake: +# mkdir build +# cd build +# cmake .. -DCMAKE_TOOLCHAIN_FILE=path/to/Retro68-build/toolchain/cmake/retro68.toolchain.cmake +# make + +cmake_minimum_required(VERSION 2.8) + +add_application(Dialog + dialog.c + dialog.r + ) diff --git a/Samples/Dialog/dialog.c b/Samples/Dialog/dialog.c new file mode 100644 index 0000000000..43d3076abc --- /dev/null +++ b/Samples/Dialog/dialog.c @@ -0,0 +1,84 @@ +/* + Copyright 2015 Wolfgang Thaller. + + This file is part of Retro68. + + Retro68 is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Retro68 is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Retro68. If not, see . +*/ + +#include +#include + +QDGlobals qd; + +pascal void ButtonFrameProc(DialogRef dlg, DialogItemIndex itemNo) +{ + DialogItemType type; + Handle itemH; + Rect box; + + GetDialogItem(dlg, 1, &type, &itemH, &box); + InsetRect(&box, -4, -4); + PenSize(3,3); + FrameRoundRect(&box,16,16); +} + +int main() +{ + WindowPtr win; + + InitGraf(&qd.thePort); + InitFonts(); + InitWindows(); + InitMenus(); + + DialogPtr dlg = GetNewDialog(128,0,(WindowPtr)-1); + InitCursor(); + SelectDialogItemText(dlg,4,0,32767); + + DialogItemType type; + Handle itemH; + Rect box; + + GetDialogItem(dlg, 2, &type, &itemH, &box); + SetDialogItem(dlg, 2, type, (Handle) NewUserItemUPP(&ButtonFrameProc), &box); + + ControlHandle cb, radio1, radio2; + GetDialogItem(dlg, 5, &type, &itemH, &box); + cb = (ControlHandle)itemH; + GetDialogItem(dlg, 6, &type, &itemH, &box); + radio1 = (ControlHandle)itemH; + GetDialogItem(dlg, 7, &type, &itemH, &box); + radio2 = (ControlHandle)itemH; + SetControlValue(radio1, 1); + + short item; + do { + ModalDialog(NULL, &item); + + if(item >= 5 && item <= 7) + { + if(item == 5) + SetControlValue(cb, !GetControlValue(cb)); + if(item == 6 || item == 7) + { + SetControlValue(radio1, item == 6); + SetControlValue(radio2, item == 7); + } + } + } while(item != 1); + + FlushEvents(everyEvent, -1); + return 0; +} diff --git a/Samples/Dialog/dialog.r b/Samples/Dialog/dialog.r new file mode 100644 index 0000000000..380f48907f --- /dev/null +++ b/Samples/Dialog/dialog.r @@ -0,0 +1,56 @@ +/* + Copyright 2015 Wolfgang Thaller. + + This file is part of Retro68. + + Retro68 is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Retro68 is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Retro68. If not, see . +*/ + +#include "Dialogs.r" + +resource 'DLOG' (128) { + { 50, 100, 240, 420 }, + dBoxProc, + visible, + noGoAway, + 0, + 128, + "", + centerMainScreen +}; + +resource 'DITL' (128) { + { + { 190-10-20, 320-10-80, 190-10, 320-10 }, + Button { enabled, "Quit" }; + + { 190-10-20-5, 320-10-80-5, 190-10+5, 320-10+5 }, + UserItem { enabled }; + + { 10, 10, 30, 310 }, + StaticText { enabled, "Static Text Item" }; + + { 40, 10, 56, 310 }, + EditText { enabled, "Edit Text Item" }; + + { 70, 10, 86, 310 }, + CheckBox { enabled, "Check Box" }; + + { 90, 10, 106, 310 }, + RadioButton { enabled, "Radio 1" }; + + { 110, 10, 126, 310 }, + RadioButton { enabled, "Radio 2" }; + } +}; diff --git a/build-toolchain.sh b/build-toolchain.sh index f8c96047e8..ed1db5fb85 100644 --- a/build-toolchain.sh +++ b/build-toolchain.sh @@ -61,6 +61,9 @@ cd .. sh "$SRC/prepare-headers.sh" "$SRC/CIncludes" toolchain/m68k-unknown-elf/include +mkdir -p toolchain/RIncludes +cp '$SRC/RIncludes/*.r' toolchain/RIncludes/ + mkdir -p build-host cd build-host cmake ${SRC} -DCMAKE_INSTALL_PREFIX=$PREFIX diff --git a/cmake/add_application.cmake b/cmake/add_application.cmake index bb46fa15e7..c2336f0b87 100644 --- a/cmake/add_application.cmake +++ b/cmake/add_application.cmake @@ -13,8 +13,21 @@ function(add_application name) list(APPEND ARGS_FILES ${ARGS_UNPARSED_ARGUMENTS}) set(files) - foreach(f ${ARGS_FILES}) - list(APPEND files "${CMAKE_CURRENT_SOURCE_DIR}/${f}") + set(rsrc_files) + foreach(f ${ARGS_FILES}) + if(${f} MATCHES "\\.r$") + add_custom_command( + OUTPUT ${f}.rsrc + COMMAND ${REZ} ${CMAKE_CURRENT_SOURCE_DIR}/${f} -I ${REZ_INCLUDE_PATH} -o ${f}.rsrc + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${f}) + list(APPEND rsrc_files "${CMAKE_CURRENT_BINARY_DIR}/${f}.rsrc") + elseif(${f} MATCHES "\\.rsrc$") + list(APPEND rsrc_files "${f}") + elseif(${f} MATCHES "\\.rsrc.bin$") + list(APPEND rsrc_files "${f}") + else() + list(APPEND files "${CMAKE_CURRENT_SOURCE_DIR}/${f}") + endif() endforeach() add_executable(${name} ${files}) @@ -29,6 +42,11 @@ function(add_application name) set_target_properties(${name} PROPERTIES LINKER_LANGUAGE CXX) endif() + foreach(f ${rsrc_files}) + list(APPEND ARGS_MAKEAPPL_ARGS --copy "${f}") + endforeach() + + if(TARGET libretro) set_target_properties(${name} PROPERTIES LINK_DEPENDS libretro) @@ -39,8 +57,8 @@ function(add_application name) add_custom_command( OUTPUT ${name}.bin ${name}.APPL ${name}.dsk COMMAND ${MAKE_APPL} ${ARGS_MAKEAPPL_ARGS} -c "${name}.flt" -o "${name}" - DEPENDS ${name}) + DEPENDS ${name} ${rsrc_files}) add_custom_target(${name}_APPL ALL DEPENDS ${name}.bin) endfunction() -cmake_policy(POP) \ No newline at end of file +cmake_policy(POP) diff --git a/cmake/retro68.toolchain.cmake.in b/cmake/retro68.toolchain.cmake.in index 0f029a0018..b76396f2da 100644 --- a/cmake/retro68.toolchain.cmake.in +++ b/cmake/retro68.toolchain.cmake.in @@ -23,6 +23,7 @@ set( CMAKE_INSTALL_PREFIX "${RETRO68_ROOT}/m68k-unknown-elf/" CACHE PATH "instal set( MAKE_APPL "${RETRO68_ROOT}/bin/MakeAPPL" ) set( REZ "${RETRO68_ROOT}/bin/Rez" ) +set( REZ_INCLUDE_PATH "${RETRO68_ROOT}/RIncludes" ) set( CMAKE_C_COMPILER "${RETRO68_ROOT}/bin/m68k-unknown-elf-gcc" ) set( CMAKE_CXX_COMPILER "${RETRO68_ROOT}/bin/m68k-unknown-elf-g++" )