Redraw of Text

Posted by Tkl1129 on Tue 23 Aug 2011 09:17 AM — 8 posts, 27,071 views.

Hong Kong #0
the mini window, I wanna make a button which "mouseover" will change button color and text color...
however, I only can change the button color but the word txt was disappear...any suggestion? Thanks.


Original:
WindowText (login, "f2", Char[Char_list]["name"] .. "(" ..  Char[Char_list]["id"] .. ")",
					space_w + 5, b_start + 4, space_w + b_width, b_start + b_height,
					ColourNameToRGB ("blue"), false)

Mouseover:
function mouseover (flags,hotspot_id)
	if hotspot_id == 1 then
		WindowText (login, "f2", Char[Char_list[hotspot_id]]["name"] .. "(" ..  Char[Char_list[hotspot_id]]["id"] .. ")",
					space_w + 5, b_start + 4, space_w + b_width, b_start + b_height,
					ColourNameToRGB ("red"), false)
		WindowText (login, "f2", "Lv: " .. "500",
					space_w + (b_width/3*2) + 5, b_start + 4, space_w + b_width, b_start + b_height,
					ColourNameToRGB ("red"), false)	
Redraw ()
end
CancelMouseover:

function cancelmouseover (flags,hotspot_id)
	if hotspot_id == 1 then
		WindowText (login, "f2", Char[Char_list[hotspot_id]]["name"] .. "(" ..  Char[Char_list[hotspot_id]]["id"] .. ")",
					space_w + 5, b_start + 4, space_w + b_width, b_start + b_height,
					ColourNameToRGB ("white"), false)
		WindowText (login, "f2", "Lv: " .. "500",
					space_w + (b_width/3*2) + 5, b_start + 4, space_w + b_width, b_start + b_height,
					ColourNameToRGB ("white"), false)			
		print(type(hotspot_id),hotspot_id)
	else
		print(type(hotspot_id),hotspot_id)
	end --if
	Repaint ()
end -- cancelmouseover



Australia Forum Administrator #1
I don't see where you change the button colour.
USA Global Moderator #2
Also, before pasting any code into the forum, you need to make sure you're escaping out the forum codes. Right now your code is all italicized because the forum saw [i]. MUSHclient can do this for you automatically by going to Edit->Convert Clipboard Forum Codes
Hong Kong #3
ok sorry...make it simple.

I don't know my approach is correct or not.

1. Want to make a login miniwindow, which have many button, some words describe the Character info on the button
2. when mouseover the button, the color of button change, words color change too
3. click to execute cmds ( This simple)
4. when Cancelmouseover, the the color change back

-------------------------------------------------------

The problem I meet, was when the mouseover, the color of button was change, but the word disappear, and while cancelmouseover, the color change back, but the word still not appear. that's my question, and the code are as below, thanks.
---------------------------------------------------------

require ("db_login")

--[[Window Info]]

local char = table.getn(Char_list)
local space_w = 40
local space_h = 15
local b_start = 40
local b_height = 20
local b_width = 180
local window_w = space_w * 2 + b_width
local window_h = b_start + (b_height + space_h) * char

--[[Window Create]]
login = "Login" .. GetPluginID ()  -- get a unique name, ensure not empty if outside plugin

WindowCreate (login, 0, 0, window_w, window_h, miniwin.pos_center_all, 4, ColourNameToRGB("black"))  -- create window
WindowFont (login, "f", "細明體", 8, false, false, false, false) -- define font
WindowFont (login, "f2", "細明體", 6, false, false, false, false) -- define font

--[[Frame]]
WindowCircleOp (login, miniwin.circle_round_rectangle, -- round rectangle
                5, 5, window_w - 5, window_h - 5,	            -- Left, Top, Right, Bottom
                ColourNameToRGB("y"), miniwin.pen_solid, 1.5,   -- pen width 2
                ColourNameToRGB("darkred"), miniwin.brush_solid,  -- brush
                10,   -- width of the ellipse used to draw the rounded corner
                10)   -- height of the ellipse used to draw the rounded corner
-- [[Tittle]]
WindowPolygon (login, "20,23,28,23,24,28",
                        ColourNameToRGB("yellow"), miniwin.pen_solid, 0.5,   -- pen (solid, width 1)
                        ColourNameToRGB("white"), miniwin.brush_solid,    -- brush (solid)
                        true,    -- fill
                        false)   -- alternate fill
WindowText (login, "f", 
                "Login : ",   -- text
                40, 20, 0, 0,        -- rectangle
                ColourNameToRGB ("yellow"), -- colour
                false)              -- not Unicode

-- [[buttons]]
function mouseup (flags, hotspot_id)
	print ("Login" .. " char " .. hotspot_id)
end -- mouseup
function mouseover (flags,hotspot_id)
	if hotspot_id == 1 then
		WindowRectOp (login, miniwin.rect_fill, space_w, b_start, space_w + b_width, b_start + b_height, ColourNameToRGB("darkgray"))  -- filled
		WindowRectOp (login, miniwin.rect_frame, space_w, b_start, space_w + b_width, b_start + b_height, ColourNameToRGB("yellow"))  -- filled
	else
		WindowRectOp (login, miniwin.rect_fill, space_w, b_start + (b_height + space_h) * (hotspot_id-1), space_w + b_width, (b_start + b_height) + (b_height + space_h) * (hotspot_id-1) , ColourNameToRGB("darkgray"))  -- filled
		WindowRectOp (login, miniwin.rect_frame, space_w, b_start + (b_height + space_h) * (hotspot_id-1), space_w + b_width, (b_start + b_height) + (b_height + space_h) * (hotspot_id-1) , ColourNameToRGB("yellow"))  -- filled

	end --if
	Redraw ()
end -- mouseover
function cancelmouseover (flags,hotspot_id)
	if hotspot_id == 1 then
		WindowRectOp (login, miniwin.rect_fill, space_w, b_start, space_w + b_width, b_start + b_height, ColourNameToRGB("darkred"))  -- filled
		WindowRectOp (login, miniwin.rect_frame, space_w, b_start, space_w + b_width, b_start + b_height, ColourNameToRGB("white"))  -- filled
	else
		WindowRectOp (login, miniwin.rect_fill, space_w, b_start + (b_height + space_h) * (hotspot_id-1), space_w + b_width, (b_start + b_height) + (b_height + space_h) * (hotspot_id-1) , ColourNameToRGB("darkred"))  -- filled
		WindowRectOp (login, miniwin.rect_frame, space_w, b_start + (b_height + space_h) * (hotspot_id-1), space_w + b_width, (b_start + b_height) + (b_height + space_h) * (hotspot_id-1) , ColourNameToRGB("white"))  -- filled
	end --if
	Redraw ()
end -- cancelmouseover


for i=1,char do
	if i==1 then
		WindowRectOp (login, miniwin.rect_frame, space_w, b_start, space_w + b_width, b_start + b_height,ColourNameToRGB("white"))
		WindowAddHotspot(login,i,  
                 space_w, b_start, space_w + b_width, b_start + b_height,
                 "mouseover", "cancelmouseover", "mousedown", "cancelmousedown", "mouseup", "Character" .. " " .. i,
                 miniwin.cursor_hand, 0)  -- hand cursor

	else
		WindowRectOp (login, miniwin.rect_frame, space_w, b_start + (b_height + space_h) * (i-1), space_w + b_width, (b_start + b_height) + (b_height + space_h) * (i-1), ColourNameToRGB("white"))
		WindowAddHotspot(login,i,  
                  space_w, b_start + (b_height + space_h) * (i-1), space_w + b_width, (b_start + b_height) + (b_height + space_h) * (i-1) , 
                 "mouseover", "cancelmouseover", "mousedown", "cancelmousedown", "mouseup", "Character" .. " " .. i,
                 miniwin.cursor_hand, 0)  -- hand cursor
	end --if
end--for
				

--[[print window]]
WindowShow (login, 1)  -- show it 
Hong Kong #4

function mouseover (flags, hotspot_id)
 print(hotspot_id)
end --function


I just add this code inside, I found the reason why the text why cannot redraw, but why the mouseup can callout the "hotspot_id" be the right id but mouseover and cancelmouseover only return "nil"?
Australia Forum Administrator #5
Hotspot IDs are strings, not numbers, so this will never be true:


	if hotspot_id == 1 then

Hong Kong #6
Oh, you had remind me...its work now


local x = tonumber("" .. hotspot_id)


the local var "x" become a number in "1"
The login miniwindow work now..thanks~
Australia Forum Administrator #7
Tkl1129 said:

Oh, you had remind me...its work now


local x = tonumber("" .. hotspot_id)



Or even:



local x = tonumber(hotspot_id)