any idea for make simple text input in LOVE?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
baby_nux
Prole
Posts: 25
Joined: Fri Mar 04, 2011 3:21 pm

any idea for make simple text input in LOVE?

Post by baby_nux »

there is any idea for make simple text input in LOVE?
similar to inputbox.. but more simpler ^^, and maybe without API call.
any help would be appreciated

( sry for my english )
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: any idea for make simple text input in LOVE?

Post by nevon »

Löve does not include any kind of gui toolkit. There are a few floating around, such as goo. But nothing I can really wholeheartedly recommend (because I haven't tried them).

If you're just going to have a single text input, you might as well just make a custom one.
User avatar
baby_nux
Prole
Posts: 25
Joined: Fri Mar 04, 2011 3:21 pm

Re: any idea for make simple text input in LOVE?

Post by baby_nux »

nevon wrote:Löve does not include any kind of gui toolkit. There are a few floating around, such as goo. But nothing I can really wholeheartedly recommend (because I haven't tried them).

If you're just going to have a single text input, you might as well just make a custom one.
i see..
hmm, how about simple text input command prompt like, have idea?
i'm new in lua and LOVE. if you mind, do you have idea how to code that in LOVE? ( with sample code ^^ )

or any one have better idea?

( sry if my english bad )
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: any idea for make simple text input in LOVE?

Post by nevon »

baby_nux wrote:how about simple text input command prompt like, have idea?
I don't even know what that means. Do you mean a text input widget or something like a terminal?
baby_nux wrote:i'm new in lua and LOVE. if you mind, do you have idea how to code that in LOVE? ( with sample code ^^ )
I could, but I have a feeling you'd learn a lot more by doing it yourself.
User avatar
baby_nux
Prole
Posts: 25
Joined: Fri Mar 04, 2011 3:21 pm

Re: any idea for make simple text input in LOVE?

Post by baby_nux »

nevon wrote: I don't even know what that means. Do you mean a text input widget or something like a terminal?
both of them, but the last one is simpler ( better than nothing ^^ )
baby_nux wrote:I could, but I have a feeling you'd learn a lot more by doing it yourself.
yes, sure... i will try
i just curious if somebody has better one.
Deif
Prole
Posts: 12
Joined: Sun Mar 06, 2011 10:01 pm

Re: any idea for make simple text input in LOVE?

Post by Deif »

I've found that coding your own widgets really helps increase your understanding of how the engine works, and how the game should work in general, so I would advise to try and have a go by yourself. At least that way you know how it works and you get to make it how you want. :monocle:
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: any idea for make simple text input in LOVE?

Post by nevon »

baby_nux wrote:
nevon wrote: I don't even know what that means. Do you mean a text input widget or something like a terminal?
both of them, but the last one is simpler ( better than nothing ^^ )
No. A regular text input would be much, much easier. You'd only have to draw the input, see whether or not it's active, detect key strokes and add chars to a string, and then print that text on top of the input. Easy as math.pi.
User avatar
baby_nux
Prole
Posts: 25
Joined: Fri Mar 04, 2011 3:21 pm

Re: any idea for make simple text input in LOVE?

Post by baby_nux »

nevon wrote: No. A regular text input would be much, much easier. You'd only have to draw the input, see whether or not it's active, detect key strokes and add chars to a string, and then print that text on top of the input. Easy as math.pi.
do you mean like activeX visual component ( GUI ) in visualbasic?
easier for win user, but my OS is ubuntu linux.
my another clue is using wxWidgets.
wxWidgets, like visual component ( GUI ) in visualbasic. Cross-Platform GUI Programming.
but i dont have much programming skill for using wxWidgets in linux, especially with lua and LOVE.

i dont have any choice now, maybe i want try the last one. terminal text input like , more simpler i think :huh: ...
User avatar
baby_nux
Prole
Posts: 25
Joined: Fri Mar 04, 2011 3:21 pm

Re: any idea for make simple text input in LOVE?

Post by baby_nux »

i have GUI widget code library in glbasic ( BASIC language for game programming ).
glbasic based from opengl and SDL, the code similiar like LOVE. maybe i can convert it to lua/LOVE code.
this code library has:
  • input ( inputbox )
  • text << for example i will show for this code below (this code for display text on screen)
  • button
  • list ( listbox )
  • toolbar
  • combo ( combobox )
  • button ( radiobutton )
  • chechbox
  • slider
  • frame
  • tab
  • file dialog
  • etc.
this is code snapshot for text widget ( glbasic language ^^ ):

Code: Select all

//! ------------------------------------------ //
//! Text
//! ------------------------------------------ //
FUNCTION DDgui_text: id$, text$, width%=0, height%=0
	DDgui_widget(id$, text$, width, height)
	DDgui_set(id$, "TYPE", "TEXT")
ENDFUNCTION

Code: Select all

// ------------------------------------------ //
//! widget c'tor - can be used as a static text widget
// ------------------------------------------ //
FUNCTION DDgui_widget%: id$, caption$, width%=0, height%=0
LOCAL count%
LOCAL fx%, fy%
LOCAL wdg AS DDGUI_WDG

	count = 1 + LEN(ddgui_stack[-1].widgets[])
	IF id$="" THEN id$="iwdg%"+count

	GETFONTSIZE fx, fy
	IF width <=gDDguiMinControlDimension% THEN width  = MAX(gDDguiMinControlDimension%, MAX(width, DDGui_TextWidthIntern(caption$) + fx))
	IF height<=gDDguiMinControlDimension% THEN height = MAX(gDDguiMinControlDimension%, MAX(height, fy+6))

	LOCAL i% = DDgui_index(ddgui_stack[-1], id$, TRUE)
	ddgui_stack[-1].widgets[i].wid$ = id$
	ddgui_stack[-1].widgets[i].wwidth=width
	ddgui_stack[-1].widgets[i].wheight=height
	ddgui_stack[-1].widgets[i].wtype$ = "WIDGET"
	ddgui_stack[-1].widgets[i].wtext$=caption$
ENDFUNCTION

Code: Select all

FUNCTION DDgui_set: id$, name$, val$
	IF LEN(id$)=0
		SELECT name$
			CASE "FOCUS";            ddgui_stack[-1].focus$=val$
			CASE "INKEY";            ddgui_stack[-1].dlg_inkey$=val$
			CASE "COL_BRIGHT";       ddgui_stack[-1].col_bright%=val$
			CASE "COL_NORM";         ddgui_stack[-1].col_norm%=val$
			CASE "COL_HOVER_BRIGHT"; ddgui_stack[-1].col_hover_bright%=val$
			CASE "COL_HOVER_NORM";   ddgui_stack[-1].col_hover_norm%=val$
			CASE "TEXT";             ddgui_stack[-1].main.wtext$=val$
			CASE "XPOS";             ddgui_stack[-1].xpos%=val$
			CASE "YPOS";             ddgui_stack[-1].ypos%=val$
			CASE "WIDTH";            ddgui_stack[-1].main.wwidth%=val$
			CASE "HEIGHT";           ddgui_stack[-1].main.wheight%=val$
			CASE "MOVEABLE";         ddgui_stack[-1].moveable%=val$
			CASE "SCALEABLE";        ddgui_stack[-1].scaleable%=val$
			DEFAULT
				DEBUG "DDgui_set dialog (\"\") property: "+name$+" is unknown\n"
		ENDSELECT
	ELSE
		LOCAL iw = DDgui_index(ddgui_stack[-1], id$, TRUE)

		ALIAS wdg AS ddgui_stack[-1].widgets[iw]

		SELECT name$
			CASE "TEXT";      wdg.wtext$ = val$
			CASE "CLICKED";   wdg.wclicked% = val$
			CASE "WIDTH";     wdg.wwidth% = val$
			CASE "HEIGHT";    wdg.wheight% = val$
			CASE "SELECT";    wdg.wselect% = val$
			CASE "COUNT";     wdg.wcount% = val$
			CASE "HOVER";     wdg.whover% = val$
			CASE "READONLY";  wdg.wreadonly% = val$
			CASE "SELSTART";  wdg.wselstart% = val$
			CASE "SELEND";    wdg.wselend% = val$
			CASE "HIDE";      wdg.whide% = val$
			CASE "TYPE";      wdg.wtype$ = val$
			CASE "FILTER";    wdg.wfilter$ = val$
			CASE "TIPTEXT";   wdg.tiptext$ = val$
			CASE "MINVAL";    wdg.wminval = val$
			CASE "MAXVAL";    wdg.wmaxval = val$
			CASE "STEP";      wdg.wstep   = val$
			CASE "SCROLL";    wdg.wscroll = val$
			CASE "ALIGN";     wdg.walign% = val$
			DEFAULT
				DEBUG "DDgui_set: Widget property "+name$+" is unknown\n"
		ENDSELECT
	ENDIF

ENDFUNCTION

Code: Select all

// ------------------------------------------ //
//! Get index in ddgui_vals$[] for given string
//! New sorting algorithm for much faster access
// ------------------------------------------ //
FUNCTION DDgui_index%: ddgui_vals AS DDGUI_DLG, BYREF name$, create%
LOCAL up%, dn%, mid%
	up=0; dn=LEN(ddgui_vals.widgets[])-1
	WHILE up < dn
		mid = (up+dn) / 2
		IF ddgui_vals.widgets[mid].wid$ > name$
			dn=MAX(mid-1, up)
		ELSE
			IF ddgui_vals.widgets[mid].wid$ < name$
				up=MIN(dn, mid+1)
			ELSE
				RETURN mid // not bigger, not smaller, guess what!?
			ENDIF
		ENDIF
	WEND

	IF LEN(ddgui_vals.widgets[]) AND ddgui_vals.widgets[up].wid$ = name$ THEN RETURN up


	// not found. But must be at [up].
	IF create%
		dn = LEN(ddgui_vals.widgets[]) // one below last
		REDIM ddgui_vals.widgets[dn+1]
		FOR mid = dn TO up+1 STEP -1
			ddgui_vals.widgets[mid] = ddgui_vals.widgets[mid-1]
		NEXT
		IF dn>0 AND ddgui_vals.widgets[up].wid$ < name$ THEN up=up+1
		LOCAL widg AS DDGUI_WDG
		widg.wid$ = name$
		ddgui_vals.widgets[up] = widg // copy a fresh on there, clear old junk

		// also make a new drawing order entry!!
		LOCAL order AS DDGUI_ORDER
		order.id$ = name$
		DIMPUSH ddgui_vals.draworder[], order

		// Internally fixed the drawing oder, when pushing new
		// widgets to the quick-dictionary array.
		FOREACH od IN ddgui_vals.draworder[]
			od.index = DDgui_index(ddgui_vals, od.id$, FALSE)
		NEXT

		RETURN up
	ENDIF
RETURN -1
ENDFUNCTION
this is some initial global variable,const, data type:

Code: Select all

// Globals you can use to tweak the DDgui experience:
GLOBAL gDDguiCaretColour% = 0x000000
GLOBAL gDDguiMinControlDimension% // min size of button etc.

TYPE DDGUI_ENTRY
	key$
	val$
ENDTYPE

TYPE DDGUI_WDG
// public:
	// all widgets
	wid$
	wtype$
	wtext$

	wxpos% // readonly
	wypos% // readonly
	wwidth%
	wheight%
	whover%
	whide%=0
	wfilter$
	tiptext$ // tooltip

	// button, slider, checkbox, radio, file, list, text, tab
	wclicked%
	// checkbox, list, tab
	wselect%
	// list, radio
	wcount%
	// text
	wreadonly%
	wselstart%
	wselend%
	// slider
	wminval=0
	wmaxval=1.0
	wstep  =0.01
// protected:
	wscroll%
	wscrollmax%
	wcaretx% // in pixels
	wcarety% // in pixels
	wframe%=0  // frame index (0=dialog's main frame)
	walign%=-1 // -1=left, 0=center, 1=right
ENDTYPE

TYPE DDGUI_ORDER
	id$       // widget id
	index%    // index in widgets list
ENDTYPE

TYPE DDGUI_AUTO
	idfrom$; idto$; objfrom$; objto$
ENDTYPE

TYPE DDGUI_DLG
// public: (with DDgui_get/set)
	focus$ // focus widget id$
	moveable%
	moving%
	scaling%
	scaleable%
	col_bright%
	col_norm%
	col_hover_bright%
	col_hover_norm%
	dlg_inkey$
	xpos%; ypos%


// protected: (not in DDgui_get/set)
	realheight%;
	kick_intern_dlg% // want a colour picker dlg? 1=color, 2=osd keyboard,
	kick_intern_id$  // id for kicking

	main AS DDGUI_WDG // dialog "widget" - used for scrollbar, only

	autos[] AS DDGUI_AUTO
	widgets[] AS DDGUI_WDG
	draworder[] AS DDGUI_ORDER // indices for drawing order

//	pairs[] AS DDGUI_ENTRY
	// some globals that speed drawing up
ENDTYPE

// for internal use, only - quicker drawing

GLOBAL ddgui_stack[] AS DDGUI_DLG // dialog stack for dawing background stuff
// GLOBAL ddgui_vals    AS DDGUI_DLG // current values

TYPE DDGUI_FONT
	left%[]  // left side of first pixel per char
	width%[] // width of that char (with 1 pixel space already)
	bHasKerning%=TRUE
ENDTYPE
GLOBAL ddgui_font_kerning AS DDGUI_FONT

GLOBAL DDGUI_AUTO_INPUT_DLG // auto-open DDgui_input, when you click a text?
GLOBAL DDGUI_IN_INPUT_DLG // for text to know, that clicking again should not pop up
if i already finished convert entire of this code ( for practice ), maybe i will try to convert for "inputbox" code.

PS:
this is sample widget for display text on screen ( glbasic language )
if someone has familiar with BASIC language, will see more clear.

( again, sry if my english very unclear ^^ )
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: any idea for make simple text input in LOVE?

Post by Robin »

baby_nux wrote:do you mean like activeX visual component ( GUI ) in visualbasic?
No. You are writing the whole damn thing from scratch.
baby_nux wrote:i dont have any choice now, maybe i want try the last one. terminal text input like , more simpler i think :huh: ...
Don't think that is simpler. A terminal text input has much more features than a simple text input. You need to worry about scrolling text etc.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests