-
Notifications
You must be signed in to change notification settings - Fork 0
/
Adapter_EmotionTileView.h
97 lines (80 loc) · 2.08 KB
/
Adapter_EmotionTileView.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef __ADAPTER_EMOTION_TILEVIEW_H__
#define __ADAPTER_EMOTION_TILEVIEW_H__
#pragma once
#include <vector>
#include <helper/SAdapterBase.h>
#include "GlobalUnits.h"
struct ItemData
{
std::string m_strID;
};
class CAdapter_EmotionTileView : public SAdapterBase
{
public:
struct IListener
{
virtual void OnEmotionItemClick(const std::string& strID) = 0;
};
public:
CAdapter_EmotionTileView(IListener* pListener)
:m_pListener(pListener)
{
}
~CAdapter_EmotionTileView(){}
protected:
virtual int getCount(){
return static_cast<int>(m_vecItems.size());
}
virtual void getView(int position, SWindow * pItem, pugi::xml_node xmlTemplate)
{
if (0 == pItem->GetChildrenCount())
pItem->InitFromXml(xmlTemplate);
size_t sPos = static_cast<size_t>(position);
if (sPos >= m_vecItems.size()) return;
ItemData* pItemData = m_vecItems[sPos];
if (NULL == pItemData) return;
SImageWnd* pImg = pItem->FindChildByName2<SImageWnd>(L"emotion");
if (NULL != pImg)
{
pItem->GetEventSet()->
subscribeEvent(EventItemPanelClick::EventID,
Subscriber(&CAdapter_EmotionTileView::OnEvtItemPanelClick, this));
std::map<std::string, IBitmap*>::iterator iter =
CGlobalUnits::GetInstance()->m_mapFace.find(pItemData->m_strID);
if (iter != CGlobalUnits::GetInstance()->m_mapFace.end())
{
pImg->SetImage(iter->second);
}
}
}
bool OnEvtItemPanelClick(EventArgs* e)
{
EventItemPanelClick* pItemClickEvt = sobj_cast<EventItemPanelClick>(e);
if (NULL == pItemClickEvt)
return false;
SItemPanel* pItem = sobj_cast<SItemPanel>(pItemClickEvt->sender);
if (pItem)
{
int nItem = static_cast<int>(pItem->GetItemIndex());
ItemData* pData = m_vecItems[nItem];
if (NULL != pData)
{
m_pListener->OnEmotionItemClick(pData->m_strID);
return true;
}
}
return false;
}
public:
void AddItem(const std::string& strID)
{
ItemData* pItemFaceData = new ItemData;
pItemFaceData->m_strID = strID;
m_vecItems.push_back(pItemFaceData);
notifyDataSetChanged();
}
private:
IListener* m_pListener;
std::vector<ItemData*> m_vecItems; // Êý¾Ý
};
#endif