Skip to content

Commit

Permalink
Document new API.
Browse files Browse the repository at this point in the history
* font

* Text rendering functions
  • Loading branch information
m1maker committed Jan 1, 2025
1 parent 5157a31 commit 79e3d23
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 61 deletions.
72 changes: 72 additions & 0 deletions docs/Foundation/Namespaces/Global/Functions/Rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
61 changes: 3 additions & 58 deletions docs/General/Advance.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ void main()
{
try
{
vector@ v;
@v = null;
alert("vector",""+v.x);
sound@ s;
@s = null;
alert("Active",""+s.active);
}
catch
{
Expand All @@ -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?

9 changes: 6 additions & 3 deletions docs/General/Application Behavior.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.

0 comments on commit 79e3d23

Please sign in to comment.