WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   How to use LineMixin? (https://www.wowinterface.com/forums/showthread.php?t=56198)

thomasjohnshannon 05-02-18 12:46 PM

How to use LineMixin?
 
Does anyone know how to use the LineMixin? I tried messing around with it but I'm not sure how to properly mix it with a texture.

Lua Code:
  1. -- Mix this into a Texture to be able to treat it like a line
  2. LineMixin = {};
  3.  
  4. function LineMixin:SetStartPoint(x, y)
  5.     self.startX, self.startY = x, y;
  6. end
  7.  
  8. function LineMixin:SetEndPoint(x, y)
  9.     self.endX, self.endY = x, y;
  10. end
  11.  
  12. function LineMixin:SetThickness(thickness)
  13.     self.thickness = thickness;
  14. end
  15.  
  16. function LineMixin:Draw()
  17.     local parent = self:GetParent();
  18.     local x, y = parent:GetLeft(), parent:GetBottom();
  19.  
  20.     self:ClearAllPoints();
  21.     DrawLine(self, parent, self.startX - x, self.startY - y, self.endX - x, self.endY - y, self.thickness or 32, 1);
  22. end

Xrystal 05-02-18 02:07 PM

You could try this in your lua file..

Code:

    object.line = CreateFromMixins(LineMixin)
    object.line:SetStartPoint(10,10)
    object.line:SetEndPoint(20,20)
    object.line:SetThickness(100)
    object.line:Draw()

I haven't tested it yet but based on the function requiring a parent window I suspect the parent window is either a frame or the texture on a frame.

Obviously replace object with the appropriate parent window object.


EDIT: .. Hmm, not as easy as I thought .. Its now sounding like the line is the texture but not 100% sure

Xrystal 05-02-18 03:01 PM

Thought I had found it .. but nada ..

It's in the taxi map frame. It looks like they have the code part there but it's not exactly the same, but maybe you have to have a Line object as well as a texture object .. but this is just theorising from browsing through those files.

https://www.townlong-yak.com/framexm...taProvider.xml

This xml line being what I suspect you have to use

<Line parentKey="Fill" atlas="_UI-Taxi-Line-horizontal" alpha="0" alphaMode="ADD" />


Will test it out and see



Edit: Yes thats it ..

In my xml file I have this and for simplicity I threw the code in here too

Code:

<UI>
   
        <Frame name="DraggingFrame" inherits = "DraggableFrameTemplate, TooltipTemplate"  parent="UIParent" frameStrata="LOW">
                <Size x="200" y="300"/>
                  <Anchors>
                        <Anchor point="CENTER" x = "150" y = "100" />
                </Anchors>
             
        <Layers>
            <Layer level="BACKGROUND">
                <Texture parentKey="Background" >
                    <Anchors>
                        <Anchor point="TOPLEFT" x = "1" y = "-1"/>
                        <Anchor point="BOTTOMRIGHT" x = "-1" y = "1"/>
                    </Anchors>
                </Texture>
            </Layer>     
            <Layer level="BACKGROUND" textureSubLevel="-2">
                <Line parentKey="Fill" atlas="_UI-Taxi-Line-horizontal" alpha="1" />
            </Layer>           
        </Layers>
       
        <Scripts>
            <OnLoad>
                self:RegisterForDrag("LeftButton")
                self.Fill.line = CreateFromMixins(LineMixin)
                self.Fill.line:SetStartPoint(10,10)
                self.Fill.line:SetEndPoint(20,20)
                self.Fill.line:SetThickness(100)
            </OnLoad>
      </Scripts>
    </Frame>

</UI>

This draws a line from the top left to the bottom right



Edit2: Grr nevermind .. this is just using the Line's natural drawing mechanism and not the drawline function at all .. as soon as I add that function I get a can't get parent problem, so maybe it's not ready to be used in its entirety yet.

Xrystal 05-02-18 03:35 PM

d'oh ...

Just realised what they meant by mixing with a texture ..

xml...

<Texture parentKey="Background" mixin = "LineMixin">

And then I removed the CreateFromMixins line from the code element... it fixes the GetParent error but now getting problems figuring out what values will work.


Edit: Well no errors at all now - here is my xml file now

Code:

<UI>
   
        <Frame name="DraggingFrame" inherits = "DraggableFrameTemplate,DialogTemplate"  parent="UIParent" frameStrata="LOW">
                <Size x="200" y="300"/>
                  <Anchors>
                        <Anchor point="CENTER" x = "0" y = "0" />
                </Anchors>
             
        <Frames> 
            <Frame name = "Canvas" parentKey = "Canvas">
                <Anchors>
                    <Anchor point="TOPLEFT"/>
                    <Anchor point="BOTTOMRIGHT"/>
                </Anchors>
               
                <Layers>
                    <Layer level="BACKGROUND">
                        <Texture name = "Paper" parentKey="Paper">
                            <Anchors>
                                <Anchor point="TOPLEFT"/>
                                <Anchor point="BOTTOMRIGHT"/>
                            </Anchors>
                            <Color r="0.0" g="0.0" b="0.0" a="0.5"/>
                        </Texture>
                    </Layer>
                    <Layer level="BACKGROUND" textureSubLevel="-2" alphaMode="ADD">
                        <Texture name = "Line"  parentKey="Line" mixin = "LineMixin">
                          <Size>
                            <AbsDimension x="1" y="1"/>
                          </Size>
                        <Anchors>
                            <Anchor point="CENTER" x = "0" y = "0" />
                        </Anchors>

                          <Color r="1.0" g="1.0" b="1.0" a="1.0"/>
                        </Texture>
                    </Layer>     
                </Layers>               
                <Scripts>
                    <OnLoad>
                        self.Line:SetStartPoint(0,0)
                        self.Line:SetEndPoint(100,100)
                        self.Line:SetThickness(32)
                        self.Line:Draw()
                    </OnLoad>
              </Scripts>
            </Frame>
        </Frames>
       
        <Scripts>
            <OnLoad>
                self:RegisterForDrag("LeftButton")
            </OnLoad>
      </Scripts>
    </Frame>

</UI>

I have tried everything that I thought would make it show up but no joy .. It might simply be due to my own understanding on how textures work

thomasjohnshannon 05-02-18 05:45 PM

Finally got a working version.

Lua Code:
  1. <UI>
  2.     <Frame name="DrawFrame" parent="UIParent" frameStrata="LOW">
  3.         <Size x="300" y="300"/>
  4.         <Anchors>
  5.             <Anchor point="CENTER" />
  6.         </Anchors>
  7.         <Layers>
  8.             <Layer level="BACKGROUND">
  9.                 <Texture parentKey="Background" setAllPoints="true">
  10.                     <Color r="0" g="0" b="0" a=".70"/>
  11.                 </Texture>
  12.             </Layer>
  13.             <Layer level="OVERLAY" textureSubLevel="7">
  14.                 <Texture parentKey="Fill" file="Interface\TAXIFRAME\UI-Taxi-Line" alpha="1" mixin="LineMixin">
  15.                     <Color r="1" g="0" b="0"/>
  16.                 </Texture>
  17.             </Layer>
  18.         </Layers>
  19.         <Scripts>
  20.             <OnLoad>
  21.                 local x, y = self:GetCenter()
  22.                 self.Fill:SetThickness(64)
  23.                 self.Fill:SetStartPoint(x,y)
  24.                 self.Fill:SetEndPoint(x-300,y+300)
  25.                 self.Fill:Draw()
  26.             </OnLoad>
  27.        </Scripts>
  28.     </Frame>
  29. </UI>

Xrystal 05-02-18 06:10 PM

sweet, made similar changes to my test frame and it works too. Better keep it in case i forget when i need/want it rofl

Gethe 05-02-18 09:21 PM

LineMixin is the old way of making lines. Lines are actually a real widget type you can create using
Lua Code:
  1. local line = frame:CreateLine(...)
or to modify your xml:
XML Code:
  1. <UI>
  2.     <Frame name="DrawFrame" parent="UIParent" frameStrata="LOW">
  3.         <Size x="300" y="300"/>
  4.         <Anchors>
  5.             <Anchor point="CENTER" />
  6.         </Anchors>
  7.         <Layers>
  8.             <Layer level="BACKGROUND">
  9.                 <Texture parentKey="Background" setAllPoints="true">
  10.                     <Color r="0" g="0" b="0" a=".70"/>
  11.                 </Texture>
  12.             </Layer>
  13.             <Layer level="OVERLAY" textureSubLevel="7">
  14.                 <Line parentKey="Fill" file="Interface\TAXIFRAME\UI-Taxi-Line" thickness="64">
  15.                     <Color r="1" g="0" b="0"/>
  16.                     <StartAnchor relativePoint="CENTER"/>
  17.                     <EndAnchor relativePoint="CENTER" x="-300" y="300"/>
  18.                 </Line>
  19.             </Layer>
  20.         </Layers>
  21.     </Frame>
  22. </UI>

The methods are similar to the mixin, so it should be easy to switch to. The main difference is that the Set(Start|End)Point methods can accept relative points and relative frames like the normal SetPoint method.

Xrystal 05-03-18 02:37 AM

rofl, I had that working easy .. I didn't know Line came after LineMixin. Googling came up with nothing apart from this post and the api file itself on github.


All times are GMT -6. The time now is 07:17 AM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI