Skip to content

Commit

Permalink
minor adjusts, version 0.4.1
Browse files Browse the repository at this point in the history
- just moving some things around
- use pretty power of 2 limits
- makes a no id option of enum
- makes panel use a color different than transparent or this breaks current style editor
- added missing draw frame color transparent detection
- QOL for myself on the new image stuff, lets use LayoutRow1 internally.
- Adds BeginPanel and EndPanel, this panel is different from original panels in that they can be closed!
- Adds SetFocusLastControl which can be used to keep things focused or switch focus of things. Focus DOESN'T scroll.
- Text Input room improvements
  • Loading branch information
ericoporto committed Feb 21, 2021
1 parent 9244108 commit e2dd9dd
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 108 deletions.
4 changes: 2 additions & 2 deletions imgi_demo/Game.agf
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<Description />
<ReleaseDate>2021-02-17</ReleaseDate>
<Genre>Adventure</Genre>
<Version>0.4.0.0</Version>
<Version>0.4.1.0</Version>
<WindowsExperienceIndex>1</WindowsExperienceIndex>
<DeveloperName>eri0o</DeveloperName>
<DeveloperURL />
Expand Down Expand Up @@ -4715,7 +4715,7 @@
<Name>ImGi</Name>
<Description>Script Module for Immediate Gui</Description>
<Author>eri0o</Author>
<Version>0.3.1</Version>
<Version>0.4.1</Version>
<Key>488029724</Key>
<IsHeader>False</IsHeader>
</Script>
Expand Down
175 changes: 99 additions & 76 deletions imgi_demo/imgi.asc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// the unclipped rect must represent the screen where ImGi is rendered.
#define UNCLIPPED_RECT unclipped_rect.Copy()

#define MAX_STACK_SIZE 500
#define MAX_STACK_SIZE 512

#define IMGI_COMMANDLIST_SIZE 696
#define IMGI_COMMANDLIST_SIZE 1024
#define IMGI_ROOTLIST_SIZE 32
#define IMGI_CONTAINERSTACK_SIZE 32
#define IMGI_CLIPSTACK_SIZE 32
Expand All @@ -33,7 +33,7 @@
#define IMGI_KEY_CTRL_RIGHT 406

// sets the max number of clipping rects used in the RENDERER
#define MAX_CLIPS 60
#define MAX_CLIPS 64

// ImGi Renderer uses a Dirty Rect approach, set the number of
// of rectangles to use, CELL_COUNT = CELL_COUNT_W * CELL_COUNT_H
Expand Down Expand Up @@ -83,13 +83,8 @@ enum ImGi_LayoutType
eImGi_Lay_Absolute = 2
};

// fake enum, just be consistent
enum ImGi_ID
{
};
enum ImGiCmd_ID
{
};
// fake enum, just be consistent (avoids me going crazy)
enum ImGi_ID { eImGi_NoID = 0 };

struct StackOfInt
{
Expand All @@ -102,10 +97,8 @@ struct StackOfInt

managed struct Rect
{
int x;
int y;
int w;
int h;
int x; int y;
int w; int h;
import static Rect * Create(int x, int y, int w, int h); // $AUTOCOMPLETESTATICONLY$
import Rect * Copy();
import Rect * Intersect(Rect * r);
Expand Down Expand Up @@ -137,24 +130,17 @@ struct ImGi_Cmd

managed struct ImGi_Layout
{
int body_x;
int body_y;
int body_w;
int body_h;
int body_x; int body_y;
int body_w; int body_h;

int next_x;
int next_y;
int next_w;
int next_h;
int next_x; int next_y;
int next_w; int next_h;

int pos_x;
int pos_y;
int pos_x; int pos_y;

int size_x;
int size_y;
int size_x; int size_y;

int max_x;
int max_y;
int max_x; int max_y;

int widths[IMGI_MAX_WIDTHS];
int items;
Expand All @@ -169,21 +155,15 @@ managed struct ImGi_Container
int cmd_head_idx;
int cmd_tail_idx;

int rect_x;
int rect_y;
int rect_w;
int rect_h;
int rect_x; int rect_y;
int rect_w; int rect_h;

int body_x;
int body_y;
int body_w;
int body_h;
int body_x; int body_y;
int body_w; int body_h;

int content_w;
int content_h;
int content_w; int content_h;

int scroll_x;
int scroll_y;
int scroll_x; int scroll_y;

int zindex;
bool open;
Expand Down Expand Up @@ -259,17 +239,11 @@ struct ImGi_Context
ImGi_Container* containers[IMGI_CONTAINERPOOL_SIZE];

/* input state */
int mouse_pos_x;
int mouse_pos_y;
int mouse_pos_x; int mouse_pos_y;
int last_mouse_pos_x; int last_mouse_pos_y;
int mouse_delta_x; int mouse_delta_y;

int last_mouse_pos_x;
int last_mouse_pos_y;

int mouse_delta_x;
int mouse_delta_y;

int scroll_delta_x;
int scroll_delta_y;
int scroll_delta_x; int scroll_delta_y;

ImGi_Mouse_Button mouse_down;
ImGi_Mouse_Button mouse_pressed;
Expand Down Expand Up @@ -301,12 +275,12 @@ struct ImGi_Context
import void PushID(String data);
import void PopID();

import int container_pool_init(int id);
import int container_pool_get(int id);
import int container_pool_init(ImGi_ID id);
import int container_pool_get(ImGi_ID id);
import void container_pool_update(int idx);

import int treenode_pool_init(int id);
import int treenode_pool_get(int id);
import int treenode_pool_init(ImGi_ID id);
import int treenode_pool_get(ImGi_ID id);
import void treenode_pool_update(int idx);

import String TextBox_raw(ImGi_Result * res, String buf, int bufsz, ImGi_ID id, Rect * r, ImGi_Opt opt);
Expand All @@ -321,14 +295,18 @@ struct ImGi_Context
import void LayoutRow3(int w1, int w2, int w3, int height = 0);
import void LayoutRow4(int w1, int w2, int w3, int w4, int height = 0);

// Controls
// things that can hold controls.
import ImGi_Res BeginWindow(String title, int x, int y, int width, int height, ImGi_Opt opt = 0);
import void EndWindow();

import void OpenPopup(String name);
import ImGi_Res BeginPopup(String name);
import void EndPopup();

import ImGi_Res BeginPanel(String name, ImGi_Opt opt);
import void EndPanel();

// Controls
import void Image(int graphic);
import void Text(String text);
import String TextBox(String label, ImGi_Result * res, String buf, int bufsz, ImGi_Opt opt = 0);
Expand Down Expand Up @@ -686,7 +664,7 @@ ImGi_Style::Create()
style.colors[eImGi_Col_WindowBG] = 12710;
style.colors[eImGi_Col_TitleBG] = 8419;
style.colors[eImGi_Col_TitleText] = 61277;
style.colors[eImGi_Col_PanelBG] = COLOR_TRANSPARENT; // 64779; /* orange */
style.colors[eImGi_Col_PanelBG] = 12710; //COLOR_TRANSPARENT;
style.colors[eImGi_Col_Button] = 19017;
style.colors[eImGi_Col_ButtonHover] = 23243;
style.colors[eImGi_Col_ButtonFocus] = 31630;
Expand All @@ -708,7 +686,7 @@ ImGi_Context::container_pool_update(int idx)
}

int
ImGi_Context::container_pool_init(int id)
ImGi_Context::container_pool_init(ImGi_ID id)
{
this.container_pool_size = IMGI_CONTAINERPOOL_SIZE;
int n = -1;
Expand All @@ -730,7 +708,7 @@ ImGi_Context::container_pool_init(int id)
}

int
ImGi_Context::container_pool_get(int id)
ImGi_Context::container_pool_get(ImGi_ID id)
{
for (int i = 0; i < this.container_pool_size; i++)
{
Expand All @@ -749,7 +727,7 @@ ImGi_Context::treenode_pool_update(int idx)
}

int
ImGi_Context::treenode_pool_init(int id)
ImGi_Context::treenode_pool_init(ImGi_ID id)
{
this.treenode_pool_size = IMGI_TREENODEPOOL_SIZE;
int n = -1, f = this.frame;
Expand All @@ -770,7 +748,7 @@ ImGi_Context::treenode_pool_init(int id)
}

int
ImGi_Context::treenode_pool_get(int id)
ImGi_Context::treenode_pool_get(ImGi_ID id)
{
for (int i = 0; i < this.treenode_pool_size; i++)
{
Expand Down Expand Up @@ -1373,8 +1351,12 @@ draw_box(this ImGi_Context*, Rect* r, int color)

void
ImGi_Context::draw_frame(Rect* r, ImGi_Color colorid)
{
this.draw_rect(r, this.style.colors[colorid]);
{
if (this.style.colors[eImGi_Col_Border] != COLOR_TRANSPARENT)
{
this.draw_rect(r, this.style.colors[colorid]);
}

if (colorid == eImGi_Col_ScrollBase || colorid == eImGi_Col_ScrollThumb ||
colorid == eImGi_Col_TitleBG)
return;
Expand Down Expand Up @@ -1761,13 +1743,7 @@ void
ImGi_Context::Image(int graphic)
{
this.layout_begin_column();
ImGi_Layout* layout = this.get_layout();
layout.widths[0] = Game.SpriteWidth[graphic];
layout.items = 1;
layout.pos_x = layout.indent;
layout.pos_y = layout.next_row;
layout.size_y = Game.SpriteHeight[graphic];
layout.item_index = 0;
this.LayoutRow1(Game.SpriteWidth[graphic], Game.SpriteHeight[graphic]);
Rect* r = this.layout_next();
this.draw_icon(graphic, r, 0);
this.layout_end_column();
Expand Down Expand Up @@ -1820,13 +1796,7 @@ ImGi_Context::ButtonImage(String label, int graphic_normal, int graphic_over, in
}

this.layout_begin_column();
ImGi_Layout* layout = this.get_layout();
layout.widths[0] = Game.SpriteWidth[graphic_normal];
layout.items = 1;
layout.pos_x = layout.indent;
layout.pos_y = layout.next_row;
layout.size_y = Game.SpriteHeight[graphic_normal];
layout.item_index = 0;
this.LayoutRow1(Game.SpriteWidth[graphic_normal], Game.SpriteHeight[graphic_normal]);
Rect* r = this.layout_next();

this.update_control(id, r, opt);
Expand Down Expand Up @@ -2453,6 +2423,39 @@ ImGi_Context::EndPopup()
this.EndWindow();
}

ImGi_Res
ImGi_Context::BeginPanel(String name, ImGi_Opt opt)
{
ImGi_ID id = this.GetID(name);
ImGi_Container* cnt = this.get_container(id, opt);
if (cnt == null || !(cnt.open))
return eImGi_Res_None;
this.stk_id_push(id);
Rect* nxt_rect = this.layout_next();
cnt.rect_x = nxt_rect.x;
cnt.rect_y = nxt_rect.y;
cnt.rect_w = nxt_rect.w;
cnt.rect_h = nxt_rect.h;
/*draw frame*/
if (!(opt & eImGi_Opt_NoFrame))
{
this.draw_frame(nxt_rect, eImGi_Col_PanelBG);
}
// places the panel on the stacks and it's area too
this.stk_container_push(cnt);
this.push_container_body(cnt, nxt_rect, opt);
this.push_clip_rect(
Rect.Create(cnt.body_x, cnt.body_y, cnt.body_w, cnt.body_h));

return eImGi_Res_Active;
}

void
ImGi_Context::EndPanel()
{
this.pop_clip_rect();
this.pop_container();
}
// Controls -->> /////////////////////////////////////////////////////////

//// Render
Expand Down Expand Up @@ -3236,6 +3239,7 @@ ImGi::Close()
{
ImGi_ID id = _ImGi.GetID();
ImGi_Container* cnt = _ImGi.get_container(id, 0);
//ImGi_Container* cnt = _ImGi.get_current_container();
if (cnt == null || (cnt.open))
cnt.open = false;
}
Expand All @@ -3250,6 +3254,25 @@ ImGi::EndPopup()
_ImGi.EndPopup();
}

static ImGi_Res
ImGi::BeginPanel(String name, ImGi_Opt opt)
{
return _ImGi.BeginPanel(name, opt);
}
static void
ImGi::EndPanel()
{
_ImGi.EndPanel();
}

//Utilities
static void
ImGi::SetFocusLastControl()
{
_ImGi.SetFocus(_ImGi.last_id);
}

//Controls
static void
ImGi::Image(int graphic)
{
Expand Down
13 changes: 12 additions & 1 deletion imgi_demo/imgi.ash
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ImGi Module Header
//
// ImGi Version 0.4.0
// ImGi Version 0.4.1
//
// ImGi is a Immediate GUI for Adventure Game Studio!
// Create dynamic GUIs through AGS Script, rendered to screen using Overlays.
Expand Down Expand Up @@ -166,6 +166,17 @@ builtin struct ImGi

/// Closes what is the current scope (Window, Popup, ...). Don't call it outside of a Window, a Popup, ...
import static void Close();

/// A panel has to be inside of a window, it will use the LayoutRow cell size for it's size. If it returns successful, you have to call EndPanel() after.
import static ImGi_Res BeginPanel(String name, ImGi_Opt opt = 0);

/// Call each time a BeginPanel is successful after all controls are listed. ex: if(ImGi.BeginPanel("Pan")){ /*ctrl*/ ImGi.EndPanel();}
import static void EndPanel();

// Utilities

/// Places the focus on what is the last control. Some controls behave differently when focused.
import static void SetFocusLastControl();

// Controls

Expand Down
Binary file modified imgi_demo/room1.crm
Binary file not shown.
Binary file modified imgi_demo/room2.crm
Binary file not shown.
Binary file modified imgi_demo/room3.crm
Binary file not shown.
Loading

0 comments on commit e2dd9dd

Please sign in to comment.