From 79e3d231bd94b9ca78307440a08167a97fac0b37 Mon Sep 17 00:00:00 2001 From: m1maker Date: Wed, 1 Jan 2025 23:29:43 +0300 Subject: [PATCH] Document new API. * font * Text rendering functions --- .../Namespaces/Global/Functions/Rendering.md | 72 +++++++++++++++++++ docs/General/Advance.md | 61 +--------------- docs/General/Application Behavior.md | 9 ++- 3 files changed, 81 insertions(+), 61 deletions(-) diff --git a/docs/Foundation/Namespaces/Global/Functions/Rendering.md b/docs/Foundation/Namespaces/Global/Functions/Rendering.md index 416de6b..7fa9130 100644 --- a/docs/Foundation/Namespaces/Global/Functions/Rendering.md +++ b/docs/Foundation/Namespaces/Global/Functions/Rendering.md @@ -13,3 +13,75 @@ - `index` (int): The index of the rendering driver. - **Return Type**: int - **Description**: Retrieves the identifier for the specified rendering driver. + +### `surface@ render_text_solid(font@ font, const string&in text, int color)` +- **Parameters**: + - `font` (font@): The font to use for rendering. + - `text` (string): The text to render. + - `color` (int): The color of the rendered text. +- **Return Type**: surface@ +- **Description**: Renders solid text using the specified font and color. + +### `surface@ render_text_solid(font@ font, const string&in text, int color, int wrapLength)` +- **Parameters**: + - `font` (font@): The font to use for rendering. + - `text` (string): The text to render. + - `color` (int): The color of the rendered text. + - `wrapLength` (int): The maximum width before wrapping. +- **Return Type**: surface@ +- **Description**: Renders solid text with word wrapping using the specified font and color. + +### `surface@ render_text_shaded(font@ font, const string&in text, int fgColor, int bgColor)` +- **Parameters**: + - `font` (font@): The font to use for rendering. + - `text` (string): The text to render. + - `fgColor` (int): The foreground color of the rendered text. + - `bgColor` (int): The background color of the rendered text. +- **Return Type**: surface@ +- **Description**: Renders shaded text using the specified font, foreground color, and background color. + +### `surface@ render_text_shaded(font@ font, const string&in text, int fgColor, int bgColor, int wrapWidth)` +- **Parameters**: + - `font` (font@): The font to use for rendering. + - `text` (string): The text to render. + - `fgColor` (int): The foreground color of the rendered text. + - `bgColor` (int): The background color of the rendered text. + - `wrapWidth` (int): The maximum width before wrapping. +- **Return Type**: surface@ +- **Description**: Renders shaded text with word wrapping using the specified font, foreground color, and background color. + +### `surface@ render_text_blended(font@ font, const string&in text, int color)` +- **Parameters**: + - `font` (font@): The font to use for rendering. + - `text` (string): The text to render. + - `color` (int): The color of the rendered text. +- **Return Type**: surface@ +- **Description**: Renders blended text using the specified font and color. + +### `surface@ render_text_blended(font@ font, const string&in text, int color, int wrapWidth)` +- **Parameters**: + - `font` (font@): The font to use for rendering. + - `text` (string): The text to render. + - `color` (int): The color of the rendered text. + - `wrapWidth` (int): The maximum width before wrapping. +- **Return Type**: surface@ +- **Description**: Renders blended text with word wrapping using the specified font and color. + +### `surface@ render_text_lcd(font@ font, const string&in text, int fgColor, int bgColor)` +- **Parameters**: + - `font` (font@): The font to use for rendering. + - `text` (string): The text to render. + - `fgColor` (int): The foreground color of the rendered text. + - `bgColor` (int): The background color of the rendered text. +- **Return Type**: surface@ +- **Description**: Renders LCD text using the specified font, foreground color, and background color. + +### `surface@ render_text_lcd(font@ font, const string&in text, int fgColor, int bgColor, int wrapWidth)` +- **Parameters**: + - `font` (font@): The font to use for rendering. + - `text` (string): The text to render. + - `fgColor` (int): The foreground color of the rendered text. + - `bgColor` (int): The background color of the rendered text. + - `wrapWidth` (int): The maximum width before wrapping. +- **Return Type**: surface@ +- **Description**: Renders LCD text with word wrapping using the specified font, foreground color, and background color. diff --git a/docs/General/Advance.md b/docs/General/Advance.md index 49a7408..6b67eda 100644 --- a/docs/General/Advance.md +++ b/docs/General/Advance.md @@ -23,9 +23,9 @@ void main() { try { - vector@ v; - @v = null; - alert("vector",""+v.x); + sound@ s; + @s = null; + alert("Active",""+s.active); } catch { @@ -36,58 +36,3 @@ void main() ``` Without try catch block, this will throw runtime error, because we're accessing the null object. But as you can see, the engine does not cause the runtime error and stop execution. Instead, it skippeds to the next code, more like continue we learned in the loops chapter, and manually exits the program. - -## Any, datatype -An `any` type is used to point to any type of value. This is best to use in areas where you don't know exactly what type or value will be stored. - -An `any` is an object - -The following functions should be note before you read into examples. - -* `void store(?value);` which stores the value of any kind. -* `bool retrieve(?&out value);` which trys to retrieve the value of the object. - -Constructor - -`any(?value);` - -Now, lets dive into example. Lets say we have to use the speak function provided by NGT, but we stuck here because you want to speak many types, including strings, ints, floats, or possibly objects. - -We will first implement the custom_speak function that supports string, int, float, bool. -Please note that in latest development, string accepts numbers passing too, so you don't have to actually implement this logic. - -Note. If you want numbers of all types, using int and double is enough. - -``` -void custom_speak(any@ t, bool interrupt=false) -{ - if(t is null) return; //Null shouldn't even used here. - string text; //Actual variable of a converted string, since the speak function accepts string. - string r_str; //Lets retrieve the string. - if(t.retrieve(r_str)) text=r_str; - //If the string fail to retrieve, lets go to int and double, one after the other. - int r_int; - if(t.retrieve(r_int)) text=""+r_int; - double r_db; - if(t.retrieve(r_db)) text=""+r_db; - //If either of above types is failed, lets retrieve bool. - bool r_bool; - if(t.retrieve(r_bool)) text=(r_bool?"true":"false"); - screen_reader::speak(text, interrupt); //Finally speaks the text. -} -``` - -Now, we've defined the speak custom function, with supporting string, bool, intiger and floatingpoint. Next, we'll use `any` object before specifying the t parameter in that speak function. - -``` -void main() -{ - custom_speak(any("hello"),true); //String. - custom_speak(any(233),false); //Int - custom_speak(any(23.21),false); //Floatingpoint. - custom_speak(any(true),false); //Bool. -} -``` - -Yep, you found that useful, aren't you? - diff --git a/docs/General/Application Behavior.md b/docs/General/Application Behavior.md index 6b3cc9b..198e9e8 100644 --- a/docs/General/Application Behavior.md +++ b/docs/General/Application Behavior.md @@ -2,7 +2,7 @@ ## Window -To display a window, use the show_window function. If you plan to utilize rendering, make sure to set the enable_renderer flag to true in show_window; otherwise, no graphics will be displayed. +To manage the application window effectively, utilize the show_window function. Setting the enable_renderer flag to true is crucial if your application requires rendering graphics or supports input devices like joysticks or gamepads. If these features are not used, you may set the flag to false, allowing the window to handle events in the background without being tied to the rendering loop. ## Application Loop @@ -24,7 +24,10 @@ Important: It is essential to call one of these functions if rendering is enable You can modify the value of `update_window_freq` (which controls the screen refresh rate in milliseconds) at any time. However, be aware that increasing this frequency may slow down event processing. Use window_present when you have completed all scenes for rendering. -## Exiting +## Background Tasks + +For applications that require concurrent processing, consider implementing a dedicated thread for background tasks. This can help maintain responsiveness in the main application loop while performing resource-intensive operations such as loading assets or processing data. -When a quit request event is received from the user, the loop is terminated gracefully. This is the preferred method for exiting the program, as it allows automatic control objects to call their destructors and free resources properly. Avoid overusing the exit function unless there is a compelling reason to terminate the program unexpectedly. If you need to return a return code, declare main as int main. +## Exiting +When a quit request event is received from the user, the loop is terminated gracefully. This is the preferred method for exiting the program, as it allows automatic control objects to call their destructors and free resources properly. Avoid overusing the exit function unless there is a compelling reason to abort execution. If you need to return a return code, declare main as int main.